Move menu natives from core to logic

This commit is contained in:
Nicholas Hastings 2014-09-04 18:01:12 -07:00
parent a1dc1101f7
commit ad7d920ce0
11 changed files with 146 additions and 90 deletions

View File

@ -9,7 +9,6 @@ project.sources += [
'sm_stringutil.cpp', 'sm_stringutil.cpp',
'MenuVoting.cpp', 'MenuVoting.cpp',
'smn_events.cpp', 'smn_events.cpp',
'smn_menus.cpp',
'CDataPack.cpp', 'CDataPack.cpp',
'frame_hooks.cpp', 'frame_hooks.cpp',
'smn_nextmap.cpp', 'smn_nextmap.cpp',

View File

@ -261,15 +261,6 @@ CRadioDisplay *CRadioStyle::MakeRadioDisplay(CRadioMenu *menu)
return display; return display;
} }
IMenuPanel *CRadioStyle::MakeRadioDisplay(const char *str, int keys)
{
CRadioDisplay *pPanel = MakeRadioDisplay(NULL);
pPanel->DirectSet(str, keys);
return pPanel;
}
void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display) void CRadioStyle::FreeRadioDisplay(CRadioDisplay *display)
{ {
m_FreeDisplays.push(display); m_FreeDisplays.push(display);
@ -336,11 +327,12 @@ void CRadioDisplay::Reset()
keys = 0; keys = 0;
} }
void CRadioDisplay::DirectSet(const char *str, int keymap) bool CRadioDisplay::DirectSet(const char *str)
{ {
m_Title.clear(); m_Title.clear();
m_BufferText.assign(str); m_BufferText.assign(str);
keys = keymap;
return true;
} }
unsigned int CRadioDisplay::GetCurrentKey() unsigned int CRadioDisplay::GetCurrentKey()

View File

@ -101,7 +101,6 @@ public:
CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL); CRadioDisplay *MakeRadioDisplay(CRadioMenu *menu=NULL);
void FreeRadioDisplay(CRadioDisplay *display); void FreeRadioDisplay(CRadioDisplay *display);
CRadioMenuPlayer *GetRadioMenuPlayer(int client); CRadioMenuPlayer *GetRadioMenuPlayer(int client);
IMenuPanel *MakeRadioDisplay(const char *str, int keys);
private: private:
CRadioMenuPlayer *m_players; CRadioMenuPlayer *m_players;
CStack<CRadioDisplay *> m_FreeDisplays; CStack<CRadioDisplay *> m_FreeDisplays;
@ -129,8 +128,7 @@ public: //IMenuPanel
bool SetCurrentKey(unsigned int key); bool SetCurrentKey(unsigned int key);
int GetAmountRemaining(); int GetAmountRemaining();
unsigned int GetApproxMemUsage(); unsigned int GetApproxMemUsage();
public: bool DirectSet(const char *str);
void DirectSet(const char *str, int keymap);
private: private:
String m_BufferText; String m_BufferText;
String m_Title; String m_Title;

View File

@ -75,6 +75,7 @@ public: //IMenuStyle
IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner); IBaseMenu *CreateMenu(IMenuHandler *pHandler, IdentityToken_t *pOwner);
unsigned int GetMaxPageItems(); unsigned int GetMaxPageItems();
unsigned int GetApproxMemUsage(); unsigned int GetApproxMemUsage();
bool IsSupported() { return true; }
private: private:
void HookCreateMessage(edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin); void HookCreateMessage(edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin);
private: private:
@ -105,6 +106,7 @@ public:
bool SetCurrentKey(unsigned int key); bool SetCurrentKey(unsigned int key);
int GetAmountRemaining(); int GetAmountRemaining();
unsigned int GetApproxMemUsage(); unsigned int GetApproxMemUsage();
bool DirectSet(const char *str) { return false; }
private: private:
KeyValues *m_pKv; KeyValues *m_pKv;
unsigned int m_NextPos; unsigned int m_NextPos;

View File

@ -68,6 +68,7 @@ binary.sources += [
'ProfileTools.cpp', 'ProfileTools.cpp',
'Logger.cpp', 'Logger.cpp',
'smn_core.cpp', 'smn_core.cpp',
'smn_menus.cpp',
] ]
if builder.target_platform == 'windows': if builder.target_platform == 'windows':
binary.sources += ['thread/WinThreads.cpp'] binary.sources += ['thread/WinThreads.cpp']

