forked from citizenfx/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuExample.cs
More file actions
316 lines (282 loc) · 11.5 KB
/
Copy pathMenuExample.cs
File metadata and controls
316 lines (282 loc) · 11.5 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
using System;
using System.Drawing;
using System.Collections.Generic;
using CitizenFX.Core;
using CitizenFX.Core.UI;
using NativeUI;
using NativeUI.PauseMenu;
using CitizenFX.Core.Native;
public class MenuExample : BaseScript
{
private bool ketchup = false;
private string dish = "Banana";
private MenuPool _menuPool;
public void AddMenuKetchup(UIMenu menu)
{
var newitem = new UIMenuCheckboxItem("Add ketchup?", UIMenuCheckboxStyle.Cross, ketchup, "Do you wish to add ketchup?");
menu.AddItem(newitem);
menu.OnCheckboxChange += (sender, item, checked_) =>
{
if (item == newitem)
{
ketchup = checked_;
Screen.ShowNotification("~r~Ketchup status: ~b~" + ketchup);
}
};
}
public void AddMenuFoods(UIMenu menu)
{
var foods = new List<dynamic>
{
"Banana",
"Apple",
"Pizza",
"Quartilicious",
0xF00D, // Dynamic!
};
var newitem = new UIMenuListItem("Food", foods, 0);
menu.AddItem(newitem);
menu.OnListChange += (sender, item, index) =>
{
if (item == newitem)
{
dish = item.Items[index].ToString();
Screen.ShowNotification("Preparing ~b~" + dish + "~w~...");
}
};
}
public void HeritageMenu(UIMenu menu)
{
var heritagemenu = _menuPool.AddSubMenu(menu, "Heritage Menu");
var heritageWindow = new UIMenuHeritageWindow(0, 0);
heritagemenu.AddWindow(heritageWindow);
List<dynamic> momfaces = new List<dynamic>() { "Hannah", "Audrey", "Jasmine", "Giselle", "Amelia", "Isabella", "Zoe", "Ava", "Camilla", "Violet", "Sophia", "Eveline", "Nicole", "Ashley", "Grace", "Brianna", "Natalie", "Olivia", "Elizabeth", "Charlotte", "Emma", "Misty" };
List<dynamic> dadfaces = new List<dynamic>() { "Benjamin", "Daniel", "Joshua", "Noah", "Andrew", "Joan", "Alex", "Isaac", "Evan", "Ethan", "Vincent", "Angel", "Diego", "Adrian", "Gabriel", "Michael", "Santiago", "Kevin", "Louis", "Samuel", "Anthony", "Claude", "Niko", "John" };
List<dynamic> lista = new List<dynamic>();
for (int i = 0; i < 101; i++) lista.Add(i);
var mom = new UIMenuListItem("Mamma", momfaces, 0);
var dad = new UIMenuListItem("Papà", dadfaces, 0);
var newItem = new UIMenuSliderHeritageItem("Heritage Slider", "This is Useful on heritage", true);
heritagemenu.AddItem(mom);
heritagemenu.AddItem(dad);
heritagemenu.AddItem(newItem);
int MomIndex = 0;
int DadIndex = 0;
heritagemenu.OnListChange += (_sender, _listItem, _newIndex) =>
{
if (_listItem == mom)
{
MomIndex = _newIndex;
heritageWindow.Index(MomIndex, DadIndex);
}
else if (_listItem == dad)
{
DadIndex = _newIndex;
heritageWindow.Index(MomIndex, DadIndex);
}
// This way the heritage window changes only if you change a list item!
};
heritagemenu.OnSliderChange += (_sender, _item, _newIndex) =>
{
if (_item == newItem)
{
Screen.ShowNotification("Wow the slider changed! Who do i look like??");
}
};
}
public void AddMenuCook(UIMenu menu)
{
var newitem = new UIMenuItem("Cook!", "Cook the dish with the appropiate ingredients and ketchup.");
newitem.SetLeftBadge(UIMenuItem.BadgeStyle.Star);
newitem.SetRightBadge(UIMenuItem.BadgeStyle.Tick);
menu.AddItem(newitem);
menu.OnItemSelect += (sender, item, index) =>
{
if (item == newitem)
{
string output = ketchup ? "You have ordered ~b~{0}~w~ ~r~with~w~ ketchup." : "You have ordered ~b~{0}~w~ ~r~without~w~ ketchup.";
Screen.ShowSubtitle(String.Format(output, dish));
}
};
menu.OnIndexChange += (sender, index) =>
{
if (sender.MenuItems[index] == newitem)
newitem.SetLeftBadge(UIMenuItem.BadgeStyle.None);
};
var colorItem = new UIMenuItem("UIMenuItem with Colors", "~b~Look!!~r~I can be colored ~y~too!!~w~", Color.FromArgb(150, 185, 230, 185), Color.FromArgb(170, 174, 219, 242));
menu.AddItem(colorItem);
var foods = new List<dynamic>
{
"Banana",
"Apple",
"Pizza",
"Quartilicious",
0xF00D, // Dynamic!
};
var BlankItem = new UIMenuSeparatorItem();
menu.AddItem(BlankItem);
var colorListItem = new UIMenuListItem("Colored ListItem.. Really?", foods, 0, "~b~Look!!~r~I can be colored ~y~too!!~w~", Color.FromArgb(150, 185, 230, 185), Color.FromArgb(170, 174, 219, 242));
menu.AddItem(colorListItem);
var Slider = new UIMenuSliderItem("Slider Item", "Cool!", true); // by default max is 100 and multipler 5 = 20 steps.
menu.AddItem(Slider);
var SliderProgress = new UIMenuSliderProgressItem("Slider Progress Item", 10, 0);
menu.AddItem(SliderProgress);
var Progress = new UIMenuProgressItem("Progress Item", "descriptiom", 10 , 0, true);
menu.AddItem(Progress);
var listPanelItem1 = new UIMenuListItem("Change Color", new List<object> { "Example", "example2" }, 0);
var ColorPanel = new UIMenuColorPanel("Color Panel Example", UIMenuColorPanel.ColorPanelType.Hair);
// you can choose between hair palette or makeup palette
menu.AddItem(listPanelItem1);
listPanelItem1.AddPanel(ColorPanel);
var listPanelItem2 = new UIMenuListItem("Change Percentage", new List<object> { "Example", "example2" }, 0);
var PercentagePanel = new UIMenuPercentagePanel("Percentage Panel Example", "0%", "100%");
// You can change every text in this Panel
menu.AddItem(listPanelItem2);
listPanelItem2.AddPanel(PercentagePanel);
var listPanelItem3 = new UIMenuListItem("Change Grid Position", new List<object> { "Example", "example2" }, 0);
var GridPanel = new UIMenuGridPanel("Up", "Left", "Right", "Down", new System.Drawing.PointF(.5f, .5f));
// you can choose the text in every position and where to place the starting position of the cirlce
// the other 2 grids panel available are not listed as they work the same way but in only 2 direction (horizontally or vertically)
// and to use them you must stream the stream folder provided with NativeUI project
menu.AddItem(listPanelItem3);
listPanelItem3.AddPanel(GridPanel);
var listPanelItem4 = new UIMenuListItem("Look at Statistics", new List<object> { "Example", "example2" }, 0);
var statistics = new UIMenuStatisticsPanel();
statistics.AddStatistics("Look at this!");
statistics.AddStatistics("I'm a statistic too!");
statistics.AddStatistics("Am i not?!");
//you can add as menu statistics you want
statistics.SetPercentage(0, 10f);
statistics.SetPercentage(1, 50f);
statistics.SetPercentage(2, 100f);
//and you can get / set their percentage
menu.AddItem(listPanelItem4);
listPanelItem4.AddPanel(statistics);
UIMenuItem PauseMenu = new UIMenuItem("Open custom pauseMenu");
menu.AddItem(PauseMenu);
PauseMenu.Activated += (_submenu, item) =>
{
_menuPool.CloseAllMenus();
OpenCustomPauseMenu();
};
// THERE ARE NO EVENTS FOR PANELS.. WHEN YOU CHANGE WHAT IS CHANGABLE THE LISTITEM WILL DO WHATEVER YOU TELL HIM TO DO
menu.OnListChange += (sender, item, index) =>
{
if (item == listPanelItem1)
{
Screen.ShowNotification("Selected color " + ((item.Panels[0] as UIMenuColorPanel).CurrentSelection + 1) + "...");
item.Description = "Selected color " + ((item.Panels[0] as UIMenuColorPanel).CurrentSelection + 1) + "...";
item.Parent.UpdateDescription(); // this is neat.. this will update the description of the item without refresh index.. try it by changing color
}
else if (item == listPanelItem2)
{
Screen.ShowSubtitle("Percentage = " + (item.Panels[0] as UIMenuPercentagePanel).Percentage + "...");
}
else if (item == listPanelItem3)
{
Screen.ShowSubtitle("GridPosition = " + (item.Panels[0] as UIMenuGridPanel).CirclePosition + "...");
}
};
}
public void AddMenuAnotherMenu(UIMenu menu)
{
var submenu = _menuPool.AddSubMenu(menu, "Another Menu");
for (int i = 0; i < 20; i++)
submenu.AddItem(new UIMenuItem("PageFiller", "Sample description that takes more than one line. Moreso, it takes way more than two lines since it's so long. Wow, check out this length!"));
}
public MenuExample()
{
_menuPool = new MenuPool();
var mainMenu = new UIMenu("Native UI", "~b~NATIVEUI SHOWCASE", true); // true means add menu Glare scaleform to the menu
_menuPool.Add(mainMenu);
HeritageMenu(mainMenu);
AddMenuKetchup(mainMenu);
AddMenuFoods(mainMenu);
AddMenuCook(mainMenu);
AddMenuAnotherMenu(mainMenu);
_menuPool.RefreshIndex();
Tick += async () =>
{
_menuPool.ProcessMenus();
if (Game.IsControlJustPressed(0, Control.SelectCharacterMichael) && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
mainMenu.Visible = !mainMenu.Visible;
};
}
public async void OpenCustomPauseMenu()
{
TabView MenuContainer = new TabView("This is the title", "Subtitle");
MenuContainer.SideStringTop = "Player_Name";
MenuContainer.SideStringMiddle = "Middle_String";
MenuContainer.SideStringBottom = "Bottom_string";
MenuContainer.DisplayHeader = true;
_menuPool.AddPauseMenu(MenuContainer);
TabItem Item1 = new TabItem("simple TabItem");
TabTextItem Item2 = new TabTextItem("TabTextItem", "This is the Title inside", "With a cool text to be added where you can write whatever you want");
TabItemSimpleList Item3 = new TabItemSimpleList("TabItemSimpleList", new Dictionary<string, string>()
{
["Item 1"] = "subItem 1",
["Item 2"] = "subItem 2",
["Item 3"] = "subItem 3",
["Item 4"] = "subItem 4",
["Item 5"] = "subItem 5",
["Item 6"] = "subItem 6"
});
List<UIMenuItem> items = new List<UIMenuItem>()
{
new UIMenuItem("Item 1"),
new UIMenuCheckboxItem("Item 2", true),
new UIMenuListItem("Item 3", new List<dynamic>(){"Item1", 2, 3.0999 }, 0),
new UIMenuSliderItem("Item 4", "", true),
new UIMenuSliderProgressItem("Item 5", 20, 0),
};
TabInteractiveListItem Item4 = new TabInteractiveListItem("TabInteractiveListItem", items);
List<MissionInformation> info = new List<MissionInformation>()
{
new MissionInformation("Mission 1", new List<Tuple<string, string>>()
{
new Tuple<string, string>("item 1", "description 1"),
new Tuple<string, string>("item 2", "description 2"),
new Tuple<string, string>("item 3", "description 3"),
new Tuple<string, string>("item 4", "description 4"),
new Tuple<string, string>("item 5", "description 5"),
}),
new MissionInformation("Mission 2", new List<Tuple<string, string>>()
{
new Tuple<string, string>("item 1", "description 1"),
new Tuple<string, string>("item 2", "description 2"),
new Tuple<string, string>("item 3", "description 3"),
new Tuple<string, string>("item 4", "description 4"),
new Tuple<string, string>("item 5", "description 5"),
}),
};
TabSubmenuItem Item5 = new TabSubmenuItem("TabSubmenuItem", new List<TabItem>()
{
new TabItem("simple TabItem"),
new TabTextItem("TabTextItem", "This is the Title inside", "With a cool text to be added where you can write whatever you want"),
new TabItemSimpleList("TabItemSimpleList", new Dictionary<string, string>()
{
["Item 1"] = "subItem 1",
["Item 2"] = "subItem 2",
["Item 3"] = "subItem 3",
["Item 4"] = "subItem 4",
["Item 5"] = "subItem 5",
["Item 6"] = "subItem 6"
}),
new TabMissionSelectItem("Mission tab", info),
new TabInteractiveListItem("TabInteractiveListItem", items)
});
TabMissionSelectItem Item6 = new TabMissionSelectItem("Mission tab", info);
MenuContainer.AddTab(Item1);
MenuContainer.AddTab(Item2);
MenuContainer.AddTab(Item3);
MenuContainer.AddTab(Item4);
MenuContainer.AddTab(Item5);
MenuContainer.AddTab(Item6);
// this way we can choose which tab is the defualt one
Item1.Active = true;
Item1.Focused = true;
Item1.Visible = true;
MenuContainer.Visible = true;
// items have events exactly the same as UIMenuItems and you can handle TabInteractiveListItem items just like that
}
}