SourceMod SDK  1.7
IMenuManager.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
34 
35 #include <IShareSys.h>
36 #include <IHandleSys.h>
37 
38 #define SMINTERFACE_MENUMANAGER_NAME "IMenuManager"
39 #define SMINTERFACE_MENUMANAGER_VERSION 16
40 
46 namespace SourceMod
47 {
51  enum ItemSelection
52  {
53  ItemSel_None,
54  ItemSel_Back,
55  ItemSel_Next,
56  ItemSel_Exit,
57  ItemSel_Item,
58  ItemSel_ExitBack,
59  };
60 
64  enum ItemOrder
65  {
66  ItemOrder_Ascending,
67  ItemOrder_Descending,
68  };
69 
73  struct menu_slots_t
74  {
75  ItemSelection type;
76  unsigned int item;
77  };
78 
79  class IBaseMenu;
80  class IMenuPanel;
81  class IMenuHandler;
82 
87  {
88  unsigned int apiVers;
91  unsigned int firstItem;
92  unsigned int lastItem;
93  unsigned int item_on_page;
95  };
96 
97  #define ITEMDRAW_DEFAULT (0)
98  #define ITEMDRAW_DISABLED (1<<0)
99  #define ITEMDRAW_RAWLINE (1<<1)
100  #define ITEMDRAW_NOTEXT (1<<2)
101  #define ITEMDRAW_SPACER (1<<3)
102  #define ITEMDRAW_IGNORE ((1<<1)|(1<<2))
103  #define ITEMDRAW_CONTROL (1<<4)
108  struct ItemDrawInfo
109  {
110  ItemDrawInfo(const char *DISPLAY=NULL, unsigned int STYLE=ITEMDRAW_DEFAULT,
111  unsigned int FLAGS=0, const char *HELPTEXT=NULL)
112  : display(DISPLAY), style(STYLE)
113  {
114  }
115  const char *display;
116  unsigned int style;
117  };
118 
123  {
124  unsigned int num_clients;
125  unsigned int num_votes;
127  {
128  int client;
129  int item;
130  } *client_list;
131  unsigned int num_items;
133  {
134  unsigned int item;
135  unsigned int count;
136  } *item_list;
138  };
139 
143  enum MenuCancelReason
144  {
145  MenuCancel_Disconnected = -1,
146  MenuCancel_Interrupted = -2,
147  MenuCancel_Exit = -3,
148  MenuCancel_NoDisplay = -4,
149  MenuCancel_Timeout = -5,
150  MenuCancel_ExitBack = -6,
151  };
152 
156  enum MenuEndReason
157  {
158  MenuEnd_Selected = 0,
159  MenuEnd_VotingDone = -1,
160  MenuEnd_VotingCancelled = -2,
161  MenuEnd_Cancelled = -3,
162  MenuEnd_Exit = -4,
163  MenuEnd_ExitBack = -5,
164  };
165 
169  enum VoteCancelReason
170  {
171  VoteCancel_Generic = -1,
172  VoteCancel_NoVotes = -2,
173  };
174 
175  #define MENU_NO_PAGINATION 0
176  #define MENU_TIME_FOREVER 0
178  #define MENUFLAG_BUTTON_EXIT (1<<0)
179  #define MENUFLAG_BUTTON_EXITBACK (1<<1)
180  #define MENUFLAG_NO_SOUND (1<<2)
181  #define MENUFLAG_BUTTON_NOVOTE (1<<3)
183  #define VOTEFLAG_NO_REVOTES (1<<0)
188  enum MenuOption
189  {
190  MenuOption_IntroMessage,
193  MenuOption_IntroColor,
196  MenuOption_Priority,
197  };
198 
202  enum MenuSource
203  {
204  MenuSource_None = 0,
205  MenuSource_External = 1,
206  MenuSource_BaseMenu = 2,
207  MenuSource_Display = 3,
208  };
209 
210  class IMenuStyle;
211 
216  {
217  public:
224  virtual IMenuStyle *GetParentStyle() =0;
225 
229  virtual void Reset() =0;
230 
238  virtual void DrawTitle(const char *text, bool onlyIfEmpty=false) =0;
239 
248  virtual unsigned int DrawItem(const ItemDrawInfo &item) =0;
249 
256  virtual bool DrawRawLine(const char *rawline) =0;
257 
265  virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
266 
274  virtual bool CanDrawItem(unsigned int drawFlags) =0;
275 
284  virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time) =0;
285 
289  virtual void DeleteThis() =0;
290 
301  virtual bool SetSelectableKeys(unsigned int keymap) =0;
302 
308  virtual unsigned int GetCurrentKey() =0;
309 
318  virtual bool SetCurrentKey(unsigned int key) =0;
319 
328  virtual int GetAmountRemaining() =0;
329 
335  virtual unsigned int GetApproxMemUsage() =0;
336 
343  virtual bool DirectSet(const char *str) =0;
344  };
345 
351  {
352  public:
358  virtual unsigned int GetStyleAPIVersion()
359  {
360  return SMINTERFACE_MENUMANAGER_VERSION;
361  }
362 
368  virtual const char *GetStyleName() =0;
369 
377  virtual IMenuPanel *CreatePanel() =0;
378 
389  virtual IBaseMenu *CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL) =0;
390 
399  virtual unsigned int GetMaxPageItems() =0;
400 
409  virtual MenuSource GetClientMenu(int client, void **object) =0;
410 
419  virtual bool CancelClientMenu(int client, bool autoIgnore=false) =0;
420 
426  virtual Handle_t GetHandle() =0;
427 
433  virtual unsigned int GetApproxMemUsage() =0;
434 
440  virtual bool IsSupported() =0;
441  };
442 
446  class IBaseMenu
447  {
448  public:
456  virtual bool AppendItem(const char *info, const ItemDrawInfo &draw) =0;
457 
468  virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw) =0;
469 
476  virtual bool RemoveItem(unsigned int position) =0;
477 
481  virtual void RemoveAllItems() =0;
482 
490  virtual const char *GetItemInfo(unsigned int position, ItemDrawInfo *draw) =0;
491 
497  virtual unsigned int GetItemCount() =0;
498 
510  virtual bool SetPagination(unsigned int itemsPerPage) =0;
511 
517  virtual unsigned int GetPagination() =0;
518 
524  virtual IMenuStyle *GetDrawStyle() =0;
525 
531  virtual void SetDefaultTitle(const char *message) =0;
532 
538  virtual const char *GetDefaultTitle() =0;
539 
547  virtual bool SetExtOption(MenuOption option, const void *valuePtr) =0;
548 
557  virtual IMenuPanel *CreatePanel() =0;
558 
567  virtual bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL) =0;
568 
577  virtual void Destroy(bool releaseHandle=true) =0;
578 
586  virtual void Cancel() =0;
587 
594  virtual Handle_t GetHandle() =0;
595 
601  virtual unsigned int GetMenuOptionFlags() =0;
602 
608  virtual void SetMenuOptionFlags(unsigned int flags) =0;
609 
615  virtual IMenuHandler *GetHandler() =0;
616 
628  virtual bool DisplayAtItem(int client,
629  unsigned int time,
630  unsigned int start_item,
631  IMenuHandler *alt_handler=NULL) =0;
632 
638  virtual unsigned int GetApproxMemUsage() =0;
639  };
640 
645  {
646  public:
652  virtual unsigned int GetMenuAPIVersion2()
653  {
654  return SMINTERFACE_MENUMANAGER_VERSION;
655  }
656 
662  virtual void OnMenuStart(IBaseMenu *menu)
663  {
664  }
665 
674  virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
675  {
676  }
677 
685  virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
686  {
687  }
688 
696  virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
697  {
698  }
699 
706  virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
707  {
708  }
709 
715  virtual void OnMenuDestroy(IBaseMenu *menu)
716  {
717  }
718 
727  virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
728  {
729  }
730 
742  virtual unsigned int OnMenuDisplayItem(IBaseMenu *menu,
743  int client,
744  IMenuPanel *panel,
745  unsigned int item,
746  const ItemDrawInfo &dr)
747  {
748  return 0;
749  }
750 
758  virtual void OnMenuVoteStart(IBaseMenu *menu)
759  {
760  }
761 
773  virtual void OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
774  {
775  }
776 
785  virtual void OnMenuVoteCancel(IBaseMenu *menu, VoteCancelReason reason)
786  {
787  }
788 
796  virtual bool OnSetHandlerOption(const char *option, const void *data)
797  {
798  return false;
799  }
800 
812  virtual void OnMenuSelect2(IBaseMenu *menu,
813  int client,
814  unsigned int item,
815  unsigned int item_on_page)
816  {
817  }
818  };
819 
823  class IMenuManager : public SMInterface
824  {
825  public:
826  virtual const char *GetInterfaceName()
827  {
829  }
830  virtual unsigned int GetInterfaceVersion()
831  {
832  return SMINTERFACE_MENUMANAGER_VERSION;
833  }
834  virtual bool IsVersionCompatible(unsigned int version)
835  {
836  if (version < 11 || version > GetInterfaceVersion())
837  {
838  return false;
839  }
840  return true;
841  }
842  public:
849  virtual IMenuStyle *FindStyleByName(const char *name) =0;
850 
856  virtual IMenuStyle *GetDefaultStyle() =0;
857 
873  virtual IMenuPanel *RenderMenu(int client, menu_states_t &states, ItemOrder order) =0;
874 
881  virtual void CancelMenu(IBaseMenu *menu) =0;
882 
893  virtual bool StartVote(IBaseMenu *menu,
894  unsigned int num_clients,
895  int clients[],
896  unsigned int max_time,
897  unsigned int flags=0) =0;
898 
904  virtual bool IsVoteInProgress() =0;
905 
909  virtual void CancelVoting() =0;
910 
917  virtual unsigned int GetRemainingVoteDelay() =0;
918 
926  virtual bool IsClientInVotePool(int client) =0;
927 
934  virtual bool RedrawClientVoteMenu(int client) =0;
935 
943  virtual bool RedrawClientVoteMenu2(int client, bool revotes) =0;
944  };
945 }
946 
947 #endif //_INCLUDE_SOURCEMOD_MENU_SYSTEM_H_
948 
unsigned int count
Definition: IMenuManager.h:135
virtual IMenuPanel * CreatePanel()=0
Creates a new IMenuPanel object using extended options specific to the IMenuStyle parent...
virtual void OnMenuDisplay(IBaseMenu *menu, int client, IMenuPanel *display)
Called before a menu is being displayed. This is where you can set an alternate title on the menu...
Definition: IMenuManager.h:674
virtual bool InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)=0
Inserts an item into the menu before a certain position; the new item will be at the given position a...
virtual IMenuStyle * FindStyleByName(const char *name)=0
Finds a style by name.
IMenuHandler * mh
Definition: IMenuManager.h:90
virtual void SetMenuOptionFlags(unsigned int flags)=0
Sets menu option flags.
virtual unsigned int GetMaxPageItems()=0
Returns the maximum number of items per page.
Manages menu creation and displaying.
Definition: IMenuManager.h:823
unsigned int item
Definition: IMenuManager.h:134
virtual unsigned int GetRemainingVoteDelay()=0
Returns the remaining vote delay from the last menu. This delay is a suggestion for all public votes...
Defines the interface for creating, reading, and removing Handles.
virtual const char * GetInterfaceName()
Must return a string defining the interface's unique name.
Definition: IMenuManager.h:826
virtual void CancelMenu(IBaseMenu *menu)=0
Cancels a menu. Calls IBaseMenu::Cancel() after doing some preparatory work. This should always be us...
virtual IMenuStyle * GetParentStyle()=0
Returns the parent IMenuStyle pointer.
virtual bool SetExtOption(MenuOption option, const void *valuePtr)=0
Sets an extended menu option.
virtual unsigned int GetInterfaceVersion()
Must return an integer defining the interface's version.
Definition: IMenuManager.h:830
virtual void OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
Called when an item is selected.
Definition: IMenuManager.h:685
virtual const char * GetItemInfo(unsigned int position, ItemDrawInfo *draw)=0
Returns an item's info.
virtual unsigned int GetApproxMemUsage()=0
For the Handle system, returns approximate memory usage.
virtual bool SetPagination(unsigned int itemsPerPage)=0
Sets the menu's pagination,.
virtual bool SetSelectableKeys(unsigned int keymap)=0
Sets the selectable key map. Returns false if the function is not supported.
virtual bool CanDrawItem(unsigned int drawFlags)=0
Returns whether the display is capable of rendering an item with the given flags. ...
virtual Handle_t GetHandle()=0
Returns a Handle the IMenuStyle object.
Contains information about a vote result.
Definition: IMenuManager.h:122
virtual bool StartVote(IBaseMenu *menu, unsigned int num_clients, int clients[], unsigned int max_time, unsigned int flags=0)=0
Displays a menu as a vote.
virtual unsigned int GetItemCount()=0
Returns the number of items.
unsigned int num_votes
Definition: IMenuManager.h:125
Defines the Share System, responsible for shared resources and dependencies.
virtual IBaseMenu * CreateMenu(IMenuHandler *handler, IdentityToken_t *pOwner=NULL)=0
Creates an IBaseMenu object of this style.
virtual unsigned int GetStyleAPIVersion()
Returns the style API version.
Definition: IMenuManager.h:358
struct SourceMod::menu_vote_result_t::menu_client_vote_t * client_list
unsigned int item_on_page
Definition: IMenuManager.h:93
virtual IMenuStyle * GetDefaultStyle()=0
Returns the default draw style Core is using.
unsigned int apiVers
Definition: IMenuManager.h:88
Pairs an item type with an item menu position.
Definition: IMenuManager.h:73
virtual void SetDefaultTitle(const char *message)=0
Sets the menu's display title/message.
const char * display
Definition: IMenuManager.h:115
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
virtual Handle_t GetHandle()=0
Returns the menu's Handle. The Handle is automatically removed when the menu is destroyed.
virtual void OnMenuDestroy(IBaseMenu *menu)
Called when the menu object is destroyed.
Definition: IMenuManager.h:715
virtual void DrawTitle(const char *text, bool onlyIfEmpty=false)=0
Sets how the title should be drawn.
unsigned int num_clients
Definition: IMenuManager.h:124
virtual void OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *results)
Called when a vote ends. This is automatically called by the wrapper, and never needs to called from ...
Definition: IMenuManager.h:773
virtual IMenuPanel * RenderMenu(int client, menu_states_t &states, ItemOrder order)=0
Given a set of menu states, converts it to an IMenuPanel object.
unsigned int num_items
Definition: IMenuManager.h:131
Information about item drawing.
Definition: IMenuManager.h:108
virtual unsigned int GetPagination()=0
Returns an item's pagination.
menu_slots_t slots[11]
Definition: IMenuManager.h:94
ItemSelection type
Definition: IMenuManager.h:75
unsigned int item
Definition: IMenuManager.h:76
virtual unsigned int GetCurrentKey()=0
Returns the current key position.
virtual unsigned int GetApproxMemUsage()=0
For the Handle system, returns approximate memory usage.
virtual bool DrawRawLine(const char *rawline)=0
Draws a raw line of text, if supported. The line does not need to be newline terminated.
virtual bool SetCurrentKey(unsigned int key)=0
Sets the next key position. This cannot be used to traverse backwards.
virtual bool IsClientInVotePool(int client)=0
Returns whether a client is in the "allowed to vote" pool determined by the initial call to StartVote...
virtual void OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
An active menu display was dropped from a client.
Definition: IMenuManager.h:696
unsigned int firstItem
Definition: IMenuManager.h:91
virtual void OnMenuVoteStart(IBaseMenu *menu)
Called when a vote has been started and displayed to clients. This is called after OnMenuStart() and ...
Definition: IMenuManager.h:758
#define SMINTERFACE_MENUMANAGER_NAME
Definition: IMenuManager.h:38
virtual unsigned int GetMenuOptionFlags()=0
Returns menu option flags.
virtual void OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsigned int item_on_page)
Called when an item is selected.
Definition: IMenuManager.h:812
virtual const char * GetStyleName()=0
Returns the name of the menu style.
Sets how a raw menu should be drawn.
Definition: IMenuManager.h:215
Describes a "MenuStyle" system which manages menu drawing and construction.
Definition: IMenuManager.h:350
int item
Definition: IMenuManager.h:129
virtual bool IsSupported()=0
Returns whether or not this style is supported by the current game.
virtual bool AppendItem(const char *info, const ItemDrawInfo &draw)=0
Appends an item to the end of a menu.
virtual int GetAmountRemaining()=0
Returns the number of characters that can be added to the menu. The internal buffer is truncated if o...
virtual MenuSource GetClientMenu(int client, void **object)=0
Returns whether or not a client is viewing a menu.
virtual bool CancelClientMenu(int client, bool autoIgnore=false)=0
Cancels a client's menu.
struct SourceMod::menu_vote_result_t::menu_item_vote_t * item_list
virtual void RemoveAllItems()=0
Removes all items from the menu.
unsigned int lastItem
Definition: IMenuManager.h:92
virtual bool DisplayAtItem(int client, unsigned int time, unsigned int start_item, IMenuHandler *alt_handler=NULL)=0
Sends the menu to a client, starting from the given item number.
virtual void OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, unsigned int &style)
Called when requesting how to render an item.
Definition: IMenuManager.h:727
Describes menu display information.
Definition: IMenuManager.h:86
virtual const char * GetDefaultTitle()=0
Returns the menu's display/title message.
virtual void CancelVoting()=0
Cancels the vote in progress. This calls IBaseMenu::Cancel().
virtual IMenuHandler * GetHandler()=0
Returns the menu's handler.
virtual void OnMenuStart(IBaseMenu *menu)
A display/selection cycle has started.
Definition: IMenuManager.h:662
unsigned int style
Definition: IMenuManager.h:116
virtual bool IsVoteInProgress()=0
Returns whether or not a vote is in progress.
Definition: IAdminSystem.h:63
virtual unsigned int OnMenuDisplayItem(IBaseMenu *menu, int client, IMenuPanel *panel, unsigned int item, const ItemDrawInfo &dr)
Called when drawing item text.
Definition: IMenuManager.h:742
virtual void OnMenuVoteCancel(IBaseMenu *menu, VoteCancelReason reason)
Called when a vote is cancelled. If this is called, then OnMenuVoteResults() will not be called...
Definition: IMenuManager.h:785
virtual bool DirectSet(const char *str)=0
Sets panel content directly.
virtual bool RedrawClientVoteMenu2(int client, bool revotes)=0
Redraws the current vote menu to a client in the voting pool.
virtual bool SendDisplay(int client, IMenuHandler *handler, unsigned int time)=0
Sends the menu display to a client.
virtual bool Display(int client, unsigned int time, IMenuHandler *alt_handler=NULL)=0
Sends the menu to a client.
virtual unsigned int DrawItem(const ItemDrawInfo &item)=0
Adds an item to the menu and returns the position (1-10).
virtual unsigned int GetApproxMemUsage()=0
For the Handle system, returns approximate memory usage.
virtual void DeleteThis()=0
Destroys the display object.
virtual IMenuStyle * GetDrawStyle()=0
Returns the menu style.
virtual bool IsVersionCompatible(unsigned int version)
Must return whether the requested version number is backwards compatible. Note: This can be overridde...
Definition: IMenuManager.h:834
virtual bool SetExtOption(MenuOption option, const void *valuePtr)=0
Sets an extended menu option.
#define ITEMDRAW_DEFAULT
Definition: IMenuManager.h:97
virtual void Reset()=0
Resets/clears the cached display text.
virtual bool OnSetHandlerOption(const char *option, const void *data)
Call to set private handler stuff.
Definition: IMenuManager.h:796
IBaseMenu * menu
Definition: IMenuManager.h:89
High-level interface for building menus.
Definition: IMenuManager.h:446
virtual IMenuPanel * CreatePanel()=0
Creates an IMenuPanel object.
virtual unsigned int GetMenuAPIVersion2()
Returns the menu api verison.
Definition: IMenuManager.h:652
virtual void OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
A display/selection cycle has ended.
Definition: IMenuManager.h:706
Contains callbacks for menu actions.
Definition: IMenuManager.h:644
virtual void Destroy(bool releaseHandle=true)=0
Destroys the menu and frees all associated resources.
virtual bool RemoveItem(unsigned int position)=0
Removes an item from the menu.
virtual void Cancel()=0
Cancels the menu on all client's displays. While the menu is being cancelled, the menu may not be re-...
virtual bool RedrawClientVoteMenu(int client)=0
Redraws the current vote menu to a client in the voting pool.
int client
Definition: IMenuManager.h:128