2 using System.Collections.Generic;
8 using Microsoft.Xna.Framework;
10 using Terraria.GameContent.UI.Elements;
14 namespace Loot.UI.Tabs.Soulforging
16 internal class GuiSoulforgeTab : GuiTab
18 public override string Header =>
"Soulforging";
19 public override int GetPageHeight()
24 private GuiSoulgauge Soulgauge;
25 private GuiInteractableItemButton ItemButton;
26 private GuiImageButton CraftButton;
27 private GuiInteractableItemButton SoulButton;
29 private GuiArrowButton ArrowLeft;
30 private GuiArrowButton ArrowRight;
31 private UIText Paginator;
33 private int CurrentPage = 1;
34 private int MaxPages = 1;
35 private const int MAX_ROWS_PER_PAGE = 7;
36 private bool ShouldUpdate =
true;
38 public override void OnInitialize()
42 Soulgauge =
new GuiSoulgauge();
43 Soulgauge.OnInitialize();
44 TabFrame.Append(Soulgauge);
46 ItemButton =
new GuiInteractableItemButton(
47 GuiButton.ButtonType.Parchment,
48 hintTexture: ModContent.GetTexture(
"Terraria/Item_24"),
49 hintText:
"Place an item here" 51 ItemButton.Top.Pixels = Soulgauge.Height.Pixels / 4f;
52 ItemButton.RightOf(Soulgauge);
53 ItemButton.Left.Pixels += ItemButton.Width.Pixels - GuiTab.PADDING * 1.5f;
54 TabFrame.Append(ItemButton);
56 CraftButton =
new GuiImageButton(GuiButton.ButtonType.None, ModContent.GetTexture(
"Terraria/UI/Craft_Toggle_3"));
57 CraftButton.Top.Pixels = ItemButton.Top.Pixels;
58 CraftButton.RightOf(ItemButton);
59 TabFrame.Append(CraftButton);
61 SoulButton =
new GuiInteractableItemButton(
62 GuiButton.ButtonType.Parchment,
63 hintTexture: Assets.Textures.PlaceholderTexture,
64 hintText:
"Place a soul here" 66 SoulButton.Top.Pixels = ItemButton.Top.Pixels;
67 SoulButton.RightOf(CraftButton);
68 TabFrame.Append(SoulButton);
70 ArrowLeft =
new GuiArrowButton(GuiArrowButton.ArrowDirection.LEFT)
72 HoverText =
"Previous",
73 Top =
new StyleDimension(24, 1.0f)
75 ArrowLeft.WhenClicked += (evt, element, btn) =>
80 ArrowRight =
new GuiArrowButton(GuiArrowButton.ArrowDirection.RIGHT)
83 Left =
new StyleDimension(-15, 0f),
84 Top =
new StyleDimension(24, 1.0f)
86 ArrowRight.WhenClicked += (evt, element, btn) =>
91 TabFrame.Append(ArrowLeft);
92 TabFrame.Append(ArrowRight);
94 Paginator =
new UIText(
"1/1")
96 Top =
new StyleDimension(24, 1.0f)
98 Paginator.Left.Pixels = -(ArrowLeft.Width.Pixels - 25) / 2f;
99 TabFrame.Append(Paginator);
102 public override void Update(GameTime gameTime)
104 base.Update(gameTime);
109 ShouldUpdate =
false;
113 public List<Item> GetAvailableCubes()
115 return Cubes.Where(item => item.stack > 0).ToList();
118 private List<Item> Cubes =
new List<Item>();
119 private List<CubeCraftRow> CubeRows =
new List<CubeCraftRow>();
120 private List<CubeCraftRow> ActiveRows =
new List<CubeCraftRow>();
122 private void CalculateRubeRows()
124 ActiveRows.ForEach(x => TabFrame.RemoveChild(x));
127 var world = ModContent.GetInstance<LootEssenceWorld>();
128 var count = world.UnlockedCubes.Count;
129 MaxPages = (int)Math.Ceiling(count / (
float)MAX_ROWS_PER_PAGE);
130 ArrowRight.CanBeClicked = MaxPages > 1 && CurrentPage != MaxPages;
131 ArrowLeft.CanBeClicked = MaxPages > 1 && CurrentPage != 1;
132 Paginator.SetText($
"{CurrentPage}/{MaxPages}");
134 foreach (var cube
in world.UnlockedCubes)
136 var row =
new CubeCraftRow(cube);
140 row.OnCubeUpdate += item =>
142 Cubes.First(x => x.type == item.type).stack = item.stack;
145 if (Cubes.All(item => item.type != cube))
147 var item =
new Item();
148 item.SetDefaults(cube);
154 row.Cube = Cubes.First(x => x.type == cube);
155 row.CubeButton.ChangeItem(0, row.Cube);
160 private void UpdateActiveRows()
163 UIElement previous = Soulgauge;
165 foreach (var row
in CubeRows.Skip((CurrentPage - 1) * MAX_ROWS_PER_PAGE).Take(MAX_ROWS_PER_PAGE).ToList())
167 row.Cube = Cubes.First(item => item.type == row.Type);
169 TabFrame.Append(row);
175 public override void OnShow()
181 public override void GiveBackItems()
183 CubeRows.ForEach(row =>
185 if (!row.CubeButton.Item.IsAir)
187 row.CubeButton.Item.noGrabDelay = 0;
188 Main.LocalPlayer.GetItem(Main.myPlayer, row.CubeButton.Item.Clone());
189 row.CubeButton.Item.TurnToAir();
190 row.Cube.TurnToAir();