Skip to content

Commit 3bda27a

Browse files
authored
[GEN][ZH] Refactor implemention for Shell recreation on Display Resolution change (#1031)
1 parent 99a5bc5 commit 3bda27a

File tree

10 files changed

+195
-87
lines changed

10 files changed

+195
-87
lines changed

Generals/Code/GameEngine/Include/GameClient/Shell.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class Shell : public SubsystemInterface
125125
virtual void update( void );
126126
//===============================================================================================
127127

128+
void recreateWindowLayouts( void );
129+
128130
void showShellMap(Bool useShellMap ); ///< access function to turn on and off the shell map
129131

130132
void hide( Bool hide ); ///< show/hide all shell layouts
@@ -141,8 +143,6 @@ class Shell : public SubsystemInterface
141143

142144
WindowLayout *findScreenByFilename( AsciiString filename ); ///< find screen
143145
inline Bool isShellActive( void ) { return m_isShellActive; } ///< Returns true if the shell is active
144-
145-
inline Int getScreenCount(void) { return m_screenCount; } ///< Return the current number of screens
146146

147147
void registerWithAnimateManager( GameWindow *win, AnimTypes animType, Bool needsToFinish, UnsignedInt delayMS = 0);
148148
Bool isAnimFinished( void );
@@ -152,13 +152,19 @@ class Shell : public SubsystemInterface
152152
void loadScheme( AsciiString name );
153153
ShellMenuSchemeManager *getShellMenuSchemeManager( void ) { return m_schemeManager; }
154154

155+
Int getScreenCount( void ) const { return m_screenCount; } ///< Return the current number of screens
156+
WindowLayout *getScreenLayout( Int index ) const;
157+
155158
WindowLayout *getSaveLoadMenuLayout( void ); ///< create if necessary and return layout for save load menu
156159
WindowLayout *getPopupReplayLayout( void ); ///< create if necessary and return layout for replay save menu
157160
WindowLayout *getOptionsLayout( Bool create ); ///< return layout for options menu, create if necessary and we are allowed to.
158161
void destroyOptionsLayout( void ); ///< destroy the shell's options layout.
159162

160163
protected:
161164

165+
void construct( void );
166+
void deconstruct( void );
167+
162168
void linkScreen( WindowLayout *screen ); ///< link screen to list
163169
void unlinkScreen( WindowLayout *screen ); ///< remove screen from list
164170

Generals/Code/GameEngine/Include/GameClient/WindowLayout.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ class WindowLayout : public MemoryPoolObject
6262
// ~WindowLayout( void ); ///< defined by memory pool glue
6363

6464
// manipulating screen properties ---------------------------------------------------------------
65-
AsciiString getFilename( void ); ///< return source window filename
66-
Bool load( AsciiString filename ); ///< create windows and load from .wnd file
67-
void hide( Bool hide ); ///< hide/unhide all windows on this screen
68-
Bool isHidden( void ); ///< return visible state of screen
65+
AsciiString getFilename( void ) const; ///< return source window filename
66+
Bool load( AsciiString filename ); ///< create windows and load from .wnd file
67+
void hide( Bool hide ); ///< hide/show all windows on this screen
68+
Bool isHidden( void ) const; ///< return visible state of screen
6969
void bringForward( void ); ///< bring all windows in this screen forward
7070

7171
// manipulating window lists --------------------------------------------------------------------
7272
void addWindow( GameWindow *window ); ///< add window to screen
7373
void removeWindow( GameWindow *window ); ///< remove window from screen
7474
void destroyWindows( void ); ///< destroy all windows in this screen
75-
GameWindow *getFirstWindow( void ); ///< get first window in list for screen
75+
GameWindow *getFirstWindow( void ) const; ///< get first window in list for screen
7676

7777
// accessing layout callbacks ------------------------------------------------------------------
7878
void runInit( void *userData = NULL ); ///< run the init method if available
@@ -110,9 +110,9 @@ class WindowLayout : public MemoryPoolObject
110110
}; // end class WindowLayout
111111

