From 9f34a64e636e7d32b8b25ab06cf2df5de1ab5d21 Mon Sep 17 00:00:00 2001 From: Peter Covington Date: Fri, 29 Dec 2023 14:08:13 -0500 Subject: [PATCH] Vgui screens now try to pass panel commands to the entity that created them --- sp/src/game/server/baseentity.h | 4 +++- sp/src/game/server/vguiscreen.cpp | 17 ++++++++++++++++- sp/src/game/server/vguiscreen.h | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sp/src/game/server/baseentity.h b/sp/src/game/server/baseentity.h index 3da44bc7..7cd4670c 100644 --- a/sp/src/game/server/baseentity.h +++ b/sp/src/game/server/baseentity.h @@ -869,7 +869,9 @@ public: bool IsAIWalkable( void ); #ifdef MAPBASE - virtual void HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) {} + // Handle a potentially complex command from a client. + // Returns true if the command was handled successfully. + virtual bool HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) { return false; } #endif // MAPBASE private: diff --git a/sp/src/game/server/vguiscreen.cpp b/sp/src/game/server/vguiscreen.cpp index e26e08cc..86795342 100644 --- a/sp/src/game/server/vguiscreen.cpp +++ b/sp/src/game/server/vguiscreen.cpp @@ -224,15 +224,30 @@ int CVGuiScreen::Restore(IRestore& restore) return status; } -void CVGuiScreen::HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) +// Handle a command from the client-side vgui panel. +bool CVGuiScreen::HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues) { +#if defined(HL2MP) // Enable this in multiplayer. + // Restrict to commands from our owning player. + if ((m_fScreenFlags & VGUI_SCREEN_ONLY_USABLE_BY_OWNER) && pClient != m_hPlayerOwner.Get()) + return false; +#endif + + // Give the owning entity a chance to handle the command. + if (GetOwnerEntity() && GetOwnerEntity()->HandleEntityCommand(pClient, pKeyValues)) + return true; + + // See if we have an output for this command. const int i = m_PanelOutputs.Find(pKeyValues->GetString()); if (m_PanelOutputs.IsValidIndex(i)) { variant_t Val; Val.Set(FIELD_VOID, NULL); m_PanelOutputs[i]->FireOutput(Val, pClient, this); + return true; } + + return false; } CBaseEntityOutput* CVGuiScreen::FindNamedOutput(const char* pszOutput) diff --git a/sp/src/game/server/vguiscreen.h b/sp/src/game/server/vguiscreen.h index 1cb7dc7e..557cacd7 100644 --- a/sp/src/game/server/vguiscreen.h +++ b/sp/src/game/server/vguiscreen.h @@ -37,7 +37,7 @@ public: virtual int Save(ISave& save); virtual int Restore(IRestore& restore); - virtual void HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues); + virtual bool HandleEntityCommand(CBasePlayer* pClient, KeyValues* pKeyValues); virtual CBaseEntityOutput* FindNamedOutput(const char* pszOutput); #endif // MAPBASE