Advertisement
JackCeparou

RiftTimerPlugin

Feb 9th, 2017
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.24 KB | None | 0 0
  1. using SharpDX.DirectWrite;
  2.  
  3. namespace Turbo.Plugins.JackCeparouCompass
  4. {
  5.     using System;
  6.     using System.Linq;
  7.     using Turbo.Plugins.Default;
  8.     using System.Globalization;
  9.  
  10.     public class RiftTimerPlugin : BasePlugin
  11.     {
  12.         //public TopLabelDecorator InRiftDecorator { get; set; }
  13.         //public TopLabelDecorator OtherAreaDecorator { get; set; }
  14.  
  15.         public IFont InRiftFont { get; set; }
  16.         public IFont OtherAreaFont { get; set; }
  17.  
  18.         public string OtherAreaPrefix { get; set; }
  19.         public string MinutesSecondsFormat { get; set; }
  20.         public string SecondsFormat { get; set; }
  21.         public string RiftPercentFormat { get; set; }
  22.         public string ClosingSecondsFormat { get; set; }
  23.  
  24.         public bool ShowClosingTimer { get; set; }
  25.  
  26.         private IQuest riftQuest { get { return Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 337492); } }
  27.         private IWatch pauseTimer;
  28.         private const uint riftClosingMilliseconds = 30000;
  29.  
  30.         public RiftTimerPlugin()
  31.         {
  32.             Enabled = true;
  33.         }
  34.  
  35.         public override void Load(IController hud)
  36.         {
  37.             base.Load(hud);
  38.  
  39.             OtherAreaPrefix = "\u2694 "; //⚔
  40.             //MinutesSecondsFormat = "{0:%m}m {0:%s}s";
  41.             MinutesSecondsFormat = "{0:%m}:{0:ss}";
  42.             //SecondsFormat = "{0:%s}s";
  43.             SecondsFormat = "{0:%s}";
  44.  
  45.             RiftPercentFormat = " ({0:#}%)";
  46.             ClosingSecondsFormat = " ({0:%s})";
  47.  
  48.             pauseTimer = Hud.CreateWatch();
  49.  
  50.             InRiftFont = Hud.Render.CreateFont("tahoma", 7, 224, 255, 210, 150, true, false, false);
  51.             InRiftFont.SetShadowBrush(222, 0, 0, 0, true);
  52.  
  53.             OtherAreaFont = Hud.Render.CreateFont("tahoma", 8, 224, 240, 240, 240, true, false, false);
  54.             OtherAreaFont.SetShadowBrush(222, 0, 0, 0, true);
  55.  
  56.             /*
  57.             InRiftDecorator = new TopLabelDecorator(hud)
  58.             {
  59.                 BackgroundBrush = Hud.Render.CreateBrush(0, 0, 0, 0, 0),
  60.                 BorderBrush = Hud.Render.CreateBrush(200, 255, 255, 255, 2),
  61.                 TextFont = Hud.Render.CreateFont("tahoma", 7, 224, 255, 210, 150, true, false, false),
  62.                 TextFunc = GetText,
  63.             };
  64.             InRiftDecorator.TextFont.SetShadowBrush(222, 0, 0, 0, true);
  65.  
  66.             OtherAreaDecorator = new TopLabelDecorator(hud)
  67.             {
  68.                 BackgroundBrush = Hud.Render.CreateBrush(0, 0, 0, 0, 0),
  69.                 BorderBrush = Hud.Render.CreateBrush(0, 0, 0, 0, 2),
  70.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 224, 240, 240, 240, true, false, false),
  71.                 TextFunc = GetText,
  72.             };
  73.             OtherAreaDecorator.TextFont.SetShadowBrush(222, 0, 0, 0, true);/**/
  74.         }
  75.  
  76.         public override void PaintTopInGame(ClipState clipState)
  77.         {
  78.             if (clipState != ClipState.AfterClip) return;
  79.             if (Hud.Inventory.InventoryMainUiElement.Visible) return;
  80.             if (riftQuest == null) return;
  81.             if (riftQuest.State == QuestState.none) return;
  82.             if (riftQuest.QuestStepId > 10) return;
  83.             if (Hud.Game.SpecialArea == SpecialArea.GreaterRift) return;
  84.  
  85.             var uiRect = Hud.Render.GetUiElement("Root.NormalLayer.eventtext_bkgrnd.eventtext_region.stackpanel.rift_wrapper.rift_container.rift_progress_bar");
  86.             if (uiRect == null)
  87.                 return; //useless ??
  88.  
  89.             var layout = OtherAreaFont.GetTextLayout(GetText());
  90.  
  91.             if (uiRect.Visible)
  92.             {
  93.                 var x = uiRect.Rectangle.Left - layout.Metrics.Width/2 + uiRect.Rectangle.Width * (float)Hud.Game.RiftPercentage / 100.0f;
  94.                 InRiftFont.DrawText(layout, x, uiRect.Rectangle.Bottom + Hud.Window.Size.Height * 0.015f);
  95.             }
  96.             else
  97.             {
  98.                 var uiMapRect = Hud.Render.MinimapUiElement;
  99.                 var x = uiMapRect.Rectangle.Right - layout.Metrics.Width - Hud.Window.Size.Height*0.033f;
  100.                 var y = uiMapRect.Rectangle.Bottom + Hud.Window.Size.Height * 0.0033f;
  101.  
  102.                 OtherAreaFont.DrawText(layout, x, y);
  103.             }
  104.  
  105.             //if (uiRect.Visible)
  106.             //{
  107.             //    var w = uiRect.Rectangle.Width;//3.4f;
  108.             //    //var x = uiRect.Rectangle.Left + uiRect.Rectangle.Width/2 - w/2;
  109.             //    var x = uiRect.Rectangle.Left + uiRect.Rectangle.Width*(float)Hud.Game.RiftPercentage/100.0f;
  110.             //    Simon.Says.Debug(Hud.Game.RiftPercentage.ToString());
  111.             //    InRiftDecorator.Paint(x, uiRect.Rectangle.Bottom + Hud.Window.Size.Height*0.015f, w, uiRect.Rectangle.Height, HorizontalAlign.Left);
  112.             //    //InRiftDecorator.Paint(uiRect.Rectangle.Left, uiRect.Rectangle.Bottom + 7, uiRect.Rectangle.Width, uiRect.Rectangle.Height, HorizontalAlign.Center);
  113.             //}
  114.             //else
  115.             //{
  116.             //    var uiMapRect = Hud.Render.MinimapUiElement;
  117.             //    OtherAreaDecorator.Paint(uiMapRect.Rectangle.Left, uiMapRect.Rectangle.Bottom, uiMapRect.Rectangle.Width - (Hud.Window.Size.Height * 0.032f) /**/, Hud.Window.Size.Height * 0.028f, HorizontalAlign.Right);
  118.             //}
  119.         }
  120.  
  121.         public override void AfterCollect()
  122.         {
  123.             if (!Hud.Game.IsInGame) return;
  124.             // game cannot be paused in multiplayer games
  125.             if (Hud.Game.NumberOfPlayersInGame > 1) return;
  126.  
  127.             if (riftQuest == null || (riftQuest != null && riftQuest.State == QuestState.none))
  128.             {
  129.                 if (pauseTimer.ElapsedMilliseconds > 0)
  130.                 {
  131.                     pauseTimer.Stop(); //probably useless if it's a stopwatch
  132.                     pauseTimer.Reset();
  133.                 }
  134.             }
  135.  
  136.             // TODO : turn this into a 'IsGamePaused' helper property
  137.             // TODO : check if pause is still not working when in Achievements tab
  138.             var uiMenu = Hud.Render.GetUiElement("Root.NormalLayer.gamemenu_dialog.gamemenu_bkgrnd");
  139.             var uiAchievements = Hud.Render.GetUiElement("Root.NormalLayer.BattleNetAchievements_main.LayoutRoot.OverlayContainer");
  140.  
  141.             if (uiMenu.Visible || uiAchievements.Visible)
  142.             {
  143.                 if (!pauseTimer.IsRunning)
  144.                     pauseTimer.Start();
  145.             }
  146.             else if (pauseTimer.IsRunning)
  147.             {
  148.                 pauseTimer.Stop();
  149.             }
  150.             //Simon.Says.Debug(pauseTimer.ElapsedMilliseconds.ToString());
  151.         }
  152.  
  153.         private string GetText()
  154.         {
  155.             var timeSpan = TimeSpan.FromMilliseconds(riftQuest.StartedOn.ElapsedMilliseconds - riftQuest.CompletedOn.ElapsedMilliseconds - pauseTimer.ElapsedMilliseconds);
  156.             var format = (timeSpan.Minutes < 1) ? SecondsFormat : MinutesSecondsFormat;
  157.  
  158.             if (Hud.Game.SpecialArea != SpecialArea.Rift)
  159.             {
  160.                 if (!string.IsNullOrWhiteSpace(OtherAreaPrefix))
  161.                     format = OtherAreaPrefix + format;
  162.  
  163.                 if (Hud.Game.RiftPercentage < 100 && Hud.Game.RiftPercentage >= 1)
  164.                 {
  165.                     format += string.Format(CultureInfo.InvariantCulture, RiftPercentFormat, Hud.Game.RiftPercentage);
  166.                 }
  167.                 else if (riftQuest.QuestStep != null)
  168.                 {
  169.                     switch (riftQuest.QuestStep.Id)
  170.                     {
  171.                         case 10:
  172.                             //format += " (Complete)";
  173.                             //format += " \u2620"; //☠
  174.                             format += " \uD83D\uDC80"; //💀
  175.                             break;
  176.                         case 3:
  177.                             //format += " (Guardian)";
  178.                             format += " \uD83D\uDC7F"; //👿
  179.                             break;
  180.                     }
  181.                 }
  182.             }
  183.  
  184.             if (ShowClosingTimer && riftQuest.State == QuestState.completed)
  185.             {
  186.                 format += string.Format(ClosingSecondsFormat, TimeSpan.FromMilliseconds(riftClosingMilliseconds - riftQuest.CompletedOn.ElapsedMilliseconds));
  187.             }
  188.  
  189.             return string.Format(format, timeSpan);
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement