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"
31 #include "../core/geometry_func.hpp"
35 #include "../script/api/script_log.hpp"
39 #include "../game/game.hpp"
40 #include "../game/game_config.hpp"
41 #include "../game/game_info.hpp"
42 #include "../game/game_instance.hpp"
44 #include "table/strings.h"
48 #include "../safeguards.h"
91 for (ScriptInfoList::const_iterator it = this->
info_list->begin(); it != this->
info_list->end(); it++, i++) {
92 if ((*it).second == info) {
104 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
125 int y = this->GetWidget<NWidgetBase>(
WID_AIL_LIST)->pos_y;
131 ScriptInfoList::const_iterator it = this->
info_list->begin();
132 for (
int i = 1; it != this->
info_list->end(); i++, it++) {
141 AIInfo *selected_info = NULL;
142 ScriptInfoList::const_iterator it = this->
info_list->begin();
143 for (
int i = 1; selected_info == NULL && it != this->
info_list->end(); i++, it++) {
144 if (this->
selected == i - 1) selected_info =
static_cast<AIInfo *
>((*it).second);
147 if (selected_info != NULL) {
155 if (selected_info->
GetURL() != NULL) {
174 GetConfig(slot)->
Change(NULL);
176 ScriptInfoList::const_iterator it = this->
info_list->begin();
177 for (
int i = 0; i < this->
selected; i++) it++;
178 GetConfig(slot)->
Change((*it).second->GetName(), (*it).second->GetVersion());
190 if (sel < (
int)this->
info_list->size()) {
193 if (click_count > 1) {
230 if (!gui_scope)
return;
247 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),
266 _nested_ai_list_widgets,
lengthof(_nested_ai_list_widgets)
293 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
324 SetDParam(0, (this->slot ==
OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
378 int current_value = config->
GetSetting((config_item).name);
385 if (!strcmp(config_item.
name,
"start_date")) {
387 str = STR_AI_SETTINGS_START_DELAY;
388 colour = TC_LIGHT_BLUE;
390 str = STR_JUST_STRING;
394 str = STR_AI_SETTINGS_SETTING;
395 colour = TC_LIGHT_BLUE;
400 DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
401 SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
417 DrawString(text_left, text_right, y + text_y_offset, str, colour);
440 for (
int i = 0; i < num; i++) it++;
453 int x = pt.x - wid->
pos_x;
476 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
489 int new_val = old_val;
504 if (new_val != old_val) {
537 int32 value = atoi(str);
595 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),
612 _nested_ai_settings_widgets,
lengthof(_nested_ai_settings_widgets)
633 const char *textfile = GetConfig(slot)->
GetTextfile(file_type, slot);
670 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),
679 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),
685 NWidget(
WWT_MATRIX, COLOUR_MAUVE,
WID_AIC_GAMELIST),
SetMinimalSize(288, 14),
SetFill(1, 0),
SetMatrixDataTip(1, 1, STR_AI_CONFIG_GAMELIST_TOOLTIP),
697 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),
706 _nested_ai_config_widgets,
lengthof(_nested_ai_config_widgets)
743 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
772 SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
781 dim.width += padding.width;
782 dim.height += padding.height;
783 *size =
maxdim(*size, dim);
798 if (_game_mode != GM_NORMAL) {
807 return slot < max_slot;
818 text = STR_JUST_RAW_STRING;
833 text = STR_AI_CONFIG_HUMAN_PLAYER;
836 text = STR_JUST_RAW_STRING;
838 text = STR_AI_CONFIG_RANDOM_AI;
841 (this->selected_slot == i) ? TC_WHITE : (
IsEditable((
CompanyID)i) ? TC_ORANGE : TC_SILVER));
867 IConsoleSetSetting(
"difficulty.max_no_competitors", new_value);
889 this->selected_slot--;
898 this->selected_slot++;
920 #if defined(ENABLE_NETWORK)
939 if (!gui_scope)
return;
948 for (
TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
973 Colours colour = dead ? COLOUR_RED :
974 (paused ? COLOUR_YELLOW : COLOUR_GREY);
975 if (button.
colour != colour) {
1004 ScriptLog::LogData *GetLogPointer()
const
1018 return game == NULL || game->
IsDead();
1049 FOR_ALL_COMPANIES(c) {
1119 bool dead = valid &&
Company::Get(i)->ai_instance->IsDead();
1120 bool paused = valid &&
Company::Get(i)->ai_instance->IsPaused();
1126 if (!valid)
continue;
1134 bool valid = game != NULL;
1135 bool dead = valid && game->
IsDead();
1136 bool paused = valid && game->
IsPaused();
1146 ScriptLog::LogData *log = this->GetLogPointer();
1148 int scroll_count = (log == NULL) ? 0 : log->used;
1156 if (log == NULL)
return;
1164 int scroll_pos =
max(0, log->used - this->vscroll->GetCapacity());
1182 assert(info != NULL);
1183 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1190 assert(info != NULL);
1191 SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
1205 ScriptLog::LogData *log = this->GetLogPointer();
1206 if (log == NULL)
return;
1210 int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
1211 if (log->lines[pos] == NULL)
break;
1214 switch (log->type[pos]) {
1215 case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK;
break;
1216 case ScriptLog::LOG_SQ_ERROR: colour = TC_RED;
break;
1217 case ScriptLog::LOG_INFO: colour = TC_BLACK;
break;
1218 case ScriptLog::LOG_WARNING: colour = TC_YELLOW;
break;
1219 case ScriptLog::LOG_ERROR: colour = TC_RED;
break;
1220 default: colour = TC_BLACK;
break;
1226 if (colour == TC_BLACK) colour = TC_WHITE;
1309 FOR_ALL_COMPANIES(c) {
1311 all_unpaused =
false;
1349 ScriptLog::LogData *log = this->GetLogPointer();
1375 if (!gui_scope)
return;
1435 static Hotkey aidebug_hotkeys[] = {
1492 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),
1509 WDP_AUTO,
"script_debug", 600, 450,
1512 _nested_ai_debug_widgets,
lengthof(_nested_ai_debug_widgets),
1513 &AIDebugWindow::hotkeys
1549 FOR_ALL_COMPANIES(c) {
1557 if (g != NULL && g->
IsDead()) {