3 * =============================================================================
4 * SourceMod Client Preferences Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
34 ClientMenuHandler g_Handler;
35 AutoMenuHandler g_AutoHandler;
37 void ClientMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
41 const char *info = menu->GetItemInfo(item, &draw);
43 AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
45 if (data->handler->forward != NULL)
47 data->handler->forward->PushCell(client);
48 data->handler->forward->PushCell(CookieMenuAction_SelectOption);
49 data->handler->forward->PushCell(data->datavalue);
50 data->handler->forward->PushString("");
51 data->handler->forward->PushCell(0);
52 data->handler->forward->Execute(NULL);
55 if (!data->handler->isAutoMenu)
60 IBaseMenu *submenu = menus->GetDefaultStyle()->CreateMenu(&g_AutoHandler, NULL);
64 Translate(message, sizeof(message), "%T:", 2, NULL, "Choose Option", &client);
65 submenu->SetDefaultTitle(message);
67 if (data->type == CookieMenu_YesNo || data->type == CookieMenu_YesNo_Int)
69 Translate(message, sizeof(message), "%T", 2, NULL, "Yes", &client);
70 submenu->AppendItem(info, message);
72 Translate(message, sizeof(message), "%T", 2, NULL, "No", &client);
73 submenu->AppendItem(info, message);
75 else if (data->type == CookieMenu_OnOff || data->type == CookieMenu_OnOff_Int)
77 Translate(message, sizeof(message), "%T", 2, NULL, "On", &client);
78 submenu->AppendItem(info, message);
80 Translate(message, sizeof(message), "%T", 2, NULL, "Off", &client);
81 submenu->AppendItem(info, message);
84 submenu->Display(client, 0, NULL);
87 unsigned int ClientMenuHandler::OnMenuDisplayItem(IBaseMenu *menu,
91 const ItemDrawInfo &dr)
95 const char *info = menu->GetItemInfo(item, &draw);
97 AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
99 if (data->handler->forward != NULL)
102 UTIL_Format(buffer, sizeof(buffer), "%s", dr.display);
104 data->handler->forward->PushCell(client);
105 data->handler->forward->PushCell(CookieMenuAction_DisplayOption);
106 data->handler->forward->PushCell(data->datavalue);
107 data->handler->forward->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
108 data->handler->forward->PushCell(sizeof(buffer));
109 data->handler->forward->Execute(NULL);
111 ItemDrawInfo newdraw(buffer, draw.style);
113 return panel->DrawItem(newdraw);
119 void AutoMenuHandler::OnMenuSelect(SourceMod::IBaseMenu *menu, int client, unsigned int item)
123 const char *info = menu->GetItemInfo(item, &draw);
125 AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
129 case CookieMenu_YesNo:
133 g_CookieManager.SetCookieValue(data->pCookie, client, "yes");
137 g_CookieManager.SetCookieValue(data->pCookie, client, "no");
141 case CookieMenu_YesNo_Int:
142 case CookieMenu_OnOff_Int:
146 g_CookieManager.SetCookieValue(data->pCookie, client, "1");
150 g_CookieManager.SetCookieValue(data->pCookie, client, "0");
154 case CookieMenu_OnOff:
158 g_CookieManager.SetCookieValue(data->pCookie, client, "on");
162 g_CookieManager.SetCookieValue(data->pCookie, client, "off");
170 g_CookieManager.GetCookieValue(data->pCookie, client, &value);
171 Translate(message, sizeof(message), "[SM] %T", 4, NULL, "Cookie Changed Value", &client, &(data->pCookie->name), value);
173 gamehelpers->TextMsg(client, 3, message);
176 void AutoMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)