Changed a few natives/stocks that should have used IsClientInGame() rather than IsClientConnected()
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_stringutil.h"
16 #include "PlayerManager.h"
17 #include "MenuStyle_Valve.h"
18 #include "Translator.h"
19 #include "PlayerManager.h"
20 #include "ConCmdManager.h"
22 SH_DECL_HOOK4_void(IServerPluginHelpers, CreateMessage, SH_NOATTRIB, false, edict_t *, DIALOG_TYPE, KeyValues *, IServerPluginCallbacks *);
24 ValveMenuStyle g_ValveMenuStyle;
25 extern const char *g_OptionNumTable[];
26 extern const char *g_OptionCmdTable[];
27 IServerPluginCallbacks *g_pVSPHandle = NULL;
28 CallClass<IServerPluginHelpers> *g_pSPHCC = NULL;
30 ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1])
34 CBaseMenuPlayer *ValveMenuStyle::GetMenuPlayer(int client)
36 return &m_players[client];
39 bool ValveMenuStyle::OnClientCommand(int client)
41 const char *cmd = engine->Cmd_Argv(0);
43 if (strcmp(cmd, "sm_vmenuselect") == 0)
45 int key_press = atoi(engine->Cmd_Argv(1));
46 g_ValveMenuStyle.ClientPressedKey(client, key_press);
53 void ValveMenuStyle::OnSourceModAllInitialized()
55 g_Players.AddClientListener(this);
56 SH_ADD_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false);
57 g_pSPHCC = SH_GET_CALLCLASS(serverpluginhelpers);
60 void ValveMenuStyle::OnSourceModShutdown()
62 SH_RELEASE_CALLCLASS(g_pSPHCC);
63 SH_REMOVE_HOOK_MEMFUNC(IServerPluginHelpers, CreateMessage, serverpluginhelpers, this, &ValveMenuStyle::HookCreateMessage, false);
64 g_Players.RemoveClientListener(this);
67 void ValveMenuStyle::HookCreateMessage(edict_t *pEdict,
70 IServerPluginCallbacks *plugin)
72 if (type != DIALOG_MENU)
77 int client = engine->IndexOfEdict(pEdict);
78 if (client < 1 || client > 256)
83 CValveMenuPlayer *player = &m_players[client];
85 /* We don't care if the player is in a menu because, for all intents and purposes,
86 * the menu is completely private. Instead, we just figure out the level we'll need
87 * in order to override it.
89 player->curPrioLevel = kv->GetInt("level", player->curPrioLevel);
91 /* Oh no! What happens if we got a menu that overwrites ours?! */
94 /* Okay, let the external menu survive for now. It may live another
95 * day to avenge its grandfather, killed in the great Menu Interruption
98 _CancelClientMenu(client, true);
102 void ValveMenuStyle::OnSourceModVSPReceived(IServerPluginCallbacks *iface)
104 g_pVSPHandle = iface;
107 IMenuPanel *ValveMenuStyle::CreatePanel()
109 return new CValveMenuDisplay();
112 IBaseMenu *ValveMenuStyle::CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner)
114 return new CValveMenu(pHandler, pOwner);
117 const char *ValveMenuStyle::GetStyleName()
122 unsigned int ValveMenuStyle::GetMaxPageItems()
127 void ValveMenuStyle::SendDisplay(int client, IMenuPanel *display)
129 m_players[client].curPrioLevel--;
130 CValveMenuDisplay *vDisplay = (CValveMenuDisplay *)display;
131 vDisplay->SendRawDisplay(client, m_players[client].curPrioLevel, m_players[client].menuHoldTime);
134 bool ValveMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, unsigned int time)
141 return BaseMenuStyle::DoClientMenu(client, menu, mh, time);
144 bool ValveMenuStyle::DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time)
148 mh->OnMenuStart(menu);
149 mh->OnMenuCancel(menu, client, MenuCancel_NoDisplay);
154 return BaseMenuStyle::DoClientMenu(client, menu, mh, time);
157 CValveMenuDisplay::CValveMenuDisplay()
163 CValveMenuDisplay::CValveMenuDisplay(CValveMenu *pMenu)
167 m_pKv->SetColor("color", pMenu->m_IntroColor);
168 m_pKv->SetString("title", pMenu->m_IntroMsg);
171 void CValveMenuDisplay::DeleteThis()
176 CValveMenuDisplay::~CValveMenuDisplay()
181 IMenuStyle *CValveMenuDisplay::GetParentStyle()
183 return &g_ValveMenuStyle;
186 void CValveMenuDisplay::Reset()
192 m_pKv = new KeyValues("menu");
194 m_TitleDrawn = false;
197 unsigned int CValveMenuDisplay::GetCurrentKey()
202 bool CValveMenuDisplay::SetCurrentKey(unsigned int key)
204 if (key < m_NextPos || key > 9)
214 bool CValveMenuDisplay::SetExtOption(MenuOption option, const void *valuePtr)
216 if (option == MenuOption_IntroMessage)
218 m_pKv->SetString("title", (const char *)valuePtr);
220 } else if (option == MenuOption_IntroColor) {
221 int *array = (int *)valuePtr;
222 m_pKv->SetColor("color", Color(array[0], array[1], array[2], array[3]));
224 } else if (option == MenuOption_Priority) {
225 m_pKv->SetInt("level", *(int *)valuePtr);
232 bool CValveMenuDisplay::CanDrawItem(unsigned int drawFlags)
235 * ITEMDRAW_RAWLINE - We can't draw random text, and this doesn't add a slot,
236 * so it's completely safe to ignore it.
237 * -----------------------------------------
239 if (drawFlags & ITEMDRAW_RAWLINE)
245 * Special cases, explained in DrawItem()
247 if ((drawFlags & ITEMDRAW_NOTEXT)
248 || (drawFlags & ITEMDRAW_SPACER))
254 * We can't draw disabled text. We could bump the position, but we
255 * want DirectDraw() to find some actual items to display.
257 if (drawFlags & ITEMDRAW_DISABLED)
265 unsigned int CValveMenuDisplay::DrawItem(const ItemDrawInfo &item)
267 if (m_NextPos > 9 || !CanDrawItem(item.style))
273 * For these cases we can't draw anything at all, but
274 * we can at least bump the position since we were explicitly asked to.
276 if ((item.style & ITEMDRAW_NOTEXT)
277 || (item.style & ITEMDRAW_SPACER))
283 UTIL_Format(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display);
285 KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true);
286 ki->SetString("command", g_OptionCmdTable[m_NextPos]);
287 ki->SetString("msg", buffer);
292 void CValveMenuDisplay::DrawTitle(const char *text, bool onlyIfEmpty/* =false */)
294 if (onlyIfEmpty && m_TitleDrawn)
299 m_pKv->SetString("msg", text);
303 bool CValveMenuDisplay::DrawRawLine(const char *rawline)
308 void CValveMenuDisplay::SendRawDisplay(int client, int priority, unsigned int time)
310 m_pKv->SetInt("level", priority);
311 m_pKv->SetInt("time", time ? time : 200);
313 SH_CALL(g_pSPHCC, &IServerPluginHelpers::CreateMessage)(
314 engine->PEntityOfEntIndex(client),
320 bool CValveMenuDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time)
322 return g_ValveMenuStyle.DoClientMenu(client, this, handler, time);
325 bool CValveMenuDisplay::SetSelectableKeys(unsigned int keymap)
330 CValveMenu::CValveMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner) :
331 CBaseMenu(pHandler, &g_ValveMenuStyle, pOwner),
332 m_IntroColor(255, 0, 0, 255)
334 strcpy(m_IntroMsg, "You have a menu, press ESC");
338 void CValveMenu::Cancel_Finally()
340 g_ValveMenuStyle.CancelMenu(this);
343 bool CValveMenu::SetPagination(unsigned int itemsPerPage)
345 if (itemsPerPage > 5)
350 return CBaseMenu::SetPagination(itemsPerPage);
353 bool CValveMenu::SetExtOption(MenuOption option, const void *valuePtr)
355 if (option == MenuOption_IntroMessage)
357 strncopy(m_IntroMsg, (const char *)valuePtr, sizeof(m_IntroMsg));
359 } else if (option == MenuOption_IntroColor) {
360 unsigned int *array = (unsigned int *)valuePtr;
361 m_IntroColor = Color(array[0], array[1], array[2], array[3]);
368 bool CValveMenu::Display(int client, unsigned int time)
375 return g_ValveMenuStyle.DoClientMenu(client, this, m_pHandler, time);
378 void CValveMenu::VoteDisplay(int client, unsigned int maxTime)
385 g_ValveMenuStyle.DoClientMenu(client, this, m_pVoteHandler, maxTime);
388 IMenuPanel *CValveMenu::CreatePanel()
390 return new CValveMenuDisplay(this);
393 bool CValveMenu::GetExitButton()
398 bool CValveMenu::SetExitButton(bool set)
403 const char *g_OptionNumTable[] =
405 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"
408 const char *g_OptionCmdTable[] =
410 "sm_vmenuselect 0", /* INVALID! */