core/MenuStyle_Radio.h
author David Anderson <dvander@alliedmods.net>
Fri Aug 30 10:16:28 2013 -0700 (2013-08-30)
changeset 4109 10eb68d668af
parent 3743 a98686a77974
permissions -rw-r--r--
Use Refcounted to manage to NativeEntry (bug 5852 part 4, r=ds).
dvander@780
     1
/**
dvander@780
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourceMod
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@780
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@1231
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@780
    28
 *
dvander@780
    29
 * Version: $Id$
dvander@780
    30
 */
dvander@780
    31
dvander@780
    32
#ifndef _INCLUDE_MENUSTYLE_RADIO_H
dvander@780
    33
#define _INCLUDE_MENUSTYLE_RADIO_H
dvander@780
    34
dvander@780
    35
#include "sm_globals.h"
dvander@780
    36
#include "MenuManager.h"
dvander@780
    37
#include "MenuStyle_Base.h"
dvander@780
    38
#include "sourcemm_api.h"
dvander@780
    39
#include <IPlayerHelpers.h>
skamonkey@3743
    40
#include "UserMessages.h"
dvander@780
    41
#include "sm_fastlink.h"
dvander@790
    42
#include <sh_stack.h>
faluco@1541
    43
#include <compat_wrappers.h>
dvander@780
    44
dvander@780
    45
using namespace SourceMod;
dvander@780
    46
dvander@790
    47
class CRadioDisplay;
dvander@790
    48
class CRadioMenu;
dvander@790
    49
dvander@1695
    50
class CRadioMenuPlayer : public CBaseMenuPlayer
dvander@1695
    51
{
dvander@1695
    52
public:
dvander@1695
    53
	void Radio_Init(int keys, const char *title, const char *buffer);
dvander@1695
    54
	bool Radio_NeedsRefresh();
dvander@1695
    55
	void Radio_Refresh();
dvander@1695
    56
	void Radio_SetIndex(unsigned int index);
dvander@1695
    57
private:
dvander@1695
    58
	unsigned int m_index;
dvander@1695
    59
	size_t display_len;
dvander@1695
    60
	char display_pkt[512];
dvander@1695
    61
	int display_keys;
dvander@1695
    62
	float display_last_refresh;
dvander@1695
    63
};
dvander@1695
    64
dvander@780
    65
class CRadioStyle : 
dvander@780
    66
	public BaseMenuStyle,
dvander@780
    67
	public SMGlobalClass,
skamonkey@3743
    68
#ifdef USE_PROTOBUF_USERMESSAGES
skamonkey@3743
    69
	public IProtobufUserMessageListener
skamonkey@3743
    70
#else
skamonkey@3743
    71
	public IBitBufUserMessageListener
skamonkey@3743
    72
#endif
dvander@780
    73
{
dvander@780
    74
public:
dvander@780
    75
	CRadioStyle();
dvander@780
    76
public: //SMGlobalClass
dvander@846
    77
	void OnSourceModAllInitialized();
dvander@785
    78
	void OnSourceModLevelChange(const char *mapName);
dvander@780
    79
	void OnSourceModShutdown();
dvander@780
    80
public: //BaseMenuStyle
dvander@780
    81
	CBaseMenuPlayer *GetMenuPlayer(int client);
dvander@787
    82
	void SendDisplay(int client, IMenuPanel *display);
dvander@1695
    83
	void ProcessWatchList();
dvander@780
    84
public: //IMenuStyle
dvander@780
    85
	const char *GetStyleName();
dvander@787
    86
	IMenuPanel *CreatePanel();
dvander@790
    87
	IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
dvander@780
    88
	unsigned int GetMaxPageItems();
dvander@1766
    89
	unsigned int GetApproxMemUsage();
dvander@780
    90
public: //IUserMessageListener
skamonkey@3743
    91
#ifdef USE_PROTOBUF_USERMESSAGES
skamonkey@3743
    92
	void OnUserMessage(int msg_id, protobuf::Message &msg, IRecipientFilter *pFilter);
skamonkey@3743
    93
#else
dvander@780
    94
	void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
skamonkey@3743
    95
#endif
dvander@780
    96
	void OnUserMessageSent(int msg_id);
dvander@780
    97
public:
dvander@780
    98
	bool IsSupported();
faluco@1541
    99
	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
dvander@790
   100
public:
dvander@790
   101
	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
dvander@790
   102
	void FreeRadioDisplay(CRadioDisplay *display);
dvander@1695
   103
	CRadioMenuPlayer *GetRadioMenuPlayer(int client);
dvander@1705
   104
	IMenuPanel *MakeRadioDisplay(const char *str, int keys);
dvander@780
   105
private:
dvander@1695
   106
	CRadioMenuPlayer *m_players;
dvander@790
   107
	CStack<CRadioDisplay *> m_FreeDisplays;
dvander@780
   108
};
dvander@780
   109
