Advertisement
s4000

CountMaterial

Jul 13th, 2023
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.45 KB | None | 0 0
  1. namespace T4.Plugins.DAV;
  2.  
  3. public class CountMaterial : BasePlugin, IGameUserInterfacePainter {
  4.     public Feature TableSetting { get; private set; }
  5.  
  6.     public float SizeMultiplier { get; set; } = 0.8f;
  7.     public IFont TextFont { get; set; } = Services.Render.GetFont(255, 255, 220, 220, fontFamily: "segoe ui", size: 9, shadowMode: FontShadowMode.Light);
  8.  
  9.     private ITexture bgIcon { get; set; } = Services.Render.GetTexture(SupportedTextureId.UIButtonLight_000);
  10.     private List<MaterialData> matList { get; set; } = new List<MaterialData>();
  11.  
  12.     public void PaintGameUserInterface(GameUserInterfaceLayer layer) {
  13.         if (layer != GameUserInterfaceLayer.OverPanels) return;
  14.         if (!Services.UserInterface.InventoryAreaControl.Visible) return;
  15.  
  16.         var rect = Services.UserInterface.GetInventorySlotControl(0, 0, 2);
  17.         var w = rect.Width * SizeMultiplier;
  18.         var h = rect.Height * SizeMultiplier;
  19.         var x = Services.UserInterface.InventoryAreaControl.Left;
  20.         foreach (var mat in matList)
  21.             mat.DrawCount(bgIcon, TextFont, x, rect.Top, w, h);
  22.     }
  23.  
  24.     public class MaterialData {
  25.         public string Name { get; private set; }
  26.         public CurrencyType Currency { get; private set; }
  27.         public ITexture Icon { get; private set; }
  28.  
  29.         private int xref { get; set; }
  30.         private int yref { get; set; }
  31.  
  32.         // public MaterialData(ItemSnoId snoId, CurrencyType currency, uint iconId, int classType, int classRank) {
  33.         public MaterialData(CurrencyType currency, ItemSnoId snoId, uint iconId, int classType, int classRank) {
  34.             var material = Services.GameData.GetItemSno(snoId);
  35.             Name = material.NameLocalized;
  36.             Currency = currency;
  37.             // Currency = material.CurrencyType;
  38.             Icon = Services.Render.GetTexture(iconId);
  39.             xref = classRank;
  40.             yref = classType;
  41.         }
  42.  
  43.         public void DrawCount(ITexture bgTexture, IFont font, float x, float y, float w, float h) {
  44.             x -= w * xref;
  45.             y -= h * yref;
  46.             bgTexture.Draw(x, y, w, h);
  47.             Icon.Draw(x, y, w, h);
  48.  
  49.             if (Services.Game.MyPlayer.Currencies.TryGetValue(Currency, out var count)) {
  50.                 var tl = font.GetTextLayout(count.ToString("#,##0"));
  51.                 tl.DrawText(x + w - tl.Width, y + h - tl.Height);
  52.             }
  53.  
  54.             if (Services.Game.CursorInsideRect(x, y, w, h))
  55.                 Services.Hint.SetHint(Name);
  56.         }
  57.     }
  58.  
  59. /*
  60. type    rank    CurrencyType    Name    ItemSnoId   SupportedTextureId
  61. 1   1   CommonHerb  Gallowvine  ItemSnoId.CraftingMaterial_Herb_Common  SupportedTextureId.InventoryMaterials_004
  62. 1   2   RareHerb    Angelbreath ItemSnoId.CraftingMaterial_Herb_Rare    SupportedTextureId.InventoryMaterials_000
  63. 1   3   SuperRareHerb   FiendRose   ItemSnoId.CraftingMaterial_Herb_SuperRare   SupportedTextureId.InventoryMaterials_003
  64. 1   4   ScosglenHerb    HowlerMoss  ItemSnoId.CraftingMaterial_Herb_Scosglen    SupportedTextureId.InventoryMaterials_032
  65. 1   5   FracturedPeaksHerb  Biteberry   ItemSnoId.CraftingMaterial_Herb_FracturedPeaks  SupportedTextureId.InventoryMaterials_001
  66. 1   6   DrySteppesHerb  Reddamine   ItemSnoId.CraftingMaterial_Herb_Drysteppes  SupportedTextureId.InventoryMaterials_006
  67. 1   7   HawezarHerb Blightshade ItemSnoId.CraftingMaterial_Herb_Hawezar SupportedTextureId.InventoryMaterials_002
  68. 1   8   KehjistanHerb   Lifesbane   ItemSnoId.CraftingMaterial_Herb_Kehjistan   SupportedTextureId.InventoryMaterials_005
  69.  
  70. 2   1   CommonOre   IronChunk   ItemSnoId.CraftingMaterial_Ore_Common   SupportedTextureId.InventoryMaterials_018
  71. 2   2   RareOre SilverOre   ItemSnoId.CraftingMaterial_Ore_Rare SupportedTextureId.InventoryMaterials_023
  72. 2   3   RareScatteredPrism  ScatteredPrism  ItemSnoId.CraftingMaterial_Rare_ScatteredPrism  SupportedTextureId.InventoryMaterials_022
  73.  
  74. 3   1   CommonLeather   Rawhide ItemSnoId.CraftingMaterial_Leather_Common   SupportedTextureId.InventoryMaterials_020
  75. 3   2   RareLeather SuperiorLeather ItemSnoId.CraftingMaterial_Leather_Rare SupportedTextureId.InventoryMaterials_026
  76.  
  77. 4   1   DemonHeart  DemonsHeart ItemSnoId.CraftingMaterial_MonsterDrop_Demon_Heart  SupportedTextureId.InventoryMaterials_014
  78. 4   2   HumanTongue Paletongue  ItemSnoId.CraftingMaterial_MonsterDrop_Human_Tongue SupportedTextureId.InventoryMaterials_019
  79. 4   3   UndeadDust  GraveDust   ItemSnoId.CraftingMaterial_MonsterDrop_Undead_Dust  SupportedTextureId.InventoryMaterials_016
  80. 4   4   WildlifeBones   CrushedBeastBones   ItemSnoId.CraftingMaterial_MonsterDrop_Wildlife_Bones   SupportedTextureId.InventoryMaterials_013
  81.  
  82. 5   1   SacredLegendarySalvage  ForgottenSoul   ItemSnoId.CraftingMaterial_Salvage_Sacred_Legendary SupportedTextureId.InventoryMaterials_015
  83. 5   2   RareSalvage VeiledCrystal   ItemSnoId.CraftingMaterial_Salvage_Rare SupportedTextureId.InventoryMaterials_031
  84. 5   3   LegendaryArmorSalvage   CoilingWard ItemSnoId.CraftingMaterial_Salvage_Legendary_Armor  SupportedTextureId.InventoryMaterials_012
  85. 5   4   LegendaryJewelrySalvage AbstruseSigil   ItemSnoId.CraftingMaterial_Salvage_Legendary_Jewelry    SupportedTextureId.InventoryMaterials_008
  86. 5   5   SigilSalvage    SigilPowder ItemSnoId.CraftingMaterial_Salvage_Nightmare_Sigil_Powder   SupportedTextureId.InventoryQuestNature_001
  87. 5   6   LegendaryWeaponSalvage  BalefulFragment ItemSnoId.CraftingMaterial_Salvage_Legendary_Weapon SupportedTextureId.InventoryMaterials_007
  88.  
  89. */
  90.  
  91. // initial setting
  92.     public override string GetDescription() => Services.Translation.Translate(this, "display material summary at inventory");
  93.  
  94.     public override void Load() {
  95.         base.Load();
  96.  
  97.         matList.Add(new MaterialData(CurrencyType.CommonHerb, ItemSnoId.CraftingMaterial_Herb_Common, SupportedTextureId.InventoryMaterials_004, 1, 1));
  98.         matList.Add(new MaterialData(CurrencyType.RareHerb, ItemSnoId.CraftingMaterial_Herb_Rare, SupportedTextureId.InventoryMaterials_000, 1, 2));
  99.         matList.Add(new MaterialData(CurrencyType.SuperRareHerb, ItemSnoId.CraftingMaterial_Herb_SuperRare, SupportedTextureId.InventoryMaterials_003, 1, 3));
  100.         matList.Add(new MaterialData(CurrencyType.ScosglenHerb, ItemSnoId.CraftingMaterial_Herb_Scosglen, SupportedTextureId.InventoryMaterials_032, 1, 4));
  101.         matList.Add(new MaterialData(CurrencyType.FracturedPeaksHerb, ItemSnoId.CraftingMaterial_Herb_FracturedPeaks, SupportedTextureId.InventoryMaterials_001, 1, 5));
  102.         matList.Add(new MaterialData(CurrencyType.DrySteppesHerb, ItemSnoId.CraftingMaterial_Herb_Drysteppes, SupportedTextureId.InventoryMaterials_006, 1, 6));
  103.         matList.Add(new MaterialData(CurrencyType.HawezarHerb, ItemSnoId.CraftingMaterial_Herb_Hawezar, SupportedTextureId.InventoryMaterials_002, 1, 7));
  104.         matList.Add(new MaterialData(CurrencyType.KehjistanHerb, ItemSnoId.CraftingMaterial_Herb_Kehjistan, SupportedTextureId.InventoryMaterials_005, 1, 8));
  105.         matList.Add(new MaterialData(CurrencyType.CommonOre, ItemSnoId.CraftingMaterial_Ore_Common, SupportedTextureId.InventoryMaterials_018, 2, 1));
  106.         matList.Add(new MaterialData(CurrencyType.RareOre, ItemSnoId.CraftingMaterial_Ore_Rare, SupportedTextureId.InventoryMaterials_023, 2, 2));
  107.         matList.Add(new MaterialData(CurrencyType.RareScatteredPrism, ItemSnoId.CraftingMaterial_Rare_ScatteredPrism, SupportedTextureId.InventoryMaterials_022, 2, 3));
  108.         matList.Add(new MaterialData(CurrencyType.CommonLeather, ItemSnoId.CraftingMaterial_Leather_Common, SupportedTextureId.InventoryMaterials_020, 3, 1));
  109.         matList.Add(new MaterialData(CurrencyType.RareLeather, ItemSnoId.CraftingMaterial_Leather_Rare, SupportedTextureId.InventoryMaterials_026, 3, 2));
  110.         matList.Add(new MaterialData(CurrencyType.DemonHeart, ItemSnoId.CraftingMaterial_MonsterDrop_Demon_Heart, SupportedTextureId.InventoryMaterials_014, 4, 1));
  111.         matList.Add(new MaterialData(CurrencyType.HumanTongue, ItemSnoId.CraftingMaterial_MonsterDrop_Human_Tongue, SupportedTextureId.InventoryMaterials_019, 4, 2));
  112.         matList.Add(new MaterialData(CurrencyType.UndeadDust, ItemSnoId.CraftingMaterial_MonsterDrop_Undead_Dust, SupportedTextureId.InventoryMaterials_016, 4, 3));
  113.         matList.Add(new MaterialData(CurrencyType.WildlifeBones, ItemSnoId.CraftingMaterial_MonsterDrop_Wildlife_Bones, SupportedTextureId.InventoryMaterials_013, 4, 4));
  114.         matList.Add(new MaterialData(CurrencyType.SacredLegendarySalvage, ItemSnoId.CraftingMaterial_Salvage_Sacred_Legendary, SupportedTextureId.InventoryMaterials_015, 5, 1));
  115.         matList.Add(new MaterialData(CurrencyType.RareSalvage, ItemSnoId.CraftingMaterial_Salvage_Rare, SupportedTextureId.InventoryMaterials_031, 5, 2));
  116.         matList.Add(new MaterialData(CurrencyType.LegendaryArmorSalvage, ItemSnoId.CraftingMaterial_Salvage_Legendary_Armor, SupportedTextureId.InventoryMaterials_012, 5, 3));
  117.         matList.Add(new MaterialData(CurrencyType.LegendaryJewelrySalvage, ItemSnoId.CraftingMaterial_Salvage_Legendary_Jewelry, SupportedTextureId.InventoryMaterials_008, 5, 4));
  118.         matList.Add(new MaterialData(CurrencyType.SigilSalvage, ItemSnoId.CraftingMaterial_Salvage_Nightmare_Sigil_Powder, SupportedTextureId.InventoryQuestNature_001, 5, 5));
  119.         matList.Add(new MaterialData(CurrencyType.LegendaryWeaponSalvage, ItemSnoId.CraftingMaterial_Salvage_Legendary_Weapon, SupportedTextureId.InventoryMaterials_007, 5, 6));
  120.  
  121.         TableSetting = new Feature() {
  122.             Plugin = this,
  123.             NameOf = nameof(TableSetting),
  124.             DisplayName = () => Services.Translation.Translate(this, "item count on tabs"),
  125.             Resources = new() {
  126.                 new FontFeatureResource() {
  127.                     NameOf = nameof(TextFont),
  128.                     DisplayText = () => Services.Translation.Translate(this, "font"),
  129.                     Font = TextFont,
  130.                 },
  131.                 new FloatFeatureResource() {
  132.                     NameOf = nameof(SizeMultiplier),
  133.                     DisplayText = () => Services.Translation.Translate(this, "size"),
  134.                     MinValue = 0.5f,
  135.                     MaxValue = 1f,
  136.                     Getter = () => SizeMultiplier,
  137.                     Setter = newValue => SizeMultiplier = MathF.Round(newValue, 1),
  138.                 },
  139.             },
  140.         };
  141.  
  142.         Services.Customization.RegisterFeature(TableSetting);
  143.     }
  144. }
Tags: Thud4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement