Skip to content

Commit

Permalink
Fix OpenTTD#7088: Retrieve an appropriate name for a non-existant AI/…
Browse files Browse the repository at this point in the history
…GS when displaying a textfile
  • Loading branch information
SamuXarick committed Nov 15, 2019
1 parent ddffe32 commit 3398ff6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/ai/ai_gui.cpp
Expand Up @@ -179,6 +179,7 @@ struct AIListWindow : public Window {
InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
InvalidateWindowClassesData(WC_AI_SETTINGS);
DeleteWindowByClass(WC_QUERY_STRING);
InvalidateWindowClassesData(WC_TEXTFILE);
}

void OnClick(Point pt, int widget, int click_count) override
Expand Down Expand Up @@ -640,15 +641,33 @@ struct ScriptTextfileWindow : public TextfileWindow {

ScriptTextfileWindow(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
{
const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
this->OnInvalidateData();
}

void SetStringParameters(int widget) const override
{
if (widget == WID_TF_CAPTION) {
SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
SetDParamStr(1, GetConfig(slot)->GetName());

if (GetConfig(slot)->GetInfo() != nullptr) {
SetDParamStr(1, GetConfig(slot)->GetInfo()->GetName());
} else {
char name[1024];
GetString(name, (slot == OWNER_DEITY) ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, lastof(name));
const char *script_name = stredup(name);
SetDParamStr(1, script_name);
}
}
}

void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
if (textfile == nullptr) {
delete this;
} else {
this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
this->SetStringParameters(WID_TF_CAPTION);
}
}
};
Expand Down

0 comments on commit 3398ff6

Please sign in to comment.