1
0
Fork 0

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

pull/10612/head
Loïc Guilloux 2023-04-07 19:33:07 +02:00 committed by GitHub
parent 82c70ed3b8
commit e4c511d403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 15 deletions

View File

@ -194,7 +194,7 @@ struct AIConfigWindow : public Window {
case WID_AIC_LIST: { // Select a slot case WID_AIC_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget); this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
this->InvalidateData(); this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowScriptListWindow((CompanyID)this->selected_slot); if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
break; break;
} }
@ -217,7 +217,7 @@ struct AIConfigWindow : public Window {
break; break;
case WID_AIC_CHANGE: // choose other AI case WID_AIC_CHANGE: // choose other AI
ShowScriptListWindow((CompanyID)this->selected_slot); ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
break; break;
case WID_AIC_CONFIGURE: // change the settings for an AI case WID_AIC_CONFIGURE: // change the settings for an AI

View File

@ -249,12 +249,12 @@ struct GSConfigWindow : public Window {
switch (widget) { switch (widget) {
case WID_GSC_GSLIST: { case WID_GSC_GSLIST: {
this->InvalidateData(); this->InvalidateData();
if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY); if (click_count > 1 && _game_mode != GM_NORMAL) ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed);
break; break;
} }
case WID_GSC_CHANGE: // choose other Game Script case WID_GSC_CHANGE: // choose other Game Script
ShowScriptListWindow((CompanyID)OWNER_DEITY); ShowScriptListWindow((CompanyID)OWNER_DEITY, _ctrl_pressed);
break; break;
case WID_GSC_CONTENT_DOWNLOAD: case WID_GSC_CONTENT_DOWNLOAD:

View File

@ -4584,6 +4584,7 @@ STR_AI_CONFIG_AILIST_TOOLTIP :{BLACK}The AIs
STR_AI_CONFIG_HUMAN_PLAYER :Human player STR_AI_CONFIG_HUMAN_PLAYER :Human player
STR_AI_CONFIG_RANDOM_AI :Random AI STR_AI_CONFIG_RANDOM_AI :Random AI
STR_AI_CONFIG_NONE :(none) STR_AI_CONFIG_NONE :(none)
STR_AI_CONFIG_NAME_VERSION :{RAW_STRING} {YELLOW}v{NUM}
STR_AI_CONFIG_MAX_COMPETITORS :{LTBLUE}Maximum no. competitors: {ORANGE}{COMMA} STR_AI_CONFIG_MAX_COMPETITORS :{LTBLUE}Maximum no. competitors: {ORANGE}{COMMA}
STR_AI_CONFIG_MOVE_UP :{BLACK}Move Up STR_AI_CONFIG_MOVE_UP :{BLACK}Move Up
@ -4597,7 +4598,7 @@ STR_AI_CONFIG_AI :{SILVER}AIs
STR_AI_CONFIG_CHANGE_AI :{BLACK}Select AI STR_AI_CONFIG_CHANGE_AI :{BLACK}Select AI
STR_AI_CONFIG_CHANGE_GAMESCRIPT :{BLACK}Select Game Script STR_AI_CONFIG_CHANGE_GAMESCRIPT :{BLACK}Select Game Script
STR_AI_CONFIG_CHANGE_TOOLTIP :{BLACK}Load another script STR_AI_CONFIG_CHANGE_TOOLTIP :{BLACK}Load another script. Ctrl+Click to show all available versions
STR_AI_CONFIG_CONFIGURE :{BLACK}Configure STR_AI_CONFIG_CONFIGURE :{BLACK}Configure
STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}Configure the parameters of the Script STR_AI_CONFIG_CONFIGURE_TOOLTIP :{BLACK}Configure the parameters of the Script

View File

@ -54,19 +54,21 @@ struct ScriptListWindow : public Window {
CompanyID slot; ///< The company we're selecting a new Script for. CompanyID slot; ///< The company we're selecting a new Script for.
int line_height; ///< Height of a row in the matrix widget. int line_height; ///< Height of a row in the matrix widget.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar. Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
bool show_all; ///< Whether to show all available versions.
/** /**
* Constructor for the window. * Constructor for the window.
* @param desc The description of the window. * @param desc The description of the window.
* @param slot The company we're changing the Script for. * @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), ScriptListWindow(WindowDesc *desc, CompanyID slot, bool show_all) : Window(desc),
slot(slot) slot(slot), show_all(show_all)
{ {
if (slot == OWNER_DEITY) { if (slot == OWNER_DEITY) {
this->info_list = Game::GetUniqueInfoList(); this->info_list = this->show_all ? Game::GetInfoList() : Game::GetUniqueInfoList();
} else { } else {
this->info_list = AI::GetUniqueInfoList(); this->info_list = this->show_all ? AI::GetInfoList() : AI::GetUniqueInfoList();
} }
this->CreateNestedTree(); 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); 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; tr.top += this->line_height;
} }
StringID str = this->show_all ? STR_AI_CONFIG_NAME_VERSION : STR_JUST_RAW_STRING;
int i = 0; int i = 0;
for (const auto &item : *this->info_list) { for (const auto &item : *this->info_list) {
i++; i++;
if (this->vscroll->IsVisible(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; 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. * Open the Script list window to chose a script for the given company slot.
* @param slot The slot to change the AI of. * @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); CloseWindowByClass(WC_SCRIPT_LIST);
new ScriptListWindow(&_script_list_desc, slot); new ScriptListWindow(&_script_list_desc, slot, show_all);
} }

View File

@ -13,7 +13,7 @@
#include "../company_type.h" #include "../company_type.h"
#include "../textfile_type.h" #include "../textfile_type.h"
void ShowScriptListWindow(CompanyID slot); void ShowScriptListWindow(CompanyID slot, bool show_all);
Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY); Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY);
void ShowScriptSettingsWindow(CompanyID slot); void ShowScriptSettingsWindow(CompanyID slot);
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot); void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot);