Advertisement
Guest User

PoolListPlugin.cs

a guest
Apr 21st, 2017
2,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.50 KB | None | 0 0
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using SharpDX.DirectInput;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.gz
  7. {
  8.     public class PoolListPlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler, INewAreaHandler, IKeyEventHandler
  9.     {
  10.         public Dictionary<int, List<string>> PoolList { get; set; }
  11.         public Dictionary<string, TopLabelDecorator> PoolDecorators { get; set; }
  12.        
  13.         public Dictionary<int, List<string>> OperatedPoolList { get; set; }
  14.         public Dictionary<string, TopLabelDecorator> OperatedPoolDecorators { get; set; }
  15.        
  16.         public bool Show { get; set; }
  17.         public IKeyEvent ToggleKeyEvent { get; set; }
  18.        
  19.         public float PosXMultiplier { get; set; }
  20.         public float PosYMultiplier { get; set; }
  21.        
  22.         public bool ShowOperated { get; set; }
  23.         public ITexture OperatedPoolTexture { get; set; }
  24.         public ITexture PoolTexture { get; set; }
  25.        
  26.         public PoolListPlugin()
  27.         {
  28.             Enabled = true;
  29.            
  30.             Show = false;
  31.             ShowOperated = true;
  32.         }
  33.        
  34.         public override void Load(IController hud)
  35.         {
  36.             base.Load(hud);
  37.            
  38.             PoolList = new Dictionary<int, List<string>>();
  39.             OperatedPoolList = new Dictionary<int, List<string>>();
  40.             for (int i = 0; i <= 5; i++)
  41.             {
  42.                 PoolList.Add(i, new List<string>());
  43.                 OperatedPoolList.Add(i, new List<string>());
  44.             }
  45.            
  46.             PoolDecorators = new Dictionary<string, TopLabelDecorator>();
  47.             OperatedPoolDecorators = new Dictionary<string, TopLabelDecorator>();
  48.            
  49.             PoolTexture = Hud.Texture.BackgroundTextureBlue;
  50.             OperatedPoolTexture = Hud.Texture.BackgroundTextureOrange;
  51.            
  52.             ToggleKeyEvent = Hud.Input.CreateKeyEvent(true, Key.F6, false, false, false);
  53.         }
  54.        
  55.         private TopLabelDecorator CreatePoolListLocationLabel(string text, bool operated)
  56.         {
  57.             return new TopLabelDecorator(Hud)
  58.             {
  59.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 120, 255, 255, 255, true, false, false),
  60.                 // Option #2: Use textures for background
  61.                 BackgroundTexture1 = Hud.Texture.ButtonTextureGray,
  62.                 BackgroundTexture2 = (operated ? OperatedPoolTexture : PoolTexture),
  63.                 BackgroundTextureOpacity2 = 0.25f,
  64.                 //delegate
  65.                 HintFunc = () => "", //delegate string
  66.                 TextFunc = () => text
  67.             };
  68.         }
  69.        
  70.         public void OnNewArea(bool newGame, ISnoArea area)
  71.         {
  72.             if (newGame)
  73.             {
  74.                 Show = false;
  75.                
  76.                 //reset
  77.                 for (int i = 0; i <= 5; i++)
  78.                 {
  79.                     PoolList[i].Clear();
  80.                     OperatedPoolList[i].Clear();
  81.                 }
  82.                
  83.                 PoolDecorators.Clear();
  84.                 OperatedPoolDecorators.Clear();
  85.             }
  86.         }
  87.        
  88.         public void AfterCollect()
  89.         {
  90.             if (Hud. Game.Me.SnoArea == null || Hud.Game.Me.SnoArea.Code == null || Hud.Game.Me.SnoArea.Code.Contains("x1_lr_level"))
  91.                 return;
  92.                
  93.             var shrines = Hud.Game.Shrines.Where(actor => actor.Type == ShrineType.PoolOfReflection);
  94.            
  95.             foreach (var shrine in shrines)
  96.             {
  97.                 if (shrine.Scene.SnoArea == null)
  98.                     continue;
  99.                 else if (shrine.Scene.SnoArea.NameLocalized == null)
  100.                     continue;
  101.                 else if (shrine.Scene.SnoArea.Act < 0 || shrine.Scene.SnoArea.Act > 5)
  102.                     continue;
  103.                
  104.                 if (shrine.IsClickable && !shrine.IsOperated)
  105.                 {
  106.                     if (!PoolDecorators.Keys.Contains(shrine.Scene.SnoArea.NameLocalized))
  107.                     {
  108.                         PoolList[shrine.Scene.SnoArea.Act].Add(shrine.Scene.SnoArea.NameLocalized);
  109.                         PoolDecorators.Add(shrine.Scene.SnoArea.NameLocalized, CreatePoolListLocationLabel(shrine.Scene.SnoArea.NameLocalized, shrine.IsOperated));
  110.                     }
  111.                 }
  112.                
  113.                 if (shrine.IsClickable && shrine.IsOperated)
  114.                 {
  115.                     if (PoolDecorators.Keys.Contains(shrine.Scene.SnoArea.NameLocalized))
  116.                     {
  117.                         PoolList[shrine.Scene.SnoArea.Act].Remove(shrine.Scene.SnoArea.NameLocalized);
  118.                         PoolDecorators.Remove(shrine.Scene.SnoArea.NameLocalized);
  119.                     }
  120.                    
  121.                     if (!OperatedPoolDecorators.Keys.Contains(shrine.Scene.SnoArea.NameLocalized))
  122.                     {
  123.                         OperatedPoolList[shrine.Scene.SnoArea.Act].Add(shrine.Scene.SnoArea.NameLocalized);
  124.                         OperatedPoolDecorators.Add(shrine.Scene.SnoArea.NameLocalized, CreatePoolListLocationLabel(shrine.Scene.SnoArea.NameLocalized, shrine.IsOperated));
  125.                     }
  126.                 }
  127.             }
  128.         }
  129.  
  130.         public void PaintTopInGame(ClipState clipState)
  131.         {
  132.             if (clipState != ClipState.BeforeClip) return;
  133.             if (!Show) return;
  134.            
  135.             var PoolX = Hud.Window.Size.Width / 6f;
  136.             var PoolW = Hud.Window.Size.Width / 8f;
  137.            
  138.             var PoolY = Hud.Window.Size.Height * 61f / 108f;
  139.             var PoolH = Hud.Window.Size.Height * 0.025f;
  140.            
  141.             var spacingX = Hud.Window.Size.Width / 100f;
  142.             var spacingY = Hud.Window.Size.Height / 216f;
  143.            
  144.             for (int act = 0; act <= 5; act++)
  145.             {
  146.                 int Row = 0;
  147.                 foreach (var pool in PoolList[act])
  148.                 {
  149.                     PoolDecorators[pool].Paint(PoolX + (act - 1) * (PoolW + spacingX), PoolY + Row * (PoolH + spacingY), PoolW, PoolH, HorizontalAlign.Center);
  150.                     Row++;
  151.                 }
  152.                
  153.                 if (!ShowOperated)
  154.                     continue;
  155.                
  156.                 if (Row > 0)
  157.                     Row++;
  158.                
  159.                 foreach (var operatedPool in OperatedPoolList[act])
  160.                 {
  161.                     OperatedPoolDecorators[operatedPool].Paint(PoolX + (act - 1) * (PoolW + spacingX), PoolY + Row * (PoolH + spacingY), PoolW, PoolH, HorizontalAlign.Center);
  162.                     Row++;
  163.                 }
  164.             }
  165.         }
  166.        
  167.         public void OnKeyEvent(IKeyEvent keyEvent)
  168.         {
  169.             if (keyEvent.IsPressed && ToggleKeyEvent.Matches(keyEvent))
  170.             {
  171.                 Show = !Show;
  172.             }
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement