2 using System.Collections.Generic;
8 using Microsoft.Xna.Framework;
9 using Microsoft.Xna.Framework.Graphics;
19 internal class GuiTabWindow : DraggableUIState
21 private GuiHeader _header;
22 private GuiCloseButton _closeButton;
23 private GuiTab _currentTab;
24 internal GuiTabState _currentTabState = GuiTabState.CUBING;
26 internal readonly Dictionary<GuiTabState, GuiTab> _tabs =
new Dictionary<GuiTabState, GuiTab>
28 {GuiTabState.CUBING,
new GuiCubingTab()},
29 {GuiTabState.ESSENCE,
new GuiEssenceTab()},
30 {GuiTabState.SOULFORGE,
new GuiSoulforgeTab()},
33 internal readonly Dictionary<GuiTabState, GuiTabToggle> _toggles =
new Dictionary<GuiTabState, GuiTabToggle>
35 {GuiTabState.CUBING,
new GuiTabToggle(GuiTabState.CUBING)},
36 {GuiTabState.ESSENCE,
new GuiTabToggle(GuiTabState.ESSENCE)},
37 {GuiTabState.SOULFORGE,
new GuiTabToggle(GuiTabState.SOULFORGE)}
40 public GuiTab GetCurrentTab()
42 _tabs.TryGetValue(_currentTabState, out _currentTab);
43 _currentTab?._GetPageHeight();
47 public T GetTab<T>() where T : GuiTab
49 return (T)_tabs.Values.FirstOrDefault(t => t.GetType() == typeof(T));
52 private void ToggleTab(UIMouseEvent evt, UIElement element, GuiTabToggle toggle)
54 if (_currentTabState == toggle.TargetState)
60 UpdateTabTo(toggle.TargetState);
63 public void UpdateTabTo(GuiTabState newState)
65 _toggles[newState].SetActive(
true);
66 _toggles[_currentTabState].SetActive(
false);
67 _currentTabState = _toggles[newState].TargetState;
71 public void UpdateTab()
73 if (HasChild(_currentTab))
75 RemoveChild(_currentTab);
78 _currentTab?.OnHide();
80 _header.SetHeader(_currentTab.Header);
82 _currentTab.Activate();
87 public void UpdateWindow()
89 Height.Set(_header.Height.Pixels + _currentTab.TotalHeight, 0);
93 public void CenterWindow()
95 float useW = Main.screenWidth > Main.minScreenW ? Main.screenWidth : Main.minScreenW;
96 float useH = Main.screenHeight > Main.minScreenH ? Main.screenHeight : Main.minScreenH;
97 Left.Set(useW * 0.5f - Width.Pixels * 0.5f, 0);
98 Top.Set(useH * 0.5f - Height.Pixels * 0.5f, 0);
101 public override void OnInitialize()
107 _header =
new GuiHeader();
110 AddDragging(_header,
this);
112 _closeButton =
new GuiCloseButton();
113 Append(_closeButton);
115 foreach (var kvp
in _tabs)
117 kvp.Value.Top.Set(_header.GetOffset(), 0);
120 var togglePosition =
new Vector2(422, _header.GetOffset());
121 var toggleOffset = Vector2.UnitY * 10;
123 foreach (var toggle
in _toggles.Select(x => x.Value))
126 toggle.WhenClicked += ToggleTab;
127 var usePosition = togglePosition + toggleOffset;
128 toggle.Left.Set(usePosition.X, 0);
129 toggle.Top.Set(usePosition.Y, 0);
130 toggleOffset.Y += toggle.Height.Pixels;
134 _toggles[_currentTabState].SetActive(
true);
138 public override void ToggleUI(UserInterface theInterface,
UIState uiStateInstance = null)
140 base.ToggleUI(theInterface, uiStateInstance);
144 Main.playerInventory =
true;
151 _currentTab?.ToggleUI(Visible);
154 public override void Update(GameTime gameTime)
156 base.Update(gameTime);
158 if (Visible && !Main.playerInventory)
160 ToggleUI(
Loot.Instance.GuiInterface);
164 public override void Draw(SpriteBatch spriteBatch)
166 base.Draw(spriteBatch);
168 if (IsMouseHovering || MouseOverUI())
170 Main.LocalPlayer.mouseInterface =
true;
174 private bool MouseOverUI()
176 var rect =
new Rectangle((
int)Left.Pixels, (
int)Top.Pixels, (
int)Width.Pixels, (
int)Height.Pixels);
177 return rect.Contains(Main.MouseScreen.ToPoint());
180 public void GiveBackItems()
182 foreach (var tab
in _tabs.Values)