1.1 --- a/core/MenuManager.cpp Sun May 13 22:36:22 2007 +0000
1.2 +++ b/core/MenuManager.cpp Mon May 14 04:46:06 2007 +0000
1.3 @@ -21,6 +21,7 @@
1.4 #include "PlayerManager.h"
1.5 #include "MenuStyle_Valve.h"
1.6 #include "ShareSys.h"
1.7 +#include "HandleSys.h"
1.8
1.9 MenuManager g_Menus;
1.10
1.11 @@ -150,10 +151,24 @@
1.12 void MenuManager::OnSourceModAllInitialized()
1.13 {
1.14 g_ShareSys.AddInterface(NULL, this);
1.15 +
1.16 + HandleAccess access;
1.17 + g_HandleSys.InitAccessDefaults(NULL, &access);
1.18 +
1.19 + /* Deny cloning to menus */
1.20 + access.access[HandleAccess_Clone] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
1.21 + m_MenuType = g_HandleSys.CreateType("IBaseMenu", this, 0, NULL, &access, g_pCoreIdent, NULL);
1.22 +
1.23 + /* Also deny deletion to styles */
1.24 + access.access[HandleAccess_Delete] = HANDLE_RESTRICT_OWNER|HANDLE_RESTRICT_IDENTITY;
1.25 + m_StyleType = g_HandleSys.CreateType("IMenuStyle", this, 0, NULL, &access, g_pCoreIdent, NULL);
1.26 }
1.27
1.28 void MenuManager::OnSourceModAllShutdown()
1.29 {
1.30 + g_HandleSys.RemoveType(m_MenuType, g_pCoreIdent);
1.31 + g_HandleSys.RemoveType(m_StyleType, g_pCoreIdent);
1.32 +
1.33 while (!m_BroadcastHandlers.empty())
1.34 {
1.35 delete m_BroadcastHandlers.front();
1.36 @@ -167,6 +182,57 @@
1.37 }
1.38 }
1.39
1.40 +void MenuManager::OnHandleDestroy(HandleType_t type, void *object)
1.41 +{
1.42 + if (type == m_MenuType)
1.43 + {
1.44 + IBaseMenu *menu = (IBaseMenu *)object;
1.45 + menu->Destroy(false);
1.46 + } else if (type == m_StyleType) {
1.47 + /* Do nothing */
1.48 + }
1.49 +}
1.50 +
1.51 +Handle_t MenuManager::CreateMenuHandle(IBaseMenu *menu, IdentityToken_t *pOwner)
1.52 +{
1.53 + if (m_MenuType == NO_HANDLE_TYPE)
1.54 + {
1.55 + return BAD_HANDLE;
1.56 + }
1.57 +
1.58 + return g_HandleSys.CreateHandle(m_MenuType, menu, pOwner, g_pCoreIdent, NULL);
1.59 +}
1.60 +
1.61 +Handle_t MenuManager::CreateStyleHandle(IMenuStyle *style)
1.62 +{
1.63 + if (m_StyleType == NO_HANDLE_TYPE)
1.64 + {
1.65 + return BAD_HANDLE;
1.66 + }
1.67 +
1.68 + return g_HandleSys.CreateHandle(m_StyleType, style, g_pCoreIdent, g_pCoreIdent, NULL);
1.69 +}
1.70 +
1.71 +HandleError MenuManager::ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
1.72 +{
1.73 + HandleSecurity sec;
1.74 +
1.75 + sec.pIdentity = g_pCoreIdent;
1.76 + sec.pOwner = NULL;
1.77 +
1.78 + return g_HandleSys.ReadHandle(handle, m_MenuType, &sec, (void **)menu);
1.79 +}
1.80 +
1.81 +HandleError MenuManager::ReadStyleHandle(Handle_t handle, IMenuStyle **style)
1.82 +{
1.83 + HandleSecurity sec;
1.84 +
1.85 + sec.pIdentity = g_pCoreIdent;
1.86 + sec.pOwner = g_pCoreIdent;
1.87 +
1.88 + return g_HandleSys.ReadHandle(handle, m_StyleType, &sec, (void **)style);
1.89 +}
1.90 +
1.91 bool MenuManager::SetDefaultStyle(IMenuStyle *style)
1.92 {
1.93 if (!style)
1.94 @@ -503,6 +569,13 @@
1.95 ItemDrawInfo padItem(NULL, ITEMDRAW_SPACER);
1.96 if (exitButton || (displayNext || displayPrev))
1.97 {
1.98 + /* If there are no control options,
1.99 + * Instead just pad with invisible slots.
1.100 + */
1.101 + if (!displayPrev && !displayPrev)
1.102 + {
1.103 + padItem.style = ITEMDRAW_NOTEXT;
1.104 + }
1.105 /* Add spacers so we can pad to the end */
1.106 for (unsigned int i=0; i<padding; i++)
1.107 {
1.108 @@ -585,6 +658,7 @@
1.109 return display;
1.110 }
1.111
1.112 +#if 0
1.113 unsigned int MenuManager::BroadcastMenu(IBaseMenu *menu,
1.114 IMenuHandler *handler,
1.115 int clients[],
1.116 @@ -683,6 +757,7 @@
1.117
1.118 return total;
1.119 }
1.120 +#endif
1.121
1.122 void MenuManager::FreeBroadcastHandler(BroadcastHandler *bh)
1.123 {