core/MenuStyle_Radio.h
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     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.
    11  * 
    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
    15  * details.
    16  *
    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/>.
    19  *
    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>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_MENUSTYLE_RADIO_H
    33 #define _INCLUDE_MENUSTYLE_RADIO_H
    34 
    35 #include "sm_globals.h"
    36 #include "MenuManager.h"
    37 #include "MenuStyle_Base.h"
    38 #include "sourcemm_api.h"
    39 #include <IPlayerHelpers.h>
    40 #include <IUserMessages.h>
    41 #include "sm_fastlink.h"
    42 #include <sh_stack.h>
    43 #include <compat_wrappers.h>
    44 
    45 using namespace SourceMod;
    46 
    47 class CRadioDisplay;
    48 class CRadioMenu;
    49 
    50 class CRadioMenuPlayer : public CBaseMenuPlayer
    51 {
    52 public:
    53 	void Radio_Init(int keys, const char *title, const char *buffer);
    54 	bool Radio_NeedsRefresh();
    55 	void Radio_Refresh();
    56 	void Radio_SetIndex(unsigned int index);
    57 private:
    58 	unsigned int m_index;
    59 	size_t display_len;
    60 	char display_pkt[512];
    61 	int display_keys;
    62 	float display_last_refresh;
    63 };
    64 
    65 class CRadioStyle : 
    66 	public BaseMenuStyle,
    67 	public SMGlobalClass,
    68 	public IUserMessageListener
    69 {
    70 public:
    71 	CRadioStyle();
    72 public: //SMGlobalClass
    73 	void OnSourceModAllInitialized();
    74 	void OnSourceModLevelChange(const char *mapName);
    75 	void OnSourceModShutdown();
    76 public: //BaseMenuStyle
    77 	CBaseMenuPlayer *GetMenuPlayer(int client);
    78 	void SendDisplay(int client, IMenuPanel *display);
    79 	void ProcessWatchList();
    80 public: //IMenuStyle
    81 	const char *GetStyleName();
    82 	IMenuPanel *CreatePanel();
    83 	IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
    84 	unsigned int GetMaxPageItems();
    85 	unsigned int GetApproxMemUsage();
    86 public: //IUserMessageListener
    87 	void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
    88 	void OnUserMessageSent(int msg_id);
    89 public:
    90 	bool IsSupported();
    91 	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
    92 public:
    93 	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
    94 	void FreeRadioDisplay(CRadioDisplay *display);
    95 	CRadioMenuPlayer *GetRadioMenuPlayer(int client);
    96 	IMenuPanel *MakeRadioDisplay(const char *str, int keys);
    97 private:
    98 	CRadioMenuPlayer *m_players;
    99 	CStack<CRadioDisplay *> m_FreeDisplays;
   100 };
   101 
   102 class CRadioDisplay : public IMenuPanel
   103 {
   104 	friend class CRadioStyle;
   105 public:
   106 	CRadioDisplay();
   107 	CRadioDisplay(CRadioMenu *menu);
   108 public: //IMenuPanel
   109 	IMenuStyle *GetParentStyle();
   110 	void Reset();
   111 	void DrawTitle(const char *text, bool onlyIfEmpty=false);
   112 	unsigned int DrawItem(const ItemDrawInfo &item);
   113 	bool DrawRawLine(const char *rawline);
   114 	bool SetExtOption(MenuOption option, const void *valuePtr);
   115 	bool CanDrawItem(unsigned int drawFlags);
   116 	bool SendDisplay(int client, IMenuHandler *handler, unsigned int time);
   117 	void DeleteThis();
   118 	void SendRawDisplay(int client, unsigned int time);
   119 	bool SetSelectableKeys(unsigned int keymap);
   120 	unsigned int GetCurrentKey();
   121 	bool SetCurrentKey(unsigned int key);
   122 	int GetAmountRemaining();
   123 	unsigned int GetApproxMemUsage();
   124 public:
   125 	void DirectSet(const char *str, int keymap);
   126 private:
   127 	String m_BufferText;
   128 	String m_Title;
   129 	unsigned int m_NextPos;
   130 	int keys;
   131 };
   132 
   133 class CRadioMenu : public CBaseMenu
   134 {
   135 public:
   136 	CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
   137 public:
   138 	bool SetExtOption(MenuOption option, const void *valuePtr);
   139 	IMenuPanel *CreatePanel();
   140 	bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
   141 	bool DisplayAtItem(int client,
   142 		unsigned int time,
   143 		unsigned int start_item,
   144 		IMenuHandler *alt_handler/* =NULL */);
   145 	void Cancel_Finally();
   146 	unsigned int GetApproxMemUsage();
   147 };
   148 
   149 extern CRadioStyle g_RadioMenuStyle;
   150 
   151 #endif //_INCLUDE_MENUSTYLE_RADIO_H