112112
// INLINING ///////////////////////////////////////////////////////////////////////////////////////
113-
inline AsciiString WindowLayout::getFilename( void ) { return m_filenameString; }
114-
inline GameWindow *WindowLayout::getFirstWindow( void ) { return m_windowList; }
115-
inline Bool WindowLayout::isHidden( void ) { return m_hidden; }
113+
inline AsciiString WindowLayout::getFilename( void ) const { return m_filenameString; }
114+
inline GameWindow *WindowLayout::getFirstWindow( void ) const { return m_windowList; }
115+
inline Bool WindowLayout::isHidden( void ) const { return m_hidden; }
116116

117117
inline void WindowLayout::runInit( void *userData ) { if( m_init ) m_init( this, userData ); }
118118
inline void WindowLayout::runUpdate( void *userData ) { if( m_update ) m_update( this, userData ); }

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -724,18 +724,9 @@ void DeclineResolution()
724724
optionPref["Resolution"] = prefString;
725725
optionPref.write();
726726

727-
// delete the shell
728-
delete TheShell;
729-
TheShell = NULL;
730-
731-
// create the shell
732-
TheShell = MSGNEW("GameClientSubsystem") Shell;
733-
if( TheShell )
734-
TheShell->init();
735-
736-
TheInGameUI->recreateControlBar();
727+
TheShell->recreateWindowLayouts();
737728

738-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
729+
TheInGameUI->recreateControlBar();
739730
}
740731
}
741732

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,18 +1241,9 @@ static void saveOptions( void )
12411241
prefString.format("%d %d", xres, yres );
12421242
(*pref)["Resolution"] = prefString;
12431243

1244-
// delete the shell
1245-
delete TheShell;
1246-
TheShell = NULL;
1247-
1248-
// create the shell
1249-
TheShell = MSGNEW("GameClientSubsystem") Shell;
1250-
if( TheShell )
1251-
TheShell->init();
1244+
TheShell->recreateWindowLayouts();
12521245

12531246
TheInGameUI->recreateControlBar();
1254-
1255-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
12561247
}
12571248
}
12581249
}

Generals/Code/GameEngine/Source/GameClient/GUI/Shell/Shell.cpp

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ Shell *TheShell = NULL; ///< the shell singleton definition
5555
//-------------------------------------------------------------------------------------------------
5656
//-------------------------------------------------------------------------------------------------
5757
Shell::Shell( void )
58+
{
59+
construct();
60+
61+
} // end Shell
62+
63+
//-------------------------------------------------------------------------------------------------
64+
//-------------------------------------------------------------------------------------------------
65+
Shell::~Shell( void )
66+
{
67+
deconstruct();
68+
69+
} // end ~Shell
70+
71+
//-------------------------------------------------------------------------------------------------
72+
void Shell::construct( void )
5873
{
5974
Int i;
6075

@@ -78,12 +93,10 @@ Shell::Shell( void )
7893
m_optionsLayout = NULL;
7994
m_screenCount = 0;
8095
//
81-
82-
} // end Shell
96+
}
8397

8498
//-------------------------------------------------------------------------------------------------
85-
//-------------------------------------------------------------------------------------------------
86-
Shell::~Shell( void )
99+
void Shell::deconstruct( void )
87100
{
88101
WindowLayout *newTop = top();
89102
while(newTop)
@@ -99,12 +112,10 @@ Shell::~Shell( void )
99112
m_background = NULL;
100113
}
101114

102-
if(m_animateWindowManager)
103-
delete m_animateWindowManager;
115+
delete m_animateWindowManager;
104116
m_animateWindowManager = NULL;
105117

106-
if(m_schemeManager)
107-
delete m_schemeManager;
118+
delete m_schemeManager;
108119
m_schemeManager = NULL;
109120

110121
// delete the save/load menu if present
@@ -133,8 +144,7 @@ Shell::~Shell( void )
133144
deleteInstance(m_optionsLayout);
134145
m_optionsLayout = NULL;
135146
}
136-
137-
} // end ~Shell
147+
}
138148

139149
//-------------------------------------------------------------------------------------------------
140150
/** Initialize the shell system */
@@ -163,7 +173,7 @@ void Shell::reset( void )
163173

164174
// pop all screens
165175
while( m_screenCount )
166-
pop();
176+
popImmediate();
167177

168178
m_animateWindowManager->reset();
169179

@@ -215,6 +225,53 @@ void Shell::update( void )
215225

216226
} // end update
217227

