Skip to content

Commit

Permalink
baseitem: Add GetParent shortcut macro
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Feb 9, 2020
1 parent 01d964d commit 8bcd477
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
10 changes: 8 additions & 2 deletions controls/BaseItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@ class CMenuBaseItem
}

CMenuItemsHolder* Parent() const { return m_pParent; }
// breaks msvc6/owocc
// template <class T> T* Parent() const { return static_cast<T*>(m_pParent); } // a shortcut to parent

#ifndef MY_COMPILER_SUCKS
template <class T> T* _Parent() const { return static_cast<T*>(m_pParent); } // a shortcut to parent
#define GetParent(type) _Parent<type>()
#else
template <class T> T* _Parent(T*) const { return static_cast<T*>(m_pParent); } // a shortcut to parent
#define GetParent(type) _Parent((type*)(NULL))
#endif
bool IsPressed() const { return m_bPressed; }
int LastFocusTime() const { return m_iLastFocusTime; }

Expand Down
2 changes: 1 addition & 1 deletion menus/ConnectionWarning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void CMenuConnectionWarning::_Init()
options.szName = L( "Adv. Options" );
SET_EVENT_MULTI( options.onReleased,
{
CMenuConnectionWarning *p = (CMenuConnectionWarning*)pSelf->Parent();
CMenuConnectionWarning *p = pSelf->GetParent(CMenuConnectionWarning);
UI_GameOptions_Menu();
p->done.SetGrayed( false );
});
Expand Down
6 changes: 3 additions & 3 deletions menus/GameOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ void CMenuGameOptions::_Init( void )
normal.szName = L( "Normal internet connection" ); // Такая строка где-то уже была, поэтому в отдельный файл НЕ ВЫНОШУ !
SET_EVENT_MULTI( normal.onChanged,
{
((CMenuGameOptions*)pSelf->Parent())->SetNetworkMode( 1400, 0, 30, 60, 25000 );
pSelf->GetParent(CMenuGameOptions)->SetNetworkMode( 1400, 0, 30, 60, 25000 );
((CMenuCheckBox*)pSelf)->bChecked = true;
});

dsl.SetRect( 240, 560, 24, 24 );
dsl.szName = L( "DSL or PPTP with limited packet size" ); // И такое тоже уже было !
SET_EVENT_MULTI( dsl.onChanged,
{
((CMenuGameOptions*)pSelf->Parent())->SetNetworkMode( 1200, 1000, 30, 60, 25000 );
pSelf->GetParent(CMenuGameOptions)->SetNetworkMode( 1200, 1000, 30, 60, 25000 );
((CMenuCheckBox*)pSelf)->bChecked = true;
});

Expand All @@ -232,7 +232,7 @@ void CMenuGameOptions::_Init( void )
slowest.szName = L( "Slow connection mode (64kbps)" ); // Было, повтор !
SET_EVENT_MULTI( slowest.onChanged,
{
((CMenuGameOptions*)pSelf->Parent())->SetNetworkMode( 900, 700, 25, 30, 7500 );
pSelf->GetParent(CMenuGameOptions)->SetNetworkMode( 900, 700, 25, 30, 7500 );
((CMenuCheckBox*)pSelf)->bChecked = true;
});
compress.SetNameAndStatus( L( "Compress" ), L( "Compress splitted packets (need split to work)" ) );
Expand Down
2 changes: 1 addition & 1 deletion menus/InputDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void CMenuInputDevices::_Init( void )
"Are you sure to disable mouse?" ) );
SET_EVENT_MULTI( msgbox.onNegative,
{
((CMenuInputDevices*)pSelf->Parent())->mouse.bChecked = false;
pSelf->GetParent(CMenuInputDevices)->mouse.bChecked = false;
});

msgbox.Show();
Expand Down
4 changes: 2 additions & 2 deletions menus/Multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ void CMenuMultiplayer::_Init( void )
EngFuncs::CvarSetValue( "cl_predict", 1.0f );
EngFuncs::CvarSetValue( "menu_mp_firsttime", 0.0f );

UI_PlayerIntroduceDialog_Show( (CMenuBaseWindow*)pSelf->Parent() );
UI_PlayerIntroduceDialog_Show( pSelf->GetParent(CMenuBaseWindow) );
});
SET_EVENT_MULTI( msgBox.onNegative,
{
EngFuncs::CvarSetValue( "menu_mp_firsttime", 0.0f );

UI_PlayerIntroduceDialog_Show( (CMenuBaseWindow*)pSelf->Parent() );
UI_PlayerIntroduceDialog_Show( pSelf->GetParent(CMenuBaseWindow) );
});
msgBox.Link( this );

Expand Down
4 changes: 2 additions & 2 deletions menus/VideoModes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ void CMenuVidModes::_Init( void )
windowed.SetCoord( 360, 620 );
SET_EVENT_MULTI( windowed.onChanged,
{
CMenuVidModes *parent = (CMenuVidModes*)pSelf->Parent();
CMenuVidModes *parent = pSelf->GetParent(CMenuVidModes);
if( !parent->windowed.bChecked && parent->vidList.GetCurrentIndex() < VID_AUTOMODE_POS )
parent->vidList.SetCurrentIndex( VID_AUTOMODE_POS );
});

SET_EVENT_MULTI( vidList.onChanged,
{
CMenuVidModes *parent = (CMenuVidModes*)pSelf->Parent();
CMenuVidModes *parent = pSelf->GetParent(CMenuVidModes);
if( !parent->windowed.bChecked && parent->vidList.GetCurrentIndex() < VID_AUTOMODE_POS )
parent->vidList.SetCurrentIndex( VID_AUTOMODE_POS );
});
Expand Down

0 comments on commit 8bcd477

Please sign in to comment.