From 93bb5ebda013e580d59cf9e27d2d6b09c38a0e22 Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:42:21 +0700 Subject: [PATCH] Allow sending panels to SourceTV client via settings --- core/MenuStyle_Base.cpp | 14 +++++++++++++- core/MenuStyle_Radio.cpp | 11 +++++++++++ core/MenuStyle_Radio.h | 3 +++ core/MenuStyle_Valve.h | 2 ++ core/logic/smn_menus.cpp | 2 ++ plugins/include/menus.inc | 3 ++- public/IMenuManager.h | 12 ++++++++++++ 7 files changed, 45 insertions(+), 2 deletions(-) diff --git a/core/MenuStyle_Base.cpp b/core/MenuStyle_Base.cpp index b35142fce..7d961503a 100644 --- a/core/MenuStyle_Base.cpp +++ b/core/MenuStyle_Base.cpp @@ -419,7 +419,19 @@ bool BaseMenuStyle::DoClientMenu(int client, IMenuPanel *menu, IMenuHandler *mh, time); #endif CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame()) + if (!pPlayer || !pPlayer->IsInGame()) + { + return false; + } + + if (pPlayer->IsSourceTV()) + { + if (!menu->IsAllowSendToSourceTV()) + { + return false; + } + } + else if (pPlayer->IsFakeClient()) { return false; } diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 035219e32..7e46eb6fb 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -332,6 +332,7 @@ void CRadioDisplay::Reset() m_Title.assign(""); m_NextPos = 1; keys = 0; + m_SendToSourceTV = false; } bool CRadioDisplay::DirectSet(const char *str) @@ -359,6 +360,16 @@ bool CRadioDisplay::SetCurrentKey(unsigned int key) return true; } +bool CRadioDisplay::IsAllowSendToSourceTV() +{ + return m_SendToSourceTV; +} + +void CRadioDisplay::SetSendToSourceTV(bool type) +{ + m_SendToSourceTV = type; +} + bool CRadioDisplay::SendDisplay(int client, IMenuHandler *handler, unsigned int time) { return g_RadioMenuStyle.DoClientMenu(client, this, handler, time); diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index afb356ef0..6c41838e3 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -132,11 +132,14 @@ public: //IMenuPanel int GetAmountRemaining(); unsigned int GetApproxMemUsage(); bool DirectSet(const char *str); + bool IsAllowSendToSourceTV(); + void SetSendToSourceTV(bool type); private: String m_BufferText; String m_Title; unsigned int m_NextPos; int keys; + bool m_SendToSourceTV; }; class CRadioMenu : public CBaseMenu diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index 03fa1226f..a81311491 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -109,6 +109,8 @@ public: int GetAmountRemaining(); unsigned int GetApproxMemUsage(); bool DirectSet(const char *str) { return false; } + bool IsAllowSendToSourceTV() { return false; } + void SetSendToSourceTV(bool type) {} private: KeyValues *m_pKv; unsigned int m_NextPos; diff --git a/core/logic/smn_menus.cpp b/core/logic/smn_menus.cpp index 152215ebe..7f6503cbe 100644 --- a/core/logic/smn_menus.cpp +++ b/core/logic/smn_menus.cpp @@ -1308,6 +1308,8 @@ static cell_t SendPanelToClient(IPluginContext *pContext, const cell_t *params) } CPanelHandler *handler = g_MenuHelpers.GetPanelHandler(pFunction); + panel->SetSendToSourceTV((params[0] >= 5) ? params[5] : false); + if (!panel->SendDisplay(params[2], handler, params[4])) { g_MenuHelpers.FreePanelHandler(handler); diff --git a/plugins/include/menus.inc b/plugins/include/menus.inc index b1cd6673a..e5d14c635 100644 --- a/plugins/include/menus.inc +++ b/plugins/include/menus.inc @@ -1061,10 +1061,11 @@ native bool SetPanelKeys(Handle panel, int keys); * @param client A client to draw to. * @param handler The MenuHandler function to catch actions with. * @param time Time to hold the menu for. + * @param sendToSTV Allow this menu to be sent to SourceTV * @return True on success, false on failure. * @error Invalid Handle. */ -native bool SendPanelToClient(Handle panel, int client, MenuHandler handler, int time); +native bool SendPanelToClient(Handle panel, int client, MenuHandler handler, int time, bool sendToSTV = false); /** * @brief Returns the amount of text the menu can still hold. If this is diff --git a/public/IMenuManager.h b/public/IMenuManager.h index 9b0978b6e..aa0eaced7 100644 --- a/public/IMenuManager.h +++ b/public/IMenuManager.h @@ -341,6 +341,18 @@ namespace SourceMod * @return True if supported, otherwise false. */ virtual bool DirectSet(const char *str) =0; + + /** + * @brief Enabled or disabled sending menus to SourceTV + * + * @return True if enabled, otherwise false. + */ + virtual bool IsAllowSendToSourceTV() = 0; + + /** + * @brief Enable or disable sending menus to SourceTV + */ + virtual void SetSendToSourceTV(bool type) = 0; }; /**