2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-01 17:22:32 +00:00
|
|
|
/** @file ai_gui.cpp %Window for configuring the AIs */
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
#include "../stdafx.h"
|
2011-12-10 13:54:10 +00:00
|
|
|
#include "../error.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "../company_base.h"
|
|
|
|
#include "../window_func.h"
|
|
|
|
#include "../network/network.h"
|
2009-02-21 02:34:53 +00:00
|
|
|
#include "../settings_func.h"
|
2009-01-20 16:49:10 +00:00
|
|
|
#include "../network/network_content.h"
|
2016-05-22 12:00:36 +00:00
|
|
|
#include "../core/geometry_func.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
#include "ai.hpp"
|
2013-06-15 15:05:54 +00:00
|
|
|
#include "ai_gui.hpp"
|
2009-01-20 16:49:10 +00:00
|
|
|
#include "ai_config.hpp"
|
2011-11-29 23:26:35 +00:00
|
|
|
#include "ai_info.hpp"
|
2023-02-04 03:17:55 +00:00
|
|
|
#include "../script/script_gui.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "../safeguards.h"
|
|
|
|
|
2012-02-12 10:58:18 +00:00
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Widgets for the configure AI window. */
|
2024-01-15 22:49:24 +00:00
|
|
|
static constexpr NWidgetPart _nested_ai_config_widgets[] = {
|
2009-03-25 21:35:53 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
2022-11-10 20:39:09 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
|
2023-11-16 20:02:07 +00:00
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse),
|
|
|
|
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_NUMBER), SetDataTip(AWV_DECREASE, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_NUMBER), SetDataTip(AWV_INCREASE, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_NUMBER), SetDataTip(STR_AI_CONFIG_MAX_COMPETITORS, STR_NULL), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE_INTERVAL), SetDataTip(AWV_DECREASE, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE_INTERVAL), SetDataTip(AWV_INCREASE, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_INTERVAL), SetDataTip(STR_AI_CONFIG_COMPETITORS_INTERVAL, STR_NULL), SetFill(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_UP), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_UP, STR_AI_CONFIG_MOVE_UP_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_MOVE_DOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_MOVE_DOWN, STR_AI_CONFIG_MOVE_DOWN_TOOLTIP),
|
|
|
|
EndContainer(),
|
2009-11-19 21:21:39 +00:00
|
|
|
EndContainer(),
|
2023-11-28 20:49:16 +00:00
|
|
|
NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
|
2023-11-16 20:02:07 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_LIST), SetMinimalSize(288, 112), SetFill(1, 0), SetMatrixDataTip(1, 8, STR_AI_CONFIG_AILIST_TOOLTIP), SetScrollbar(WID_AIC_SCROLLBAR),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
|
|
|
|
EndContainer(),
|
2023-11-28 20:49:16 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
|
2023-04-16 18:14:22 +00:00
|
|
|
EndContainer(),
|
2023-11-28 20:49:16 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
|
|
|
|
NWidget(NWID_VERTICAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 1), SetDataTip(STR_AI_CONFIG_CHANGE_AI, STR_AI_CONFIG_CHANGE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 1), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
|
2023-11-16 20:02:07 +00:00
|
|
|
EndContainer(),
|
2023-11-28 20:49:16 +00:00
|
|
|
NWidget(NWID_VERTICAL, NC_EQUALSIZE),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
|
|
|
|
EndContainer(),
|
2023-11-16 20:02:07 +00:00
|
|
|
EndContainer(),
|
2009-12-16 16:57:26 +00:00
|
|
|
EndContainer(),
|
2009-11-19 21:21:39 +00:00
|
|
|
EndContainer(),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Window definition for the configure AI window. */
|
2023-11-02 19:33:01 +00:00
|
|
|
static WindowDesc _ai_config_desc(__FILE__, __LINE__,
|
2023-11-02 21:28:24 +00:00
|
|
|
WDP_CENTER, nullptr, 0, 0,
|
2009-01-20 16:49:10 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2023-09-03 20:54:13 +00:00
|
|
|
std::begin(_nested_ai_config_widgets), std::end(_nested_ai_config_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-20 16:49:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Window to configure which AIs will start.
|
|
|
|
*/
|
|
|
|
struct AIConfigWindow : public Window {
|
2010-08-01 22:08:29 +00:00
|
|
|
CompanyID selected_slot; ///< The currently selected AI slot or \c INVALID_COMPANY.
|
|
|
|
int line_height; ///< Height of a single AI-name line.
|
2011-05-01 09:24:19 +00:00
|
|
|
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
AIConfigWindow() : Window(&_ai_config_desc)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2013-05-26 19:23:42 +00:00
|
|
|
this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
|
2009-08-02 18:54:49 +00:00
|
|
|
this->selected_slot = INVALID_COMPANY;
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
|
|
|
|
this->vscroll->SetCount(MAX_COMPANIES);
|
2009-08-02 18:54:49 +00:00
|
|
|
this->OnInvalidateData(0);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2023-10-13 11:59:15 +00:00
|
|
|
void Close([[maybe_unused]] int data = 0) override
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2023-02-04 03:17:55 +00:00
|
|
|
CloseWindowByClass(WC_SCRIPT_LIST);
|
|
|
|
CloseWindowByClass(WC_SCRIPT_SETTINGS);
|
2021-05-15 21:12:25 +00:00
|
|
|
this->Window::Close();
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void SetStringParameters(WidgetID widget) const override
|
2009-08-02 18:54:49 +00:00
|
|
|
{
|
2009-11-15 17:22:47 +00:00
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_NUMBER:
|
2011-01-02 12:41:24 +00:00
|
|
|
SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
|
2009-11-15 17:22:47 +00:00
|
|
|
break;
|
2023-04-16 18:14:22 +00:00
|
|
|
|
|
|
|
case WID_AIC_INTERVAL:
|
|
|
|
SetDParam(0, GetGameSettings().difficulty.competitors_interval);
|
|
|
|
break;
|
2009-11-19 21:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-15 17:22:47 +00:00
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
|
2009-11-19 21:21:39 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2023-04-16 18:14:22 +00:00
|
|
|
case WID_AIC_DECREASE_NUMBER:
|
|
|
|
case WID_AIC_INCREASE_NUMBER:
|
|
|
|
case WID_AIC_DECREASE_INTERVAL:
|
|
|
|
case WID_AIC_INCREASE_INTERVAL:
|
2022-10-02 18:23:21 +00:00
|
|
|
*size = maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST:
|
2023-11-21 19:04:24 +00:00
|
|
|
this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
|
2021-04-21 14:22:45 +00:00
|
|
|
resize->height = this->line_height;
|
2013-06-30 14:33:15 +00:00
|
|
|
size->height = 8 * this->line_height;
|
2009-11-15 17:22:47 +00:00
|
|
|
break;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-02 12:41:24 +00:00
|
|
|
/**
|
|
|
|
* Can the AI config in the given company slot be edited?
|
|
|
|
* @param slot The slot to query.
|
|
|
|
* @return True if and only if the given AI Config slot can e edited.
|
|
|
|
*/
|
|
|
|
static bool IsEditable(CompanyID slot)
|
|
|
|
{
|
|
|
|
if (_game_mode != GM_NORMAL) {
|
|
|
|
return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
|
|
|
|
}
|
2019-04-22 08:10:04 +00:00
|
|
|
if (Company::IsValidID(slot)) return false;
|
2011-01-02 12:41:24 +00:00
|
|
|
|
|
|
|
int max_slot = GetGameSettings().difficulty.max_no_competitors;
|
|
|
|
for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) {
|
|
|
|
if (Company::IsValidHumanID(cid)) max_slot++;
|
|
|
|
}
|
|
|
|
return slot < max_slot;
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void DrawWidget(const Rect &r, WidgetID widget) const override
|
2009-08-02 18:54:49 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST: {
|
2022-09-23 08:36:22 +00:00
|
|
|
Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
|
2010-08-12 08:37:01 +00:00
|
|
|
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
|
2009-08-02 18:54:49 +00:00
|
|
|
StringID text;
|
|
|
|
|
2011-01-02 12:41:24 +00:00
|
|
|
if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
|
|
|
|
text = STR_AI_CONFIG_HUMAN_PLAYER;
|
2019-04-10 21:07:06 +00:00
|
|
|
} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
|
2009-08-02 18:54:49 +00:00
|
|
|
SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
|
|
|
|
text = STR_JUST_RAW_STRING;
|
|
|
|
} else {
|
2009-08-05 17:59:21 +00:00
|
|
|
text = STR_AI_CONFIG_RANDOM_AI;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2022-10-15 15:55:47 +00:00
|
|
|
DrawString(tr, text,
|
2011-01-02 12:41:24 +00:00
|
|
|
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
|
2022-10-15 15:55:47 +00:00
|
|
|
tr.top += this->line_height;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 19:11:59 +00:00
|
|
|
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2023-04-25 17:43:45 +00:00
|
|
|
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) {
|
2023-02-04 03:17:55 +00:00
|
|
|
if (this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
|
2012-02-12 10:58:18 +00:00
|
|
|
|
|
|
|
ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
switch (widget) {
|
2023-04-16 18:14:22 +00:00
|
|
|
case WID_AIC_DECREASE_NUMBER:
|
|
|
|
case WID_AIC_INCREASE_NUMBER: {
|
2009-11-19 21:21:39 +00:00
|
|
|
int new_value;
|
2023-04-16 18:14:22 +00:00
|
|
|
if (widget == WID_AIC_DECREASE_NUMBER) {
|
2021-01-08 10:16:18 +00:00
|
|
|
new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
|
2009-11-19 21:21:39 +00:00
|
|
|
} else {
|
2021-01-08 10:16:18 +00:00
|
|
|
new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
|
2009-01-21 01:56:42 +00:00
|
|
|
}
|
2009-11-19 21:21:39 +00:00
|
|
|
IConsoleSetSetting("difficulty.max_no_competitors", new_value);
|
2023-12-01 12:52:33 +00:00
|
|
|
this->InvalidateData();
|
2009-01-21 01:56:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-16 18:14:22 +00:00
|
|
|
case WID_AIC_DECREASE_INTERVAL:
|
|
|
|
case WID_AIC_INCREASE_INTERVAL: {
|
|
|
|
int new_value;
|
|
|
|
if (widget == WID_AIC_DECREASE_INTERVAL) {
|
|
|
|
new_value = std::max(static_cast<int>(MIN_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval - 1);
|
|
|
|
} else {
|
|
|
|
new_value = std::min(static_cast<int>(MAX_COMPETITORS_INTERVAL), GetGameSettings().difficulty.competitors_interval + 1);
|
|
|
|
}
|
|
|
|
IConsoleSetSetting("difficulty.competitors_interval", new_value);
|
2023-12-01 12:52:33 +00:00
|
|
|
this->InvalidateData();
|
2023-04-16 18:14:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST: { // Select a slot
|
2021-04-21 14:22:45 +00:00
|
|
|
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
|
2009-09-30 21:07:54 +00:00
|
|
|
this->InvalidateData();
|
2023-04-07 17:33:07 +00:00
|
|
|
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
2009-01-20 16:49:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_MOVE_UP:
|
2011-01-02 12:41:24 +00:00
|
|
|
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
|
|
|
|
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
|
2009-12-16 16:57:26 +00:00
|
|
|
this->selected_slot--;
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->ScrollTowards(this->selected_slot);
|
2009-12-16 16:57:26 +00:00
|
|
|
this->InvalidateData();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_MOVE_DOWN:
|
2011-01-02 12:41:24 +00:00
|
|
|
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
|
|
|
|
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
|
2009-12-16 16:57:26 +00:00
|
|
|
this->selected_slot++;
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->ScrollTowards(this->selected_slot);
|
2009-12-16 16:57:26 +00:00
|
|
|
this->InvalidateData();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-11-28 20:49:16 +00:00
|
|
|
case WID_AIC_OPEN_URL: {
|
|
|
|
const AIConfig *config = AIConfig::GetConfig(this->selected_slot);
|
|
|
|
if (this->selected_slot == INVALID_COMPANY || config == nullptr || config->GetInfo() == nullptr) return;
|
|
|
|
OpenBrowser(config->GetInfo()->GetURL());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CHANGE: // choose other AI
|
2023-04-07 17:33:07 +00:00
|
|
|
ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
|
2009-01-20 16:49:10 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CONFIGURE: // change the settings for an AI
|
2023-02-04 03:17:55 +00:00
|
|
|
ShowScriptSettingsWindow((CompanyID)this->selected_slot);
|
2009-01-20 16:49:10 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CONTENT_DOWNLOAD:
|
2009-12-15 00:33:44 +00:00
|
|
|
if (!_network_available) {
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
2009-12-15 00:33:44 +00:00
|
|
|
} else {
|
2022-11-10 20:39:09 +00:00
|
|
|
ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI);
|
2009-12-15 00:33:44 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
2023-09-16 20:20:53 +00:00
|
|
|
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2011-01-02 12:41:24 +00:00
|
|
|
if (!IsEditable(this->selected_slot)) {
|
2009-12-08 23:32:32 +00:00
|
|
|
this->selected_slot = INVALID_COMPANY;
|
|
|
|
}
|
|
|
|
|
2011-03-13 21:35:50 +00:00
|
|
|
if (!gui_scope) return;
|
|
|
|
|
2023-11-28 20:49:16 +00:00
|
|
|
AIConfig *config = AIConfig::GetConfig(this->selected_slot);
|
|
|
|
|
2023-04-16 18:14:22 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_DECREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == 0);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL);
|
2022-11-10 20:39:09 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
|
2023-11-28 20:49:16 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || config->GetConfigList()->empty());
|
2022-11-10 20:39:09 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
|
2012-02-12 10:58:18 +00:00
|
|
|
|
2023-11-28 20:49:16 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == INVALID_COMPANY || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty());
|
2023-04-25 17:43:45 +00:00
|
|
|
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
2023-11-28 20:49:16 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || !config->GetTextfile(tft, this->selected_slot).has_value());
|
2012-02-12 10:58:18 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Open the AI config window. */
|
2009-01-20 16:49:10 +00:00
|
|
|
void ShowAIConfigWindow()
|
|
|
|
{
|
2021-05-17 13:46:38 +00:00
|
|
|
CloseWindowByClass(WC_GAME_OPTIONS);
|
2009-01-20 16:49:10 +00:00
|
|
|
new AIConfigWindow();
|
|
|
|
}
|
|
|
|
|