Advertisement
Guest User

GLQ_GRProgressionToTime.cs

a guest
Oct 10th, 2017
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.42 KB | None | 0 0
  1. // http://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-plugin-review-zone/632463-v7-3-international-glq-grprogressiontotime.html
  2.  
  3. using Turbo.Plugins.Default;
  4. using System.Linq;
  5. using System;
  6. using System.Globalization;
  7.  
  8. namespace Turbo.Plugins.glq
  9. {
  10.     public class GLQ_GRProgressionToTime : BasePlugin, IInGameTopPainter, IAfterCollectHandler
  11.     {
  12.         public IFont BonusTimeFont { get; set; }
  13.         public IFont MalusTimeFont { get; set; }
  14.        
  15.         public string SecondsFormat { get; set; }
  16.         public string MinutesSecondsFormat { get; set; }
  17.  
  18.         private IFont currentFont;
  19.        
  20.         public bool IsGreaterRift
  21.         {
  22.             get
  23.             {
  24.                 return riftQuest != null &&
  25.                        (riftQuest.QuestStepId == 13 || riftQuest.QuestStepId == 16 || riftQuest.QuestStepId == 34 ||
  26.                         riftQuest.QuestStepId == 46);
  27.             }
  28.         }
  29.  
  30.         private IQuest riftQuest
  31.         {
  32.             get
  33.             {
  34.                 return Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 337492) ?? // rift
  35.                        Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 382695);   // gr
  36.             }
  37.         }
  38.        
  39.         private const uint greaterriftMaxTimeMilliseconds = 900000;
  40.         private IWatch pauseTimer;  //for solo
  41.  
  42.         public GLQ_GRProgressionToTime()
  43.         {
  44.             Enabled = true;
  45.         }
  46.  
  47.         public override void Load(IController hud)
  48.         {
  49.             base.Load(hud);
  50.             MalusTimeFont = Hud.Render.CreateFont("tahoma", 7, 255, 250, 100, 100, true, false, 160, 0, 0, 0, true);
  51.             BonusTimeFont = Hud.Render.CreateFont("tahoma", 7, 255, 128, 255, 0, true, false, 160, 0, 0, 0, true);
  52.            
  53.             MinutesSecondsFormat = "{0:%m}m {0:ss}s";
  54.            
  55.             pauseTimer = Hud.CreateWatch();     //solo
  56.         }
  57.        
  58.         //pauseTimer handling for GR-Solos
  59.         public void AfterCollect()
  60.         {
  61.             if (ResetTimers()) return;
  62.  
  63.             if (GamePauseTimers()) return;
  64.  
  65.             RestartStopTimers();
  66.         }
  67.  
  68.         private void RestartStopTimers()
  69.         {
  70.             // (re)start/stop timers if needed
  71.             if (pauseTimer.IsRunning)
  72.                 pauseTimer.Stop();
  73.         }
  74.  
  75.         private bool GamePauseTimers()
  76.         {
  77.             // game pause
  78.             if (Hud.Game.IsPaused || (IsGreaterRift && Hud.Game.NumberOfPlayersInGame == 1 && Hud.Game.IsLoading))
  79.             {
  80.                 if (!pauseTimer.IsRunning)
  81.                     pauseTimer.Start();
  82.  
  83.                 return true;
  84.             }
  85.             return false;
  86.         }
  87.  
  88.         private bool ResetTimers()
  89.         {
  90.             // reset states if needed
  91.             if (riftQuest == null || (riftQuest != null && riftQuest.State == QuestState.none))
  92.             {
  93.                 if (pauseTimer.IsRunning || pauseTimer.ElapsedMilliseconds > 0)
  94.                 {
  95.                     pauseTimer.Reset();
  96.                 }
  97.                
  98.                 return true;
  99.             }
  100.             return false;
  101.         }
  102.        
  103.         public void PaintTopInGame(ClipState clipState)
  104.         {
  105.             if (clipState != ClipState.BeforeClip) return;
  106.             if (!IsGreaterRift) return;
  107.            
  108.             var ui = Hud.Render.GreaterRiftBarUiElement;
  109.            
  110.             if (ui == null || !ui.Visible) return;
  111.             var secondsElapsed = riftQuest.StartedOn.ElapsedMilliseconds;
  112.             var percent = (float)Hud.Game.RiftPercentage;
  113.            
  114.             if (secondsElapsed > greaterriftMaxTimeMilliseconds) return;
  115.  
  116.             string text;
  117.             var _myTime_ms = percent*9000f - secondsElapsed - pauseTimer.ElapsedMilliseconds;
  118.             var _myTime_span = TimeSpan.FromMilliseconds(_myTime_ms);
  119.            
  120.             if (_myTime_ms <= 0)
  121.             {
  122.                 text = "- " + String.Format(CultureInfo.InvariantCulture, MinutesSecondsFormat, _myTime_span);
  123.                 currentFont = MalusTimeFont;
  124.             }
  125.             else
  126.             {
  127.                 text = "+ " + String.Format(CultureInfo.InvariantCulture, MinutesSecondsFormat, _myTime_span);
  128.                 currentFont = BonusTimeFont;
  129.             }
  130.            
  131.             var textLayout = currentFont.GetTextLayout(text);
  132.             var x = ui.Rectangle.Left + ui.Rectangle.Width / 100.0f * percent - textLayout.Metrics.Width / 2;
  133.             var y = ui.Rectangle.Top - ui.Rectangle.Height * 0.1f - textLayout.Metrics.Height;
  134.             currentFont.DrawText(textLayout, x, y);
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement