forked from Guad/NativeUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuExample.cs
100 lines (92 loc) · 3.08 KB
/
MenuExample.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using GTA;
using GTA.Native;
using GTA.UI;
using NativeUI;
using Screen = GTA.UI.Screen;
public class MenuExample : Script
{
private bool ketchup = false;
private string dish = "Banana";
private MenuPool _menuPool;
public void AddMenuKetchup(UIMenu menu)
{
var newitem = new UIMenuCheckboxItem("Add ketchup?", 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.IndexToItem(index).ToString();
Screen.ShowNotification("Preparing ~b~" + dish + "~w~...");
}
};
}
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);
};
}
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");
_menuPool.Add(mainMenu);
AddMenuKetchup(mainMenu);
AddMenuFoods(mainMenu);
AddMenuCook(mainMenu);
AddMenuAnotherMenu(mainMenu);
_menuPool.RefreshIndex();
Tick += (o, e) => _menuPool.ProcessMenus();
KeyDown += (o, e) =>
{
if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen()) // Our menu on/off switch
mainMenu.Visible = !mainMenu.Visible;
};
}
}