Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MinimapFrame.cs
Go to the documentation of this file.
1using System;
9
11
13{
14 private class Button
15 {
16 public bool IsHighlighted;
17
18 private readonly Vector2 _position;
19
21
22 private readonly Action _onMouseDown;
23
24 private Vector2 Size => new Vector2(_hoverTexture.Width(), _hoverTexture.Height());
25
26 public Button(Asset<Texture2D> hoverTexture, Vector2 position, Action mouseDownCallback)
27 {
28 _position = position;
29 _hoverTexture = hoverTexture;
30 _onMouseDown = mouseDownCallback;
31 }
32
33 public void Click()
34 {
36 }
37
38 public void Draw(SpriteBatch spriteBatch, Vector2 parentPosition)
39 {
40 if (IsHighlighted)
41 {
42 spriteBatch.Draw(_hoverTexture.Value, _position + parentPosition, Color.White);
43 }
44 }
45
46 public bool IsTouchingPoint(Vector2 testPoint, Vector2 parentPosition)
47 {
48 Vector2 vector = _position + parentPosition + Size * 0.5f;
49 Vector2 vector2 = Vector2.Max(Size, new Vector2(22f, 22f)) * 0.5f;
50 Vector2 vector3 = testPoint - vector;
51 if (Math.Abs(vector3.X) < vector2.X)
52 {
53 return Math.Abs(vector3.Y) < vector2.Y;
54 }
55 return false;
56 }
57 }
58
59 private const float DEFAULT_ZOOM = 1.05f;
60
61 private const float ZOOM_OUT_MULTIPLIER = 0.975f;
62
63 private const float ZOOM_IN_MULTIPLIER = 1.025f;
64
66
67 private readonly Vector2 _frameOffset;
68
70
72
74
75 public string ConfigKey { get; set; }
76
77 public string NameKey { get; set; }
78
79 public Vector2 MinimapPosition { get; set; }
80
82 {
83 get
84 {
86 }
87 set
88 {
90 }
91 }
92
93 public MinimapFrame(Asset<Texture2D> frameTexture, Vector2 frameOffset)
94 {
95 _frameTexture = frameTexture;
96 _frameOffset = frameOffset;
97 }
98
99 public void SetResetButton(Asset<Texture2D> hoverTexture, Vector2 position)
100 {
101 _resetButton = new Button(hoverTexture, position, delegate
102 {
103 ResetZoom();
104 });
105 }
106
107 private void ResetZoom()
108 {
109 Main.mapMinimapScale = 1.05f;
110 }
111
112 public void SetZoomInButton(Asset<Texture2D> hoverTexture, Vector2 position)
113 {
114 _zoomInButton = new Button(hoverTexture, position, delegate
115 {
116 ZoomInButton();
117 });
118 }
119
120 private void ZoomInButton()
121 {
122 Main.mapMinimapScale *= 1.025f;
123 }
124
125 public void SetZoomOutButton(Asset<Texture2D> hoverTexture, Vector2 position)
126 {
127 _zoomOutButton = new Button(hoverTexture, position, delegate
128 {
130 });
131 }
132
133 private void ZoomOutButton()
134 {
135 Main.mapMinimapScale *= 0.975f;
136 }
137
138 public void Update()
139 {
140 Button buttonUnderMouse = GetButtonUnderMouse();
141 _zoomInButton.IsHighlighted = buttonUnderMouse == _zoomInButton;
142 _zoomOutButton.IsHighlighted = buttonUnderMouse == _zoomOutButton;
143 _resetButton.IsHighlighted = buttonUnderMouse == _resetButton;
144 if (buttonUnderMouse == null || Main.LocalPlayer.lastMouseInterface)
145 {
146 return;
147 }
148 buttonUnderMouse.IsHighlighted = true;
150 {
151 return;
152 }
153 Main.LocalPlayer.mouseInterface = true;
154 if (Main.mouseLeft)
155 {
156 buttonUnderMouse.Click();
158 {
160 }
161 }
162 }
163
164 public void DrawBackground(SpriteBatch spriteBatch)
165 {
166 spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)MinimapPosition.X - 6, (int)MinimapPosition.Y - 6, 244, 244), Color.Black * Main.mapMinimapAlpha);
167 }
168
169 public void DrawForeground(SpriteBatch spriteBatch)
170 {
172 _zoomInButton.Draw(spriteBatch, FramePosition);
173 _zoomOutButton.Draw(spriteBatch, FramePosition);
174 _resetButton.Draw(spriteBatch, FramePosition);
175 }
176
178 {
179 Vector2 testPoint = new Vector2(Main.mouseX, Main.mouseY);
181 {
182 return _zoomInButton;
183 }
185 {
186 return _zoomOutButton;
187 }
189 {
190 return _resetButton;
191 }
192 return null;
193 }
194
195 [Conditional("DEBUG")]
196 private void ValidateState()
197 {
198 }
199}
void Draw(Texture2D texture, Vector2 position, Color color)
static double Abs(double value)
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< Texture2D > MagicPixel
Button(Asset< Texture2D > hoverTexture, Vector2 position, Action mouseDownCallback)
void Draw(SpriteBatch spriteBatch, Vector2 parentPosition)
bool IsTouchingPoint(Vector2 testPoint, Vector2 parentPosition)
void SetZoomInButton(Asset< Texture2D > hoverTexture, Vector2 position)
MinimapFrame(Asset< Texture2D > frameTexture, Vector2 frameOffset)
void DrawBackground(SpriteBatch spriteBatch)
void SetZoomOutButton(Asset< Texture2D > hoverTexture, Vector2 position)
readonly Asset< Texture2D > _frameTexture
void SetResetButton(Asset< Texture2D > hoverTexture, Vector2 position)
void DrawForeground(SpriteBatch spriteBatch)
static bool mouseLeftRelease
Definition Main.cs:1755
static float mapMinimapAlpha
Definition Main.cs:926
static int mouseY
Definition Main.cs:606
static Player LocalPlayer
Definition Main.cs:2829
static int mouseX
Definition Main.cs:604
static bool mouseLeft
Definition Main.cs:614
static Vector2 Max(Vector2 value1, Vector2 value2)
Definition Vector2.cs:187