Advertisement
Guest User

InventoryMainStatPlugin

a guest
Jun 10th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | None | 0 0
  1. using System.Linq;
  2. using Turbo.Plugins.Default;
  3.  
  4. namespace Turbo.Plugins.Turbro
  5. {
  6.     public class InventoryMainStatPlugin : BasePlugin, IInGameTopPainter
  7.     {
  8.         public bool OverlayMainStatOnItems { get; set; }
  9.         public IFont MainStatFont { get; set; }
  10.  
  11.         private int stashPage, stashTab, stashTabAbs;
  12.         private float rv;
  13.  
  14.         public InventoryMainStatPlugin()
  15.         {
  16.             Enabled = true;
  17.             OverlayMainStatOnItems = true;
  18.         }
  19.  
  20.         public override void Load(IController hud)
  21.         {
  22.             base.Load(hud);
  23.  
  24.             MainStatFont = Hud.Render.CreateFont("tahoma", 8, 255, 200, 200, 200, false, false, false);
  25.             MainStatFont.SetShadowBrush(128, 0, 0, 0, true);
  26.         }
  27.  
  28.         public void PaintTopInGame(ClipState clipState)
  29.         {
  30.             if(!OverlayMainStatOnItems) return;
  31.             if (clipState != ClipState.Inventory) return;
  32.            
  33.             stashTab = Hud.Inventory.SelectedStashTabIndex;
  34.             stashPage = Hud.Inventory.SelectedStashPageIndex;
  35.             stashTabAbs = stashTab + stashPage * Hud.Inventory.MaxStashTabCountPerPage;
  36.  
  37.             rv = 32.0f / 600.0f * Hud.Window.Size.Height;
  38.  
  39.             var items = Hud.Game.Items.Where(x => x.Location != ItemLocation.Merchant && x.Location != ItemLocation.Floor);
  40.             foreach (var item in items)
  41.             {
  42.                 if (item.Location == ItemLocation.Stash)
  43.                 {
  44.                     var tabIndex = item.InventoryY / 10;
  45.                     if (tabIndex != stashTabAbs) continue;
  46.                 }
  47.  
  48.                 if ((item.InventoryX < 0) || (item.InventoryY < 0)) continue;
  49.  
  50.                 var rect = Hud.Inventory.GetItemRect(item);
  51.                 if (rect == System.Drawing.RectangleF.Empty) continue;
  52.  
  53.                 DrawItemMainStat(item, rect);
  54.             }
  55.        }
  56.  
  57.         private static string GetMainStatString(IItem item)
  58.         {
  59.             if (item != null && item.Perfections != null)
  60.             {
  61.                 foreach (IItemPerfection perfection in item.Perfections)
  62.                 {
  63.                     if (perfection.Attribute.Code == "Dexterity_Item") return "dex";
  64.                     if (perfection.Attribute.Code == "Intelligence_Item") return "int";
  65.                     if (perfection.Attribute.Code == "Strength_Item") return "str";
  66.                 }
  67.             }
  68.             return null;
  69.         }
  70.  
  71.         private void DrawItemMainStat(IItem item, System.Drawing.RectangleF rect)
  72.         {
  73.             var text = GetMainStatString(item);
  74.             if(text != null)
  75.             {
  76.                 var font = MainStatFont;
  77.                 var textLayout = font.GetTextLayout(text);
  78.                 font.DrawText(textLayout, rect.Left + rv / 15.0f, rect.Top + rv / 35.0f);
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement