Fix: Closing the Game Options window closes all textfile windows.

Record the parent window that opens a textfile window so only child windows are closed instead of all.
This commit is contained in:
2025-05-04 17:50:31 +01:00
committed by Peter Nelson
parent dabf2ede67
commit ac76212b80
12 changed files with 44 additions and 45 deletions

View File

@@ -103,7 +103,7 @@ struct BaseSetTextfileWindow : public TextfileWindow {
const std::string name; ///< Name of the content.
const StringID content_type; ///< STR_CONTENT_TYPE_xxx for title.
BaseSetTextfileWindow(TextfileType file_type, const std::string &name, const std::string &textfile, StringID content_type) : TextfileWindow(file_type), name(name), content_type(content_type)
BaseSetTextfileWindow(Window *parent, TextfileType file_type, const std::string &name, const std::string &textfile, StringID content_type) : TextfileWindow(parent, file_type), name(name), content_type(content_type)
{
this->ConstructWindow();
this->LoadTextfile(textfile, BASESET_DIR);
@@ -126,10 +126,10 @@ struct BaseSetTextfileWindow : public TextfileWindow {
* @param content_type STR_CONTENT_TYPE_xxx for title.
*/
template <class TBaseSet>
void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet *baseset, StringID content_type)
void ShowBaseSetTextfileWindow(Window *parent, TextfileType file_type, const TBaseSet *baseset, StringID content_type)
{
CloseWindowById(WC_TEXTFILE, file_type);
new BaseSetTextfileWindow(file_type, baseset->name, *baseset->GetTextfile(file_type), content_type);
parent->CloseChildWindowById(WC_TEXTFILE, file_type);
new BaseSetTextfileWindow(parent, file_type, baseset->name, *baseset->GetTextfile(file_type), content_type);
}
/**
@@ -464,7 +464,6 @@ struct GameOptionsWindow : Window {
void Close([[maybe_unused]] int data = 0) override
{
CloseWindowById(WC_CUSTOM_CURRENCY, 0);
CloseWindowByClass(WC_TEXTFILE);
if (this->reload) _switch_mode = SM_MENU;
this->Window::Close();
}
@@ -939,19 +938,19 @@ struct GameOptionsWindow : Window {
if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END) {
if (BaseGraphics::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
return;
}
if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_CONTENT_END) {
if (BaseSounds::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
return;
}
if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END) {
if (BaseMusic::GetUsedSet() == nullptr) return;
ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
return;
}
switch (widget) {
@@ -984,7 +983,7 @@ struct GameOptionsWindow : Window {
break;
case WID_GO_SURVEY_PREVIEW_BUTTON:
ShowSurveyResultTextfileWindow();
ShowSurveyResultTextfileWindow(this);
break;
case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off