dvander@787
   110
class CRadioDisplay : public IMenuPanel
dvander@780
   111
{
dvander@790
   112
	friend class CRadioStyle;
dvander@780
   113
public:
dvander@780
   114
	CRadioDisplay();
dvander@780
   115
	CRadioDisplay(CRadioMenu *menu);
dvander@787
   116
public: //IMenuPanel
dvander@780
   117
	IMenuStyle *GetParentStyle();
dvander@780
   118
	void Reset();
dvander@780
   119
	void DrawTitle(const char *text, bool onlyIfEmpty=false);
dvander@780
   120
	unsigned int DrawItem(const ItemDrawInfo &item);
dvander@780
   121
	bool DrawRawLine(const char *rawline);
dvander@780
   122
	bool SetExtOption(MenuOption option, const void *valuePtr);
dvander@780
   123
	bool CanDrawItem(unsigned int drawFlags);
dvander@780
   124
	bool SendDisplay(int client, IMenuHandler *handler, unsigned int time);
dvander@780
   125
	void DeleteThis();
dvander@780
   126
	void SendRawDisplay(int client, unsigned int time);
dvander@819
   127
	bool SetSelectableKeys(unsigned int keymap);
dvander@840
   128
	unsigned int GetCurrentKey();
dvander@840
   129
	bool SetCurrentKey(unsigned int key);
dvander@1361
   130
	int GetAmountRemaining();
dvander@1766
   131
	unsigned int GetApproxMemUsage();
dvander@1705
   132
public:
dvander@1705
   133
	void DirectSet(const char *str, int keymap);
dvander@780
   134
private:
dvander@780
   135
	String m_BufferText;
dvander@780
   136
	String m_Title;
dvander@780
   137
	unsigned int m_NextPos;
dvander@780
   138
	int keys;
dvander@780
   139
};
dvander@780
   140
dvander@780
   141
class CRadioMenu : public CBaseMenu
dvander@780
   142
{
dvander@780
   143
public:
dvander@790
   144
	CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
dvander@780
   145
public:
dvander@780
   146
	bool SetExtOption(MenuOption option, const void *valuePtr);
dvander@787
   147
	IMenuPanel *CreatePanel();
dvander@1269
   148
	bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
dvander@1474
   149
	bool DisplayAtItem(int client,
dvander@1474
   150
		unsigned int time,
dvander@1474
   151
		unsigned int start_item,
dvander@1474
   152
		IMenuHandler *alt_handler/* =NULL */);
skamonkey@3570
   153
	bool SetPagination(unsigned int itemsPerPage);
dvander@780
   154
	void Cancel_Finally();
dvander@1766
   155
	unsigned int GetApproxMemUsage();
dvander@780
   156
};
dvander@780
   157
dvander@780
   158
extern CRadioStyle g_RadioMenuStyle;
dvander@780
   159
dvander@780
   160
#endif //_INCLUDE_MENUSTYLE_RADIO_H