summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-jumpstats/options_menu.sp
blob: 903a8bb0530b02c53314aaa0eef2ced0540d8836 (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
static TopMenu optionsTopMenu;
static TopMenuObject catJumpstats;
static TopMenuObject itemsJumpstats[JSOPTION_COUNT];



// =====[ PUBLIC ]=====

void DisplayJumpstatsOptionsMenu(int client)
{
	optionsTopMenu.DisplayCategory(catJumpstats, client);
}



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

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

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

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 == catJumpstats)
		{
			Format(buffer, maxlength, "%T", "Options Menu - Jumpstats", param);
		}
	}
}

public void TopMenuHandler_HUD(TopMenu topmenu, TopMenuAction action, TopMenuObject topobj_id, int param, char[] buffer, int maxlength)
{
	JSOption option = JSOPTION_INVALID;
	for (int i = 0; i < view_as<int>(JSOPTION_COUNT); i++)
	{
		if (topobj_id == itemsJumpstats[i])
		{
			option = view_as<JSOption>(i);
			break;
		}
	}
	
	if (option == JSOPTION_INVALID)
	{
		return;
	}
	
	if (action == TopMenuAction_DisplayOption)
	{
		if (option == JSOption_JumpstatsMaster ||
			option == JSOption_ExtendedChatReport ||
			option == JSOption_FailstatsConsole ||
			option == JSOption_FailstatsChat ||
			option == JSOption_JumpstatsAlways)
		{
			FormatToggleableOptionDisplay(param, option, buffer, maxlength);
		}
		else
		{
			FormatDistanceTierOptionDisplay(param, option, buffer, maxlength);
		}
	}
	else if (action == TopMenuAction_SelectOption)
	{
		GOKZ_JS_CycleOption(param, option);
		optionsTopMenu.Display(param, TopMenuPosition_LastCategory);
	}
}



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

static void FormatToggleableOptionDisplay(int client, JSOption option, char[] buffer, int maxlength)
{
	if (GOKZ_JS_GetOption(client, option) == JSToggleOption_Disabled)
	{
		FormatEx(buffer, maxlength, "%T - %T", 
			gI_JSOptionPhrases[option], client, 
			"Options Menu - Disabled", client);
	}
	else
	{
		FormatEx(buffer, maxlength, "%T - %T", 
			gI_JSOptionPhrases[option], client, 
			"Options Menu - Enabled", client);
	}
}

static void FormatDistanceTierOptionDisplay(int client, JSOption option, char[] buffer, int maxlength)
{
	int optionValue = GOKZ_JS_GetOption(client, option);
	if (optionValue == DistanceTier_None) // Disabled
	{
		FormatEx(buffer, maxlength, "%T - %T", 
			gI_JSOptionPhrases[option], client, 
			"Options Menu - Disabled", client);
	}
	else
	{
		// Add a plus sign to anything below the highest tier
		if (optionValue < DISTANCETIER_COUNT - 1)
		{
			FormatEx(buffer, maxlength, "%T - %s+", 
				gI_JSOptionPhrases[option], client, 
				gC_DistanceTiers[optionValue]);
		}
		else
		{
			FormatEx(buffer, maxlength, "%T - %s", 
				gI_JSOptionPhrases[option], client, 
				gC_DistanceTiers[optionValue]);
		}
	}
}