Advertisement
jarppaaja

UpgradeRareRecipe rev 915

Jan 31st, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.28 KB | None | 0 0
  1. // UpgradeRareRecipe.cs "$Revision: 915 $" "$Date: 2019-01-31 17:52:57 +0200 (to, 31 tammi 2019) $"
  2. using SharpDX.Direct2D1;
  3. using System.Linq;
  4. using Turbo.Plugins;
  5. using Turbo.Plugins.Default;
  6.  
  7. namespace Turbo.plugins.JarJar.DefaultUI
  8. {
  9.     class UpgradeRareRecipe : BasePlugin, ICustomizer, IInGameWorldPainter, IInGameTopPainter
  10.     {
  11.         public bool ShowInventoryBorder { get; set; } = true;
  12.         public bool ShowStashBorder { get; set; } = true;
  13.         public bool ShowItemInfo { get; set; } = true;
  14.  
  15.         public string[] ItemTypes { get; set; } = { };  // = item.SnoItem.SnoItemType.Code
  16.  
  17.         public IFont ItemTypeFont { get; set; }
  18.         public IBrush InventoryBorderBrush { get; set; }
  19.         public WorldDecoratorCollection RareKeepDecorator { get; set; }
  20.  
  21.         int stashPage, stashTab, stashTabAbs;
  22.  
  23.         public UpgradeRareRecipe() { Enabled = true; }
  24.  
  25.         public void Customize()
  26.         {
  27.             // Disable original HoveredItemInfoPlugin.
  28.             Hud.TogglePlugin<Turbo.Plugins.Default.HoveredItemInfoPlugin>(false);
  29.         }
  30.  
  31.         public override void Load(IController hud)
  32.         {
  33.             base.Load(hud);
  34.  
  35.             ItemTypeFont = Hud.Render.CreateFont("tahoma", 7, 255, 154, 105, 24, true, false, 128, 0, 0, 0, true);
  36.  
  37.             InventoryBorderBrush = Hud.Render.CreateBrush(200, 204, 51, 0, 2f, DashStyle.DashDot);   // brownish red
  38.  
  39.             RareKeepDecorator = new WorldDecoratorCollection(
  40.                 new GroundCircleDecorator(Hud)
  41.                 {
  42.                     Brush = Hud.Render.CreateBrush(192, 255, 255, 0, -2),
  43.                     Radius = 1.25f,
  44.                     RadiusTransformator = new StandardPingRadiusTransformator(Hud, 333),
  45.                 },
  46.                 new MapShapeDecorator(Hud)
  47.                 {
  48.                     ShapePainter = new CircleShapePainter(Hud),
  49.                     Brush = Hud.Render.CreateBrush(255, 255, 255, 0, 0),
  50.                     ShadowBrush = Hud.Render.CreateBrush(96, 0, 0, 0, 1),
  51.                     Radius = 6,
  52.                     RadiusTransformator = new StandardPingRadiusTransformator(Hud, 333),
  53.                 });
  54.         }
  55.  
  56.         public void PaintWorld(WorldLayer layer)
  57.         {
  58.             var items = Hud.Game.Items.Where(item => item.Location == ItemLocation.Floor && item.IsRare && item.SnoItem.Level == 70);
  59.             foreach (var item in items)
  60.             {
  61.                 if (isRecipeItem(item))
  62.                 {
  63.                     RareKeepDecorator.Paint(layer, item, item.FloorCoordinate, null);
  64.                 }
  65.             }
  66.         }
  67.  
  68.         public void PaintTopInGame(ClipState clipState)
  69.         {
  70.             if (ShowItemInfo && clipState == ClipState.AfterClip)
  71.             {
  72.                 paintHoveredItem();
  73.                 return;
  74.             }
  75.             if ((ShowInventoryBorder || ShowStashBorder) && clipState == ClipState.Inventory)
  76.             {
  77.                 paintItemBorder();
  78.                 return;
  79.             }
  80.         }
  81.  
  82.         void paintHoveredItem()
  83.         {
  84.             var item = Hud.Inventory.HoveredItem;
  85.             if (item == null || item.Unidentified) return;
  86.  
  87.             var uicMain = Hud.Inventory.GetHoveredItemMainUiElement();
  88.             var uicTop = Hud.Inventory.GetHoveredItemTopUiElement();
  89.  
  90.             var iLevelText = string.Format("{0} {1}", item.SnoItem.Level, item.SnoItem.SnoItemType.Code);
  91.             var iLevelLayout = ItemTypeFont.GetTextLayout(iLevelText);
  92.             ItemTypeFont.DrawText(iLevelLayout, uicTop.Rectangle.Left - Hud.Window.Size.Height * 0.0166f, uicTop.Rectangle.Top + (Hud.Window.Size.Height * 0.022f - iLevelLayout.Metrics.Height) / 2);
  93.         }
  94.  
  95.         void paintItemBorder()
  96.         {
  97.             var uiInv = Hud.Inventory.InventoryMainUiElement;
  98.             if (!uiInv.Visible) return;
  99.  
  100.             stashTab = Hud.Inventory.SelectedStashTabIndex;
  101.             stashPage = Hud.Inventory.SelectedStashPageIndex;
  102.             stashTabAbs = stashTab + stashPage * Hud.Inventory.MaxStashTabCountPerPage;
  103.  
  104.             var items = Hud.Game.Items.Where(item => (
  105.                 (ShowStashBorder && item.Location == ItemLocation.Stash) ||
  106.                 (ShowInventoryBorder && item.Location == ItemLocation.Inventory)) &&
  107.                 item.IsRare && item.SnoItem.Level == 70);
  108.             foreach (var item in items)
  109.             {
  110.                 if (item.Location == ItemLocation.Stash)
  111.                 {
  112.                     var tabIndex = item.InventoryY / 10;
  113.                     if (tabIndex != stashTabAbs) continue;
  114.                 }
  115.                 if ((item.InventoryX < 0) || (item.InventoryY < 0)) continue;
  116.                 if (isRecipeItem(item))
  117.                 {
  118.                     var rect = Hud.Inventory.GetItemRect(item);
  119.                     rect.Inflate(1f, 1f);
  120.                     if (rect == System.Drawing.RectangleF.Empty) continue;
  121.                     InventoryBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
  122.                 }
  123.             }
  124.         }
  125.  
  126.         bool isRecipeItem(IItem item)
  127.         {
  128.             // Highlight everything without configuration.
  129.             return ItemTypes.Length == 0 ? true : ItemTypes.Any(x => x == item.SnoItem.SnoItemType.Code);
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement