core/MenuStyle_Base.h
author David Anderson <dvander@alliedmods.net>
Sun May 13 04:43:52 2007 +0000 (2007-05-13)
changeset 778 07e49a8cf046
parent 775 9c537df13ec8
child 780 570fa34723bf
permissions -rw-r--r--
fixed various linux compilation problems
added menus to the makefile
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_MENUSTYLE_BASE_H
    16 #define _INCLUDE_MENUSTYLE_BASE_H
    17 
    18 #include <IMenuManager.h>
    19 #include <IPlayerHelpers.h>
    20 #include <sh_string.h>
    21 #include <sh_vector.h>
    22 #include "sm_memtable.h"
    23 #include "sm_fastlink.h"
    24 
    25 using namespace SourceMod;
    26 using namespace SourceHook;
    27 
    28 class CItem
    29 {
    30 public:
    31 	CItem()
    32 	{
    33 		infoString = -1;
    34 		displayString = -1;
    35 		style = 0;
    36 	}
    37 public:
    38 	int infoString;
    39 	int displayString;
    40 	unsigned int style;
    41 };
    42 
    43 class CBaseMenuPlayer
    44 {
    45 public:
    46 	CBaseMenuPlayer() : bInMenu(false), bAutoIgnore(false)
    47 	{
    48 	}
    49 	menu_states_t states;
    50 	bool bInMenu;
    51 	bool bAutoIgnore;
    52 	float menuStartTime;
    53 	unsigned int menuHoldTime;
    54 };
    55 
    56 class CBaseMenu;
    57 
    58 class BaseMenuStyle : 
    59 	public IMenuStyle,
    60 	public IClientListener
    61 {
    62 public:
    63 	BaseMenuStyle();
    64 public: //IMenuStyle
    65 	bool CancelClientMenu(int client, bool autoIgnore/* =false */);
    66 	MenuSource GetClientMenu(int client, void **object);
    67 public: //IClientListener
    68 	void OnClientDisconnected(int client);
    69 public: //what derived must implement
    70 	virtual CBaseMenuPlayer *GetMenuPlayer(int client) =0;
    71 	virtual void SendDisplay(int client, IMenuDisplay *display) =0;
    72 public: //what derived may implement 
    73 	virtual bool DoClientMenu(int client, CBaseMenu *menu, IMenuHandler *mh, unsigned int time);
    74 	virtual bool DoClientMenu(int client, IMenuDisplay *menu, IMenuHandler *mh, unsigned int time);
    75 	virtual void AddClientToWatch(int client);
    76 	virtual void RemoveClientFromWatch(int client);
    77 	virtual void ProcessWatchList();
    78 	virtual MenuSource GetClientExternMenu(int client, void **object);
    79 public: //helpers
    80 	void CancelMenu(CBaseMenu *menu);
    81 	void ClientPressedKey(int client, unsigned int key_press);
    82 protected:
    83 	void _CancelClientMenu(int client, bool bAutoIgnore=false, MenuCancelReason reason=MenuCancel_Interrupt);
    84 	bool RedoClientMenu(int client, ItemOrder order);
    85 protected:
    86 	FastLink<int> m_WatchList;
    87 };
    88 
    89 class CBaseMenu : public IBaseMenu
    90 {
    91 public:
    92 	CBaseMenu(IMenuStyle *pStyle);
    93 	virtual ~CBaseMenu();
    94 public:
    95 	virtual bool AppendItem(const char *info, const ItemDrawInfo &draw);
    96 	virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw);
    97 	virtual bool RemoveItem(unsigned int position);
    98 	virtual void RemoveAllItems();
    99 	virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw=NULL);
   100 	virtual unsigned int GetItemCount();
   101 	virtual bool SetPagination(unsigned int itemsPerPage);
   102 	virtual unsigned int GetPagination();
   103 	virtual IMenuStyle *GetDrawStyle();
   104 	virtual void SetDefaultTitle(const char *message);
   105 	virtual const char *GetDefaultTitle();
   106 	virtual bool GetExitButton();
   107 	virtual bool SetExitButton(bool set);
   108 	virtual void Cancel();
   109 	virtual void Destroy();
   110 	virtual void Cancel_Finally() =0;
   111 protected:
   112 	String m_Title;
   113 	IMenuStyle *m_pStyle;
   114 	BaseStringTable m_Strings;
   115 	unsigned int m_Pagination;
   116 	CVector<CItem> m_items;
   117 	bool m_ExitButton;
   118 	bool m_bShouldDelete;
   119 	bool m_bCancelling;
   120 };
   121 
   122 #endif //_INCLUDE_MENUSTYLE_BASE_H