Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
WingSlotSupport.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using Loot.Api.Cubes;
4 using Loot.UI;
5 using Loot.UI.Tabs.CraftingTab;
6 using Microsoft.Xna.Framework.Input;
7 using Terraria;
8 using Terraria.GameInput;
9 using Terraria.ModLoader;
10 
11 namespace Loot.ModSupport
12 {
13  internal class WingSlotSupport : ModSupport
14  {
15  public override string ModName => "WingSlot";
16 
17  public bool IsInvalid;
18 
19  // "Adds" this check for the item to be equipped into the wing slot
20  // If it returns true, it stops the item being equipped
21  private static bool WingSlotHandler()
22  => Loot.Instance.GuiInterface?.CurrentState is GuiTabWindow tabUi
23  && tabUi.Visible;
24 
25  public override bool CheckValidity(Mod mod)
26  {
27  IsInvalid = mod.Version < new Version(1, 6, 1);
28  return !IsInvalid;
29  }
30 
31  public override void AddClientSupport(Mod mod)
32  {
33  mod.Call("add", (Func<bool>)WingSlotHandler);
34  }
35 
36  private static bool RightClickFunctionalityRequirements(Item item)
37  {
38  if (ModSupportTunneler.GetModSupport<WingSlotSupport>().IsInvalid && item.wingSlot > 0)
39  return false;
40 
41  return !PlayerInput.WritingText
42  && Main.hasFocus
43  && Main.keyState.IsKeyDown(Keys.LeftControl)
44  && Loot.Instance.GuiInterface.CurrentState != null;
45  }
46 
47  private static void SwapItems(ICraftingTab craftingTab, Item item)
48  {
49  craftingTab.GiveBackItems();
50  craftingTab.OverrideSlottedItem(item);
51  }
52 
54  {
55  // Needed to enable right click for possible items
56  public override bool CanRightClick(Item item)
57  {
58  if (!RightClickFunctionalityRequirements(item))
59  return false;
60 
61  if (!(Loot.Instance.GuiInterface.CurrentState is GuiTabWindow ui)
62  || !(ui.GetCurrentTab() is ICraftingTab tab))
63  return false;
64 
65  return ui.Visible && tab.AcceptsItem(item);
66  }
67 
68  // Auto slot item in UI if possible
69  public override void RightClick(Item item, Player player)
70  {
71  // We need to rerun checks here because our forced right click above
72  // becomes meaningless to items that can already be right clicked
73  // meaning that items such as goodie bags will end up in this hook
74  // regardless of our forced right click functionality in CanRightClick
75  // by which we need to assume any possible item can be passed into this hook
76  if (!(Loot.Instance.GuiInterface.CurrentState is GuiTabWindow ui)
77  || !(ui.GetCurrentTab() is ICraftingTab tab))
78  return;
79 
80  if (RightClickFunctionalityRequirements(item) && !(item.modItem is MagicalCube) && ui.Visible && tab.AcceptsItem(item))
81  {
82  SwapItems(tab, item);
83  // else // item has innate right click or mod allows it, do nothing
84  }
85  }
86 
87  // Give notice how to slot
88  public override void ModifyTooltips(Item item, List<TooltipLine> tooltips)
89  {
90  if (!(Loot.Instance.GuiInterface.CurrentState is GuiTabWindow ui)
91  || !(ui.GetCurrentTab() is ICraftingTab tab))
92  return;
93 
94  if ((ModSupportTunneler.GetModSupport<WingSlotSupport>().IsInvalid && item.wingSlot > 0) // block wings if low version if wingslot
95  || !tab.AcceptsItem(item)
97  return;
98 
99  var i = tooltips.FindIndex(x => x.mod.Equals("Terraria") && x.Name.Equals("ItemName"));
100  if (i != -1) tooltips[i].text += " (control right click to slot into UI)";
101  }
102  }
103  }
104 }
override void ModifyTooltips(Item item, List< TooltipLine > tooltips)
Defines an item that may be modified by modifiers from mods
Definition: LootModItem.cs:21
Defines a magical cube A magical cube is used to change modifiers on an item
Definition: MagicalCube.cs:12
override void RightClick(Item item, Player player)
static LootModItem GetInfo(Item item)
void OverrideSlottedItem(Item newItem)