228+
//-------------------------------------------------------------------------------------------------
229+
namespace
230+
{
231+
struct ScreenInfo
232+
{
233+
ScreenInfo() : isHidden(false) {}
234+
AsciiString filename;
235+
bool isHidden;
236+
};
237+
}
238+
239+
//-------------------------------------------------------------------------------------------------
240+
void Shell::recreateWindowLayouts( void )
241+
{
242+
// collect state of the current shell
243+
const Int screenCount = getScreenCount();
244+
std::vector<ScreenInfo> screenStackInfos;
245+
246+
{
247+
screenStackInfos.resize(screenCount);
248+
Int screenIndex = 0;
249+
for (; screenIndex < screenCount; ++screenIndex)
250+
{
251+
const WindowLayout* layout = getScreenLayout(screenIndex);
252+
ScreenInfo& screenInfo = screenStackInfos[screenIndex];
253+
screenInfo.filename = layout->getFilename();
254+
screenInfo.isHidden = layout->isHidden();
255+
}
256+
}
257+
258+
// reconstruct the shell now
259+
deconstruct();
260+
construct();
261+
init();
262+
263+
// restore the screen stack
264+
Int screenIndex = 0;
265+
for (; screenIndex < screenCount; ++screenIndex)
266+
{
267+
const ScreenInfo& screenInfo = screenStackInfos[screenIndex];
268+
push(screenInfo.filename);
269+
270+
WindowLayout* layout = getScreenLayout(screenIndex);
271+
layout->hide(screenInfo.isHidden);
272+
}
273+
}
274+
218275
//-------------------------------------------------------------------------------------------------
219276
/** Find a screen via the .wnd script filename loaded */
220277
//-------------------------------------------------------------------------------------------------
@@ -240,6 +297,15 @@ WindowLayout *Shell::findScreenByFilename( AsciiString filename )
240297

241298
} // end findScreenByFilename
242299

300+
//-------------------------------------------------------------------------------------------------
301+
WindowLayout *Shell::getScreenLayout( Int index ) const
302+
{
303+
if (index >= 0 && index < m_screenCount)
304+
return m_screenStack[index];
305+
306+
return NULL;
307+
}
308+
243309
//-------------------------------------------------------------------------------------------------
244310
/** Hide or unhide all window layouts loaded */
245311
//-------------------------------------------------------------------------------------------------
@@ -458,7 +524,7 @@ void Shell::showShell( Bool runInit )
458524

459525
if (!TheGlobalData->m_shellMapOn && m_screenCount == 0)
460526
//else
461-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
527+
push( AsciiString("Menus/MainMenu.wnd") );
462528
m_isShellActive = TRUE;
463529
} // end showShell
464530

GeneralsMD/Code/GameEngine/Include/GameClient/Shell.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class Shell : public SubsystemInterface
125125
virtual void update( void );
126126
//===============================================================================================
127127

128+
void recreateWindowLayouts( void );
129+
128130
void showShellMap(Bool useShellMap ); ///< access function to turn on and off the shell map
129131

130132
void hide( Bool hide ); ///< show/hide all shell layouts
@@ -141,8 +143,6 @@ class Shell : public SubsystemInterface
141143

142144
WindowLayout *findScreenByFilename( AsciiString filename ); ///< find screen
143145
inline Bool isShellActive( void ) { return m_isShellActive; } ///< Returns true if the shell is active
144-
145-
inline Int getScreenCount(void) { return m_screenCount; } ///< Return the current number of screens
146146

147147
void registerWithAnimateManager( GameWindow *win, AnimTypes animType, Bool needsToFinish, UnsignedInt delayMS = 0);
148148
Bool isAnimFinished( void );
@@ -152,13 +152,19 @@ class Shell : public SubsystemInterface
152152
void loadScheme( AsciiString name );
153153
ShellMenuSchemeManager *getShellMenuSchemeManager( void ) { return m_schemeManager; }
154154

155+
Int getScreenCount( void ) const { return m_screenCount; } ///< Return the current number of screens
156+
WindowLayout *getScreenLayout( Int index ) const;
157+
155158
WindowLayout *getSaveLoadMenuLayout( void ); ///< create if necessary and return layout for save load menu
156159
WindowLayout *getPopupReplayLayout( void ); ///< create if necessary and return layout for replay save menu
157160
WindowLayout *getOptionsLayout( Bool create ); ///< return layout for options menu, create if necessary and we are allowed to.
158161
void destroyOptionsLayout( void ); ///< destroy the shell's options layout.
159162