View File

@ -162,6 +162,7 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
timersys = core->timersys; timersys = core->timersys;
playerhelpers = core->playerhelpers; playerhelpers = core->playerhelpers;
gamehelpers = core->gamehelpers; gamehelpers = core->gamehelpers;
menus = core->menus;
g_pSourcePawn = *core->spe1; g_pSourcePawn = *core->spe1;
g_pSourcePawn2 = *core->spe2; g_pSourcePawn2 = *core->spe2;
SMGlobalClass::head = core->listeners; SMGlobalClass::head = core->listeners;

View File

@ -55,6 +55,7 @@ extern IGameHelpers *gamehelpers;
extern IScriptManager *scripts; extern IScriptManager *scripts;
extern IExtensionSys *extsys; extern IExtensionSys *extsys;
extern ILogger *logger; extern ILogger *logger;
extern IMenuManager *menus;
#endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */ #endif /* _INCLUDE_SOURCEMOD_COMMON_LOGIC_H_ */

View File

@ -120,6 +120,7 @@ namespace SourceMod
class IPhraseCollection; class IPhraseCollection;
class ITranslator; class ITranslator;
class IGameConfig; class IGameConfig;
class IMenuManager;
} }
class IVEngineServer; class IVEngineServer;
@ -288,6 +289,7 @@ struct sm_core_t
ITimerSystem *timersys; ITimerSystem *timersys;
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
IMenuManager *menus;
ISourcePawnEngine **spe1; ISourcePawnEngine **spe1;
ISourcePawnEngine2 **spe2; ISourcePawnEngine2 **spe2;
/* Functions */ /* Functions */

View File

