extensions/clientprefs/menus.cpp
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/extensions/clientprefs/menus.cpp	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,179 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Client Preferences Extension
     1.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include "menus.h"
    1.36 -
    1.37 -ClientMenuHandler g_Handler;
    1.38 -AutoMenuHandler g_AutoHandler;
    1.39 -
    1.40 -void ClientMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
    1.41 -{
    1.42 -	ItemDrawInfo draw;
    1.43 -
    1.44 -	const char *info = menu->GetItemInfo(item, &draw);
    1.45 -
    1.46 -	AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
    1.47 -
    1.48 -	if (data->handler->forward != NULL)
    1.49 -	{
    1.50 -		data->handler->forward->PushCell(client);
    1.51 -		data->handler->forward->PushCell(CookieMenuAction_SelectOption);
    1.52 -		data->handler->forward->PushCell(data->datavalue);
    1.53 -		data->handler->forward->PushString("");
    1.54 -		data->handler->forward->PushCell(0);
    1.55 -		data->handler->forward->Execute(NULL);
    1.56 -	}
    1.57 -
    1.58 -	if (!data->handler->isAutoMenu)
    1.59 -	{
    1.60 -		return;
    1.61 -	}
    1.62 -
    1.63 -	IBaseMenu *submenu = menus->GetDefaultStyle()->CreateMenu(&g_AutoHandler, NULL);
    1.64 -
    1.65 -	char message[256];
    1.66 -
    1.67 -	Translate(message, sizeof(message), "%T:", 2, NULL, "Choose Option", &client);
    1.68 -	submenu->SetDefaultTitle(message);
    1.69 -
    1.70 -	if (data->type == CookieMenu_YesNo || data->type == CookieMenu_YesNo_Int)
    1.71 -	{
    1.72 -		Translate(message, sizeof(message), "%T", 2, NULL, "Yes", &client);
    1.73 -		submenu->AppendItem(info, message);
    1.74 -
    1.75 -		Translate(message, sizeof(message), "%T", 2, NULL, "No", &client);
    1.76 -		submenu->AppendItem(info, message);
    1.77 -	}
    1.78 -	else if (data->type == CookieMenu_OnOff || data->type == CookieMenu_OnOff_Int)
    1.79 -	{
    1.80 -		Translate(message, sizeof(message), "%T", 2, NULL, "On", &client);
    1.81 -		submenu->AppendItem(info, message);
    1.82 -
    1.83 -		Translate(message, sizeof(message), "%T", 2, NULL, "Off", &client);
    1.84 -		submenu->AppendItem(info, message);
    1.85 -	}
    1.86 -
    1.87 -	submenu->Display(client, 0, NULL);
    1.88 -}
    1.89 -
    1.90 -unsigned int ClientMenuHandler::OnMenuDisplayItem(IBaseMenu *menu, 
    1.91 -										   int client, 
    1.92 -										   IMenuPanel *panel,
    1.93 -										   unsigned int item, 
    1.94 -										   const ItemDrawInfo &dr)
    1.95 -{
    1.96 -	ItemDrawInfo draw;
    1.97 -
    1.98 -	const char *info = menu->GetItemInfo(item, &draw);
    1.99 -
   1.100 -	AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
   1.101 -
   1.102 -	if (data->handler->forward != NULL)
   1.103 -	{
   1.104 -		char buffer[100];
   1.105 -		UTIL_Format(buffer, sizeof(buffer), "%s", dr.display);
   1.106 -
   1.107 -		data->handler->forward->PushCell(client);
   1.108 -		data->handler->forward->PushCell(CookieMenuAction_DisplayOption);
   1.109 -		data->handler->forward->PushCell(data->datavalue);
   1.110 -		data->handler->forward->PushStringEx(buffer, sizeof(buffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
   1.111 -		data->handler->forward->PushCell(sizeof(buffer));
   1.112 -		data->handler->forward->Execute(NULL);
   1.113 -
   1.114 -		ItemDrawInfo newdraw(buffer, draw.style);
   1.115 -
   1.116 -		return panel->DrawItem(newdraw);
   1.117 -	}
   1.118 -
   1.119 -	return 0;
   1.120 -}
   1.121 -
   1.122 -void AutoMenuHandler::OnMenuSelect(SourceMod::IBaseMenu *menu, int client, unsigned int item)
   1.123 -{
   1.124 -	ItemDrawInfo draw;
   1.125 -
   1.126 -	const char *info = menu->GetItemInfo(item, &draw);
   1.127 -
   1.128 -	AutoMenuData *data = (AutoMenuData *)strtol(info, NULL, 16);
   1.129 -
   1.130 -	switch (data->type)
   1.131 -	{
   1.132 -	case CookieMenu_YesNo:
   1.133 -		{
   1.134 -			if (item == 0)
   1.135 -			{
   1.136 -				g_CookieManager.SetCookieValue(data->pCookie, client, "yes");
   1.137 -			}
   1.138 -			else
   1.139 -			{
   1.140 -				g_CookieManager.SetCookieValue(data->pCookie, client, "no");
   1.141 -			}
   1.142 -			break;
   1.143 -		}
   1.144 -	case CookieMenu_YesNo_Int:
   1.145 -	case CookieMenu_OnOff_Int:
   1.146 -		{
   1.147 -			if (item == 0)
   1.148 -			{
   1.149 -				g_CookieManager.SetCookieValue(data->pCookie, client, "1");
   1.150 -			}
   1.151 -			else
   1.152 -			{
   1.153 -				g_CookieManager.SetCookieValue(data->pCookie, client, "0");
   1.154 -			}
   1.155 -			break;
   1.156 -		}
   1.157 -	case CookieMenu_OnOff:
   1.158 -		{
   1.159 -			if (item == 0)
   1.160 -			{
   1.161 -				g_CookieManager.SetCookieValue(data->pCookie, client, "on");
   1.162 -			}
   1.163 -			else
   1.164 -			{
   1.165 -				g_CookieManager.SetCookieValue(data->pCookie, client, "off");
   1.166 -			}
   1.167 -			break;
   1.168 -		}
   1.169 -	}
   1.170 -
   1.171 -	char message[255];
   1.172 -	char *value;
   1.173 -	g_CookieManager.GetCookieValue(data->pCookie, client, &value);
   1.174 -	Translate(message, sizeof(message), "[SM] %T", 4, NULL, "Cookie Changed Value", &client, &(data->pCookie->name), value);
   1.175 -
   1.176 -	gamehelpers->TextMsg(client, 3, message);
   1.177 -}
   1.178 -
   1.179 -void AutoMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
   1.180 -{
   1.181 -	menu->Destroy(true);
   1.182 -}