Fix #10578: Allow to select any version of AI/GS from GUI (#10604)

This commit is contained in:
Loïc Guilloux
2023-04-07 19:33:07 +02:00
committed by GitHub
parent 82c70ed3b8
commit e4c511d403
5 changed files with 22 additions and 15 deletions

View File

@@ -54,19 +54,21 @@ struct ScriptListWindow : public Window {
CompanyID slot; ///< The company we're selecting a new Script for.
int line_height; ///< Height of a row in the matrix widget.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
bool show_all; ///< Whether to show all available versions.
/**
* Constructor for the window.
* @param desc The description of the window.
* @param slot The company we're changing the Script for.
* @param show_all Whether to show all available versions.
*/
ScriptListWindow(WindowDesc *desc, CompanyID slot) : Window(desc),
slot(slot)
ScriptListWindow(WindowDesc *desc, CompanyID slot, bool show_all) : Window(desc),
slot(slot), show_all(show_all)
{
if (slot == OWNER_DEITY) {
this->info_list = Game::GetUniqueInfoList();
this->info_list = this->show_all ? Game::GetInfoList() : Game::GetUniqueInfoList();
} else {
this->info_list = AI::GetUniqueInfoList();
this->info_list = this->show_all ? AI::GetInfoList() : AI::GetUniqueInfoList();
}
this->CreateNestedTree();
@@ -120,11 +122,14 @@ struct ScriptListWindow : public Window {
DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
tr.top += this->line_height;
}
StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
int i = 0;
for (const auto &item : *this->info_list) {
i++;
if (this->vscroll->IsVisible(i)) {
DrawString(tr, item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
SetDParamStr(0, item.second->GetName());
SetDParam(1, item.second->GetVersion());
DrawString(tr, str, (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
tr.top += this->line_height;
}
}
@@ -262,13 +267,14 @@ static WindowDesc _script_list_desc(
);
/**
* Open the AI list window to chose an AI for the given company slot.
* @param slot The slot to change the AI of.
* Open the Script list window to chose a script for the given company slot.
* @param slot The slot to change the script of.
* @param show_all Whether to show all available versions.
*/
void ShowScriptListWindow(CompanyID slot)
void ShowScriptListWindow(CompanyID slot, bool show_all)
{
CloseWindowByClass(WC_SCRIPT_LIST);
new ScriptListWindow(&_script_list_desc, slot);
new ScriptListWindow(&_script_list_desc, slot, show_all);
}