Vgui screens now try to pass panel commands to the entity that created them

This commit is contained in:
Peter Covington 2023-12-29 14:08:13 -05:00
parent eb46739ab5
commit 9f34a64e63
No known key found for this signature in database
GPG Key ID: CE9E79A4A4BDE09B
3 changed files with 20 additions and 3 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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