Skip to content

Commit e9f2ede

Browse files
committed
Move some of the code from ShellUtil into Shell and avoid deleting TheShell
1 parent 7f58155 commit e9f2ede

File tree

6 files changed

+117
-77
lines changed

6 files changed

+117
-77
lines changed

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

Lines changed: 5 additions & 0 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();
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
@@ -160,6 +162,9 @@ class Shell : public SubsystemInterface
160162

161163
protected:
162164

165+
void construct( void );
166+
void deconstruct( void );
167+
163168
void linkScreen( WindowLayout *screen ); ///< link screen to list
164169
void unlinkScreen( WindowLayout *screen ); ///< remove screen from list
165170

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
namespace shell
2222
{
2323

24-
// Will recreate the Shell with the same state that it was left with.
25-
// Currently works correctly in the Main Menu only.
26-
void recreateShell();
24+
// Will recreate the UI. Currently works correctly in the Main Menu only.
25+
void recreateUI();
26+
27+
void showMainMenuButtons();
2728

2829
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void DeclineResolution()
762762
optionPref["Resolution"] = prefString;
763763
optionPref.write();
764764

765-
shell::recreateShell();
765+
shell::recreateUI();
766766
}
767767
}
768768

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ static void saveOptions( void )
11141114
prefString.format("%d %d", xres, yres );
11151115
(*pref)["Resolution"] = prefString;
11161116

1117-
shell::recreateShell();
1117+
shell::recreateUI();
11181118
}
11191119
}
11201120
}

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

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ Shell *TheShell = NULL; ///< the shell singleton definition
5757
//-------------------------------------------------------------------------------------------------
5858
//-------------------------------------------------------------------------------------------------
5959
Shell::Shell( void )
60+
{
61+
construct();
62+
63+
} // end Shell
64+
65+
//-------------------------------------------------------------------------------------------------
66+
//-------------------------------------------------------------------------------------------------
67+
Shell::~Shell( void )
68+
{
69+
deconstruct();
70+
71+
} // end ~Shell
72+
73+
//-------------------------------------------------------------------------------------------------
74+
void Shell::construct( void )
6075
{
6176
Int i;
6277

@@ -80,12 +95,10 @@ Shell::Shell( void )
8095
m_optionsLayout = NULL;
8196
m_screenCount = 0;
8297
//
83-
84-
} // end Shell
98+
}
8599

86100
//-------------------------------------------------------------------------------------------------
87-
//-------------------------------------------------------------------------------------------------
88-
Shell::~Shell( void )
101+
void Shell::deconstruct( void )
89102
{
90103
WindowLayout *newTop = top();
91104
while(newTop)
@@ -101,12 +114,10 @@ Shell::~Shell( void )
101114
m_background = NULL;
102115
}
103116

104-
if(m_animateWindowManager)
105-
delete m_animateWindowManager;
117+
delete m_animateWindowManager;
106118
m_animateWindowManager = NULL;
107119

108-
if(m_schemeManager)
109-
delete m_schemeManager;
120+
delete m_schemeManager;
110121
m_schemeManager = NULL;
111122

112123
// delete the save/load menu if present
@@ -135,8 +146,7 @@ Shell::~Shell( void )
135146
deleteInstance(m_optionsLayout);
136147
m_optionsLayout = NULL;
137148
}
138-
139-
} // end ~Shell
149+
}
140150

141151
//-------------------------------------------------------------------------------------------------
142152
/** Initialize the shell system */
@@ -165,7 +175,7 @@ void Shell::reset( void )
165175

166176
// pop all screens
167177
while( m_screenCount )
168-
pop();
178+
popImmediate();
169179

170180
m_animateWindowManager->reset();
171181

@@ -217,6 +227,71 @@ void Shell::update( void )
217227

218228
} // end update
219229