@ -29,20 +29,16 @@
* Version: $Id$ * Version: $Id$
*/ */
#include "sm_globals.h" #include "common_logic.h"
#include <sh_stack.h> #include <sh_stack.h>
#include "MenuManager.h" #include <IMenuManager.h>
#include "MenuStyle_Valve.h" #include <IPlayerHelpers.h>
#include "MenuStyle_Radio.h" #include "DebugReporter.h"
#include "PlayerManager.h"
#include "sm_stringutil.h"
#include "sourcemm_api.h"
#if defined MENU_DEBUG #if defined MENU_DEBUG
#include "Logger.h" #include "Logger.h"
#endif #endif
#include "ChatTriggers.h" #include <ISourceMod.h>
#include "logic_bridge.h" #include <stdlib.h>
#include "sourcemod.h"
#if defined CreateMenu #if defined CreateMenu
#undef CreateMenu #undef CreateMenu
@ -68,6 +64,50 @@ enum MenuAction
MenuAction_DisplayItem = (1<<9), /**< the odd duck */ MenuAction_DisplayItem = (1<<9), /**< the odd duck */
}; };
static HandleError ReadMenuHandle(Handle_t handle, IBaseMenu **menu)
{
static HandleType_t menuType = NO_HANDLE_TYPE;
if (menuType == NO_HANDLE_TYPE && !handlesys->FindHandleType("IBaseMenu", &menuType))
{
// This should never happen so exact error doesn't matter.
return HandleError_Index;
}
HandleSecurity sec;
sec.pIdentity = g_pCoreIdent;
sec.pOwner = NULL;
return handlesys->ReadHandle(handle, menuType, &sec, (void **)menu);
}
static HandleError ReadStyleHandle(Handle_t handle, IMenuStyle **style)
{
static HandleType_t styleType = NO_HANDLE_TYPE;
if (styleType == NO_HANDLE_TYPE && !handlesys->FindHandleType("IMenuStyle", &styleType))
{
// This should never happen so exact error doesn't matter.
return HandleError_Index;
}
HandleSecurity sec;
sec.pIdentity = g_pCoreIdent;
sec.pOwner = g_pCoreIdent;
return handlesys->ReadHandle(handle, styleType, &sec, (void **)style);
}
static IMenuStyle &ValveMenuStyle()
{
static IMenuStyle *valveMenuStyle = menus->FindStyleByName("valve");
return *valveMenuStyle;
}
static IMenuStyle &RadioMenuStyle()
{
static IMenuStyle *radioMenuStyle = menus->FindStyleByName("radio");
return *radioMenuStyle;
}
class CPanelHandler : public IMenuHandler class CPanelHandler : public IMenuHandler
{ {
friend class MenuNativeHelpers; friend class MenuNativeHelpers;
@ -269,13 +309,13 @@ void CPanelHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int item)
{ {
if (m_pFunc) if (m_pFunc)
{ {
unsigned int old_reply = g_ChatTriggers.SetReplyTo(SM_REPLY_CHAT); unsigned int old_reply = playerhelpers->SetReplyTo(SM_REPLY_CHAT);
m_pFunc->PushCell(BAD_HANDLE); m_pFunc->PushCell(BAD_HANDLE);
m_pFunc->PushCell(MenuAction_Select); m_pFunc->PushCell(MenuAction_Select);
m_pFunc->PushCell(client); m_pFunc->PushCell(client);
m_pFunc->PushCell(item); m_pFunc->PushCell(item);
m_pFunc->Execute(NULL); m_pFunc->Execute(NULL);
g_ChatTriggers.SetReplyTo(old_reply); playerhelpers->SetReplyTo(old_reply);
} }
g_MenuHelpers.FreePanelHandler(this); g_MenuHelpers.FreePanelHandler(this);
} }
@ -330,18 +370,18 @@ void CMenuHandler::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item,
s_CurSelectPosition = &first_item; s_CurSelectPosition = &first_item;
unsigned int old_reply = g_ChatTriggers.SetReplyTo(SM_REPLY_CHAT); unsigned int old_reply = playerhelpers->SetReplyTo(SM_REPLY_CHAT);
DoAction(menu, MenuAction_Select, client, item); DoAction(menu, MenuAction_Select, client, item);
g_ChatTriggers.SetReplyTo(old_reply); playerhelpers->SetReplyTo(old_reply);
s_CurSelectPosition = old_pos; s_CurSelectPosition = old_pos;
} }
void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason) void CMenuHandler::OnMenuCancel(IBaseMenu *menu, int client, MenuCancelReason reason)
{ {
unsigned int old_reply = g_ChatTriggers.SetReplyTo(SM_REPLY_CHAT); unsigned int old_reply = playerhelpers->SetReplyTo(SM_REPLY_CHAT);
DoAction(menu, MenuAction_Cancel, client, (cell_t)reason); DoAction(menu, MenuAction_Cancel, client, (cell_t)reason);
g_ChatTriggers.SetReplyTo(old_reply); playerhelpers->SetReplyTo(old_reply);
} }
void CMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason) void CMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
@ -470,7 +510,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *
if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base)) if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base))
!= SP_ERROR_NONE) != SP_ERROR_NONE)
{ {
logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t)); g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t));
no_call = true; no_call = true;
} else { } else {
cell_t target_offs = sizeof(cell_t) * results->num_clients; cell_t target_offs = sizeof(cell_t) * results->num_clients;
@ -503,7 +543,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *
if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base)) if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base))
!= SP_ERROR_NONE) != SP_ERROR_NONE)
{ {
logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size); g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size);
no_call = true; no_call = true;
} else { } else {
cell_t target_offs = sizeof(cell_t) * results->num_items; cell_t target_offs = sizeof(cell_t) * results->num_items;
@ -592,14 +632,14 @@ inline IMenuStyle *GetStyleFromCell(cell_t cell)
if (cell == MenuStyle_Valve) if (cell == MenuStyle_Valve)
{ {
return &g_ValveMenuStyle; return &ValveMenuStyle();
} else if (cell == MenuStyle_Radio } else if (cell == MenuStyle_Radio
&& g_RadioMenuStyle.IsSupported()) && RadioMenuStyle().IsSupported())
{ {
return &g_RadioMenuStyle; return &RadioMenuStyle();
} }
return g_Menus.GetDefaultStyle(); return menus->GetDefaultStyle();
} }
/*********************************** /***********************************
@ -608,7 +648,7 @@ inline IMenuStyle *GetStyleFromCell(cell_t cell)
static cell_t CreateMenu(IPluginContext *pContext, const cell_t *params) static cell_t CreateMenu(IPluginContext *pContext, const cell_t *params)
{ {
IMenuStyle *style = g_Menus.GetDefaultStyle(); IMenuStyle *style = menus->GetDefaultStyle();
IPluginFunction *pFunction; IPluginFunction *pFunction;
if ((pFunction=pContext->GetFunctionById(params[1])) == NULL) if ((pFunction=pContext->GetFunctionById(params[1])) == NULL)
@ -635,7 +675,7 @@ static cell_t DisplayMenu(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -649,7 +689,7 @@ static cell_t DisplayMenuAtItem(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -659,7 +699,7 @@ static cell_t DisplayMenuAtItem(IPluginContext *pContext, const cell_t *params)
static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params) static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
{ {
if (g_Menus.IsVoteInProgress()) if (menus->IsVoteInProgress())
{ {
return pContext->ThrowNativeError("A vote is already in progress"); return pContext->ThrowNativeError("A vote is already in progress");
} }
@ -668,7 +708,7 @@ static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -682,7 +722,7 @@ static cell_t VoteMenu(IPluginContext *pContext, const cell_t *params)
flags = params[5]; flags = params[5];
} }
if (!g_Menus.StartVote(menu, params[3], addr, params[4], flags)) if (!menus->StartVote(menu, params[3], addr, params[4], flags))
{ {
return 0; return 0;
} }
@ -696,7 +736,7 @@ static cell_t AddMenuItem(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -717,7 +757,7 @@ static cell_t InsertMenuItem(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -738,7 +778,7 @@ static cell_t RemoveMenuItem(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -752,7 +792,7 @@ static cell_t RemoveAllMenuItems(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -768,7 +808,7 @@ static cell_t GetMenuItem(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -797,7 +837,7 @@ static cell_t SetMenuPagination(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -811,7 +851,7 @@ static cell_t GetMenuPagination(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -825,7 +865,7 @@ static cell_t GetMenuItemCount(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -839,13 +879,13 @@ static cell_t SetMenuTitle(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
char buffer[1024]; char buffer[1024];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2);
menu->SetDefaultTitle(buffer); menu->SetDefaultTitle(buffer);
@ -858,7 +898,7 @@ static cell_t GetMenuTitle(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -877,7 +917,7 @@ static cell_t CreatePanelFromMenu(IPluginContext *pContext, const cell_t *params
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -898,7 +938,7 @@ static cell_t GetMenuExitButton(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -912,7 +952,7 @@ static cell_t GetMenuExitBackButton(IPluginContext *pContext, const cell_t *para
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -926,7 +966,7 @@ static cell_t SetMenuExitButton(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -952,7 +992,7 @@ static cell_t SetMenuNoVoteButton(IPluginContext *pContext, const cell_t *params
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -978,7 +1018,7 @@ static cell_t SetMenuExitBackButton(IPluginContext *pContext, const cell_t *para
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -1003,19 +1043,19 @@ static cell_t CancelMenu(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
g_Menus.CancelMenu(menu); menus->CancelMenu(menu);
return 1; return 1;
} }
static cell_t IsVoteInProgress(IPluginContext *pContext, const cell_t *params) static cell_t IsVoteInProgress(IPluginContext *pContext, const cell_t *params)
{ {
return g_Menus.IsVoteInProgress() ? 1 : 0; return menus->IsVoteInProgress() ? 1 : 0;
} }
static cell_t GetMenuStyle(IPluginContext *pContext, const cell_t *params) static cell_t GetMenuStyle(IPluginContext *pContext, const cell_t *params)
@ -1024,7 +1064,7 @@ static cell_t GetMenuStyle(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -1051,12 +1091,12 @@ static cell_t CreatePanel(IPluginContext *pContext, const cell_t *params)
if (hndl != 0) if (hndl != 0)
{ {
if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None) if ((err = ReadStyleHandle(params[1], &style)) != HandleError_None)
{ {
return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
} }
} else { } else {
style = g_Menus.GetDefaultStyle(); style = menus->GetDefaultStyle();
} }
IMenuPanel *panel = style->CreatePanel(); IMenuPanel *panel = style->CreatePanel();
@ -1079,12 +1119,12 @@ static cell_t CreateMenuEx(IPluginContext *pContext, const cell_t *params)
if (hndl != 0) if (hndl != 0)
{ {
if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None) if ((err = ReadStyleHandle(params[1], &style)) != HandleError_None)
{ {
return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
} }
} else { } else {
style = g_Menus.GetDefaultStyle(); style = menus->GetDefaultStyle();
} }
IPluginFunction *pFunction; IPluginFunction *pFunction;
@ -1114,12 +1154,12 @@ static cell_t GetClientMenu(IPluginContext *pContext, const cell_t *params)
if (hndl != 0) if (hndl != 0)
{ {
if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None) if ((err = ReadStyleHandle(params[1], &style)) != HandleError_None)
{ {
return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
} }
} else { } else {
style = g_Menus.GetDefaultStyle(); style = menus->GetDefaultStyle();
} }
return style->GetClientMenu(params[1], NULL); return style->GetClientMenu(params[1], NULL);
@ -1133,12 +1173,12 @@ static cell_t CancelClientMenu(IPluginContext *pContext, const cell_t *params)
if (hndl != 0) if (hndl != 0)
{ {
if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None) if ((err = ReadStyleHandle(params[1], &style)) != HandleError_None)
{ {
return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
} }
} else { } else {
style = g_Menus.GetDefaultStyle(); style = menus->GetDefaultStyle();
} }
return style->CancelClientMenu(params[1], params[2] ? true : false) ? 1 : 0; return style->CancelClientMenu(params[1], params[2] ? true : false) ? 1 : 0;
@ -1152,12 +1192,12 @@ static cell_t GetMaxPageItems(IPluginContext *pContext, const cell_t *params)
if (hndl != 0) if (hndl != 0)
{ {
if ((err=g_Menus.ReadStyleHandle(params[1], &style)) != HandleError_None) if ((err = ReadStyleHandle(params[1], &style)) != HandleError_None)
{ {
return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("MenuStyle handle %x is invalid (error %d)", hndl, err);
} }
} else { } else {
style = g_Menus.GetDefaultStyle(); style = menus->GetDefaultStyle();
} }
return style->GetMaxPageItems(); return style->GetMaxPageItems();
@ -1354,7 +1394,7 @@ static cell_t GetMenuOptionFlags(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -1368,7 +1408,7 @@ static cell_t SetMenuOptionFlags(IPluginContext *pContext, const cell_t *params)
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -1380,12 +1420,12 @@ static cell_t SetMenuOptionFlags(IPluginContext *pContext, const cell_t *params)
static cell_t CancelVote(IPluginContext *pContxt, const cell_t *params) static cell_t CancelVote(IPluginContext *pContxt, const cell_t *params)
{ {
if (!g_Menus.IsVoteInProgress()) if (!menus->IsVoteInProgress())
{ {
return pContxt->ThrowNativeError("No vote is in progress"); return pContxt->ThrowNativeError("No vote is in progress");
} }
g_Menus.CancelVoting(); menus->CancelVoting();
return 1; return 1;
} }
@ -1396,7 +1436,7 @@ static cell_t SetVoteResultCallback(IPluginContext *pContext, const cell_t *para
HandleError err; HandleError err;
IBaseMenu *menu; IBaseMenu *menu;
if ((err=g_Menus.ReadMenuHandle(params[1], &menu)) != HandleError_None) if ((err = ReadMenuHandle(params[1], &menu)) != HandleError_None)
{ {
return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err); return pContext->ThrowNativeError("Menu handle %x is invalid (error %d)", hndl, err);
} }
@ -1422,7 +1462,7 @@ static cell_t SetVoteResultCallback(IPluginContext *pContext, const cell_t *para
static cell_t CheckVoteDelay(IPluginContext *pContext, const cell_t *params) static cell_t CheckVoteDelay(IPluginContext *pContext, const cell_t *params)
{ {
return g_Menus.GetRemainingVoteDelay(); return menus->GetRemainingVoteDelay();
} }
static cell_t GetMenuSelectionPosition(IPluginContext *pContext, const cell_t *params) static cell_t GetMenuSelectionPosition(IPluginContext *pContext, const cell_t *params)
@ -1441,17 +1481,17 @@ static cell_t IsClientInVotePool(IPluginContext *pContext, const cell_t *params)
IGamePlayer *pPlayer; IGamePlayer *pPlayer;
client = params[1]; client = params[1];
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) if ((pPlayer = playerhelpers->GetGamePlayer(client)) == NULL)
{ {
return pContext->ThrowNativeError("Invalid client index %d", client); return pContext->ThrowNativeError("Invalid client index %d", client);
} }
if (!g_Menus.IsVoteInProgress()) if (!menus->IsVoteInProgress())
{ {
return pContext->ThrowNativeError("No vote is in progress"); return pContext->ThrowNativeError("No vote is in progress");
} }
return g_Menus.IsClientInVotePool(client) ? 1 : 0; return menus->IsClientInVotePool(client) ? 1 : 0;
} }
static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *params) static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *params)
@ -1460,17 +1500,17 @@ static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *param
IGamePlayer *pPlayer; IGamePlayer *pPlayer;
client = params[1]; client = params[1];
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) if ((pPlayer = playerhelpers->GetGamePlayer(client)) == NULL)
{ {
return pContext->ThrowNativeError("Invalid client index %d", client); return pContext->ThrowNativeError("Invalid client index %d", client);
} }
if (!g_Menus.IsVoteInProgress()) if (!menus->IsVoteInProgress())
{ {
return pContext->ThrowNativeError("No vote is in progress"); return pContext->ThrowNativeError("No vote is in progress");
} }
if (!g_Menus.IsClientInVotePool(client)) if (!menus->IsClientInVotePool(client))
{ {
return pContext->ThrowNativeError("Client is not in the voting pool"); return pContext->ThrowNativeError("Client is not in the voting pool");
} }
@ -1481,7 +1521,7 @@ static cell_t RedrawClientVoteMenu(IPluginContext *pContext, const cell_t *param
revote = false; revote = false;
} }
return g_Menus.RedrawClientVoteMenu2(client, revote) ? 1 : 0; return menus->RedrawClientVoteMenu2(client, revote) ? 1 : 0;
} }
class EmptyMenuHandler : public IMenuHandler class EmptyMenuHandler : public IMenuHandler
@ -1492,7 +1532,7 @@ public:
static cell_t InternalShowMenu(IPluginContext *pContext, const cell_t *params) static cell_t InternalShowMenu(IPluginContext *pContext, const cell_t *params)
{ {
int client = params[1]; int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client);
if (pPlayer == NULL) if (pPlayer == NULL)
{ {
@ -1503,7 +1543,7 @@ static cell_t InternalShowMenu(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("Client %d is not in game", client); return pContext->ThrowNativeError("Client %d is not in game", client);
} }
if (!g_RadioMenuStyle.IsSupported()) if (!RadioMenuStyle().IsSupported())
{ {
return pContext->ThrowNativeError("Radio menus are not supported on this mod"); return pContext->ThrowNativeError("Radio menus are not supported on this mod");
} }
@ -1511,13 +1551,16 @@ static cell_t InternalShowMenu(IPluginContext *pContext, const cell_t *params)
char *str; char *str;
pContext->LocalToString(params[2], &str); pContext->LocalToString(params[2], &str);
IMenuPanel *pPanel = g_RadioMenuStyle.MakeRadioDisplay(str, params[4]); IMenuPanel *pPanel = RadioMenuStyle().CreatePanel();
if (pPanel == NULL) if (pPanel == NULL)
{ {
return 0; return 0;
} }
pPanel->DirectSet(str);
pPanel->SetSelectableKeys(params[4]);
IMenuHandler *pHandler; IMenuHandler *pHandler;
CPanelHandler *pActualHandler = NULL; CPanelHandler *pActualHandler = NULL;
if (params[5] != -1) if (params[5] != -1)

View File

@ -43,6 +43,7 @@
#include "logic_bridge.h" #include "logic_bridge.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "HalfLife2.h" #include "HalfLife2.h"
#include "MenuManager.h"
#include "CoreConfig.h" #include "CoreConfig.h"
#include "ConCmdManager.h" #include "ConCmdManager.h"
#include "IDBDriver.h" #include "IDBDriver.h"
@ -576,6 +577,7 @@ static sm_core_t core_bridge =
&g_Timers, &g_Timers,
&g_Players, &g_Players,
&g_HL2, &g_HL2,
&g_Menus,
&g_pSourcePawn, &g_pSourcePawn,
&g_pSourcePawn2, &g_pSourcePawn2,
/* Functions */ /* Functions */

View File

@ -333,6 +333,14 @@ namespace SourceMod
* @return Approximate number of bytes being used. * @return Approximate number of bytes being used.
*/ */
virtual unsigned int GetApproxMemUsage() =0; virtual unsigned int GetApproxMemUsage() =0;
/**
* @brief Sets panel content directly
*
* @param str New panel contents.
* @return True if supported, otherwise false.
*/
virtual bool DirectSet(const char *str) =0;
}; };
/** /**
@ -423,6 +431,13 @@ namespace SourceMod
* @return Approximate number of bytes being used. * @return Approximate number of bytes being used.
*/ */
virtual unsigned int GetApproxMemUsage() =0; virtual unsigned int GetApproxMemUsage() =0;
/**
* @brief Returns whether or not this style is supported by the current game.
*
* @return True if supported, otherwise false.
*/
virtual bool IsSupported() =0;
}; };
/** /**