1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/mapmanager/menus.sp Wed Dec 19 22:19:34 2007 +0000
1.3 @@ -0,0 +1,263 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Map Manager Plugin
1.8 + * Contains menu callbacks
1.9 + *
1.10 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.11 + * =============================================================================
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
1.15 + * Free Software Foundation.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 + * details.
1.21 + *
1.22 + * You should have received a copy of the GNU General Public License along with
1.23 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 + *
1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 + * by the Valve Corporation. You must obey the GNU General Public License in
1.29 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 + * this exception to all derivative works. AlliedModders LLC defines further
1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 + * or <http://www.sourcemod.net/license.php>.
1.33 + *
1.34 + * Version: $Id$
1.35 + */
1.36 +
1.37 +// Following callbacks are for sm_map
1.38 +public AdminMenu_Map(Handle:topmenu,
1.39 + TopMenuAction:action,
1.40 + TopMenuObject:object_id,
1.41 + param,
1.42 + String:buffer[],
1.43 + maxlength)
1.44 +{
1.45 + if (action == TopMenuAction_DisplayOption)
1.46 + {
1.47 + Format(buffer, maxlength, "%T", "Choose Map", param);
1.48 + }
1.49 + else if (action == TopMenuAction_SelectOption)
1.50 + {
1.51 + DisplayMenu(g_Menu_Map, param, MENU_TIME_FOREVER);
1.52 + }
1.53 +}
1.54 +
1.55 +public MenuHandler_Map(Handle:menu, MenuAction:action, param1, param2)
1.56 +{
1.57 + if (action == MenuAction_Cancel)
1.58 + {
1.59 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.60 + {
1.61 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.62 + }
1.63 + }
1.64 + else if (action == MenuAction_Select)
1.65 + {
1.66 + GetMenuItem(menu, param2, g_Client_Data[param1], sizeof(g_Client_Data[]));
1.67 + DisplayWhenMenu(param1);
1.68 + }
1.69 +}
1.70 +
1.71 +public MenuHandler_ChangeMap(Handle:menu, MenuAction:action, param1, param2)
1.72 +{
1.73 + if (action == MenuAction_Cancel)
1.74 + {
1.75 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.76 + {
1.77 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.78 + }
1.79 + }
1.80 + else if (action == MenuAction_Select)
1.81 + {
1.82 + decl String:when[2];
1.83 + GetMenuItem(menu, param2, when, sizeof(when));
1.84 + SetMapChange(client, g_Client_Data[param1], when[0])
1.85 + }
1.86 +}
1.87 +
1.88 +// Following callbacks are for sm_votemap
1.89 +public AdminMenu_VoteMap(Handle:topmenu,
1.90 + TopMenuAction:action,
1.91 + TopMenuObject:object_id,
1.92 + param,
1.93 + String:buffer[],
1.94 + maxlength)
1.95 +{
1.96 + if (action == TopMenuAction_DisplayOption)
1.97 + {
1.98 + Format(buffer, maxlength, "%T", "Map vote", param);
1.99 + }
1.100 + else if (action == TopMenuAction_SelectOption)
1.101 + {
1.102 + g_VoteMapInUse = param;
1.103 + ClearArray(g_SelectedMaps);
1.104 + DisplayMenu(g_Menu_Votemap, param, MENU_TIME_FOREVER);
1.105 + }
1.106 + else if (action == TopMenuAction_DrawOption)
1.107 + {
1.108 + /* disable this option if a vote is already running, theres no maps listed or someone else has already accessed this menu */
1.109 + buffer[0] = (!IsNewVoteAllowed() || g_VoteMapInUse) ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT;
1.110 + }
1.111 +}
1.112 +
1.113 +public MenuHandler_VoteMap(Handle:menu, MenuAction:action, param1, param2)
1.114 +{
1.115 + if (action == MenuAction_Cancel)
1.116 + {
1.117 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.118 + {
1.119 + DisplayWhenMenu(param1, true);
1.120 + }
1.121 + else // no action was selected.
1.122 + {
1.123 + /* Re-enable the menu option */
1.124 + g_VoteMapInUse = 0;
1.125 + }
1.126 + }
1.127 + else if (action == MenuAction_DrawItem)
1.128 + {
1.129 + decl String:info[32];
1.130 +
1.131 + GetMenuItem(menu, param2, info, sizeof(info));
1.132 +
1.133 + if (FindStringInArray(g_SelectedMaps, info) != -1)
1.134 + {
1.135 + return ITEMDRAW_IGNORE;
1.136 + }
1.137 + else
1.138 + {
1.139 + return ITEMDRAW_DEFAULT;
1.140 + }
1.141 + }
1.142 + else if (action == MenuAction_Select)
1.143 + {
1.144 + decl String:info[32];
1.145 +
1.146 + GetMenuItem(menu, param2, info, sizeof(info));
1.147 +
1.148 + PushArrayString(g_SelectedMaps, info);
1.149 +
1.150 + /* Redisplay the list */
1.151 + if (GetArraySize(g_SelectedMaps) < 5)
1.152 + {
1.153 + DisplayMenu(g_MapList, param1, MENU_TIME_FOREVER);
1.154 + }
1.155 + else
1.156 + {
1.157 + DisplayWhenMenu(param1, true);
1.158 + }
1.159 + }
1.160 +
1.161 + return 0;
1.162 +}
1.163 +
1.164 +public MenuHandler_VoteWhen(Handle:menu, MenuAction:action, param1, param2)
1.165 +{
1.166 + if (action == MenuAction_End)
1.167 + {
1.168 + CloseHandle(menu);
1.169 + }
1.170 + else if (action == MenuAction_Cancel)
1.171 + {
1.172 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.173 + {
1.174 + g_Menu_Info[param1][0] = 'i';
1.175 + DisplayConfirmVoteMenu(param1);
1.176 + }
1.177 + else
1.178 + {
1.179 + g_VoteMapInUse = 0;
1.180 + }
1.181 + }
1.182 + else if (action == MenuAction_Select)
1.183 + {
1.184 + GetMenuItem(menu, param2, g_Menu_Info[param1], sizeof(g_Menu_Info[]));
1.185 +
1.186 + DisplayConfirmVoteMenu(param1);
1.187 + }
1.188 +}
1.189 +
1.190 +public MenuHandler_Confirm(Handle:menu, MenuAction:action, param1, param2)
1.191 +{
1.192 + if (action == MenuAction_End)
1.193 + {
1.194 + CloseHandle(menu);
1.195 + }
1.196 + else if (action == MenuAction_Cancel)
1.197 + {
1.198 + g_VoteMapInUse = 0;
1.199 +
1.200 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.201 + {
1.202 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.203 + }
1.204 + }
1.205 + else if (action == MenuAction_Select)
1.206 + {
1.207 + decl String:maps[5][64];
1.208 + new selectedmaps = GetArraySize(g_SelectedMaps);
1.209 +
1.210 + for (new i = 0; i < selectedmaps; i++)
1.211 + {
1.212 + GetArrayString(g_SelectedMaps, i, maps[i], sizeof(maps[]));
1.213 + }
1.214 +
1.215 + DisplayVoteMapMenu(param1, selectedmaps, maps);
1.216 + }
1.217 +}
1.218 +
1.219 +public MenuHandler_Accept(Handle:menu, MenuAction:action, param1, param2)
1.220 +{
1.221 + if (action == MenuAction_End)
1.222 + {
1.223 + CloseHandle(menu);
1.224 + g_VoteMapInUse = 0;
1.225 + }
1.226 + else if (action == MenuAction_Select)
1.227 + {
1.228 + decl String:map[64]
1.229 + GetMenuItem(menu, 1, map, sizeof(map));
1.230 +
1.231 + SetMapChange(param1, map, g_Client_Data[param1][0])
1.232 + }
1.233 +}
1.234 +
1.235 +public Handler_MapSelectMenu(Handle:menu, MenuAction:action, param1, param2)
1.236 +{
1.237 + switch (action)
1.238 + {
1.239 + case MenuAction_Select:
1.240 + {
1.241 + if (GetArraySize(g_RTVMapList) >= GetConVarInt(g_Cvar_Maps))
1.242 + {
1.243 + PrintToChat(param1, "[SM] %t", "Max Nominations");
1.244 + return;
1.245 + }
1.246 +
1.247 + decl String:map[64], String:name[64];
1.248 + GetMenuItem(menu, param2, map, sizeof(map));
1.249 +
1.250 + if (FindStringInArray(g_RTVMapList, map) != -1)
1.251 + {
1.252 + PrintToChat(param1, "[SM] %t", "Map Already Nominated");
1.253 + return;
1.254 + }
1.255 +
1.256 + GetClientName(param1, name, 64);
1.257 +
1.258 + PushArrayString(g_RTVMapList, map);
1.259 + RemoveMenuItem(menu, param2);
1.260 +
1.261 + g_Nominated[param1] = true;
1.262 +
1.263 + PrintToChatAll("[SM] %t", "Map Nominated", name, map);
1.264 + }
1.265 + }
1.266 +}
1.267 \ No newline at end of file