core/MenuStyle_Radio.h
author Scott Ehlert <ds@alliedmods.net>
Sun Sep 14 03:01:05 2008 -0500 (2008-09-14)
changeset 2289 44045ead61cd
parent 1952 b7aa2b626807
parent 1947 e73a1e51833b
child 3570 cfdf2ed4c724
permissions -rw-r--r--
Eliminated head: da55a80522cf, a remnant of sourcemod-1.1.0 branch
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>
dvander@780
    40
#include <IUserMessages.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,
dvander@780
    68
	public IUserMessageListener
dvander@780
    69
{
dvander@780
    70
public:
dvander@780
    71
	CRadioStyle();
dvander@780
    72
public: //SMGlobalClass
dvander@846
    73
	void OnSourceModAllInitialized();
dvander@785
    74
	void OnSourceModLevelChange(const char *mapName);
dvander@780
    75
	void OnSourceModShutdown();
dvander@780
    76
public: //BaseMenuStyle
dvander@780
    77
	CBaseMenuPlayer *GetMenuPlayer(int client);
dvander@787
    78
	void SendDisplay(int client, IMenuPanel *display);
dvander@1695
    79
	void ProcessWatchList();
dvander@780
    80
public: //IMenuStyle
dvander@780
    81
	const char *GetStyleName();
dvander@787
    82
	IMenuPanel *CreatePanel();
dvander@790
    83
	IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
dvander@780
    84
	unsigned int GetMaxPageItems();
dvander@1766
    85
	unsigned int GetApproxMemUsage();
dvander@780
    86
public: //IUserMessageListener
dvander@780
    87
	void OnUserMessage(int msg_id, bf_write *bf, IRecipientFilter *pFilter);
dvander@780
    88
	void OnUserMessageSent(int msg_id);
dvander@780
    89
public:
dvander@780
    90
	bool IsSupported();
faluco@1541
    91
	bool OnClientCommand(int client, const char *cmdname, const CCommand &cmd);
dvander@790
    92
public:
dvander@790
    93
	CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
dvander@790
    94
	void FreeRadioDisplay(CRadioDisplay *display);
dvander@1695
    95
	CRadioMenuPlayer *GetRadioMenuPlayer(int client);
dvander@1705
    96
	IMenuPanel *MakeRadioDisplay(const char *str, int keys);
dvander@780
    97
private:
dvander@1695
    98
	CRadioMenuPlayer *m_players;
dvander@790
    99
	CStack<CRadioDisplay *> m_FreeDisplays;
dvander@780
   100
};
dvander@780
   101
dvander@787
   102
class CRadioDisplay : public IMenuPanel
dvander@780
   103
{
dvander@790
   104
	friend class CRadioStyle;
dvander@780
   105
public:
dvander@780
   106
	CRadioDisplay();
dvander@780
   107
	CRadioDisplay(CRadioMenu *menu);
dvander@787
   108
public: //IMenuPanel
dvander@780
   109
	IMenuStyle *GetParentStyle();
dvander@780
   110
	void Reset();
dvander@780
   111
	void DrawTitle(const char *text, bool onlyIfEmpty=false);
dvander@780
   112
	unsigned int DrawItem(const ItemDrawInfo &item);
dvander@780
   113
	bool DrawRawLine(const char *rawline);
dvander@780
   114
	bool SetExtOption(MenuOption option, const void *valuePtr);
dvander@780
   115
	bool CanDrawItem(unsigned int drawFlags);
dvander@780
   116
	bool SendDisplay(int client, IMenuHandler *handler, unsigned int time);
dvander@780
   117
	void DeleteThis();
dvander@780
   118
	void SendRawDisplay(int client, unsigned int time);
dvander@819
   119
	bool SetSelectableKeys(unsigned int keymap);
dvander@840
   120
	unsigned int GetCurrentKey();
dvander@840
   121
	bool SetCurrentKey(unsigned int key);
dvander@1361
   122
	int GetAmountRemaining();
dvander@1766
   123
	unsigned int GetApproxMemUsage();
dvander@1705
   124
public:
dvander@1705
   125
	void DirectSet(const char *str, int keymap);
dvander@780
   126
private:
dvander@780
   127
	String m_BufferText;
dvander@780
   128
	String m_Title;
dvander@780
   129
	unsigned int m_NextPos;
dvander@780
   130
	int keys;
dvander@780
   131
};
dvander@780
   132
dvander@780
   133
class CRadioMenu : public CBaseMenu
dvander@780
   134
{
dvander@780
   135
public:
dvander@790
   136
	CRadioMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
dvander@780
   137
public:
dvander@780
   138
	bool SetExtOption(MenuOption option, const void *valuePtr);
dvander@787
   139
	IMenuPanel *CreatePanel();
dvander@1269
   140
	bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL);
dvander@1474
   141
	bool DisplayAtItem(int client,
dvander@1474
   142
		unsigned int time,
dvander@1474
   143
		unsigned int start_item,
dvander@1474
   144
		IMenuHandler *alt_handler/* =NULL */);
dvander@780
   145
	void Cancel_Finally();
dvander@1766
   146
	unsigned int GetApproxMemUsage();
dvander@780
   147
};
dvander@780
   148
dvander@780
   149
extern CRadioStyle g_RadioMenuStyle;
dvander@780
   150
dvander@780
   151
#endif //_INCLUDE_MENUSTYLE_RADIO_H