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
|
#define ITEM_INFO_NAME "name"
#define ITEM_INFO_MODE "mode"
#define ITEM_INFO_RANK "rank"
#define ITEM_INFO_POINTS "points"
int profileTargetPlayer[MAXPLAYERS];
int profileMode[MAXPLAYERS];
bool profileWaitingForUpdate[MAXPLAYERS];
// =====[ PUBLIC ]=====
void ShowProfile(int client, int player = 0)
{
if (player != 0)
{
profileTargetPlayer[client] = player;
profileMode[client] = GOKZ_GetCoreOption(player, Option_Mode);
}
if (GOKZ_GL_GetRankPoints(profileTargetPlayer[client], profileMode[client]) < 0)
{
if (!profileWaitingForUpdate[client])
{
GOKZ_GL_UpdatePoints(profileTargetPlayer[client], profileMode[client]);
profileWaitingForUpdate[client] = true;
}
return;
}
profileWaitingForUpdate[client] = false;
Menu menu = new Menu(MenuHandler_Profile);
menu.SetTitle("%T - %N", "Profile Menu - Title", client, profileTargetPlayer[client]);
ProfileMenuAddItems(client, menu);
menu.Display(client, MENU_TIME_FOREVER);
}
// =====[ EVENTS ]=====
void Profile_OnClientConnected(int client)
{
profileTargetPlayer[client] = 0;
profileWaitingForUpdate[client] = false;
}
void Profile_OnClientDisconnect(int client)
{
profileTargetPlayer[client] = 0;
profileWaitingForUpdate[client] = false;
}
void Profile_OnPointsUpdated(int player, int mode)
{
for (int client = 1; client <= MaxClients; client++)
{
if (profileWaitingForUpdate[client]
&& profileTargetPlayer[client] == player
&& profileMode[client] == mode)
{
ShowProfile(client);
}
}
}
public int MenuHandler_Profile(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[16];
menu.GetItem(param2, info, sizeof(info));
if (StrEqual(info, ITEM_INFO_MODE, false))
{
if (++profileMode[param1] == MODE_COUNT)
{
profileMode[param1] = 0;
}
}
else if (StrEqual(info, ITEM_INFO_RANK, false))
{
ShowRankInfo(param1);
return 0;
}
else if (StrEqual(info, ITEM_INFO_POINTS, false))
{
ShowPointsInfo(param1);
return 0;
}
ShowProfile(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
// =====[ PRIVATE ]=====
static void ProfileMenuAddItems(int client, Menu menu)
{
char display[32];
int player = profileTargetPlayer[client];
int mode = profileMode[client];
FormatEx(display, sizeof(display), "%T: %s",
"Profile Menu - Mode", client, gC_ModeNames[mode]);
menu.AddItem(ITEM_INFO_MODE, display);
FormatEx(display, sizeof(display), "%T: %s",
"Profile Menu - Rank", client, gC_rankName[gI_Rank[player][mode]]);
menu.AddItem(ITEM_INFO_RANK, display);
FormatEx(display, sizeof(display), "%T: %d",
"Profile Menu - Points", client, GOKZ_GL_GetRankPoints(player, mode));
menu.AddItem(ITEM_INFO_POINTS, display);
}
static void ShowRankInfo(int client)
{
Menu menu = new Menu(MenuHandler_RankInfo);
menu.SetTitle("%T - %N", "Rank Info Menu - Title", client, profileTargetPlayer[client]);
RankInfoMenuAddItems(client, menu);
menu.Display(client, MENU_TIME_FOREVER);
}
static void RankInfoMenuAddItems(int client, Menu menu)
{
char display[32];
int player = profileTargetPlayer[client];
int mode = profileMode[client];
FormatEx(display, sizeof(display), "%T: %s",
"Rank Info Menu - Current Rank", client, gC_rankName[gI_Rank[player][mode]]);
menu.AddItem("", display);
int next_rank = gI_Rank[player][mode] + 1;
if (next_rank == RANK_COUNT)
{
FormatEx(display, sizeof(display), "%T: -",
"Rank Info Menu - Next Rank", client);
menu.AddItem("", display);
FormatEx(display, sizeof(display), "%T: 0",
"Rank Info Menu - Points needed", client);
menu.AddItem("", display);
}
else
{
FormatEx(display, sizeof(display), "%T: %s",
"Rank Info Menu - Next Rank", client, gC_rankName[next_rank]);
menu.AddItem("", display);
FormatEx(display, sizeof(display), "%T: %d",
"Rank Info Menu - Points needed", client, gI_rankThreshold[mode][next_rank] - GOKZ_GL_GetRankPoints(player, mode));
menu.AddItem("", display);
}
}
static int MenuHandler_RankInfo(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Cancel)
{
ShowProfile(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
static void ShowPointsInfo(int client)
{
Menu menu = new Menu(MenuHandler_PointsInfo);
menu.SetTitle("%T - %N", "Points Info Menu - Title", client, profileTargetPlayer[client]);
PointsInfoMenuAddItems(client, menu);
menu.Display(client, MENU_TIME_FOREVER);
}
static void PointsInfoMenuAddItems(int client, Menu menu)
{
char display[32];
int player = profileTargetPlayer[client];
int mode = profileMode[client];
FormatEx(display, sizeof(display), "%T: %d",
"Points Info Menu - Overall Points", client, GOKZ_GL_GetPoints(player, mode, TimeType_Nub));
menu.AddItem("", display);
FormatEx(display, sizeof(display), "%T: %d",
"Points Info Menu - Pro Points", client, GOKZ_GL_GetPoints(player, mode, TimeType_Pro));
menu.AddItem("", display);
FormatEx(display, sizeof(display), "%T: %d",
"Points Info Menu - Overall Completion", client, GOKZ_GL_GetFinishes(player, mode, TimeType_Nub));
menu.AddItem("", display);
FormatEx(display, sizeof(display), "%T: %d",
"Points Info Menu - Pro Completion", client, GOKZ_GL_GetFinishes(player, mode, TimeType_Pro));
menu.AddItem("", display);
}
static int MenuHandler_PointsInfo(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Cancel)
{
ShowProfile(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
|