summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/gokz-profile/options.sp
blob: de8da514ee592fe50e0e81fd1beab2748d2ea3f0 (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

// =====[ OPTIONS ]=====

void OnOptionsMenuReady_Options()
{
	RegisterOptions();
}

void RegisterOptions()
{
	for (ProfileOption option; option < PROFILEOPTION_COUNT; option++)
	{
		GOKZ_RegisterOption(gC_ProfileOptionNames[option], gC_ProfileOptionDescriptions[option], 
			OptionType_Int, gI_ProfileOptionDefaults[option], 0, gI_ProfileOptionCounts[option] - 1);
	}
}



// =====[ OPTIONS MENU ]=====

TopMenu gTM_Options;
TopMenuObject gTMO_CatProfile;
TopMenuObject gTMO_ItemsProfile[PROFILEOPTION_COUNT];

void OnOptionsMenuCreated_OptionsMenu(TopMenu topMenu)
{
	if (gTM_Options == topMenu && gTMO_CatProfile != INVALID_TOPMENUOBJECT)
	{
		return;
	}
	
	gTMO_CatProfile = topMenu.AddCategory(PROFILE_OPTION_CATEGORY, TopMenuHandler_Categories);
}

void OnOptionsMenuReady_OptionsMenu(TopMenu topMenu)
{
	// Make sure category exists
	if (gTMO_CatProfile == INVALID_TOPMENUOBJECT)
	{
		GOKZ_OnOptionsMenuCreated(topMenu);
	}
	
	if (gTM_Options == topMenu)
	{
		return;
	}
	
	gTM_Options = topMenu;
	
	// Add gokz-profile option items	
	for (int option = 0; option < view_as<int>(PROFILEOPTION_COUNT); option++)
	{
		gTMO_ItemsProfile[option] = gTM_Options.AddItem(gC_ProfileOptionNames[option], TopMenuHandler_Profile, gTMO_CatProfile);
	}
}

void DisplayProfileOptionsMenu(int client)
{
	if (gTMO_CatProfile != INVALID_TOPMENUOBJECT)
	{
		gTM_Options.DisplayCategory(gTMO_CatProfile, client);
	}
}

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

public void TopMenuHandler_Profile(TopMenu topmenu, TopMenuAction action, TopMenuObject topobj_id, int param, char[] buffer, int maxlength)
{
	ProfileOption option = PROFILEOPTION_INVALID;
	for (int i = 0; i < view_as<int>(PROFILEOPTION_COUNT); i++)
	{
		if (topobj_id == gTMO_ItemsProfile[i])
		{
			option = view_as<ProfileOption>(i);
			break;
		}
	}
	
	if (option == PROFILEOPTION_INVALID)
	{
		return;
	}
	
	if (action == TopMenuAction_DisplayOption)
	{
		if (option == ProfileOption_TagType)
		{
			FormatEx(buffer, maxlength, "%T - %T",
					gC_ProfileOptionPhrases[option], param,
					gC_ProfileTagTypePhrases[GOKZ_GetOption(param, gC_ProfileOptionNames[option])], param);
		}
		else
		{
			FormatEx(buffer, maxlength, "%T - %T",
					gC_ProfileOptionPhrases[option], param,
					gC_ProfileBoolPhrases[GOKZ_GetOption(param, gC_ProfileOptionNames[option])], param);
		}
	}
	else if (action == TopMenuAction_SelectOption)
	{
		GOKZ_CycleOption(param, gC_ProfileOptionNames[option]);

		if (option == ProfileOption_TagType)
		{
			for (int i = 0; i < PROFILETAGTYPE_COUNT; i++)
			{
				int tagType = GOKZ_GetOption(param, gC_ProfileOptionNames[option]);
				if (!CanUseTagType(param, tagType))
				{
					GOKZ_CycleOption(param, gC_ProfileOptionNames[option]);
				}
			}
		}

		gTM_Options.Display(param, TopMenuPosition_LastCategory);
	}
}