From 3bc519aecf614f3f5a46369cd0ad33777f14d7c4 Mon Sep 17 00:00:00 2001 From: hymei Date: Wed, 23 Feb 2022 21:11:56 +0800 Subject: [PATCH] arm64 : fix vgui2 VPAMEL in messagemap --- .../client/cstrike/VGUI/buypreset_listbox.cpp | 6 ++-- game/client/cstrike/VGUI/buypreset_listbox.h | 15 ++++++--- gameui/BasePanel.cpp | 7 ++--- public/vgui_controls/BuildGroup.h | 1 + public/vgui_controls/Menu.h | 4 +-- public/vgui_controls/MessageMap.h | 3 +- public/vgui_controls/PHandle.h | 13 +++++--- public/vgui_controls/Panel.h | 2 +- vgui2/vgui_controls/BuildGroup.cpp | 12 +++++++ vgui2/vgui_controls/Menu.cpp | 6 ++-- vgui2/vgui_controls/MenuItem.cpp | 4 +-- vgui2/vgui_controls/Panel.cpp | 31 +++++++++++++------ 12 files changed, 69 insertions(+), 35 deletions(-) diff --git a/game/client/cstrike/VGUI/buypreset_listbox.cpp b/game/client/cstrike/VGUI/buypreset_listbox.cpp index add8dd75..70dc046a 100644 --- a/game/client/cstrike/VGUI/buypreset_listbox.cpp +++ b/game/client/cstrike/VGUI/buypreset_listbox.cpp @@ -135,7 +135,7 @@ int BuyPresetListBox::computeVPixelsNeeded( void ) /** * Adds an item to the end of the listbox. UserData is assumed to be a pointer that can be freed by the listbox if non-NULL. */ -int BuyPresetListBox::AddItem( vgui::Panel *panel, void * userData ) +int BuyPresetListBox::AddItem( vgui::Panel *panel, IBuyPresetListBoxUserData * userData ) { assert(panel); @@ -192,7 +192,7 @@ Panel * BuyPresetListBox::GetItemPanel(int index) const /** * Returns the userData in the given index, or NULL */ -void * BuyPresetListBox::GetItemUserData(int index) +auto BuyPresetListBox::GetItemUserData(int index) -> IBuyPresetListBoxUserData * { if ( index < 0 || index >= m_items.Count() ) { @@ -206,7 +206,7 @@ void * BuyPresetListBox::GetItemUserData(int index) /** * Sets the userData in the given index */ -void BuyPresetListBox::SetItemUserData( int index, void * userData ) +void BuyPresetListBox::SetItemUserData( int index, IBuyPresetListBoxUserData * userData ) { if ( index < 0 || index >= m_items.Count() ) return; diff --git a/game/client/cstrike/VGUI/buypreset_listbox.h b/game/client/cstrike/VGUI/buypreset_listbox.h index 68d6de69..a09abf0e 100644 --- a/game/client/cstrike/VGUI/buypreset_listbox.h +++ b/game/client/cstrike/VGUI/buypreset_listbox.h @@ -27,14 +27,21 @@ public: BuyPresetListBox( vgui::Panel *parent, char const *panelName ); ~BuyPresetListBox(); - virtual int AddItem( vgui::Panel *panel, void * userData ); ///< Adds an item to the end of the listbox. UserData is assumed to be a pointer that can be freed by the listbox if non-NULL. + class IBuyPresetListBoxUserData + { + protected: + friend BuyPresetListBox; + virtual ~IBuyPresetListBoxUserData() {}; + }; + + virtual int AddItem( vgui::Panel *panel, IBuyPresetListBoxUserData *userData ); ///< Adds an item to the end of the listbox. UserData is assumed to be a pointer that will be deleted by the listbox if non-NULL. virtual int GetItemCount( void ) const; ///< Returns the number of items in the listbox void SwapItems( int index1, int index2 ); ///< Exchanges two items in the listbox void MakeItemVisible( int index ); ///< Try to ensure that the given index is visible vgui::Panel * GetItemPanel( int index ) const; ///< Returns the panel in the given index, or NULL - void * GetItemUserData( int index ); ///< Returns the userData in the given index, or NULL - void SetItemUserData( int index, void * userData ); ///< Sets the userData in the given index + IBuyPresetListBoxUserData * GetItemUserData( int index ); ///< Returns the userData in the given index, or NULL + void SetItemUserData( int index, IBuyPresetListBoxUserData * userData ); ///< Sets the userData in the given index virtual void RemoveItem( int index ); ///< Removes an item from the table (changing the indices of all following items), deleting the panel and userData virtual void DeleteAllItems(); ///< clears the listbox, deleting all panels and userData @@ -60,7 +67,7 @@ private: typedef struct dataitem_s { vgui::Panel *panel; - void * userData; + IBuyPresetListBoxUserData * userData; } DataItem; CUtlVector< DataItem > m_items; diff --git a/gameui/BasePanel.cpp b/gameui/BasePanel.cpp index 09a4ece2..9f5a8854 100644 --- a/gameui/BasePanel.cpp +++ b/gameui/BasePanel.cpp @@ -633,7 +633,7 @@ public: } } - MESSAGE_FUNC_INT( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", VPanel); + MESSAGE_FUNC_HANDLE( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", menuItem); private: CFooterPanel *m_pConsoleFooter; @@ -644,9 +644,8 @@ private: //----------------------------------------------------------------------------- // Purpose: Respond to cursor entering a menuItem. //----------------------------------------------------------------------------- -void CGameMenu::OnCursorEnteredMenuItem(int VPanel) +void CGameMenu::OnCursorEnteredMenuItem(VPANEL menuItem) { - VPANEL menuItem = (VPANEL)VPanel; MenuItem *item = static_cast(ipanel()->GetPanel(menuItem, GetModuleName())); KeyValues *pCommand = item->GetCommand(); if ( !pCommand->GetFirstSubKey() ) @@ -655,7 +654,7 @@ void CGameMenu::OnCursorEnteredMenuItem(int VPanel) if ( !pszCmd || !pszCmd[0] ) return; - BaseClass::OnCursorEnteredMenuItem( VPanel ); + BaseClass::OnCursorEnteredMenuItem( menuItem ); } static CBackgroundMenuButton* CreateMenuButton( CBasePanel *parent, const char *panelName, const wchar_t *panelText ) diff --git a/public/vgui_controls/BuildGroup.h b/public/vgui_controls/BuildGroup.h index a0fcf352..c6ce0f4e 100644 --- a/public/vgui_controls/BuildGroup.h +++ b/public/vgui_controls/BuildGroup.h @@ -94,6 +94,7 @@ public: virtual const char *GetResourceName(void) { return m_pResourceName; } virtual void PanelAdded(Panel* panel); + virtual void PanelRemoved(Panel* panel); virtual bool MousePressed(MouseCode code,Panel* panel); virtual bool MouseReleased(MouseCode code,Panel* panel); diff --git a/public/vgui_controls/Menu.h b/public/vgui_controls/Menu.h index fbe44b29..f5a396cb 100644 --- a/public/vgui_controls/Menu.h +++ b/public/vgui_controls/Menu.h @@ -295,8 +295,8 @@ protected: void SetCurrentlySelectedItem(MenuItem *item); void SetCurrentlySelectedItem(int itemID); - MESSAGE_FUNC_INT( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", VPanel); - MESSAGE_FUNC_INT( OnCursorExitedMenuItem, "CursorExitedMenuItem", VPanel); + MESSAGE_FUNC_HANDLE( OnCursorEnteredMenuItem, "CursorEnteredMenuItem", menuItem); + MESSAGE_FUNC_HANDLE( OnCursorExitedMenuItem, "CursorExitedMenuItem", menuItem); void MoveAlongMenuItemList(int direction, int loopCount); diff --git a/public/vgui_controls/MessageMap.h b/public/vgui_controls/MessageMap.h index 226c0adc..b8b2ed20 100644 --- a/public/vgui_controls/MessageMap.h +++ b/public/vgui_controls/MessageMap.h @@ -46,7 +46,7 @@ class __virtual_inheritance Panel; #else class Panel; #endif -typedef unsigned int VPANEL; +typedef uintp VPANEL; typedef void (Panel::*MessageFunc_t)(void); @@ -222,6 +222,7 @@ public: \ #define MESSAGE_FUNC_PTR_WCHARPTR( name, scriptname, p1, p2 ) _MessageFuncCommon( name, scriptname, 2, vgui::DATATYPE_PTR, #p1, vgui::DATATYPE_CONSTWCHARPTR, #p2 ); virtual void name( vgui::Panel *p1, const wchar_t *p2 ) #define MESSAGE_FUNC_HANDLE_WCHARPTR( name, scriptname, p1, p2 ) _MessageFuncCommon( name, scriptname, 2, vgui::DATATYPE_HANDLE, #p1, vgui::DATATYPE_CONSTWCHARPTR, #p2 ); virtual void name( vgui::VPANEL p1, const wchar_t *p2 ) #define MESSAGE_FUNC_CHARPTR_CHARPTR( name, scriptname, p1, p2 ) _MessageFuncCommon( name, scriptname, 2, vgui::DATATYPE_CONSTCHARPTR, #p1, vgui::DATATYPE_CONSTCHARPTR, #p2 ); virtual void name( const char *p1, const char *p2 ) +#define MESSAGE_FUNC_HANDLE_HANDLE( name, scriptname, p1, p2 ) _MessageFuncCommon( name, scriptname, 2, vgui::DATATYPE_HANDLE, #p1, vgui::DATATYPE_HANDLE, #p2 ); virtual void name( vgui::VPANEL p1, vgui::VPANEL p2 ) // unlimited parameters (passed in the whole KeyValues) #define MESSAGE_FUNC_PARAMS( name, scriptname, p1 ) _MessageFuncCommon( name, scriptname, 1, vgui::DATATYPE_KEYVALUES, NULL, 0, 0 ); virtual void name( KeyValues *p1 ) diff --git a/public/vgui_controls/PHandle.h b/public/vgui_controls/PHandle.h index 959ee4a9..5fdbc8bc 100644 --- a/public/vgui_controls/PHandle.h +++ b/public/vgui_controls/PHandle.h @@ -27,16 +27,21 @@ class PHandle public: PHandle() : m_iPanelID(INVALID_PANEL) {} //m_iSerialNumber(0), m_pListEntry(0) {} - Panel *Get(); + Panel *Get() const; Panel *Set( Panel *pPanel ); Panel *Set( HPanel hPanel ); - operator Panel *() { return Get(); } + operator Panel *() const { return Get(); } Panel * operator ->() { return Get(); } Panel * operator = (Panel *pPanel) { return Set(pPanel); } - bool operator == (Panel *pPanel) { return (Get() == pPanel); } - operator bool () { return Get() != 0; } + //bool operator == (Panel *pPanel) { return (Get() == pPanel); } + operator bool () const { return Get() != 0; } + + friend bool operator == ( const PHandle &p1, const PHandle &p2 ) + { + return p1.m_iPanelID == p2.m_iPanelID; + } private: HPanel m_iPanelID; diff --git a/public/vgui_controls/Panel.h b/public/vgui_controls/Panel.h index 5d1abd1f..0a3aa41a 100644 --- a/public/vgui_controls/Panel.h +++ b/public/vgui_controls/Panel.h @@ -673,7 +673,7 @@ protected: protected: virtual void OnChildSettingsApplied( KeyValues *pInResourceData, Panel *pChild ); - MESSAGE_FUNC_ENUM_ENUM( OnRequestFocus, "OnRequestFocus", VPANEL, subFocus, VPANEL, defaultPanel); + MESSAGE_FUNC_HANDLE_HANDLE( OnRequestFocus, "OnRequestFocus", subFocus, defaultPanel); MESSAGE_FUNC_INT_INT( OnScreenSizeChanged, "OnScreenSizeChanged", oldwide, oldtall ); virtual void *QueryInterface(EInterfaceID id); diff --git a/vgui2/vgui_controls/BuildGroup.cpp b/vgui2/vgui_controls/BuildGroup.cpp index bef4a3c0..a5001cbe 100644 --- a/vgui2/vgui_controls/BuildGroup.cpp +++ b/vgui2/vgui_controls/BuildGroup.cpp @@ -869,6 +869,18 @@ void BuildGroup::PanelAdded(Panel *panel) _panelDar.AddToTail(temp); } +//----------------------------------------------------------------------------- +// Purpose: Add panel the list of panels that are in the build group +//----------------------------------------------------------------------------- +void BuildGroup::PanelRemoved(Panel *panel) +{ + Assert(panel); + + PHandle temp; + temp = panel; + _panelDar.FindAndRemove(temp); +} + //----------------------------------------------------------------------------- // Purpose: loads the control settings from file //----------------------------------------------------------------------------- diff --git a/vgui2/vgui_controls/Menu.cpp b/vgui2/vgui_controls/Menu.cpp index 58536356..f578ed10 100644 --- a/vgui2/vgui_controls/Menu.cpp +++ b/vgui2/vgui_controls/Menu.cpp @@ -2365,9 +2365,8 @@ int Menu::GetCurrentlyHighlightedItem() //----------------------------------------------------------------------------- // Purpose: Respond to cursor entering a menuItem. //----------------------------------------------------------------------------- -void Menu::OnCursorEnteredMenuItem(int VPanel) +void Menu::OnCursorEnteredMenuItem(VPANEL menuItem) { - VPANEL menuItem = (VPANEL)VPanel; // if we are in mouse mode if (m_iInputMode == MOUSE) { @@ -2389,9 +2388,8 @@ void Menu::OnCursorEnteredMenuItem(int VPanel) //----------------------------------------------------------------------------- // Purpose: Respond to cursor exiting a menuItem //----------------------------------------------------------------------------- -void Menu::OnCursorExitedMenuItem(int VPanel) +void Menu::OnCursorExitedMenuItem(VPANEL menuItem) { - VPANEL menuItem = (VPANEL)VPanel; // only care if we are in mouse mode if (m_iInputMode == MOUSE) { diff --git a/vgui2/vgui_controls/MenuItem.cpp b/vgui2/vgui_controls/MenuItem.cpp index 209ec365..5db44276 100644 --- a/vgui2/vgui_controls/MenuItem.cpp +++ b/vgui2/vgui_controls/MenuItem.cpp @@ -222,7 +222,7 @@ void MenuItem::OnCursorEntered() // forward the message on to the parent of this menu. KeyValues *msg = new KeyValues ("CursorEnteredMenuItem"); // tell the parent this menuitem is the one that was entered so it can highlight it - msg->SetInt("VPanel", GetVPanel()); + msg->SetInt("menuItem", ToHandle() ); ivgui()->PostMessage(GetVParent(), msg, NULL); } @@ -236,7 +236,7 @@ void MenuItem::OnCursorExited() // forward the message on to the parent of this menu. KeyValues *msg = new KeyValues ("CursorExitedMenuItem"); // tell the parent this menuitem is the one that was entered so it can unhighlight it - msg->SetInt("VPanel", GetVPanel()); + msg->SetInt("menuItem", ToHandle() ); ivgui()->PostMessage(GetVParent(), msg, NULL); } diff --git a/vgui2/vgui_controls/Panel.cpp b/vgui2/vgui_controls/Panel.cpp index 7a8628e0..3c53f350 100644 --- a/vgui2/vgui_controls/Panel.cpp +++ b/vgui2/vgui_controls/Panel.cpp @@ -880,7 +880,7 @@ const char *Panel::GetClassName() { // loop up the panel map name PanelMessageMap *panelMap = GetMessageMap(); - if ( panelMap ) + if ( panelMap && panelMap->pfnClassName ) { return panelMap->pfnClassName(); } @@ -3575,7 +3575,7 @@ void Panel::RequestFocus(int direction) //----------------------------------------------------------------------------- void Panel::OnRequestFocus(VPANEL subFocus, VPANEL defaultPanel) { - CallParentFunction(new KeyValues("OnRequestFocus", "subFocus", subFocus, "defaultPanel", defaultPanel)); + CallParentFunction(new KeyValues("OnRequestFocus", "subFocus", ivgui()->PanelToHandle( subFocus ), "defaultPanel", ivgui()->PanelToHandle( defaultPanel ))); } //----------------------------------------------------------------------------- @@ -3800,13 +3800,17 @@ void Panel::SetTall(int tall) void Panel::SetBuildGroup(BuildGroup* buildGroup) { - //TODO: remove from old group - - Assert(buildGroup != NULL); - - _buildGroup = buildGroup; - - _buildGroup->PanelAdded(this); + if ( _buildGroup == buildGroup ) + return; + if ( _buildGroup.Get() ) + { + _buildGroup->PanelRemoved( this ); + } + _buildGroup = buildGroup; + if ( _buildGroup.Get() ) + { + _buildGroup->PanelAdded(this); + } } bool Panel::IsBuildGroupEnabled() @@ -5134,6 +5138,13 @@ void Panel::OnMessage(const KeyValues *params, VPANEL ifromPanel) VPANEL vp = ivgui()->HandleToPanel( param1->GetInt() ); (this->*((MessageFunc_HandleConstCharPtr_t)pMap->func))( vp, param2->GetWString() ); } + else if ( (DATATYPE_HANDLE == pMap->firstParamType) && (DATATYPE_HANDLE == pMap->secondParamType) ) + { + typedef void (Panel::*MessageFunc_HandleConstCharPtr_t)(VPANEL, VPANEL); + VPANEL vp1 = ivgui()->HandleToPanel( param1->GetInt() ); + VPANEL vp2 = ivgui()->HandleToPanel( param1->GetInt() ); + (this->*((MessageFunc_HandleConstCharPtr_t)pMap->func))( vp1, vp2 ); + } else { // the message isn't handled @@ -5515,7 +5526,7 @@ void Panel::OnDelete() // Purpose: Panel handle implementation // Returns a pointer to a valid panel, NULL if the panel has been deleted //----------------------------------------------------------------------------- -Panel *PHandle::Get() +Panel *PHandle::Get() const { if (m_iPanelID != INVALID_PANEL) {