Files
@ r27835:eabfaa878ced
Branch filter:
Location: cpp/openttd-patchpack/source/src/ai/ai_gui.cpp - annotation
r27835:eabfaa878ced
12.6 KiB
text/x-c
Add: calendar date for Survey results
This means no heuristics is possible on around which date people
play the game.
This means no heuristics is possible on around which date people
play the game.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r18845:66bf168f1100 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r18617:524f2e0f54dc r10696:8dfe83e30d01 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r11185:ac324a2379e8 r10840:7a608f4ad153 r22386:2ec8551a1144 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r20388:7a2f2cbf65ab r10840:7a608f4ad153 r18510:9d33e9643f80 r26856:c988753485d9 r10696:8dfe83e30d01 r10696:8dfe83e30d01 r21383:942c32fb8b0e r21383:942c32fb8b0e r19068:3e8bf48b7b8a r15620:0378519ad922 r11486:edda18b2134e r11486:edda18b2134e r13742:180ad925befc r26532:48cddf601bc5 r11486:edda18b2134e r18673:e5a4490b411b r13968:ef1d3e81523a r18749:61ed9890edec r27104:635f8101e375 r27104:635f8101e375 r13659:b0b84c1c2151 r26498:675708fb9285 r13659:b0b84c1c2151 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r18749:61ed9890edec r18673:e5a4490b411b r18673:e5a4490b411b r13968:ef1d3e81523a r13659:b0b84c1c2151 r18749:61ed9890edec r18749:61ed9890edec r20507:d54715c529f7 r18749:61ed9890edec r18749:61ed9890edec r11486:edda18b2134e r11486:edda18b2134e r26532:48cddf601bc5 r26532:48cddf601bc5 r26532:48cddf601bc5 r26532:48cddf601bc5 r18749:61ed9890edec r18749:61ed9890edec r25190:c33b3edbcf73 r19068:3e8bf48b7b8a r19068:3e8bf48b7b8a r11486:edda18b2134e r25190:c33b3edbcf73 r11486:edda18b2134e r11486:edda18b2134e r11486:edda18b2134e r15620:0378519ad922 r20280:ca1fc41725ff r20283:2a199c78224c r10840:7a608f4ad153 r19745:d8f95208ad9e r13554:d1964ead02ee r11368:058349c3a02c r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r15620:0378519ad922 r15620:0378519ad922 r17616:3ed8a6b01283 r10840:7a608f4ad153 r20280:ca1fc41725ff r10840:7a608f4ad153 r20280:ca1fc41725ff r18673:e5a4490b411b r12591:0f17c8004d0f r18673:e5a4490b411b r15769:4a935f419828 r15769:4a935f419828 r12591:0f17c8004d0f r10840:7a608f4ad153 r10840:7a608f4ad153 r25564:c875d92c537a r10840:7a608f4ad153 r26856:c988753485d9 r26856:c988753485d9 r25564:c875d92c537a r10840:7a608f4ad153 r10840:7a608f4ad153 r23499:f9bf6ad58697 r12591:0f17c8004d0f r13567:9f40d27b2fd6 r18673:e5a4490b411b r16950:9855f8364bec r13567:9f40d27b2fd6 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r13659:b0b84c1c2151 r13659:b0b84c1c2151 r13567:9f40d27b2fd6 r23499:f9bf6ad58697 r13659:b0b84c1c2151 r13659:b0b84c1c2151 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r26423:b2ef3bb21347 r26423:b2ef3bb21347 r26423:b2ef3bb21347 r18673:e5a4490b411b r26563:75f924e74612 r25213:cae9268da683 r20508:eda733209ea3 r13567:9f40d27b2fd6 r12591:0f17c8004d0f r12591:0f17c8004d0f r12591:0f17c8004d0f r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r23674:a5bafa1a02c5 r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r16950:9855f8364bec r23499:f9bf6ad58697 r12591:0f17c8004d0f r12591:0f17c8004d0f r18673:e5a4490b411b r26575:d5725bf82346 r15769:4a935f419828 r12591:0f17c8004d0f r12591:0f17c8004d0f r16950:9855f8364bec r16950:9855f8364bec r23607:36c15679007d r12591:0f17c8004d0f r12591:0f17c8004d0f r12591:0f17c8004d0f r12622:202e83a6cee7 r12591:0f17c8004d0f r26549:82dacf005b0a r16950:9855f8364bec r26549:82dacf005b0a r12591:0f17c8004d0f r12591:0f17c8004d0f r12591:0f17c8004d0f r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r23499:f9bf6ad58697 r10840:7a608f4ad153 r27371:b9ad4c1bff08 r26856:c988753485d9 r19068:3e8bf48b7b8a r19068:3e8bf48b7b8a r19068:3e8bf48b7b8a r19068:3e8bf48b7b8a r19068:3e8bf48b7b8a r10840:7a608f4ad153 r27104:635f8101e375 r27104:635f8101e375 r13659:b0b84c1c2151 r27104:635f8101e375 r24597:afde5721a3b6 r13659:b0b84c1c2151 r24597:afde5721a3b6 r10853:44b4b13121cb r13659:b0b84c1c2151 r10853:44b4b13121cb r10853:44b4b13121cb r10853:44b4b13121cb r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r18673:e5a4490b411b r25213:cae9268da683 r13159:03d1e6e6c70a r27038:297671ffbe62 r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r18673:e5a4490b411b r16950:9855f8364bec r16950:9855f8364bec r13968:ef1d3e81523a r15769:4a935f419828 r13968:ef1d3e81523a r13968:ef1d3e81523a r13968:ef1d3e81523a r13968:ef1d3e81523a r18673:e5a4490b411b r16950:9855f8364bec r16950:9855f8364bec r13968:ef1d3e81523a r15769:4a935f419828 r13968:ef1d3e81523a r13968:ef1d3e81523a r13968:ef1d3e81523a r13968:ef1d3e81523a r18673:e5a4490b411b r27038:297671ffbe62 r10840:7a608f4ad153 r10840:7a608f4ad153 r18673:e5a4490b411b r26856:c988753485d9 r10840:7a608f4ad153 r10840:7a608f4ad153 r18673:e5a4490b411b r25564:c875d92c537a r10840:7a608f4ad153 r13959:44bb928ae22d r18673:e5a4490b411b r13959:44bb928ae22d r14635:a75264d517b7 r13959:44bb928ae22d r26532:48cddf601bc5 r13959:44bb928ae22d r13959:44bb928ae22d r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r23499:f9bf6ad58697 r10840:7a608f4ad153 r16950:9855f8364bec r13895:009db002ff3f r13895:009db002ff3f r13895:009db002ff3f r17484:696d6356f836 r17484:696d6356f836 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r26532:48cddf601bc5 r26856:c988753485d9 r26532:48cddf601bc5 r26532:48cddf601bc5 r19068:3e8bf48b7b8a r27371:b9ad4c1bff08 r27259:59b91be38623 r19068:3e8bf48b7b8a r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 r15620:0378519ad922 r10840:7a608f4ad153 r10840:7a608f4ad153 r25565:6a5de7df7ea1 r10840:7a608f4ad153 r10840:7a608f4ad153 r10840:7a608f4ad153 | /*
* 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/>.
*/
/** @file ai_gui.cpp %Window for configuring the AIs */
#include "../stdafx.h"
#include "../error.h"
#include "../company_base.h"
#include "../window_func.h"
#include "../network/network.h"
#include "../settings_func.h"
#include "../network/network_content.h"
#include "../core/geometry_func.hpp"
#include "ai.hpp"
#include "ai_gui.hpp"
#include "ai_config.hpp"
#include "ai_info.hpp"
#include "../script/script_gui.h"
#include "table/strings.h"
#include "../safeguards.h"
/** Widgets for the configure AI window. */
static const NWidgetPart _nested_ai_config_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION_AI, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIC_BACKGROUND),
NWidget(NWID_VERTICAL), SetPIP(4, 4, 4),
NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
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),
NWidget(NWID_SPACER), SetMinimalSize(6, 0),
NWidget(WWT_TEXT, COLOUR_MAUVE, WID_AIC_NUMBER), SetDataTip(STR_AI_CONFIG_MAX_COMPETITORS, STR_NULL), SetFill(1, 0),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
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),
NWidget(NWID_SPACER), SetMinimalSize(6, 0),
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), SetPIP(7, 0, 7),
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(),
EndContainer(),
NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_AI, STR_NULL), SetPadding(0, 5, 0, 5),
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(),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 9),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CHANGE_AI, STR_AI_CONFIG_CHANGE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONTENT_DOWNLOAD), SetFill(1, 0), SetMinimalSize(279, 0), SetPadding(0, 7, 9, 7), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
EndContainer(),
};
/** Window definition for the configure AI window. */
static WindowDesc _ai_config_desc(
WDP_CENTER, "settings_script_config", 0, 0,
WC_GAME_OPTIONS, WC_NONE,
0,
_nested_ai_config_widgets, lengthof(_nested_ai_config_widgets)
);
/**
* Window to configure which AIs will start.
*/
struct AIConfigWindow : public Window {
CompanyID selected_slot; ///< The currently selected AI slot or \c INVALID_COMPANY.
int line_height; ///< Height of a single AI-name line.
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
AIConfigWindow() : Window(&_ai_config_desc)
{
this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect.
this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR);
this->selected_slot = INVALID_COMPANY;
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIC_LIST);
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
this->vscroll->SetCount(MAX_COMPANIES);
this->OnInvalidateData(0);
}
void Close() override
{
CloseWindowByClass(WC_SCRIPT_LIST);
CloseWindowByClass(WC_SCRIPT_SETTINGS);
this->Window::Close();
}
void SetStringParameters(int widget) const override
{
switch (widget) {
case WID_AIC_NUMBER:
SetDParam(0, GetGameSettings().difficulty.max_no_competitors);
break;
case WID_AIC_INTERVAL:
SetDParam(0, GetGameSettings().difficulty.competitors_interval);
break;
}
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
case WID_AIC_DECREASE_NUMBER:
case WID_AIC_INCREASE_NUMBER:
case WID_AIC_DECREASE_INTERVAL:
case WID_AIC_INCREASE_INTERVAL:
*size = maxdim(*size, NWidgetScrollbar::GetHorizontalDimension());
break;
case WID_AIC_LIST:
this->line_height = FONT_HEIGHT_NORMAL + padding.height;
resize->height = this->line_height;
size->height = 8 * this->line_height;
break;
}
}
/**
* 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;
}
if (Company::IsValidID(slot)) return false;
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;
}
void DrawWidget(const Rect &r, int widget) const override
{
switch (widget) {
case WID_AIC_LIST: {
Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < MAX_COMPANIES; i++) {
StringID text;
if ((_game_mode != GM_NORMAL && i == 0) || (_game_mode == GM_NORMAL && Company::IsValidHumanID(i))) {
text = STR_AI_CONFIG_HUMAN_PLAYER;
} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != nullptr) {
SetDParamStr(0, AIConfig::GetConfig((CompanyID)i)->GetInfo()->GetName());
text = STR_JUST_RAW_STRING;
} else {
text = STR_AI_CONFIG_RANDOM_AI;
}
DrawString(tr, text,
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
tr.top += this->line_height;
}
break;
}
}
}
void OnClick(Point pt, int widget, int click_count) override
{
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) {
if (this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot) == nullptr) return;
ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
return;
}
switch (widget) {
case WID_AIC_DECREASE_NUMBER:
case WID_AIC_INCREASE_NUMBER: {
int new_value;
if (widget == WID_AIC_DECREASE_NUMBER) {
new_value = std::max(0, GetGameSettings().difficulty.max_no_competitors - 1);
} else {
new_value = std::min(MAX_COMPANIES - 1, GetGameSettings().difficulty.max_no_competitors + 1);
}
IConsoleSetSetting("difficulty.max_no_competitors", new_value);
break;
}
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);
break;
}
case WID_AIC_LIST: { // Select a slot
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget);
this->InvalidateData();
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
break;
}
case WID_AIC_MOVE_UP:
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]);
this->selected_slot--;
this->vscroll->ScrollTowards(this->selected_slot);
this->InvalidateData();
}
break;
case WID_AIC_MOVE_DOWN:
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]);
this->selected_slot++;
this->vscroll->ScrollTowards(this->selected_slot);
this->InvalidateData();
}
break;
case WID_AIC_CHANGE: // choose other AI
ShowScriptListWindow((CompanyID)this->selected_slot, _ctrl_pressed);
break;
case WID_AIC_CONFIGURE: // change the settings for an AI
ShowScriptSettingsWindow((CompanyID)this->selected_slot);
break;
case WID_AIC_CLOSE:
this->Close();
break;
case WID_AIC_CONTENT_DOWNLOAD:
if (!_network_available) {
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
} else {
ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_AI);
}
break;
}
}
/**
* 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.
*/
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!IsEditable(this->selected_slot)) {
this->selected_slot = INVALID_COMPANY;
}
if (!gui_scope) return;
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);
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
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)));
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || !AIConfig::GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot).has_value());
}
}
};
/** Open the AI config window. */
void ShowAIConfigWindow()
{
CloseWindowByClass(WC_GAME_OPTIONS);
new AIConfigWindow();
}
|