12 #include "../stdafx.h"
13 #include "../table/sprites.h"
15 #include "../settings_gui.h"
16 #include "../querystring_gui.h"
17 #include "../stringfilter_type.h"
18 #include "../company_base.h"
19 #include "../company_gui.h"
20 #include "../strings_func.h"
21 #include "../window_func.h"
22 #include "../gfx_func.h"
23 #include "../command_func.h"
24 #include "../network/network.h"
25 #include "../settings_func.h"
26 #include "../network/network_content.h"
27 #include "../textfile_gui.h"
28 #include "../widgets/dropdown_type.h"
29 #include "../widgets/dropdown_func.h"
30 #include "../hotkeys.h"
34 #include "../script/api/script_log.hpp"
38 #include "../game/game.hpp"
39 #include "../game/game_config.hpp"
40 #include "../game/game_info.hpp"
41 #include "../game/game_instance.hpp"
43 #include "table/strings.h"
47 #include "../safeguards.h"
90 for (ScriptInfoList::const_iterator it = this->
info_list->begin(); it != this->
info_list->end(); it++, i++) {
91 if ((*it).second == info) {
103 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
124 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
130 ScriptInfoList::const_iterator it = this->
info_list->begin();
131 for (
int i = 1; it != this->
info_list->end(); i++, it++) {
140 AIInfo *selected_info = NULL;
141 ScriptInfoList::const_iterator it = this->
info_list->begin();
142 for (
int i = 1; selected_info == NULL && it != this->
info_list->end(); i++, it++) {
143 if (this->
selected == i - 1) selected_info =
static_cast<AIInfo *
>((*it).second);
146 if (selected_info != NULL) {
154 if (selected_info->
GetURL() != NULL) {
173 GetConfig(slot)->
Change(NULL);
175 ScriptInfoList::const_iterator it = this->
info_list->begin();
176 for (
int i = 0; i < this->
selected; i++) it++;
177 GetConfig(slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
189 if (sel < (
int)this->
info_list->size()) {
192 if (click_count > 1) {
229 if (!gui_scope)
return;
246 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIL_LIST),
SetMinimalSize(188, 112),
SetFill(1, 1),
SetResize(1, 1),
SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP),
SetScrollbar(
WID_AIL_SCROLLBAR),
265 _nested_ai_list_widgets,
lengthof(_nested_ai_list_widgets)
292 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
323 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
377 int current_value = config->
GetSetting((config_item).name);
384 if (!strcmp(config_item.
name,
"start_date")) {
386 str = STR_AI_SETTINGS_START_DELAY;
387 colour = TC_LIGHT_BLUE;
389 str = STR_JUST_STRING;
393 str = STR_AI_SETTINGS_SETTING;
394 colour = TC_LIGHT_BLUE;
399 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
400 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
416 DrawString(text_left, text_right, y + text_y_offset, str, colour);
439 for (
int i = 0; i < num; i++) it++;
452 int x = pt.x - wid->
pos_x;
475 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
488 int new_val = old_val;
503 if (new_val != old_val) {
536 int32 value = atoi(str);
594 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIS_BACKGROUND),
SetMinimalSize(188, 182),
SetResize(1, 1),
SetFill(1, 0),
SetMatrixDataTip(1, 0, STR_NULL),
SetScrollbar(
WID_AIS_SCROLLBAR),
611 _nested_ai_settings_widgets,
lengthof(_nested_ai_settings_widgets)
632 const char *textfile = GetConfig(slot)->
GetTextfile(file_type, slot);
669 NWidget(
WWT_TEXT, COLOUR_MAUVE,
WID_AIC_NUMBER),
SetDataTip(STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS, STR_NULL),
SetFill(1, 0),
SetPadding(1, 0, 0, 0),
678 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),
684 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
696 NWidget(
WWT_PUSHTXTBTN, COLOUR_YELLOW,
WID_AIC_CONTENT_DOWNLOAD),
SetFill(1, 0),
SetMinimalSize(279, 12),
SetPadding(0, 7, 9, 7),
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
705 _nested_ai_config_widgets,
lengthof(_nested_ai_config_widgets)
742 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
781 if (_game_mode != GM_NORMAL) {
790 return slot < max_slot;
801 text = STR_JUST_RAW_STRING;
816 text = STR_AI_CONFIG_HUMAN_PLAYER;
819 text = STR_JUST_RAW_STRING;
821 text = STR_AI_CONFIG_RANDOM_AI;
824 (this->selected_slot == i) ? TC_WHITE : (
IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
850 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
872 this->selected_slot--;
881 this->selected_slot++;
903 #if defined(ENABLE_NETWORK)
922 if (!gui_scope)
return;
931 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
956 Colours colour = dead ? COLOUR_RED :
957 (paused ? COLOUR_YELLOW : COLOUR_GREY);
958 if (button.
colour != colour) {
987 ScriptLog::LogData *GetLogPointer()
const
1001 return game == NULL || game->
IsDead();
1032 FOR_ALL_COMPANIES(c) {
1102 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
1103 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
1109 if (!valid)
continue;
1117 bool valid = game != NULL;
1118 bool dead = valid && game->
IsDead();
1119 bool paused = valid && game->
IsPaused();
1129 ScriptLog::LogData *log = this->GetLogPointer();
1131 int scroll_count = (log == NULL) ? 0 : log->used;
1139 if (log == NULL)
return;
1147 int scroll_pos =
max(0, log->used - this->vscroll->GetCapacity());
1165 assert(info != NULL);
1166 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1173 assert(info != NULL);
1174 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1188 ScriptLog::LogData *log = this->GetLogPointer();
1189 if (log == NULL)
return;
1193 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1194 if (log->lines[pos] == NULL)
break;
1197 switch (log->type[pos]) {
1198 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1199 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1200 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1201 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1202 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1203 default: colour = TC_BLACK;
break;
1209 if (colour == TC_BLACK) colour = TC_WHITE;
1292 FOR_ALL_COMPANIES(c) {
1294 all_unpaused =
false;
1332 ScriptLog::LogData *log = this->GetLogPointer();
1358 if (!gui_scope)
return;
1418 static Hotkey aidebug_hotkeys[] = {
1475 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_AID_BREAK_STR_EDIT_BOX),
SetFill(1, 1),
SetResize(1, 0),
SetPadding(2, 2, 2, 2),
SetDataTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1492 WDP_AUTO,
"script_debug", 600, 450,
1495 _nested_ai_debug_widgets,
lengthof(_nested_ai_debug_widgets),
1496 &AIDebugWindow::hotkeys
1532 FOR_ALL_COMPANIES(c) {
1540 if (g != NULL && g->
IsDead()) {