Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
GuiTab.cs
Go to the documentation of this file.
1 using Loot.Ext;
2 using Loot.UI.Common;
3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
5 using Terraria;
6 using Terraria.UI;
7 
8 namespace Loot.UI
9 {
10  internal abstract class GuiTab : UIElement
11  {
12  internal const int SPACING = GuiUtils.SPACING;
13  internal const int PADDING = GuiUtils.PADDING;
14 
15  public abstract string Header { get; }
16  private int _pageHeight;
17 
18  internal int _GetPageHeight()
19  {
20  _pageHeight = GetPageHeight();
21  return _pageHeight;
22  }
23 
24  public abstract int GetPageHeight();
25 
26  public virtual void OnShow()
27  {
28 
29  }
30 
31  public virtual void OnHide()
32  {
33 
34  }
35  internal virtual void ToggleUI(bool visible)
36  {
37  }
38 
39  public virtual void GiveBackItems()
40  {
41 
42  }
43 
44  protected UIElement TabFrame;
45  protected static Texture2D _topTexture => Assets.Textures.GUI.PanelTopTexture;
46  protected static Texture2D _middleTexture => Assets.Textures.GUI.PanelTileTexture;
47  protected static Texture2D _bottomTexture => Assets.Textures.GUI.PanelBottomTexture;
48 
49  public int TotalHeight => _topTexture.Height + _pageHeight + _bottomTexture.Height;
50 
51  public override void OnInitialize()
52  {
53  _GetPageHeight();
54 
55  Height.Set(_pageHeight + _topTexture.Height + _bottomTexture.Height, 0);
56  Width.Set(422, 0);
57 
58  TabFrame = new UIElement
59  {
60  Top = new StyleDimension(SPACING, 0),
61  Left = new StyleDimension(SPACING, 0),
62  Width = new StyleDimension(Width.Pixels - SPACING * 2, 0),
63  Height = new StyleDimension(Height.Pixels - SPACING * 2, 0)
64  };
65  Append(TabFrame);
66  }
67 
68  protected override void DrawSelf(SpriteBatch spriteBatch)
69  {
70  var parentBounds = GetOuterDimensions().ToRectangle();
71 
72  Rectangle BoundsWithOffset(Vector2 bounds, Point off)
73  {
74  return new Rectangle(parentBounds.X + off.X, parentBounds.Y + off.Y, (int)bounds.X, (int)bounds.Y);
75  }
76 
77  spriteBatch.Draw(
78  _topTexture,
79  _topTexture.BoundsFromParent(parentBounds),
80  Color.White
81  );
82 
83  Point offset = new Point(
84  0,
85  _topTexture.Height
86  );
87 
88  for (int i = 0; i < _pageHeight; i++)
89  {
90  spriteBatch.Draw(
91  _middleTexture,
92  _middleTexture.BoundsFromParent(BoundsWithOffset(_middleTexture.Size(), offset)),
93  Color.White
94  );
95  offset.Y += 1;
96  }
97 
98  spriteBatch.Draw(
99  _bottomTexture,
100  _bottomTexture.BoundsFromParent(BoundsWithOffset(_bottomTexture.Size(), offset)),
101  Color.White
102  );
103 
104  //#if DEBUG
105  // spriteBatch.Draw(
106  // Main.magicPixel,
107  // GetOuterDimensions().ToRectangle(),
108  // Color.Blue * 0.4f
109  // );
110 
111  // spriteBatch.Draw(
112  // Main.magicPixel,
113  // TabFrame.GetOuterDimensions().ToRectangle(),
114  // Color.Orange * 0.4f
115  // );
116  //#endif
117  }
118  }
119 }