core/MenuStyle_Radio.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3743 a98686a77974
permissions -rw-r--r--
Update CS:GO team score gamedata.
     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 "UserMessages.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 #ifdef USE_PROTOBUF_USERMESSAGES
    69 	public IProtobufUserMessageListener
    70 #else
    71 	public IBitBufUserMessageListener
    72 #endif
    73 {
    74 public:
    75 	CRadioStyle();
    76 public: //SMGlobalClass
    77 	void OnSourceModAllInitialized();
    78 	void OnSourceModLevelChange(const char *mapName);
    79 	void OnSourceModShutdown();
    80 public: //BaseMenuStyle
    81 	CBaseMenuPlayer *GetMenuPlayer(int client);
    82 	void SendDisplay(int client, IMenuPanel *display);
    83 	void ProcessWatchList();
    84 public: //IMenuStyle
    85 	const char *GetStyleName();
    86 	IMenuPanel *CreatePanel();
    87 	IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
    88 	unsigned int GetMaxPageItems();
    89 	unsigned int GetApproxMemUsage();
    90 public: //IUserMessageListener
    91 #ifdef USE_PROTOBUF_USERMESSAGES
    92 	void OnUserMessage(int msg_id, protobuf::Message &msg, IRecipientFilter *pFilter);
    93 #else
    94 	void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
    95 #endif
    96 	void OnUserMessageSent(int msg_id);
    97 public:
    98 	bool IsSupported();
    99 	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
   100 public:
   101 	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
   102 	void FreeRadioDisplay(CRadioDisplay *display);
   103 	CRadioMenuPlayer *GetRadioMenuPlayer(int client);
   104 	IMenuPanel *MakeRadioDisplay(const char *str, int keys);
   105 private:
   106 	CRadioMenuPlayer *m_players;
   107 	CStack<CRadioDisplay *> m_FreeDisplays;
   108 };
   109 
   110 class CRadioDisplay : public IMenuPanel
   111 {
   112 	friend class CRadioStyle;
   113 public:
   114 	CRadioDisplay();
   115 	CRadioDisplay(CRadioMenu *menu);
   116 public: //IMenuPanel
   117 	IMenuStyle *GetParentStyle();
   118 	void Reset();
   119 	void DrawTitle(const char *text, bool onlyIfEmpty=false);
   120 	unsigned int DrawItem(const ItemDrawInfo &item);
   121 	bool DrawRawLine(const char *rawline);
   122 	bool SetExtOption(MenuOption option, const void *valuePtr);
   123 	bool CanDrawItem(unsigned int drawFlags);
   124 	bool SendDisplay(int client, IMenuHandler *handler, unsigned int time);
   125 	void DeleteThis();
   126 	void SendRawDisplay(int client, unsigned int time);
   127 	bool SetSelectableKeys(unsigned int keymap);
   128 	unsigned int GetCurrentKey();
   129 	bool SetCurrentKey(unsigned int key);
   130 	int GetAmountRemaining();
   131 	unsigned int GetApproxMemUsage();
   132 public:
   133 	void DirectSet(const char *str, int keymap);
   134 private:
   135 	String m_BufferText;
   136 	String m_Title;
   137 	unsigned int m_NextPos;
   138 	int keys;
   139 };
   140 
   141 class CRadioMenu : public CBaseMenu
   142 {
   143 public:
   144 	CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
   145 public:
   146 	bool SetExtOption(MenuOption option, const void *valuePtr);
   147 	IMenuPanel *CreatePanel();
   148 	bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
   149 	bool DisplayAtItem(int client,
   150 		unsigned int time,
   151 		unsigned int start_item,
   152 		IMenuHandler *alt_handler/* =NULL */);
   153 	bool SetPagination(unsigned int itemsPerPage);
   154 	void Cancel_Finally();
   155 	unsigned int GetApproxMemUsage();
   156 };
   157 
   158 extern CRadioStyle g_RadioMenuStyle;
   159 
   160 #endif //_INCLUDE_MENUSTYLE_RADIO_H