Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #include "MenuStyle_Radio.h"
34 #include "sm_stringutil.h"
35 #include "UserMessages.h"
36 #include "GameConfigs.h"
37 #include "PlayerManager.h"
38 #if defined MENU_DEBUG
42 extern const char *g_RadioNumTable[];
43 CRadioStyle g_RadioMenuStyle;
44 int g_ShowMenuId = -1;
45 bool g_bRadioInit = false;
47 CRadioStyle::CRadioStyle() : m_players(new CBaseMenuPlayer[256+1])
51 void CRadioStyle::OnSourceModAllInitialized()
53 g_Players.AddClientListener(this);
56 void CRadioStyle::OnSourceModLevelChange(const char *mapName)
64 const char *msg = g_pGameConf->GetKeyValue("HudRadioMenuMsg");
65 if (!msg || msg[0] == '\0')
70 g_ShowMenuId = g_UserMsgs.GetMessageIndex(msg);
77 g_Menus.AddStyle(this);
78 g_Menus.SetDefaultStyle(this);
80 g_UserMsgs.HookUserMessage(g_ShowMenuId, this, false);
83 void CRadioStyle::OnSourceModShutdown()
85 g_Players.RemoveClientListener(this);
86 g_UserMsgs.UnhookUserMessage(g_ShowMenuId, this, false);
88 while (!m_FreeDisplays.empty())
90 delete m_FreeDisplays.front();
95 bool CRadioStyle::IsSupported()
97 return (g_ShowMenuId != -1);
100 bool CRadioStyle::OnClientCommand(int client)
102 const char *cmd = engine->Cmd_Argv(0);
104 if (strcmp(cmd, "menuselect") == 0)
106 if (!m_players[client].bInMenu)
111 int arg = atoi(engine->Cmd_Argv(1));
112 ClientPressedKey(client, arg);
119 static unsigned int g_last_holdtime = 0;
120 static unsigned int g_last_client_count = 0;
121 static int g_last_clients[256];
123 void CRadioStyle::OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter)
125 int count = pFilter->GetRecipientCount();
126 bf_read br(bf->GetBasePointer(), 2);
129 int c = br.ReadChar();
131 g_last_holdtime = (c == -1) ? 0 : (unsigned)c;
133 for (int i=0; i<count; i++)
135 g_last_clients[g_last_client_count++] = pFilter->GetRecipientIndex(i);
139 void CRadioStyle::OnUserMessageSent(int msg_id)
141 for (unsigned int i=0; i<g_last_client_count; i++)
143 int client = g_last_clients[i];
144 #if defined MENU_DEBUG
145 g_Logger.LogMessage("[SM_MENU] CRadioStyle got ShowMenu (client %d) (bInMenu %d)",
147 m_players[client].bInExternMenu);
149 if (m_players[client].bInMenu)
151 _CancelClientMenu(client, MenuCancel_Interrupted, true);
153 m_players[client].bInExternMenu = true;
154 m_players[client].menuHoldTime = g_last_holdtime;
156 g_last_client_count = 0;
159 void CRadioStyle::SendDisplay(int client, IMenuPanel *display)
161 CRadioDisplay *rDisplay = (CRadioDisplay *)display;
162 rDisplay->SendRawDisplay(client, m_players[client].menuHoldTime);
165 IMenuPanel *CRadioStyle::CreatePanel()
167 return g_RadioMenuStyle.MakeRadioDisplay();
170 IBaseMenu *CRadioStyle::CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner)
172 return new CRadioMenu(pHandler, pOwner);
175 unsigned int CRadioStyle::GetMaxPageItems()
180 const char *CRadioStyle::GetStyleName()
185 CBaseMenuPlayer *CRadioStyle::GetMenuPlayer(int client)
187 return &m_players[client];
190 CRadioDisplay *CRadioStyle::MakeRadioDisplay(CRadioMenu *menu)
192 CRadioDisplay *display;
193 if (m_FreeDisplays.empty())
195 display = new CRadioDisplay();
197 display = m_FreeDisplays.front();
198 m_FreeDisplays.pop();
204 void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display)
206 m_FreeDisplays.push(display);
209 CRadioDisplay::CRadioDisplay()
214 CRadioDisplay::CRadioDisplay(CRadioMenu *menu)
219 bool CRadioDisplay::DrawRawLine(const char *rawline)
221 m_BufferText.append(rawline);
222 m_BufferText.append("\n");
226 void CRadioDisplay::Reset()
228 m_BufferText.assign("");
234 unsigned int CRadioDisplay::GetCurrentKey()
239 bool CRadioDisplay::SetCurrentKey(unsigned int key)
241 if (key < m_NextPos || m_NextPos > 10)
251 bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time)
253 return g_RadioMenuStyle.DoClientMenu(client, this, handler, time);
256 bool CRadioDisplay::SetExtOption(MenuOption option, const void *valuePtr)
261 IMenuStyle *CRadioDisplay::GetParentStyle()
263 return &g_RadioMenuStyle;
266 void CRadioDisplay::DrawTitle(const char *text, bool onlyIfEmpty/* =false */)
268 if (m_Title.size() != 0 && onlyIfEmpty)
272 m_Title.assign(text);
275 unsigned int CRadioDisplay::DrawItem(const ItemDrawInfo &item)
277 if (m_NextPos > 10 || !CanDrawItem(item.style))
282 if (item.style & ITEMDRAW_RAWLINE)
284 if (item.style & ITEMDRAW_SPACER)
286 m_BufferText.append(" \n");
288 m_BufferText.append(item.display);
289 m_BufferText.append("\n");
292 } else if (item.style & ITEMDRAW_SPACER) {
293 m_BufferText.append(" \n");
295 } else if (item.style & ITEMDRAW_NOTEXT) {
299 if (item.style & ITEMDRAW_DISABLED)
301 m_BufferText.append(g_RadioNumTable[m_NextPos]);
302 m_BufferText.append(item.display);
303 m_BufferText.append("\n");
305 m_BufferText.append("->");
306 m_BufferText.append(g_RadioNumTable[m_NextPos]);
307 m_BufferText.append(item.display);
308 m_BufferText.append("\n");
309 keys |= (1<<(m_NextPos-1));
315 bool CRadioDisplay::CanDrawItem(unsigned int drawFlags)
317 if ((drawFlags & ITEMDRAW_IGNORE) == ITEMDRAW_IGNORE)
322 if ((drawFlags & ITEMDRAW_DISABLED) && (drawFlags & ITEMDRAW_CONTROL))
330 void CRadioDisplay::SendRawDisplay(int client, unsigned int time)
335 len = UTIL_Format(buffer, sizeof(buffer), "%s\n%s", m_Title.c_str(), m_BufferText.c_str());
337 cell_t players[1] = {client};
339 int _sel_keys = (keys == 0) ? (1<<9) : keys;
350 bf_write *buffer = g_UserMsgs.StartMessage(g_ShowMenuId, players, 1, 0);
351 buffer->WriteWord(_sel_keys);
352 buffer->WriteChar(time ? time : -1);
353 buffer->WriteByte( (len > 240) ? 1 : 0 );
354 buffer->WriteString(ptr);
355 g_UserMsgs.EndMessage();
367 void CRadioDisplay::DeleteThis()
372 bool CRadioDisplay::SetSelectableKeys(unsigned int keymap)
374 keys = (signed)keymap;
378 CRadioMenu::CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner) :
379 CBaseMenu(pHandler, &g_RadioMenuStyle, pOwner)
383 bool CRadioMenu::SetExtOption(MenuOption option, const void *valuePtr)
388 IMenuPanel *CRadioMenu::CreatePanel()
390 return g_RadioMenuStyle.MakeRadioDisplay(this);
393 bool CRadioMenu::Display(int client, unsigned int time)
395 #if defined MENU_DEBUG
396 g_Logger.LogMessage("[SM_MENU] CRadioMenu::Display(%p) (client %d) (time %d)",
406 return g_RadioMenuStyle.DoClientMenu(client, this, m_pHandler, time);
409 void CRadioMenu::VoteDisplay(int client, unsigned int maxTime)
411 #if defined MENU_DEBUG
412 g_Logger.LogMessage("[SM_MENU] CRadioMenu::VoteDisplay(%p) (client %d) (time %d)",
422 g_RadioMenuStyle.DoClientMenu(client, this, m_pVoteHandler, maxTime);
425 void CRadioMenu::Cancel_Finally()
427 g_RadioMenuStyle.CancelMenu(this);
430 const char *g_RadioNumTable[11] =
432 "0. ", "1. ", "2. ", "3. ", "4. ", "5. ", "6. ", "7. ", "8. ", "9. ", "0. "