230+
//-------------------------------------------------------------------------------------------------
231+
namespace
232+
{
233+
struct ScreenInfo
234+
{
235+
ScreenInfo() : isHidden(false) {}
236+
AsciiString filename;
237+
bool isHidden;
238+
};
239+
}
240+
241+
//-------------------------------------------------------------------------------------------------
242+
void Shell::recreateWindowLayouts()
243+
{
244+
// collect state of the current shell
245+
const Int screenCount = getScreenCount();
246+
std::vector<ScreenInfo> screenStackInfos;
247+
Bool showOptions = false;
248+
249+
{
250+
screenStackInfos.resize(screenCount);
251+
Int screenIndex = 0;
252+
for (; screenIndex < screenCount; ++screenIndex)
253+
{
254+
const WindowLayout* layout = getScreenLayout(screenIndex);
255+
ScreenInfo& screenInfo = screenStackInfos[screenIndex];
256+
screenInfo.filename = layout->getFilename();
257+
screenInfo.isHidden = layout->isHidden();
258+
}
259+
260+
const WindowLayout* optionsLayout = getOptionsLayout(false);
261+
if (optionsLayout != NULL)
262+
{
263+
DEBUG_ASSERTCRASH(!optionsLayout->isHidden(), ("options menu layout is hidden\n"));
264+
showOptions = true;
265+
}
266+
}
267+
268+
// reconstruct the shell now
269+
deconstruct();
270+
construct();
271+
init();
272+
273+
// restore the screen stack
274+
Int screenIndex = 0;
275+
for (; screenIndex < screenCount; ++screenIndex)
276+
{
277+
const ScreenInfo& screenInfo = screenStackInfos[screenIndex];
278+
push(screenInfo.filename);
279+
280+
WindowLayout* layout = getScreenLayout(screenIndex);
281+
layout->hide(screenInfo.isHidden);
282+
}
283+
284+
if (showOptions)
285+
{
286+
// restore the options menu
287+
WindowLayout* layout = getOptionsLayout(true);
288+
DEBUG_ASSERTCRASH(layout != NULL, ("options menu layout is NULL\n"));
289+
layout->runInit();
290+
layout->hide(false);
291+
layout->bringForward();
292+
}
293+
}
294+
220295
//-------------------------------------------------------------------------------------------------
221296
/** Find a screen via the .wnd script filename loaded */
222297
//-------------------------------------------------------------------------------------------------
@@ -473,7 +548,7 @@ void Shell::showShell( Bool runInit )
473548
Profile::StopRange("init");
474549
#endif
475550
//else
476-
TheShell->push( AsciiString("Menus/MainMenu.wnd") );
551+
push( AsciiString("Menus/MainMenu.wnd") );
477552
}
478553
m_isShellActive = TRUE;
479554
} // end showShell

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Shell/ShellUtil.cpp

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,75 +28,34 @@
2828
namespace shell
2929
{
3030

31-
namespace
31+
void recreateUI()
3232
{
33-
struct ScreenInfo
34-
{
35-
ScreenInfo() : isHidden(false) {}
36-
AsciiString filename;
37-
bool isHidden;
38-
};
39-
}
40-
41-
void recreateShell()
42-
{
43-
// collect state of the current shell
44-
const Int screenCount = TheShell->getScreenCount();
45-
std::vector<ScreenInfo> screenStackInfos;
46-
Bool showOptions = false;
33+
TheShell->recreateWindowLayouts();
4734

48-
{
49-
screenStackInfos.resize(screenCount);
50-
Int screenIndex = 0;
51-
for (; screenIndex < screenCount; ++screenIndex)
52-
{
53-
const WindowLayout* layout = TheShell->getScreenLayout(screenIndex);
54-
ScreenInfo& screenInfo = screenStackInfos[screenIndex];
55-
screenInfo.filename = layout->getFilename();
56-
screenInfo.isHidden = layout->isHidden();
57-
}
35+
showMainMenuButtons();
5836

59-
const WindowLayout* optionsLayout = TheShell->getOptionsLayout(false);
60-
if (optionsLayout != NULL)
61-
{
62-
DEBUG_ASSERTCRASH(!optionsLayout->isHidden(), ("options menu layout is hidden\n"));
63-
showOptions = true;
64-
}
65-
}
66-
67-
// recreate the shell
68-
delete TheShell;
69-
TheShell = MSGNEW("GameClientSubsystem") Shell;
70-
TheShell->init();
37+
TheInGameUI->recreateControlBar();
38+
}
7139

72-
// restore the screen stack
40+
void showMainMenuButtons()
41+
{
42+
Int screenCount = TheShell->getScreenCount();
7343
Int screenIndex = 0;
7444
for (; screenIndex < screenCount; ++screenIndex)
7545
{
76-
const ScreenInfo& screenInfo = screenStackInfos[screenIndex];
77-
TheShell->push(screenInfo.filename);
78-
7946
WindowLayout* layout = TheShell->getScreenLayout(screenIndex);
80-
layout->hide(screenInfo.isHidden);
81-
}
82-
83-
if (showOptions)
84-
{
85-
// restore the options menu
86-
WindowLayout* layout = TheShell->getOptionsLayout(true);
87-
DEBUG_ASSERTCRASH(layout != NULL, ("options menu layout is NULL\n"));
88-
layout->runInit();
89-
layout->hide(false);
90-
layout->bringForward();
91-
}
92-
93-
// Show the main menu logo and buttons right away.
94-
if (TransitionGroup* transitionGroup = TheTransitionHandler->setGroup("MainMenuDefaultMenuLogoFade", true))
95-
{
96-
transitionGroup->skip();
47+
if (0 == layout->getFilename().compareNoCase("Menus/MainMenu.wnd"))
48+
{
49+
if (!layout->isHidden())
50+
{
51+
if (TransitionGroup* transitionGroup = TheTransitionHandler->setGroup("MainMenuDefaultMenuLogoFade", true))
52+
{
53+
transitionGroup->skip();
54+
}
55+
}
56+
break;
57+
}
9758
}
98-
99-
TheInGameUI->recreateControlBar();
10059
}
10160

10261
} // namespace shell

0 commit comments

Comments
 (0)