160163
protected:
161164

165+
void construct( void );
166+
void deconstruct( void );
167+
162168
void linkScreen( WindowLayout *screen ); ///< link screen to list
163169
void unlinkScreen( WindowLayout *screen ); ///< remove screen from list
164170

GeneralsMD/Code/GameEngine/Include/GameClient/WindowLayout.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ class WindowLayout : public MemoryPoolObject
6262
// ~WindowLayout( void ); ///< defined by memory pool glue
6363

6464
// manipulating screen properties ---------------------------------------------------------------
65-
AsciiString getFilename( void ); ///< return source window filename
66-
Bool load( AsciiString filename ); ///< create windows and load from .wnd file
67-
void hide( Bool hide ); ///< hide/unhide all windows on this screen
68-
Bool isHidden( void ); ///< return visible state of screen
65+
AsciiString getFilename( void ) const; ///< return source window filename
66+
Bool load( AsciiString filename ); ///< create windows and load from .wnd file
67+
void hide( Bool hide ); ///< hide/show all windows on this screen
68+
Bool isHidden( void ) const; ///< return visible state of screen
6969
void bringForward( void ); ///< bring all windows in this screen forward
7070

7171
// manipulating window lists --------------------------------------------------------------------
7272
void addWindow( GameWindow *window ); ///< add window to screen
7373
void removeWindow( GameWindow *window ); ///< remove window from screen
7474
void destroyWindows( void ); ///< destroy all windows in this screen
75-
GameWindow *getFirstWindow( void ); ///< get first window in list for screen
75+
GameWindow *getFirstWindow( void ) const; ///< get first window in list for screen
7676

7777
// accessing layout callbacks ------------------------------------------------------------------
7878
void runInit( void *userData = NULL ); ///< run the init method if available
@@ -110,9 +110,9 @@ class WindowLayout : public MemoryPoolObject
110110
}; // end class WindowLayout
111111

112112
// INLINING ///////////////////////////////////////////////////////////////////////////////////////
113-
inline AsciiString WindowLayout::getFilename( void ) { return m_filenameString; }
114-
inline GameWindow *WindowLayout::getFirstWindow( void ) { return m_windowList; }
115-
inline Bool WindowLayout::isHidden( void ) { return m_hidden; }
113+
inline AsciiString WindowLayout::getFilename( void ) const { return m_filenameString; }
114+
inline GameWindow *WindowLayout::getFirstWindow( void ) const { return m_windowList; }
115+
inline Bool WindowLayout::isHidden( void ) const { return m_hidden; }
116116

117117
inline void WindowLayout::runInit( void *userData ) { if( m_init ) m_init( this, userData ); }
118118
inline void WindowLayout::runUpdate( void *userData ) { if( m_update ) m_update( this, userData ); }

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/MainMenu.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,9 @@ void DeclineResolution()
761761
optionPref["Resolution"] = prefString;
762762
optionPref.write();
763763

764-
// delete the shell
765-
delete TheShell;
766-
TheShell = NULL;
767-
768-
// create the shell
769-
TheShell = MSGNEW("GameClientSubsystem") Shell;
770-
if( TheShell )
771-
TheShell->init();
772-
773-
TheInGameUI->recreateControlBar();
764+
TheShell->recreateWindowLayouts();
774765

775-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
766+
TheInGameUI->recreateControlBar();
776767
}
777768
}
778769

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,18 +1301,9 @@ static void saveOptions( void )
13011301
prefString.format("%d %d", xres, yres );
13021302
(*pref)["Resolution"] = prefString;
13031303

1304-
// delete the shell
1305-
delete TheShell;
1306-
TheShell = NULL;
1307-
1308-
// create the shell
1309-
TheShell = MSGNEW("GameClientSubsystem") Shell;
1310-
if( TheShell )
1311-
TheShell->init();
1312-
1313-
TheInGameUI->recreateControlBar();
1304+
TheShell->recreateWindowLayouts();
13141305

1315-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
1306+
TheInGameUI->recreateControlBar();
13161307
}
13171308
}
13181309
}

0 commit comments

Comments
 (0)