added category menu for nominations and putting maps into sub menus
This commit is contained in:
parent
a02fea8cc8
commit
b6c0cb232d
@ -71,6 +71,9 @@ Handle g_Cvar_VIPTimeframe = INVALID_HANDLE;
|
|||||||
Handle g_Cvar_VIPTimeframeMinTime = INVALID_HANDLE;
|
Handle g_Cvar_VIPTimeframeMinTime = INVALID_HANDLE;
|
||||||
Handle g_Cvar_VIPTimeframeMaxTime = INVALID_HANDLE;
|
Handle g_Cvar_VIPTimeframeMaxTime = INVALID_HANDLE;
|
||||||
|
|
||||||
|
KeyValues g_Config;
|
||||||
|
|
||||||
|
|
||||||
int g_Player_NominationDelay[MAXPLAYERS+1];
|
int g_Player_NominationDelay[MAXPLAYERS+1];
|
||||||
int g_NominationDelay;
|
int g_NominationDelay;
|
||||||
|
|
||||||
@ -127,6 +130,26 @@ public void OnMapStart()
|
|||||||
//we have too many dbs so i am just re-using racetimercss
|
//we have too many dbs so i am just re-using racetimercss
|
||||||
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
Database.Connect(SQL_OnDatabaseConnect, "racetimercss");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(g_Config)
|
||||||
|
delete g_Config;
|
||||||
|
|
||||||
|
char sConfigFile[PLATFORM_MAX_PATH];
|
||||||
|
BuildPath(Path_SM, sConfigFile, sizeof(sConfigFile), "configs/mapchooser_extended.cfg");
|
||||||
|
if(!FileExists(sConfigFile))
|
||||||
|
{
|
||||||
|
LogMessage("Could not find config: \"%s\"", sConfigFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_Config = new KeyValues("mapchooser_extended");
|
||||||
|
if(!g_Config.ImportFromFile(sConfigFile))
|
||||||
|
{
|
||||||
|
delete g_Config;
|
||||||
|
LogMessage("ImportFromFile() failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
g_Config.Rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
|
||||||
@ -700,26 +723,45 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetNominateMenuTitle(Menu menu, int client)
|
||||||
|
{
|
||||||
|
int nominate_worth = GetPlayerWorthRTV_boost_(client);
|
||||||
|
if (Leader_Is(client))
|
||||||
|
SetMenuTitle(menu, "Nominate Map: (%i Nomination Boost Leader)", 999);
|
||||||
|
else
|
||||||
|
SetMenuTitle(menu, "Nominate Map: (%i Nomination Boost)", nominate_worth);
|
||||||
|
}
|
||||||
|
|
||||||
void AttemptNominate(int client, const char[] filter = "")
|
void AttemptNominate(int client, const char[] filter = "")
|
||||||
{
|
{
|
||||||
if(!client)
|
if(!client)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Menu menu = g_MapMenu;
|
Menu menu = g_MapMenu;
|
||||||
menu = BuildMapMenu(filter, client);
|
if (filter[0])
|
||||||
|
|
||||||
int nominate_worth = GetPlayerWorthRTV_boost_(client);
|
|
||||||
if (Leader_Is(client))
|
|
||||||
{
|
{
|
||||||
SetMenuTitle(menu, "Nominate Map: (%i Nomination Boost Leader)", 999);
|
// preserves the existing behavior for the "map wasnt found, try a substring search" fallback
|
||||||
|
menu = BuildMapMenu(filter, client);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetMenuTitle(menu, "Nominate Map: (%i Nomination Boost)", nominate_worth);
|
menu = BuildCategoryMenu(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetNominateMenuTitle(menu, client);
|
||||||
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GetMapCategory(const char[] mapname, char[] output_category, int maxlen)
|
||||||
|
{
|
||||||
|
strcopy(output_category, maxlen, "Uncategorized");
|
||||||
|
if (g_Config && g_Config.JumpToKey(mapname))
|
||||||
|
{
|
||||||
|
g_Config.GetString("MapCategory", output_category, maxlen, "Uncategorized");
|
||||||
|
g_Config.Rewind();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AttemptAdminNominate(int client, const char[] filter = "")
|
void AttemptAdminNominate(int client, const char[] filter = "")
|
||||||
{
|
{
|
||||||
if(!client)
|
if(!client)
|
||||||
@ -867,11 +909,81 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu BuildMapMenu(const char[] filter, int client)
|
Menu BuildCategoryMenu(int client)
|
||||||
|
{
|
||||||
|
Menu menu = CreateMenu(Handler_CategorySelectMenu, MENU_ACTIONS_DEFAULT);
|
||||||
|
|
||||||
|
//2023 edit to allow hiding/unhiding unavailable maps
|
||||||
|
char hiding_unavailable_maps[MAX_NAME_LENGTH];
|
||||||
|
if (g_bClientsIgnoring[client])
|
||||||
|
Format(hiding_unavailable_maps, sizeof(hiding_unavailable_maps), "Show all unavailable maps");
|
||||||
|
else
|
||||||
|
Format(hiding_unavailable_maps, sizeof(hiding_unavailable_maps), "Hide all unavailable maps");
|
||||||
|
AddMenuItem(menu, hiding_unavailable_maps, hiding_unavailable_maps);
|
||||||
|
|
||||||
|
ArrayList categories = CreateArray(ByteCountToCells(64));
|
||||||
|
static char map[PLATFORM_MAX_PATH];
|
||||||
|
static char category[64];
|
||||||
|
|
||||||
|
for (int i = 0; i < GetArraySize(g_MapList); i++)
|
||||||
|
{
|
||||||
|
GetArrayString(g_MapList, i, map, sizeof(map));
|
||||||
|
GetMapCategory(map, category, sizeof(category));
|
||||||
|
|
||||||
|
if (FindStringInArray(categories, category) == -1)
|
||||||
|
PushArrayString(categories, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
SortADTArray(categories, Sort_Ascending, Sort_String);
|
||||||
|
|
||||||
|
for (int i = 0; i < GetArraySize(categories); i++)
|
||||||
|
{
|
||||||
|
GetArrayString(categories, i, category, sizeof(category));
|
||||||
|
AddMenuItem(menu, category, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete categories;
|
||||||
|
|
||||||
|
SetMenuExitButton(menu, true);
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Handler_CategorySelectMenu(Menu menu, MenuAction action, int param1, int param2)
|
||||||
|
{
|
||||||
|
switch(action)
|
||||||
|
{
|
||||||
|
case MenuAction_End:
|
||||||
|
{
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
case MenuAction_Select:
|
||||||
|
{
|
||||||
|
static char item[64];
|
||||||
|
GetMenuItem(menu, param2, item, sizeof(item));
|
||||||
|
|
||||||
|
if (StrEqual(item, "Hide all unavailable maps") || StrEqual(item, "Show all unavailable maps"))
|
||||||
|
{
|
||||||
|
sql_insert_update_hiding_unavailable(param1);
|
||||||
|
Menu refreshed = BuildCategoryMenu(param1);
|
||||||
|
SetNominateMenuTitle(refreshed, param1);
|
||||||
|
DisplayMenu(refreshed, param1, MENU_TIME_FOREVER);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu submenu = BuildMapMenu("", param1, item);
|
||||||
|
SetNominateMenuTitle(submenu, param1);
|
||||||
|
DisplayMenu(submenu, param1, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Menu BuildMapMenu(const char[] filter, int client, const char[] category = "")
|
||||||
{
|
{
|
||||||
Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
|
Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
|
||||||
|
|
||||||
static char map[PLATFORM_MAX_PATH * 2];
|
static char map[PLATFORM_MAX_PATH * 2];
|
||||||
|
static char mapCategory[64];
|
||||||
|
|
||||||
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
|
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
|
||||||
ArrayList MapList = CreateArray(arraySize);
|
ArrayList MapList = CreateArray(arraySize);
|
||||||
@ -909,22 +1021,19 @@ Menu BuildMapMenu(const char[] filter, int client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//2023 edit to allow hiding/unhiding unavailable maps
|
|
||||||
char hiding_unavailable_maps[MAX_NAME_LENGTH];
|
|
||||||
if (g_bClientsIgnoring[client])
|
|
||||||
{
|
|
||||||
Format(hiding_unavailable_maps, sizeof(hiding_unavailable_maps), "Show all unavailable maps");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Format(hiding_unavailable_maps, sizeof(hiding_unavailable_maps), "Hide all unavailable maps");
|
|
||||||
}
|
|
||||||
AddMenuItem(menu, hiding_unavailable_maps, hiding_unavailable_maps);
|
|
||||||
|
|
||||||
for(int i = 0; i < GetArraySize(g_MapList); i++)
|
for(int i = 0; i < GetArraySize(g_MapList); i++)
|
||||||
{
|
{
|
||||||
GetArrayString(g_MapList, i, map, sizeof(map));
|
GetArrayString(g_MapList, i, map, sizeof(map));
|
||||||
|
|
||||||
|
if (category[0])
|
||||||
|
{
|
||||||
|
//only shows maps that are in this actual category.
|
||||||
|
GetMapCategory(map, mapCategory, sizeof(mapCategory));
|
||||||
|
if (!StrEqual(mapCategory, category))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(!filter[0] || StrContains(map, filter, false) != -1)
|
if(!filter[0] || StrContains(map, filter, false) != -1)
|
||||||
{
|
{
|
||||||
if (client != 0 && nominated_maps)
|
if (client != 0 && nominated_maps)
|
||||||
@ -966,7 +1075,10 @@ Menu BuildMapMenu(const char[] filter, int client)
|
|||||||
delete OwnerList;
|
delete OwnerList;
|
||||||
delete sm;
|
delete sm;
|
||||||
|
|
||||||
SetMenuExitButton(menu, true);
|
if (category[0])
|
||||||
|
SetMenuExitBackButton(menu, true);
|
||||||
|
else
|
||||||
|
SetMenuExitButton(menu, true);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
@ -1013,6 +1125,15 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
|
|||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case MenuAction_Cancel:
|
||||||
|
{
|
||||||
|
if (param2 == MenuCancel_ExitBack)
|
||||||
|
{
|
||||||
|
Menu back = BuildCategoryMenu(param1);
|
||||||
|
SetNominateMenuTitle(back, param1);
|
||||||
|
DisplayMenu(back, param1, MENU_TIME_FOREVER);
|
||||||
|
}
|
||||||
|
}
|
||||||
case MenuAction_Select:
|
case MenuAction_Select:
|
||||||
{
|
{
|
||||||
//2023-03-22 edit since client sometimes is 0 which fucks up mapchooser
|
//2023-03-22 edit since client sometimes is 0 which fucks up mapchooser
|
||||||
@ -1028,19 +1149,6 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
|
|||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
GetMenuItem(menu, param2, map, sizeof(map));
|
GetMenuItem(menu, param2, map, sizeof(map));
|
||||||
|
|
||||||
if (StrEqual(map, "Hide all unavailable maps"))
|
|
||||||
{
|
|
||||||
PrintToChat(param1, "Hiding all unavailable maps from the nomination list");
|
|
||||||
sql_insert_update_hiding_unavailable(param1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (StrEqual(map, "Show all unavailable maps"))
|
|
||||||
{
|
|
||||||
PrintToChat(param1, "Displaying all unavailable maps from the nomination list");
|
|
||||||
sql_insert_update_hiding_unavailable(param1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetClientName(param1, name, MAX_NAME_LENGTH);
|
GetClientName(param1, name, MAX_NAME_LENGTH);
|
||||||
int Index_Cooldown = GetExcludedMapListingPriority(map);
|
int Index_Cooldown = GetExcludedMapListingPriority(map);
|
||||||
if (Index_Cooldown > 0)
|
if (Index_Cooldown > 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user