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
|
/*
Opens the menu with a list of recently broken records for the given mode
and time type.
*/
static int recentRecordsMode[MAXPLAYERS + 1];
void DB_OpenRecentRecords(int client, int mode, int timeType)
{
char query[1024];
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(client));
data.WriteCell(mode);
data.WriteCell(timeType);
Transaction txn = SQL_CreateTransaction();
switch (timeType)
{
case TimeType_Nub:FormatEx(query, sizeof(query), sql_getrecentrecords, mode, LR_PLAYER_TOP_CUTOFF);
case TimeType_Pro:FormatEx(query, sizeof(query), sql_getrecentrecords_pro, mode, LR_PLAYER_TOP_CUTOFF);
}
txn.AddQuery(query);
SQL_ExecuteTransaction(gH_DB, txn, DB_TxnSuccess_OpenRecentRecords, DB_TxnFailure_Generic_DataPack, data, DBPrio_Low);
}
public void DB_TxnSuccess_OpenRecentRecords(Handle db, DataPack data, int numQueries, Handle[] results, any[] queryData)
{
data.Reset();
int client = GetClientOfUserId(data.ReadCell());
int mode = data.ReadCell();
int timeType = data.ReadCell();
delete data;
if (!IsValidClient(client))
{
return;
}
// Check if there are any times
if (SQL_GetRowCount(results[0]) == 0)
{
switch (timeType)
{
case TimeType_Nub:GOKZ_PrintToChat(client, true, "%t", "No Times Found");
case TimeType_Pro:GOKZ_PrintToChat(client, true, "%t", "No Times Found (PRO)");
}
return;
}
Menu menu = new Menu(MenuHandler_RecentRecordsSubmenu);
menu.Pagination = 5;
// Set submenu title
menu.SetTitle("%T", "Recent Records Submenu - Title", client,
gC_TimeTypeNames[timeType], gC_ModeNames[mode]);
// Add submenu items
char display[256], mapName[64], playerName[33];
int course;
float runTime;
while (SQL_FetchRow(results[0]))
{
SQL_FetchString(results[0], 0, mapName, sizeof(mapName));
course = SQL_FetchInt(results[0], 1);
SQL_FetchString(results[0], 3, playerName, sizeof(playerName));
runTime = GOKZ_DB_TimeIntToFloat(SQL_FetchInt(results[0], 4));
if (course == 0)
{
FormatEx(display, sizeof(display), "%s - %s (%s)",
mapName, playerName, GOKZ_FormatTime(runTime));
}
else
{
FormatEx(display, sizeof(display), "%s B%d - %s (%s)",
mapName, course, playerName, GOKZ_FormatTime(runTime));
}
menu.AddItem(IntToStringEx(SQL_FetchInt(results[0], 2)), display, ITEMDRAW_DISABLED);
}
menu.Display(client, MENU_TIME_FOREVER);
}
// =====[ MENUS ]=====
void DisplayRecentRecordsModeMenu(int client)
{
Menu menu = new Menu(MenuHandler_RecentRecordsMode);
menu.SetTitle("%T", "Recent Records Mode Menu - Title", client);
GOKZ_MenuAddModeItems(client, menu, false);
menu.Display(client, MENU_TIME_FOREVER);
}
void DisplayRecentRecordsTimeTypeMenu(int client, int mode)
{
recentRecordsMode[client] = mode;
Menu menu = new Menu(MenuHandler_RecentRecordsTimeType);
menu.SetTitle("%T", "Recent Records Menu - Title", client, gC_ModeNames[recentRecordsMode[client]]);
RecentRecordsTimeTypeAddItems(client, menu);
menu.Display(client, MENU_TIME_FOREVER);
}
static void RecentRecordsTimeTypeAddItems(int client, Menu menu)
{
char display[32];
for (int timeType = 0; timeType < TIMETYPE_COUNT; timeType++)
{
FormatEx(display, sizeof(display), "%T", "Recent Records Menu - Record Type", client, gC_TimeTypeNames[timeType]);
menu.AddItem("", display, ITEMDRAW_DEFAULT);
}
}
// =====[ MENU HANDLERS ]=====
public int MenuHandler_RecentRecordsMode(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
DisplayRecentRecordsTimeTypeMenu(param1, param2);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
public int MenuHandler_RecentRecordsTimeType(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
DB_OpenRecentRecords(param1, recentRecordsMode[param1], param2);
}
else if (action == MenuAction_Cancel && param2 == MenuCancel_Exit)
{
DisplayRecentRecordsModeMenu(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
public int MenuHandler_RecentRecordsSubmenu(Menu menu, MenuAction action, int param1, int param2)
{
// TODO Menu item info is course's MapCourseID, but is currently not used
if (action == MenuAction_Cancel && param2 == MenuCancel_Exit)
{
DisplayRecentRecordsTimeTypeMenu(param1, recentRecordsMode[param1]);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
|