Added ReadMapList support for sm_votemap in the admin menu
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401746
This commit is contained in:
parent
ac058124cc
commit
5b2e32da18
@ -27,7 +27,11 @@
|
|||||||
"target" "mapcyclefile"
|
"target" "mapcyclefile"
|
||||||
}
|
}
|
||||||
|
|
||||||
"admin menu"
|
"sm_map menu"
|
||||||
|
{
|
||||||
|
"file" "addons/sourcemod/configs/adminmenu_maplist.ini"
|
||||||
|
}
|
||||||
|
"sm_votemap menu"
|
||||||
{
|
{
|
||||||
"file" "addons/sourcemod/configs/adminmenu_maplist.ini"
|
"file" "addons/sourcemod/configs/adminmenu_maplist.ini"
|
||||||
}
|
}
|
||||||
|
@ -84,16 +84,19 @@ public OnPluginStart()
|
|||||||
|
|
||||||
decl String:mapListPath[PLATFORM_MAX_PATH];
|
decl String:mapListPath[PLATFORM_MAX_PATH];
|
||||||
BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
|
BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
|
||||||
SetMapListCompatBind("admin menu", mapListPath);
|
SetMapListCompatBind("sm_map menu", mapListPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnMapStart()
|
public OnMapStart()
|
||||||
{
|
{
|
||||||
LoadMapList(g_MapList);
|
|
||||||
|
|
||||||
ParseConfigs();
|
ParseConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OnConfigsExecuted()
|
||||||
|
{
|
||||||
|
LoadMapList(g_MapList);
|
||||||
|
}
|
||||||
|
|
||||||
public OnAdminMenuReady(Handle:topmenu)
|
public OnAdminMenuReady(Handle:topmenu)
|
||||||
{
|
{
|
||||||
/* Block us from being called twice */
|
/* Block us from being called twice */
|
||||||
|
@ -91,7 +91,7 @@ LoadMapList(Handle:menu)
|
|||||||
|
|
||||||
if ((map_array = ReadMapList(g_map_array,
|
if ((map_array = ReadMapList(g_map_array,
|
||||||
g_map_serial,
|
g_map_serial,
|
||||||
"admin menu",
|
"sm_map menu",
|
||||||
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
|
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
|
||||||
!= INVALID_HANDLE)
|
!= INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
|
@ -121,9 +121,13 @@ public OnPluginStart()
|
|||||||
g_MapList = CreateMenu(MenuHandler_Map, MenuAction_DrawItem);
|
g_MapList = CreateMenu(MenuHandler_Map, MenuAction_DrawItem);
|
||||||
SetMenuTitle(g_MapList, "Please select a map");
|
SetMenuTitle(g_MapList, "Please select a map");
|
||||||
SetMenuExitBackButton(g_MapList, true);
|
SetMenuExitBackButton(g_MapList, true);
|
||||||
|
|
||||||
|
decl String:mapListPath[PLATFORM_MAX_PATH];
|
||||||
|
BuildPath(Path_SM, mapListPath, sizeof(mapListPath), "configs/adminmenu_maplist.ini");
|
||||||
|
SetMapListCompatBind("sm_votemap menu", mapListPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnMapStart()
|
public OnConfigsExecuted()
|
||||||
{
|
{
|
||||||
g_mapCount = LoadMapList(g_MapList);
|
g_mapCount = LoadMapList(g_MapList);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
new Handle:g_MapList = INVALID_HANDLE;
|
new Handle:g_MapList = INVALID_HANDLE;
|
||||||
new g_mapFileTime;
|
|
||||||
new g_mapCount;
|
new g_mapCount;
|
||||||
|
|
||||||
new Handle:g_SelectedMaps;
|
new Handle:g_SelectedMaps;
|
||||||
@ -215,111 +214,37 @@ public Action:Command_Votemap(client, args)
|
|||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new Handle:g_map_array = INVALID_HANDLE;
|
||||||
|
new g_map_serial = -1;
|
||||||
|
|
||||||
LoadMapList(Handle:menu)
|
LoadMapList(Handle:menu)
|
||||||
{
|
{
|
||||||
decl String:mapPath[256];
|
new Handle:map_array;
|
||||||
BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/adminmenu_maplist.ini");
|
|
||||||
|
|
||||||
if (!FileExists(mapPath))
|
if ((map_array = ReadMapList(g_map_array,
|
||||||
{
|
g_map_serial,
|
||||||
if (g_MapList != INVALID_HANDLE)
|
"sm_votemap menu",
|
||||||
{
|
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
|
||||||
RemoveAllMenuItems(menu);
|
!= INVALID_HANDLE)
|
||||||
}
|
|
||||||
|
|
||||||
return LoadMapFolder(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the file hasn't changed, there's no reason to reload
|
|
||||||
// all of the maps.
|
|
||||||
new fileTime = GetFileTime(mapPath, FileTime_LastChange);
|
|
||||||
if (g_mapFileTime == fileTime)
|
|
||||||
{
|
{
|
||||||
return GetMenuItemCount(menu);
|
g_map_array = map_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mapFileTime = fileTime;
|
if (g_map_array == INVALID_HANDLE)
|
||||||
|
|
||||||
// Reset the array
|
|
||||||
if (g_MapList != INVALID_HANDLE)
|
|
||||||
{
|
{
|
||||||
RemoveAllMenuItems(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
new Handle:file = OpenFile(mapPath, "rt");
|
|
||||||
if (file == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
|
|
||||||
return LoadMapFolder(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
decl String:buffer[256], len;
|
|
||||||
while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
|
|
||||||
{
|
|
||||||
TrimString(buffer);
|
|
||||||
|
|
||||||
if ((len = StrContains(buffer, ".bsp", false)) != -1)
|
|
||||||
{
|
|
||||||
buffer[len] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer[0] == '\0'
|
|
||||||
|| buffer[0] == ';'
|
|
||||||
|| buffer[0] == '/'
|
|
||||||
|| !IsValidConVarChar(buffer[0])
|
|
||||||
|| !IsMapValid(buffer))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddMenuItem(menu, buffer, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
CloseHandle(file);
|
|
||||||
|
|
||||||
new count = GetMenuItemCount(menu);
|
|
||||||
|
|
||||||
if (!count)
|
|
||||||
{
|
|
||||||
return LoadMapFolder(menu);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadMapFolder(Handle:menu)
|
|
||||||
{
|
|
||||||
LogMessage("[SM] Loading menu map list from maps folder");
|
|
||||||
|
|
||||||
new Handle:mapDir = OpenDirectory("maps/");
|
|
||||||
|
|
||||||
if (mapDir == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
LogError("[SM] Could not open map directory for reading");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
new String:mapName[64];
|
RemoveAllMenuItems(menu);
|
||||||
new String:buffer[64];
|
|
||||||
new FileType:fileType;
|
|
||||||
new len;
|
|
||||||
|
|
||||||
while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
|
decl String:map_name[64];
|
||||||
|
new map_count = GetArraySize(g_map_array);
|
||||||
|
|
||||||
|
for (new i = 0; i < map_count; i++)
|
||||||
{
|
{
|
||||||
if(fileType == FileType_File)
|
GetArrayString(g_map_array, i, map_name, sizeof(map_name));
|
||||||
{
|
AddMenuItem(menu, map_name, map_name);
|
||||||
len = strlen(mapName);
|
}
|
||||||
|
|
||||||
if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
|
return map_count;
|
||||||
{
|
|
||||||
AddMenuItem(menu, buffer, buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CloseHandle(mapDir);
|
|
||||||
|
|
||||||
return GetMenuItemCount(menu);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user