summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-hud/options_menu.sp
blob: 705df27f34630a4a8a11d7b095f8a6cfe3c78a15 (plain)
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
static TopMenu optionsTopMenu;
static TopMenuObject catHUD;
static TopMenuObject itemsHUD[HUDOPTION_COUNT];



// =====[ EVENTS ]=====

void OnOptionsMenuCreated_OptionsMenu(TopMenu topMenu)
{
	if (optionsTopMenu == topMenu && catHUD != INVALID_TOPMENUOBJECT)
	{
		return;
	}
	
	catHUD = topMenu.AddCategory(HUD_OPTION_CATEGORY, TopMenuHandler_Categories);
}

void OnOptionsMenuReady_OptionsMenu(TopMenu topMenu)
{
	// Make sure category exists
	if (catHUD == INVALID_TOPMENUOBJECT)
	{
		GOKZ_OnOptionsMenuCreated(topMenu);
	}
	
	if (optionsTopMenu == topMenu)
	{
		return;
	}
	
	optionsTopMenu = topMenu;
	
	// Add HUD option items	
	for (int option = 0; option < view_as<int>(HUDOPTION_COUNT); option++)
	{
		itemsHUD[option] = optionsTopMenu.AddItem(gC_HUDOptionNames[option], TopMenuHandler_HUD, catHUD);
	}
}

public void TopMenuHandler_Categories(TopMenu topmenu, TopMenuAction action, TopMenuObject topobj_id, int param, char[] buffer, int maxlength)
{
	if (action == TopMenuAction_DisplayOption || action == TopMenuAction_DisplayTitle)
	{
		if (topobj_id == catHUD)
		{
			Format(buffer, maxlength, "%T", "Options Menu - HUD", param);
		}
	}
}

public void TopMenuHandler_HUD(TopMenu topmenu, TopMenuAction action, TopMenuObject topobj_id, int param, char[] buffer, int maxlength)
{
	HUDOption option = HUDOPTION_INVALID;
	for (int i = 0; i < view_as<int>(HUDOPTION_COUNT); i++)
	{
		if (topobj_id == itemsHUD[i])
		{
			option = view_as<HUDOption>(i);
			break;
		}
	}
	
	if (option == HUDOPTION_INVALID)
	{
		return;
	}
	
	if (action == TopMenuAction_DisplayOption)
	{
		switch (option)
		{
			case HUDOption_TPMenu:
			{
				FormatEx(buffer, maxlength, "%T - %T", 
					gC_HUDOptionPhrases[option], param, 
					gC_TPMenuPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_ShowKeys:
			{
				FormatEx(buffer, maxlength, "%T - %T", 
					gC_HUDOptionPhrases[option], param, 
					gC_ShowKeysPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_TimerText:
			{
				FormatEx(buffer, maxlength, "%T - %T", 
					gC_HUDOptionPhrases[option], param, 
					gC_TimerTextPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_TimerStyle:
			{
				int optionValue = GOKZ_HUD_GetOption(param, option);
				if (optionValue == TimerStyle_Precise)
				{
					FormatEx(buffer, maxlength, "%T - 01:23.45", 
						gC_HUDOptionPhrases[option], param);
				}
				else
				{
					FormatEx(buffer, maxlength, "%T - 1:23", 
						gC_HUDOptionPhrases[option], param);
				}
			}
			case HUDOption_TimerType:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_TimerTypePhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_SpeedText:
			{
				FormatEx(buffer, maxlength, "%T - %T", 
					gC_HUDOptionPhrases[option], param, 
					gC_SpeedTextPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_ShowControls:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_ShowControlsPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_DeadstrafeColor:
			{
				FormatEx(buffer, maxlength, "%T - %T", 
					gC_HUDOptionPhrases[option], param, 
					gC_DeadstrafeColorPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_UpdateRate:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_HUDUpdateRatePhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_ShowSpectators:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_ShowSpecsPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_SpecListPosition:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_SpecListPositionPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			case HUDOption_DynamicMenu:
			{
				FormatEx(buffer, maxlength, "%T - %T",
					gC_HUDOptionPhrases[option], param,
					gC_DynamicMenuPhrases[GOKZ_HUD_GetOption(param, option)], param);
			}
			default:FormatToggleableOptionDisplay(param, option, buffer, maxlength);
		}
	}
	else if (action == TopMenuAction_SelectOption)
	{
		GOKZ_HUD_CycleOption(param, option);
		optionsTopMenu.Display(param, TopMenuPosition_LastCategory);
	}
}



// =====[ PRIVATE ]=====

static void FormatToggleableOptionDisplay(int client, HUDOption option, char[] buffer, int maxlength)
{
	if (GOKZ_HUD_GetOption(client, option) == 0)
	{
		FormatEx(buffer, maxlength, "%T - %T", 
			gC_HUDOptionPhrases[option], client, 
			"Options Menu - Disabled", client);
	}
	else
	{
		FormatEx(buffer, maxlength, "%T - %T", 
			gC_HUDOptionPhrases[option], client, 
			"Options Menu - Enabled", client);
	}
}