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
|
/*
Lets player select a replay bot to play back.
*/
static int selectedReplayMode[MAXPLAYERS + 1];
// =====[ PUBLIC ]=====
void DisplayReplayModeMenu(int client)
{
if (g_ReplayInfoCache.Length == 0)
{
GOKZ_PrintToChat(client, true, "%t", "No Replays Found (Map)");
GOKZ_PlayErrorSound(client);
return;
}
Menu menu = new Menu(MenuHandler_ReplayMode);
menu.SetTitle("%T", "Replay Menu (Mode) - Title", client, gC_CurrentMap);
GOKZ_MenuAddModeItems(client, menu, false);
menu.Display(client, MENU_TIME_FOREVER);
}
// =====[ EVENTS ]=====
public int MenuHandler_ReplayMode(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
selectedReplayMode[param1] = param2;
DisplayReplayMenu(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
public int MenuHandler_Replay(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[4];
menu.GetItem(param2, info, sizeof(info));
int replayIndex = StringToInt(info);
int replayInfo[RP_CACHE_BLOCKSIZE];
g_ReplayInfoCache.GetArray(replayIndex, replayInfo);
char path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path),
"%s/%s/%d_%s_%s_%s.%s",
RP_DIRECTORY_RUNS, gC_CurrentMap, replayInfo[0], gC_ModeNamesShort[replayInfo[1]], gC_StyleNamesShort[replayInfo[2]], gC_TimeTypeNames[replayInfo[3]], RP_FILE_EXTENSION);
if (!FileExists(path))
{
BuildPath(Path_SM, path, sizeof(path),
"%s/%d_%s_%s_%s.%s",
RP_DIRECTORY, gC_CurrentMap, replayInfo[0], gC_ModeNamesShort[replayInfo[1]], gC_StyleNamesShort[replayInfo[2]], gC_TimeTypeNames[replayInfo[3]], RP_FILE_EXTENSION);
if (!FileExists(path))
{
LogError("Failed to load file: \"%s\".", path);
GOKZ_PrintToChat(param1, true, "%t", "Replay Menu - No File");
return 0;
}
}
LoadReplayBot(param1, path);
}
else if (action == MenuAction_Cancel)
{
DisplayReplayModeMenu(param1);
}
else if (action == MenuAction_End)
{
delete menu;
}
return 0;
}
// =====[ PRIVATE ]=====
static void DisplayReplayMenu(int client)
{
Menu menu = new Menu(MenuHandler_Replay);
menu.SetTitle("%T", "Replay Menu - Title", client, gC_CurrentMap, gC_ModeNames[selectedReplayMode[client]]);
if (ReplayMenuAddItems(client, menu) > 0)
{
menu.Display(client, MENU_TIME_FOREVER);
}
else
{
GOKZ_PrintToChat(client, true, "%t", "No Replays Found (Mode)", gC_ModeNames[selectedReplayMode[client]]);
GOKZ_PlayErrorSound(client);
DisplayReplayModeMenu(client);
}
}
// Returns the number of replay menu items added
static int ReplayMenuAddItems(int client, Menu menu)
{
int replaysAdded = 0;
int replayCount = g_ReplayInfoCache.Length;
int replayInfo[RP_CACHE_BLOCKSIZE];
char temp[32], indexString[4];
menu.RemoveAllItems();
for (int i = 0; i < replayCount; i++)
{
IntToString(i, indexString, sizeof(indexString));
g_ReplayInfoCache.GetArray(i, replayInfo);
if (replayInfo[1] != selectedReplayMode[client]) // Wrong mode!
{
continue;
}
if (replayInfo[0] == 0)
{
FormatEx(temp, sizeof(temp), "Main %s", gC_TimeTypeNames[replayInfo[3]]);
}
else
{
FormatEx(temp, sizeof(temp), "Bonus %d %s", replayInfo[0], gC_TimeTypeNames[replayInfo[3]]);
}
menu.AddItem(indexString, temp, ITEMDRAW_DEFAULT);
replaysAdded++;
}
return replaysAdded;
}
|