forked from Guad/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIMenuItem.cs
More file actions
324 lines (273 loc) · 10.7 KB
/
UIMenuItem.cs
File metadata and controls
324 lines (273 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
using System;
using System.Drawing;
namespace NativeUI
{
/// <summary>
/// Simple item with a label.
/// </summary>
public class UIMenuItem
{
protected UIResRectangle _rectangle;
protected UIResText _text;
protected Sprite _selectedSprite;
protected Sprite _badgeLeft;
protected Sprite _badgeRight;
protected UIResText _labelText;
/// <summary>
/// Called when user selects the current item.
/// </summary>
public event ItemActivatedEvent Activated;
/// <summary>
/// Basic menu button.
/// </summary>
/// <param name="text">Button label.</param>
public UIMenuItem(string text) : this(text, "")
{
}
/// <summary>
/// Basic menu button.
/// </summary>
/// <param name="text">Button label.</param>
/// <param name="description">Description.</param>
public UIMenuItem(string text, string description)
{
Enabled = true;
_rectangle = new UIResRectangle(new Point(0, 0), new Size(431, 38), Color.FromArgb(150, 0, 0, 0));
_text = new UIResText(text, new Point(8, 0), 0.33f, Color.WhiteSmoke, GTA.UI.Font.ChaletLondon, UIResText.Alignment.Left);
Description = description;
_selectedSprite = new Sprite("commonmenu", "gradient_nav", new Point(0, 0), new Size(431, 38));
_badgeLeft = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_badgeRight = new Sprite("commonmenu", "", new Point(0, 0), new Size(40, 40));
_labelText = new UIResText("", new Point(0, 0), 0.35f) {TextAlignment = UIResText.Alignment.Right};
}
/// <summary>
/// Whether this item is currently selected.
/// </summary>
public virtual bool Selected { get; set; }
/// <summary>
/// Whether this item is currently being hovered on with a mouse.
/// </summary>
public virtual bool Hovered { get; set; }
/// <summary>
/// This item's description.
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// Whether this item is enabled or disabled (text is greyed out and you cannot select it).
/// </summary>
public virtual bool Enabled { get; set; }
internal virtual void ItemActivate(UIMenu sender)
{
Activated?.Invoke(sender, this);
}
/// <summary>
/// Set item's position.
/// </summary>
/// <param name="y"></param>
public virtual void Position(int y)
{
_rectangle.Position = new Point(Offset.X, y + 144 + Offset.Y);
_selectedSprite.Position = new Point(0 + Offset.X, y + 144 + Offset.Y);
_text.Position = new Point(8 + Offset.X, y + 147 + Offset.Y);
_badgeLeft.Position = new Point(0 + Offset.X, y + 142 + Offset.Y);
_badgeRight.Position = new Point(385 + Offset.X, y + 142 + Offset.Y);
_labelText.Position = new Point(420 + Offset.X, y + 148 + Offset.Y);
}
/// <summary>
/// Draw this item.
/// </summary>
public virtual void Draw()
{
_rectangle.Size = new Size(431 + Parent.WidthOffset, 38);
_selectedSprite.Size = new Size(431 + Parent.WidthOffset, 38);
if (Hovered && !Selected)
{
_rectangle.Color = Color.FromArgb(20, 255, 255, 255);
_rectangle.Draw();
}
if (Selected)
_selectedSprite.Draw();
_text.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
if (LeftBadge != BadgeStyle.None)
{
_text.Position = new Point(35 + Offset.X, (int)_text.Position.Y);
_badgeLeft.TextureDict = BadgeToSpriteLib(LeftBadge);
_badgeLeft.TextureName = BadgeToSpriteName(LeftBadge, Selected);
_badgeLeft.Color = BadgeToColor(LeftBadge, Selected);
_badgeLeft.Draw();
}
else
{
_text.Position = new Point(8 + Offset.X, (int)_text.Position.Y);
}
if (RightBadge != BadgeStyle.None)
{
_badgeRight.Position = new Point(385 + Offset.X + Parent.WidthOffset, _badgeRight.Position.Y);
_badgeRight.TextureDict = BadgeToSpriteLib(RightBadge);
_badgeRight.TextureName = BadgeToSpriteName(RightBadge, Selected);
_badgeRight.Color = BadgeToColor(RightBadge, Selected);
_badgeRight.Draw();
}
if (!String.IsNullOrWhiteSpace(RightLabel))
{
_labelText.Position = new Point(420 + Offset.X + Parent.WidthOffset, (int)_labelText.Position.Y);
_labelText.Caption = RightLabel;
_labelText.Color = _text.Color = Enabled ? Selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148);
_labelText.Draw();
}
_text.Draw();
}
/// <summary>
/// This item's offset.
/// </summary>
public Point Offset { get; set; }
/// <summary>
/// Returns this item's label.
/// </summary>
public string Text
{
get { return _text.Caption; }
set { _text.Caption = value; }
}
/// <summary>
/// Set the left badge. Set it to None to remove the badge.
/// </summary>
/// <param name="badge"></param>
public virtual void SetLeftBadge(BadgeStyle badge)
{
LeftBadge = badge;
}
/// <summary>
/// Set the right badge. Set it to None to remove the badge.
/// </summary>
/// <param name="badge"></param>
public virtual void SetRightBadge(BadgeStyle badge)
{
RightBadge = badge;
}
/// <summary>
/// Set the right label.
/// </summary>
/// <param name="text">Text as label. Set it to "" to remove the label.</param>
public virtual void SetRightLabel(string text)
{
RightLabel = text;
}
/// <summary>
/// Returns the current right label.
/// </summary>
public virtual string RightLabel { get; private set; }
/// <summary>
/// Returns the current left badge.
/// </summary>
public virtual BadgeStyle LeftBadge { get; private set; }
/// <summary>
/// Returns the current right badge.
/// </summary>
public virtual BadgeStyle RightBadge { get; private set; }
public enum BadgeStyle
{
None,
BronzeMedal,
GoldMedal,
SilverMedal,
Alert,
Crown,
Ammo,
Armour,
Barber,
Clothes,
Franklin,
Bike,
Car,
Gun,
Heart,
Makeup,
Mask,
Michael,
Star,
Tatoo,
Trevor,
Lock,
Tick,
}
internal static string BadgeToSpriteLib(BadgeStyle badge)
{
switch (badge)
{
default:
return "commonmenu";
}
}
internal static string BadgeToSpriteName(BadgeStyle badge, bool selected)
{
switch (badge)
{
case BadgeStyle.None:
return "";
case BadgeStyle.BronzeMedal:
return "mp_medal_bronze";
case BadgeStyle.GoldMedal:
return "mp_medal_gold";
case BadgeStyle.SilverMedal:
return "medal_silver";
case BadgeStyle.Alert:
return "mp_alerttriangle";
case BadgeStyle.Crown:
return "mp_hostcrown";
case BadgeStyle.Ammo:
return selected ? "shop_ammo_icon_b" : "shop_ammo_icon_a";
case BadgeStyle.Armour:
return selected ? "shop_armour_icon_b" : "shop_armour_icon_a";
case BadgeStyle.Barber:
return selected ? "shop_barber_icon_b" : "shop_barber_icon_a";
case BadgeStyle.Clothes:
return selected ? "shop_clothing_icon_b" : "shop_clothing_icon_a";
case BadgeStyle.Franklin:
return selected ? "shop_franklin_icon_b" : "shop_franklin_icon_a";
case BadgeStyle.Bike:
return selected ? "shop_garage_bike_icon_b" : "shop_garage_bike_icon_a";
case BadgeStyle.Car:
return selected ? "shop_garage_icon_b" : "shop_garage_icon_a";
case BadgeStyle.Gun:
return selected ? "shop_gunclub_icon_b" : "shop_gunclub_icon_a";
case BadgeStyle.Heart:
return selected ? "shop_health_icon_b" : "shop_health_icon_a";
case BadgeStyle.Lock:
return "shop_lock";
case BadgeStyle.Makeup:
return selected ? "shop_makeup_icon_b" : "shop_makeup_icon_a";
case BadgeStyle.Mask:
return selected ? "shop_mask_icon_b" : "shop_mask_icon_a";
case BadgeStyle.Michael:
return selected ? "shop_michael_icon_b" : "shop_michael_icon_a";
case BadgeStyle.Star:
return "shop_new_star";
case BadgeStyle.Tatoo:
return selected ? "shop_tattoos_icon_b" : "shop_tattoos_icon_";
case BadgeStyle.Tick:
return "shop_tick_icon";
case BadgeStyle.Trevor:
return selected ? "shop_trevor_icon_b" : "shop_trevor_icon_a";
default:
return "";
}
}
internal static Color BadgeToColor(BadgeStyle badge, bool selected)
{
switch (badge)
{
case BadgeStyle.Lock:
case BadgeStyle.Tick:
case BadgeStyle.Crown:
return selected ? Color.FromArgb(255, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255);
default:
return Color.FromArgb(255, 255, 255, 255);
}
}
/// <summary>
/// Returns the menu this item is in.
/// </summary>
public UIMenu Parent { get; set; }
}
}