2009-01-12 17:11:45 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2010-04-02 17:35:20 +00:00
|
|
|
#include "../table/sprites.h"
|
2011-12-10 13:54:10 +00:00
|
|
|
#include "../error.h"
|
2012-06-01 10:44:45 +00:00
|
|
|
#include "../settings_gui.h"
|
2010-04-02 17:35:20 +00:00
|
|
|
#include "../querystring_gui.h"
|
2012-06-13 18:58:29 +00:00
|
|
|
#include "../stringfilter_type.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "../company_base.h"
|
|
|
|
#include "../company_gui.h"
|
|
|
|
#include "../strings_func.h"
|
|
|
|
#include "../window_func.h"
|
|
|
|
#include "../gfx_func.h"
|
|
|
|
#include "../command_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"
|
2012-02-12 10:58:18 +00:00
|
|
|
#include "../textfile_gui.h"
|
2012-06-01 15:19:59 +00:00
|
|
|
#include "../widgets/dropdown_type.h"
|
|
|
|
#include "../widgets/dropdown_func.h"
|
2012-09-23 14:37:59 +00:00
|
|
|
#include "../hotkeys.h"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
#include "ai.hpp"
|
2011-11-29 23:07:38 +00:00
|
|
|
#include "../script/api/script_log.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"
|
2009-06-10 19:26:04 +00:00
|
|
|
#include "ai_instance.hpp"
|
2011-12-19 20:56:06 +00:00
|
|
|
#include "../game/game.hpp"
|
|
|
|
#include "../game/game_config.hpp"
|
|
|
|
#include "../game/game_info.hpp"
|
|
|
|
#include "../game/game_instance.hpp"
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2011-11-08 21:48:00 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
static ScriptConfig *GetConfig(CompanyID slot)
|
|
|
|
{
|
|
|
|
if (slot == OWNER_DEITY) return GameConfig::GetConfig();
|
|
|
|
return AIConfig::GetConfig(slot);
|
|
|
|
}
|
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
/**
|
|
|
|
* Window that let you choose an available AI.
|
|
|
|
*/
|
|
|
|
struct AIListWindow : public Window {
|
2011-12-19 20:56:06 +00:00
|
|
|
const ScriptInfoList *info_list; ///< The list of Scripts.
|
|
|
|
int selected; ///< The currently selected Script.
|
|
|
|
CompanyID slot; ///< The company we're selecting a new Script for.
|
2011-11-29 23:21:52 +00:00
|
|
|
int line_height; ///< Height of a row in the matrix widget.
|
|
|
|
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the window.
|
|
|
|
* @param desc The description of the window.
|
|
|
|
* @param slot The company we're changing the AI for.
|
|
|
|
*/
|
2009-08-02 18:54:49 +00:00
|
|
|
AIListWindow(const WindowDesc *desc, CompanyID slot) : Window(),
|
2009-01-20 16:49:10 +00:00
|
|
|
slot(slot)
|
|
|
|
{
|
2011-12-19 20:56:06 +00:00
|
|
|
if (slot == OWNER_DEITY) {
|
|
|
|
this->info_list = Game::GetUniqueInfoList();
|
|
|
|
} else {
|
|
|
|
this->info_list = AI::GetUniqueInfoList();
|
|
|
|
}
|
2009-08-02 18:54:49 +00:00
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
this->CreateNestedTree(desc);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_AIL_SCROLLBAR);
|
2010-08-12 08:37:01 +00:00
|
|
|
this->FinishInitNested(desc); // Initializes 'this->line_height' as side effect.
|
2009-08-02 18:54:49 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
this->vscroll->SetCount((int)this->info_list->size() + 1);
|
2009-01-21 00:36:22 +00:00
|
|
|
|
|
|
|
/* Try if we can find the currently selected AI */
|
|
|
|
this->selected = -1;
|
2011-12-19 20:56:06 +00:00
|
|
|
if (GetConfig(slot)->HasScript()) {
|
|
|
|
ScriptInfo *info = GetConfig(slot)->GetInfo();
|
2009-01-21 00:36:22 +00:00
|
|
|
int i = 0;
|
2011-12-19 20:56:06 +00:00
|
|
|
for (ScriptInfoList::const_iterator it = this->info_list->begin(); it != this->info_list->end(); it++, i++) {
|
2009-01-21 00:36:22 +00:00
|
|
|
if ((*it).second == info) {
|
|
|
|
this->selected = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2009-01-21 00:36:22 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_AIL_CAPTION:
|
|
|
|
SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-02 18:54:49 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget == WID_AIL_LIST) {
|
2009-08-02 18:54:49 +00:00
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
|
|
|
|
resize->width = 1;
|
|
|
|
resize->height = this->line_height;
|
2009-09-19 11:31:12 +00:00
|
|
|
size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIL_LIST: {
|
2009-08-02 18:54:49 +00:00
|
|
|
/* Draw a list of all available AIs. */
|
2011-12-16 16:27:45 +00:00
|
|
|
int y = this->GetWidget<NWidgetBase>(WID_AIL_LIST)->pos_y;
|
2009-08-02 18:54:49 +00:00
|
|
|
/* First AI in the list is hardcoded to random */
|
2010-08-12 08:37:01 +00:00
|
|
|
if (this->vscroll->IsVisible(0)) {
|
2012-05-23 19:07:34 +00:00
|
|
|
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_LEFT, y + WD_MATRIX_TOP, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += this->line_height;
|
|
|
|
}
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptInfoList::const_iterator it = this->info_list->begin();
|
|
|
|
for (int i = 1; it != this->info_list->end(); i++, it++) {
|
2010-08-12 08:37:01 +00:00
|
|
|
if (this->vscroll->IsVisible(i)) {
|
2012-05-23 19:07:34 +00:00
|
|
|
DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, (*it).second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += this->line_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-02-02 22:57:22 +00:00
|
|
|
}
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIL_INFO_BG: {
|
2009-08-02 18:54:49 +00:00
|
|
|
AIInfo *selected_info = NULL;
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptInfoList::const_iterator it = this->info_list->begin();
|
|
|
|
for (int i = 1; selected_info == NULL && it != this->info_list->end(); i++, it++) {
|
2011-11-29 23:21:52 +00:00
|
|
|
if (this->selected == i - 1) selected_info = static_cast<AIInfo *>((*it).second);
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
/* Some info about the currently selected AI. */
|
|
|
|
if (selected_info != NULL) {
|
|
|
|
int y = r.top + WD_FRAMERECT_TOP;
|
|
|
|
SetDParamStr(0, selected_info->GetAuthor());
|
2009-08-05 17:59:21 +00:00
|
|
|
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_AUTHOR);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
|
|
|
SetDParam(0, selected_info->GetVersion());
|
2009-08-05 17:59:21 +00:00
|
|
|
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_VERSION);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
|
|
|
if (selected_info->GetURL() != NULL) {
|
|
|
|
SetDParamStr(0, selected_info->GetURL());
|
2009-08-05 17:59:21 +00:00
|
|
|
DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, STR_AI_LIST_URL);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
|
|
|
}
|
|
|
|
SetDParamStr(0, selected_info->GetDescription());
|
2012-05-23 19:07:34 +00:00
|
|
|
DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_FRAMERECT_BOTTOM, STR_JUST_RAW_STRING, TC_WHITE);
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-19 15:14:23 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Changes the AI of the current slot.
|
|
|
|
*/
|
2009-01-20 16:49:10 +00:00
|
|
|
void ChangeAI()
|
|
|
|
{
|
|
|
|
if (this->selected == -1) {
|
2011-12-19 20:56:06 +00:00
|
|
|
GetConfig(slot)->Change(NULL);
|
2009-01-20 16:49:10 +00:00
|
|
|
} else {
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptInfoList::const_iterator it = this->info_list->begin();
|
2009-01-20 16:49:10 +00:00
|
|
|
for (int i = 0; i < this->selected; i++) it++;
|
2011-12-19 20:56:06 +00:00
|
|
|
GetConfig(slot)->Change((*it).second->GetName(), (*it).second->GetVersion());
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
2011-12-24 13:08:11 +00:00
|
|
|
InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_AI);
|
2011-12-27 15:17:42 +00:00
|
|
|
InvalidateWindowClassesData(WC_AI_SETTINGS);
|
2011-12-27 15:35:47 +00:00
|
|
|
DeleteWindowByClass(WC_QUERY_STRING);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIL_LIST: { // Select one of the AIs
|
|
|
|
int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_AIL_LIST, 0, this->line_height) - 1;
|
2011-12-19 20:56:06 +00:00
|
|
|
if (sel < (int)this->info_list->size()) {
|
2009-01-20 16:49:10 +00:00
|
|
|
this->selected = sel;
|
|
|
|
this->SetDirty();
|
2010-01-30 18:34:48 +00:00
|
|
|
if (click_count > 1) {
|
|
|
|
this->ChangeAI();
|
|
|
|
delete this;
|
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIL_ACCEPT: {
|
2009-01-20 16:49:10 +00:00
|
|
|
this->ChangeAI();
|
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIL_CANCEL:
|
2009-01-20 16:49:10 +00:00
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIL_LIST);
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
|
|
|
|
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
2010-11-18 22:24: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.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2010-11-18 22:24:10 +00:00
|
|
|
{
|
2011-01-02 12:41:24 +00:00
|
|
|
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-13 21:34:49 +00:00
|
|
|
if (!gui_scope) return;
|
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
this->vscroll->SetCount((int)this->info_list->size() + 1);
|
2010-11-18 23:31:06 +00:00
|
|
|
|
|
|
|
/* selected goes from -1 .. length of ai list - 1. */
|
|
|
|
this->selected = min(this->selected, this->vscroll->GetCount() - 2);
|
2010-11-18 22:24:10 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Widgets for the AI list window. */
|
2009-03-25 21:35:53 +00:00
|
|
|
static const NWidgetPart _nested_ai_list_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
2011-12-19 20:56:06 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIL_CAPTION), SetDataTip(STR_AI_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIL_LIST), SetMinimalSize(188, 112), SetFill(1, 1), SetResize(1, 1), SetDataTip(0x501, STR_AI_LIST_TOOLTIP), SetScrollbar(WID_AIL_SCROLLBAR),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIL_SCROLLBAR),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, WID_AIL_INFO_BG), SetMinimalTextLines(8, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM), SetResize(1, 0),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2010-08-23 22:25:50 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-12-15 00:33:44 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIL_CANCEL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_LIST_CANCEL, STR_AI_LIST_CANCEL_TOOLTIP),
|
2009-12-15 00:33:44 +00:00
|
|
|
EndContainer(),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Window definition for the ai list window. */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _ai_list_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_CENTER, 200, 234,
|
2009-01-20 16:49:10 +00:00
|
|
|
WC_AI_LIST, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_ai_list_widgets, lengthof(_nested_ai_list_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/**
|
|
|
|
* Open the AI list window to chose an AI for the given company slot.
|
|
|
|
* @param slot The slot to change the AI of.
|
|
|
|
*/
|
2009-11-09 10:40:33 +00:00
|
|
|
static void ShowAIListWindow(CompanyID slot)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
|
|
|
DeleteWindowByClass(WC_AI_LIST);
|
|
|
|
new AIListWindow(&_ai_list_desc, slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Window for settings the parameters of an AI.
|
|
|
|
*/
|
|
|
|
struct AISettingsWindow : public Window {
|
2011-11-08 21:48:00 +00:00
|
|
|
CompanyID slot; ///< The currently show company's setting.
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptConfig *ai_config; ///< The configuration we're modifying.
|
2011-11-08 21:48:00 +00:00
|
|
|
int clicked_button; ///< The button we clicked.
|
|
|
|
bool clicked_increase; ///< Whether we clicked the increase or decrease button.
|
2012-06-01 15:19:59 +00:00
|
|
|
bool clicked_dropdown; ///< Whether the dropdown is open.
|
|
|
|
bool closing_dropdown; ///< True, if the dropdown list is currently closing.
|
2011-11-08 21:48:00 +00:00
|
|
|
int timeout; ///< Timeout for unclicking the button.
|
|
|
|
int clicked_row; ///< The clicked row of settings.
|
|
|
|
int line_height; ///< Height of a row in the matrix widget.
|
|
|
|
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
|
2011-11-29 23:26:35 +00:00
|
|
|
typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
|
2011-11-08 21:48:00 +00:00
|
|
|
VisibleSettingsList visible_settings; ///< List of visible AI settings
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the window.
|
|
|
|
* @param desc The description of the window.
|
|
|
|
* @param slot The company we're changing the settings for.
|
|
|
|
*/
|
2009-08-02 18:54:49 +00:00
|
|
|
AISettingsWindow(const WindowDesc *desc, CompanyID slot) : Window(),
|
2009-01-20 16:49:10 +00:00
|
|
|
slot(slot),
|
|
|
|
clicked_button(-1),
|
2012-06-01 15:19:59 +00:00
|
|
|
clicked_dropdown(false),
|
|
|
|
closing_dropdown(false),
|
2009-01-20 16:49:10 +00:00
|
|
|
timeout(0)
|
|
|
|
{
|
2011-12-19 20:56:06 +00:00
|
|
|
this->ai_config = GetConfig(slot);
|
2011-11-08 21:48:00 +00:00
|
|
|
this->RebuildVisibleSettings();
|
2009-08-02 18:54:49 +00:00
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
this->CreateNestedTree(desc);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
|
2010-08-12 08:37:01 +00:00
|
|
|
this->FinishInitNested(desc, slot); // Initializes 'this->line_height' as side effect.
|
2010-01-29 21:38:55 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
|
2009-08-02 18:54:49 +00:00
|
|
|
|
2011-11-12 18:48:21 +00:00
|
|
|
this->vscroll->SetCount((int)this->visible_settings.size());
|
2011-11-08 21:48:00 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case WID_AIS_CAPTION:
|
|
|
|
SetDParam(0, (this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 21:48:00 +00:00
|
|
|
/**
|
|
|
|
* Rebuilds the list of visible settings. AI settings with the flag
|
|
|
|
* AICONFIG_AI_DEVELOPER set will only be visible if the game setting
|
|
|
|
* gui.ai_developer_tools is enabled.
|
|
|
|
*/
|
|
|
|
void RebuildVisibleSettings()
|
|
|
|
{
|
|
|
|
visible_settings.clear();
|
|
|
|
|
2011-11-29 23:26:35 +00:00
|
|
|
ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
2011-11-08 21:48:00 +00:00
|
|
|
for (; it != this->ai_config->GetConfigList()->end(); it++) {
|
2011-11-29 23:26:35 +00:00
|
|
|
bool no_hide = (it->flags & SCRIPTCONFIG_DEVELOPER) == 0;
|
2011-11-08 21:48:00 +00:00
|
|
|
if (no_hide || _settings_client.gui.ai_developer_tools) {
|
|
|
|
visible_settings.push_back(&(*it));
|
|
|
|
}
|
|
|
|
}
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-02 18:54:49 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget == WID_AIS_BACKGROUND) {
|
2009-08-02 18:54:49 +00:00
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
|
|
|
|
resize->width = 1;
|
|
|
|
resize->height = this->line_height;
|
2009-09-19 11:31:12 +00:00
|
|
|
size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget != WID_AIS_BACKGROUND) return;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptConfig *config = this->ai_config;
|
2011-11-08 21:48:00 +00:00
|
|
|
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
|
2009-01-20 16:49:10 +00:00
|
|
|
int i = 0;
|
2010-08-12 08:37:01 +00:00
|
|
|
for (; !this->vscroll->IsVisible(i); i++) it++;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2010-11-13 09:56:25 +00:00
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
2012-06-01 14:41:09 +00:00
|
|
|
uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
|
|
|
|
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
|
|
|
|
uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
|
2009-11-20 16:01:29 +00:00
|
|
|
|
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
int y = r.top;
|
2012-06-01 14:42:48 +00:00
|
|
|
int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
|
2011-11-08 21:48:00 +00:00
|
|
|
for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
|
2011-11-29 23:26:35 +00:00
|
|
|
const ScriptConfigItem &config_item = **it;
|
2011-11-08 21:48:00 +00:00
|
|
|
int current_value = config->GetSetting((config_item).name);
|
2011-12-19 20:56:06 +00:00
|
|
|
bool editable = _game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)) || (config_item.flags & SCRIPTCONFIG_INGAME) != 0;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2010-08-17 09:49:31 +00:00
|
|
|
StringID str;
|
|
|
|
TextColour colour;
|
|
|
|
uint idx = 0;
|
2011-11-08 21:48:00 +00:00
|
|
|
if (StrEmpty(config_item.description)) {
|
2011-12-18 18:21:55 +00:00
|
|
|
if (!strcmp(config_item.name, "start_date")) {
|
|
|
|
/* Build-in translation */
|
|
|
|
str = STR_AI_SETTINGS_START_DELAY;
|
|
|
|
colour = TC_LIGHT_BLUE;
|
|
|
|
} else {
|
|
|
|
str = STR_JUST_STRING;
|
|
|
|
colour = TC_ORANGE;
|
|
|
|
}
|
2010-08-17 09:49:31 +00:00
|
|
|
} else {
|
|
|
|
str = STR_AI_SETTINGS_SETTING;
|
|
|
|
colour = TC_LIGHT_BLUE;
|
2011-11-08 21:48:00 +00:00
|
|
|
SetDParamStr(idx++, config_item.description);
|
2010-08-17 09:49:31 +00:00
|
|
|
}
|
2010-08-13 07:34:28 +00:00
|
|
|
|
2011-11-29 23:26:35 +00:00
|
|
|
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
2012-06-01 14:42:48 +00:00
|
|
|
DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable);
|
2010-08-17 09:49:31 +00:00
|
|
|
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
2009-01-20 16:49:10 +00:00
|
|
|
} else {
|
2012-06-01 15:19:59 +00:00
|
|
|
if (config_item.complete_labels) {
|
|
|
|
DrawDropDownButton(buttons_left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && clicked_dropdown, editable);
|
|
|
|
} else {
|
|
|
|
DrawArrowButtons(buttons_left, y + button_y_offset, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
|
|
|
}
|
2011-11-08 21:48:00 +00:00
|
|
|
if (config_item.labels != NULL && config_item.labels->Contains(current_value)) {
|
2010-08-17 09:49:31 +00:00
|
|
|
SetDParam(idx++, STR_JUST_RAW_STRING);
|
2011-11-08 21:48:00 +00:00
|
|
|
SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
|
2009-02-06 00:25:37 +00:00
|
|
|
} else {
|
2010-08-17 09:49:31 +00:00
|
|
|
SetDParam(idx++, STR_JUST_INT);
|
|
|
|
SetDParam(idx++, current_value);
|
2009-02-06 00:25:37 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
2010-08-17 09:49:31 +00:00
|
|
|
DrawString(text_left, text_right, y + WD_MATRIX_TOP, str, colour);
|
2009-08-02 18:54:49 +00:00
|
|
|
y += this->line_height;
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Check whether we modified the difficulty level or not.
|
|
|
|
*/
|
2010-01-29 01:03:22 +00:00
|
|
|
void CheckDifficultyLevel()
|
|
|
|
{
|
2010-01-29 21:38:55 +00:00
|
|
|
if (_game_mode == GM_MENU) {
|
|
|
|
if (_settings_newgame.difficulty.diff_level != 3) {
|
|
|
|
_settings_newgame.difficulty.diff_level = 3;
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_WARNING_DIFFICULTY_TO_CUSTOM, INVALID_STRING_ID, WL_WARNING);
|
2010-01-29 21:38:55 +00:00
|
|
|
}
|
|
|
|
} else if (_settings_game.difficulty.diff_level != 3) {
|
|
|
|
IConsoleSetSetting("difficulty.diff_level", 3);
|
2010-01-29 01:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:19:59 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
if (this->closing_dropdown) {
|
|
|
|
this->closing_dropdown = false;
|
|
|
|
this->clicked_dropdown = false;
|
|
|
|
}
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIS_BACKGROUND: {
|
|
|
|
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
|
2010-08-12 08:37:01 +00:00
|
|
|
int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
|
2011-11-08 21:48:00 +00:00
|
|
|
if (num >= (int)this->visible_settings.size()) break;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2011-11-08 21:48:00 +00:00
|
|
|
VisibleSettingsList::const_iterator it = this->visible_settings.begin();
|
2009-01-20 16:49:10 +00:00
|
|
|
for (int i = 0; i < num; i++) it++;
|
2011-11-29 23:26:35 +00:00
|
|
|
const ScriptConfigItem config_item = **it;
|
2011-12-19 20:56:06 +00:00
|
|
|
if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return;
|
2010-01-29 21:38:55 +00:00
|
|
|
|
2012-06-01 15:13:34 +00:00
|
|
|
if (this->clicked_row != num) {
|
|
|
|
DeleteChildWindows(WC_QUERY_STRING);
|
2012-06-01 15:19:59 +00:00
|
|
|
HideDropDownMenu(this);
|
2012-06-01 15:13:34 +00:00
|
|
|
this->clicked_row = num;
|
2012-06-01 15:19:59 +00:00
|
|
|
this->clicked_dropdown = false;
|
2012-06-01 15:13:34 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 23:26:35 +00:00
|
|
|
bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2009-11-20 16:01:29 +00:00
|
|
|
int x = pt.x - wid->pos_x;
|
2012-06-01 15:08:40 +00:00
|
|
|
if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x;
|
2009-11-20 16:01:29 +00:00
|
|
|
x -= 4;
|
2012-06-01 15:13:34 +00:00
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
/* One of the arrows is clicked (or green/red rect in case of bool value) */
|
2012-06-01 15:13:34 +00:00
|
|
|
int old_val = this->ai_config->GetSetting(config_item.name);
|
2012-06-01 15:19:59 +00:00
|
|
|
if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
|
|
|
|
if (this->clicked_dropdown) {
|
|
|
|
/* unclick the dropdown */
|
|
|
|
HideDropDownMenu(this);
|
|
|
|
this->clicked_dropdown = false;
|
|
|
|
this->closing_dropdown = false;
|
|
|
|
} else {
|
|
|
|
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND);
|
|
|
|
int rel_y = (pt.y - (int)wid->pos_y) % this->line_height;
|
|
|
|
|
|
|
|
Rect wi_rect;
|
|
|
|
wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
|
|
|
|
wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
|
|
|
|
wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
|
|
|
|
wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
|
|
|
|
|
|
|
|
/* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
|
|
|
|
if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
|
|
|
|
this->clicked_dropdown = true;
|
|
|
|
this->closing_dropdown = false;
|
|
|
|
|
|
|
|
DropDownList *list = new DropDownList();
|
|
|
|
for (int i = config_item.min_value; i <= config_item.max_value; i++) {
|
|
|
|
list->push_back(new DropDownListCharStringItem(config_item.labels->Find(i)->second, i, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowDropDownListAt(this, list, old_val, -1, wi_rect, COLOUR_ORANGE, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
|
2012-06-01 15:13:34 +00:00
|
|
|
int new_val = old_val;
|
2009-01-20 16:49:10 +00:00
|
|
|
if (bool_item) {
|
|
|
|
new_val = !new_val;
|
2012-06-01 14:41:09 +00:00
|
|
|
} else if (x >= SETTING_BUTTON_WIDTH / 2) {
|
2009-01-20 16:49:10 +00:00
|
|
|
/* Increase button clicked */
|
|
|
|
new_val += config_item.step_size;
|
|
|
|
if (new_val > config_item.max_value) new_val = config_item.max_value;
|
|
|
|
this->clicked_increase = true;
|
|
|
|
} else {
|
|
|
|
/* Decrease button clicked */
|
|
|
|
new_val -= config_item.step_size;
|
|
|
|
if (new_val < config_item.min_value) new_val = config_item.min_value;
|
|
|
|
this->clicked_increase = false;
|
|
|
|
}
|
|
|
|
|
2011-05-27 18:02:55 +00:00
|
|
|
if (new_val != old_val) {
|
|
|
|
this->ai_config->SetSetting(config_item.name, new_val);
|
|
|
|
this->clicked_button = num;
|
|
|
|
this->timeout = 5;
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2011-05-27 18:02:55 +00:00
|
|
|
this->CheckDifficultyLevel();
|
|
|
|
}
|
2012-06-01 15:19:59 +00:00
|
|
|
} else if (!bool_item && !config_item.complete_labels) {
|
2009-01-20 16:49:10 +00:00
|
|
|
/* Display a query box so users can enter a custom value. */
|
2012-06-01 15:13:34 +00:00
|
|
|
SetDParam(0, old_val);
|
2011-04-17 18:42:17 +00:00
|
|
|
ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
2011-06-11 21:12:28 +00:00
|
|
|
this->SetDirty();
|
2009-01-20 16:49:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIS_ACCEPT:
|
2009-01-20 16:49:10 +00:00
|
|
|
delete this;
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIS_RESET:
|
2011-01-02 12:41:24 +00:00
|
|
|
if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
|
|
|
|
this->ai_config->ResetSettings();
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (StrEmpty(str)) return;
|
2011-11-29 23:26:35 +00:00
|
|
|
ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
2009-01-20 16:49:10 +00:00
|
|
|
for (int i = 0; i < this->clicked_row; i++) it++;
|
2011-12-19 20:56:06 +00:00
|
|
|
if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
|
2009-01-20 16:49:10 +00:00
|
|
|
int32 value = atoi(str);
|
|
|
|
this->ai_config->SetSetting((*it).name, value);
|
2010-01-29 01:03:22 +00:00
|
|
|
this->CheckDifficultyLevel();
|
2009-01-20 16:49:10 +00:00
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:19:59 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
assert(this->clicked_dropdown);
|
|
|
|
ScriptConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
|
|
|
|
for (int i = 0; i < this->clicked_row; i++) it++;
|
|
|
|
if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && (it->flags & SCRIPTCONFIG_INGAME) == 0) return;
|
|
|
|
this->ai_config->SetSetting((*it).name, index);
|
|
|
|
this->CheckDifficultyLevel();
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
|
|
|
|
{
|
|
|
|
/* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
|
|
|
|
* the same dropdown button was clicked again, and then not open the dropdown again.
|
|
|
|
* So, we only remember that it was closed, and process it on the next OnPaint, which is
|
|
|
|
* after OnClick. */
|
|
|
|
assert(this->clicked_dropdown);
|
|
|
|
this->closing_dropdown = true;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_AIS_BACKGROUND);
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
|
|
|
|
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnTick()
|
|
|
|
{
|
2009-01-21 01:56:42 +00:00
|
|
|
if (--this->timeout == 0) {
|
|
|
|
this->clicked_button = -1;
|
|
|
|
this->SetDirty();
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-02 12:41:24 +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.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2011-01-02 12:41:24 +00:00
|
|
|
{
|
2012-02-11 22:25:20 +00:00
|
|
|
this->RebuildVisibleSettings();
|
2011-01-02 12:41:24 +00:00
|
|
|
}
|
2009-01-20 16:49:10 +00:00
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Widgets for the AI settings window. */
|
2009-03-25 21:35:53 +00:00
|
|
|
static const NWidgetPart _nested_ai_settings_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
2011-12-19 20:56:06 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_AIS_CAPTION), SetDataTip(STR_AI_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIS_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetDataTip(0x501, STR_NULL), SetScrollbar(WID_AIS_SCROLLBAR),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIS_SCROLLBAR),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2009-11-22 22:08:28 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_AIS_RESET), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_AI_SETTINGS_RESET, STR_NULL),
|
2009-11-22 22:08:28 +00:00
|
|
|
EndContainer(),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Window definition for the AI settings window. */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _ai_settings_desc(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_CENTER, 500, 208,
|
2009-01-20 16:49:10 +00:00
|
|
|
WC_AI_SETTINGS, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_ai_settings_widgets, lengthof(_nested_ai_settings_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-20 16:49:10 +00:00
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/**
|
|
|
|
* Open the AI settings window to change the AI settings for an AI.
|
|
|
|
* @param slot The CompanyID of the AI to change the settings.
|
|
|
|
*/
|
2009-11-09 10:40:33 +00:00
|
|
|
static void ShowAISettingsWindow(CompanyID slot)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
|
|
|
DeleteWindowByClass(WC_AI_LIST);
|
|
|
|
DeleteWindowByClass(WC_AI_SETTINGS);
|
|
|
|
new AISettingsWindow(&_ai_settings_desc, slot);
|
|
|
|
}
|
|
|
|
|
2012-02-12 10:58:18 +00:00
|
|
|
|
|
|
|
/** Window for displaying the textfile of a AI. */
|
|
|
|
struct ScriptTextfileWindow : public TextfileWindow {
|
|
|
|
CompanyID slot; ///< View the textfile of this CompanyID slot.
|
|
|
|
|
|
|
|
ScriptTextfileWindow(TextfileType file_type, CompanyID slot) : TextfileWindow(file_type), slot(slot)
|
|
|
|
{
|
|
|
|
const char *textfile = GetConfig(slot)->GetTextfile(file_type, slot);
|
|
|
|
this->LoadTextfile(textfile, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
if (widget == WID_TF_CAPTION) {
|
|
|
|
SetDParam(0, (slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI);
|
|
|
|
SetDParamStr(1, GetConfig(slot)->GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open the AI version of the textfile window.
|
|
|
|
* @param file_type The type of textfile to display.
|
|
|
|
* @param slot The slot the Script is using.
|
|
|
|
*/
|
|
|
|
void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot)
|
|
|
|
{
|
|
|
|
DeleteWindowByClass(WC_TEXTFILE);
|
|
|
|
new ScriptTextfileWindow(file_type, slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Widgets for the configure AI window. */
|
2009-03-25 21:35:53 +00:00
|
|
|
static const NWidgetPart _nested_ai_config_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_CAPTION, 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),
|
2009-12-16 16:57:26 +00:00
|
|
|
NWidget(NWID_VERTICAL), SetPIP(4, 4, 4),
|
2011-12-19 20:56:06 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_DECREASE), SetFill(0, 1), SetDataTip(AWV_DECREASE, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_AIC_INCREASE), SetFill(0, 1), SetDataTip(AWV_INCREASE, STR_NULL),
|
2009-11-19 21:21:39 +00:00
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(6, 0),
|
2011-12-16 16:27:45 +00:00
|
|
|
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),
|
2009-11-19 21:21:39 +00:00
|
|
|
EndContainer(),
|
2011-12-19 20:56:06 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
2011-12-16 16:27:45 +00:00
|
|
|
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),
|
2009-12-16 16:57:26 +00:00
|
|
|
EndContainer(),
|
2009-11-19 21:21:39 +00:00
|
|
|
EndContainer(),
|
2011-12-19 20:56:06 +00:00
|
|
|
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), SetDataTip(0x801, STR_AI_CONFIG_AILIST_TOOLTIP), SetScrollbar(WID_AIC_SCROLLBAR),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_AIC_SCROLLBAR),
|
|
|
|
EndContainer(),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_SPACER), SetMinimalSize(0, 9),
|
2011-12-19 20:56:06 +00:00
|
|
|
NWidget(WWT_FRAME, COLOUR_MAUVE), SetDataTip(STR_AI_CONFIG_GAMESCRIPT, STR_NULL), SetPadding(0, 5, 4, 5),
|
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_AIC_GAMELIST), SetMinimalSize(288, 14), SetFill(1, 0), SetDataTip(0x101, STR_AI_CONFIG_GAMELIST_TOOLTIP),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CHANGE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CHANGE, STR_AI_CONFIG_CHANGE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CONFIGURE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_CONFIG_CONFIGURE, STR_AI_CONFIG_CONFIGURE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_CLOSE), SetFill(1, 0), SetMinimalSize(93, 12), SetDataTip(STR_AI_SETTINGS_CLOSE, STR_NULL),
|
2012-02-12 10:58:18 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_AIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, 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),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2011-12-19 20:56:06 +00:00
|
|
|
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),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Window definition for the configure AI window. */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _ai_config_desc(
|
2009-11-28 15:01:49 +00:00
|
|
|
WDP_CENTER, 0, 0,
|
2009-01-20 16:49:10 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_ai_config_widgets, lengthof(_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
|
|
|
|
2010-08-01 22:03:55 +00:00
|
|
|
AIConfigWindow() : Window()
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2011-12-19 20:50:21 +00:00
|
|
|
this->InitNested(&_ai_config_desc, 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);
|
|
|
|
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-08-02 18:54:49 +00:00
|
|
|
this->OnInvalidateData(0);
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~AIConfigWindow()
|
|
|
|
{
|
|
|
|
DeleteWindowByClass(WC_AI_LIST);
|
|
|
|
DeleteWindowByClass(WC_AI_SETTINGS);
|
|
|
|
}
|
|
|
|
|
2009-11-19 21:21:39 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
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;
|
2011-12-19 20:56:06 +00:00
|
|
|
case WID_AIC_CHANGE:
|
|
|
|
switch (selected_slot) {
|
|
|
|
case OWNER_DEITY:
|
|
|
|
SetDParam(0, STR_AI_CONFIG_CHANGE_GAMESCRIPT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INVALID_COMPANY:
|
|
|
|
SetDParam(0, STR_AI_CONFIG_CHANGE_NONE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetDParam(0, STR_AI_CONFIG_CHANGE_AI);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2009-11-19 21:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-15 17:22:47 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-11-19 21:21:39 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-19 20:56:06 +00:00
|
|
|
case WID_AIC_GAMELIST:
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST:
|
2009-11-15 17:22:47 +00:00
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
|
|
|
|
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)
|
|
|
|
{
|
2011-12-19 20:56:06 +00:00
|
|
|
if (slot == OWNER_DEITY) return _game_mode != GM_NORMAL;
|
|
|
|
|
2011-01-02 12:41:24 +00:00
|
|
|
if (_game_mode != GM_NORMAL) {
|
|
|
|
return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors;
|
|
|
|
}
|
|
|
|
if (Company::IsValidID(slot) || slot < 0) 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;
|
|
|
|
}
|
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-19 20:56:06 +00:00
|
|
|
case WID_AIC_GAMELIST: {
|
|
|
|
StringID text = STR_AI_CONFIG_NONE;
|
|
|
|
|
|
|
|
if (GameConfig::GetConfig()->GetInfo() != NULL) {
|
|
|
|
SetDParamStr(0, GameConfig::GetConfig()->GetInfo()->GetName());
|
|
|
|
text = STR_JUST_RAW_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawString(r.left + 10, r.right - 10, r.top + WD_MATRIX_TOP, text,
|
|
|
|
(this->selected_slot == OWNER_DEITY) ? TC_WHITE : (IsEditable(OWNER_DEITY) ? TC_ORANGE : TC_SILVER));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST: {
|
2009-08-02 18:54:49 +00:00
|
|
|
int y = r.top;
|
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;
|
|
|
|
} else if (AIConfig::GetConfig((CompanyID)i)->GetInfo() != NULL) {
|
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
|
|
|
}
|
|
|
|
DrawString(r.left + 10, r.right - 10, y + WD_MATRIX_TOP, text,
|
2011-01-02 12:41:24 +00:00
|
|
|
(this->selected_slot == i) ? TC_WHITE : (IsEditable((CompanyID)i) ? TC_ORANGE : TC_SILVER));
|
2009-08-02 18:54:49 +00:00
|
|
|
y += this->line_height;
|
|
|
|
}
|
|
|
|
break;
|
2009-01-20 16:49:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2009-01-20 16:49:10 +00:00
|
|
|
{
|
2012-02-12 10:58:18 +00:00
|
|
|
if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_END) {
|
|
|
|
if (this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot) == NULL) return;
|
|
|
|
|
|
|
|
ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-20 16:49:10 +00:00
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_DECREASE:
|
|
|
|
case WID_AIC_INCREASE: {
|
2009-11-19 21:21:39 +00:00
|
|
|
int new_value;
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget == WID_AIC_DECREASE) {
|
2011-01-02 12:41:24 +00:00
|
|
|
new_value = max(0, GetGameSettings().difficulty.max_no_competitors - 1);
|
2009-11-19 21:21:39 +00:00
|
|
|
} else {
|
2011-01-02 12:41:24 +00:00
|
|
|
new_value = 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);
|
|
|
|
this->InvalidateData();
|
2009-01-21 01:56:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
case WID_AIC_GAMELIST: {
|
|
|
|
this->selected_slot = OWNER_DEITY;
|
|
|
|
this->InvalidateData();
|
|
|
|
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_LIST: { // Select a slot
|
2010-08-12 08:37:01 +00:00
|
|
|
this->selected_slot = (CompanyID)this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
|
2009-09-30 21:07:54 +00:00
|
|
|
this->InvalidateData();
|
2010-01-30 18:34:48 +00:00
|
|
|
if (click_count > 1 && this->selected_slot != INVALID_COMPANY) ShowAIListWindow((CompanyID)this->selected_slot);
|
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;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CHANGE: // choose other AI
|
2009-01-20 16:49:10 +00:00
|
|
|
ShowAIListWindow((CompanyID)this->selected_slot);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CONFIGURE: // change the settings for an AI
|
2009-01-20 16:49:10 +00:00
|
|
|
ShowAISettingsWindow((CompanyID)this->selected_slot);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AIC_CLOSE:
|
2009-01-20 16:49:10 +00:00
|
|
|
delete this;
|
|
|
|
break;
|
2009-12-15 00:33:44 +00:00
|
|
|
|
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 {
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
ShowNetworkContentListWindow(NULL, CONTENT_TYPE_AI);
|
2011-12-21 15:15:43 +00:00
|
|
|
_network_content_client.RequestContentList(CONTENT_TYPE_GAME);
|
2009-12-15 00:33:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
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;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_DECREASE, GetGameSettings().difficulty.max_no_competitors == 0);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_INCREASE, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_CHANGE, this->selected_slot == INVALID_COMPANY);
|
2011-12-19 20:56:06 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || GetConfig(this->selected_slot)->GetConfigList()->size() == 0);
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_MOVE_UP, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot - 1)));
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, this->selected_slot == OWNER_DEITY || this->selected_slot == INVALID_COMPANY || !IsEditable((CompanyID)(this->selected_slot + 1)));
|
2012-02-12 10:58:18 +00:00
|
|
|
|
|
|
|
for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
|
|
|
|
this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || (GetConfig(this->selected_slot)->GetTextfile(tft, this->selected_slot) == NULL));
|
|
|
|
}
|
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()
|
|
|
|
{
|
2011-12-19 20:50:21 +00:00
|
|
|
DeleteWindowByClass(WC_GAME_OPTIONS);
|
2009-01-20 16:49:10 +00:00
|
|
|
new AIConfigWindow();
|
|
|
|
}
|
|
|
|
|
2012-08-21 17:07:17 +00:00
|
|
|
/**
|
|
|
|
* Set the widget colour of a button based on the
|
|
|
|
* state of the script. (dead or alive)
|
|
|
|
* @param button the button to update.
|
|
|
|
* @param dead true if the script is dead, otherwise false.
|
2012-09-21 19:58:18 +00:00
|
|
|
* @param paused true if the script is paused, otherwise false.
|
2012-08-21 17:07:17 +00:00
|
|
|
* @return true if the colour was changed and the window need to be marked as dirty.
|
|
|
|
*/
|
2012-09-21 19:58:18 +00:00
|
|
|
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
|
2012-08-21 17:07:17 +00:00
|
|
|
{
|
2012-09-21 19:58:18 +00:00
|
|
|
/* Dead scripts are indicated with red background and
|
|
|
|
* paused scripts are indicated with yellow background. */
|
|
|
|
Colours colour = dead ? COLOUR_RED :
|
|
|
|
(paused ? COLOUR_YELLOW : COLOUR_GREY);
|
2012-08-21 17:07:17 +00:00
|
|
|
if (button.colour != colour) {
|
|
|
|
button.colour = colour;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-25 21:35:53 +00:00
|
|
|
/**
|
2011-11-29 23:15:35 +00:00
|
|
|
* Window with everything an AI prints via ScriptLog.
|
2009-03-25 21:35:53 +00:00
|
|
|
*/
|
2010-04-02 17:35:20 +00:00
|
|
|
struct AIDebugWindow : public QueryStringBaseWindow {
|
2011-12-16 16:27:45 +00:00
|
|
|
static const int top_offset; ///< Offset of the text at the top of the WID_AID_LOG_PANEL.
|
|
|
|
static const int bottom_offset; ///< Offset of the text at the bottom of the WID_AID_LOG_PANEL.
|
2009-08-09 10:42:01 +00:00
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
static const unsigned int MAX_BREAK_STR_STRING_LENGTH = 256; ///< Maximum length of the break string.
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
static CompanyID ai_debug_company; ///< The AI that is (was last) being debugged.
|
2011-05-01 09:24:19 +00:00
|
|
|
int redraw_timer; ///< Timer for redrawing the window, otherwise it'll happen every tick.
|
|
|
|
int last_vscroll_pos; ///< Last position of the scrolling.
|
|
|
|
bool autoscroll; ///< Whether automatically scrolling should be enabled or not.
|
|
|
|
bool show_break_box; ///< Whether the break/debug box is visible.
|
2010-04-02 17:35:20 +00:00
|
|
|
static bool break_check_enabled; ///< Stop an AI when it prints a matching string
|
|
|
|
static char break_string[MAX_BREAK_STR_STRING_LENGTH]; ///< The string to match to the AI output
|
2012-06-13 18:58:29 +00:00
|
|
|
static StringFilter break_string_filter; ///< Log filter for break.
|
2010-04-02 17:43:25 +00:00
|
|
|
static bool case_sensitive_break_check; ///< Is the matching done case-sensitive
|
2010-04-02 17:35:20 +00:00
|
|
|
int highlight_row; ///< The output row that matches the given string, or -1
|
2011-05-01 09:24:19 +00:00
|
|
|
Scrollbar *vscroll; ///< Cache of the vertical scrollbar.
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptLog::LogData *GetLogPointer() const
|
|
|
|
{
|
|
|
|
if (ai_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer();
|
|
|
|
return (ScriptLog::LogData *)Company::Get(ai_debug_company)->ai_instance->GetLogPointer();
|
|
|
|
}
|
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the window.
|
|
|
|
* @param desc The description of the window.
|
|
|
|
* @param number The window number (actually unused).
|
|
|
|
*/
|
2010-04-02 17:35:20 +00:00
|
|
|
AIDebugWindow(const WindowDesc *desc, WindowNumber number) : QueryStringBaseWindow(MAX_BREAK_STR_STRING_LENGTH)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2010-04-03 17:22:24 +00:00
|
|
|
this->CreateNestedTree(desc);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll = this->GetScrollbar(WID_AID_SCROLLBAR);
|
2010-04-03 17:22:24 +00:00
|
|
|
this->show_break_box = _settings_client.gui.ai_developer_tools;
|
2011-12-16 16:27:45 +00:00
|
|
|
this->GetWidget<NWidgetStacked>(WID_AID_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
|
2010-04-03 17:22:24 +00:00
|
|
|
this->FinishInitNested(desc, number);
|
|
|
|
|
|
|
|
if (!this->show_break_box) break_check_enabled = false;
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Disable the companies who are not active or not an AI */
|
|
|
|
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(i + WID_AID_COMPANY_BUTTON_START, !Company::IsValidAiID(i));
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2011-12-19 20:56:06 +00:00
|
|
|
this->EnableWidget(WID_AID_SCRIPT_GAME);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->DisableWidget(WID_AID_RELOAD_TOGGLE);
|
|
|
|
this->DisableWidget(WID_AID_SETTINGS);
|
|
|
|
this->DisableWidget(WID_AID_CONTINUE_BTN);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-04-19 14:42:03 +00:00
|
|
|
this->last_vscroll_pos = 0;
|
|
|
|
this->autoscroll = true;
|
2010-04-02 17:35:20 +00:00
|
|
|
this->highlight_row = -1;
|
2012-06-04 15:30:29 +00:00
|
|
|
this->text.Initialize(this->edit_str_buf, this->edit_str_size, MAX_BREAK_STR_STRING_LENGTH);
|
2010-04-02 17:35:20 +00:00
|
|
|
|
|
|
|
/* Restore the break string value from static variable */
|
|
|
|
strecpy(this->edit_str_buf, this->break_string, this->edit_str_buf + MAX_BREAK_STR_STRING_LENGTH);
|
2012-06-04 15:30:29 +00:00
|
|
|
this->text.UpdateSize();
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-04-02 17:35:20 +00:00
|
|
|
/* Restore button state from static class variables */
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
this->LowerWidget(WID_AID_SCRIPT_GAME);
|
2012-09-21 19:58:18 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, !Game::IsPaused());
|
2011-12-19 20:56:06 +00:00
|
|
|
} else if (ai_debug_company != INVALID_COMPANY) {
|
|
|
|
this->LowerWidget(ai_debug_company + WID_AID_COMPANY_BUTTON_START);
|
2012-09-21 19:58:18 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, !AI::IsPaused(ai_debug_company));
|
2011-12-19 20:56:06 +00:00
|
|
|
}
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
|
|
|
|
this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-08-02 18:54:49 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
if (widget == WID_AID_LOG_PANEL) {
|
2009-08-02 18:54:49 +00:00
|
|
|
resize->height = FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
|
2009-10-17 14:29:10 +00:00
|
|
|
size->height = 14 * resize->height + this->top_offset + this->bottom_offset;
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
/* Check if the currently selected company is still active. */
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == INVALID_COMPANY || (ai_debug_company != OWNER_DEITY && !Company::IsValidAiID(ai_debug_company))) {
|
2009-01-12 17:11:45 +00:00
|
|
|
if (ai_debug_company != INVALID_COMPANY) {
|
2011-04-30 17:08:18 +00:00
|
|
|
/* Raise the widget for the previous selection. */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->RaiseWidget(ai_debug_company + WID_AID_COMPANY_BUTTON_START);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
ai_debug_company = INVALID_COMPANY;
|
|
|
|
}
|
|
|
|
|
2009-06-10 22:05:01 +00:00
|
|
|
const Company *c;
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
if (c->is_ai) {
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Lower the widget corresponding to this company. */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->LowerWidget(c->index + WID_AID_COMPANY_BUTTON_START);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-06-10 22:05:01 +00:00
|
|
|
ai_debug_company = c->index;
|
2009-01-12 17:11:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-09-01 17:49:26 +00:00
|
|
|
|
|
|
|
/* If no AI is available, see if there is a game script. */
|
|
|
|
if (ai_debug_company == INVALID_COMPANY && Game::GetInstance() != NULL) {
|
|
|
|
/* Lower the widget corresponding to the game script. */
|
|
|
|
this->LowerWidget(WID_AID_SCRIPT_GAME);
|
|
|
|
|
|
|
|
ai_debug_company = OWNER_DEITY;
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2010-01-29 21:38:55 +00:00
|
|
|
/* Update "Reload AI" and "AI settings" buttons */
|
2011-12-19 20:56:06 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AID_SETTINGS, ai_debug_company == INVALID_COMPANY);
|
|
|
|
this->SetWidgetDisabledState(WID_AID_RELOAD_TOGGLE, ai_debug_company == INVALID_COMPANY || ai_debug_company == OWNER_DEITY);
|
|
|
|
this->SetWidgetDisabledState(WID_AID_SCRIPT_GAME, Game::GetGameInstance() == NULL);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
|
|
|
/* Draw standard stuff */
|
|
|
|
this->DrawWidgets();
|
|
|
|
|
2009-12-21 16:24:29 +00:00
|
|
|
if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Paint the company icons */
|
|
|
|
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidgetCore *button = this->GetWidget<NWidgetCore>(i + WID_AID_COMPANY_BUTTON_START);
|
2009-12-09 00:08:13 +00:00
|
|
|
bool dirty = false;
|
|
|
|
|
|
|
|
bool valid = Company::IsValidAiID(i);
|
|
|
|
bool disabled = !valid;
|
|
|
|
if (button->IsDisabled() != disabled) {
|
|
|
|
/* Invalid/non-AI companies have button disabled */
|
|
|
|
button->SetDisabled(disabled);
|
|
|
|
dirty = true;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2012-09-21 19:58:18 +00:00
|
|
|
/* Mark dead/paused AIs by setting the background colour. */
|
2009-12-09 00:08:13 +00:00
|
|
|
bool dead = valid && Company::Get(i)->ai_instance->IsDead();
|
2012-09-21 19:58:18 +00:00
|
|
|
bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
|
2012-08-21 17:07:17 +00:00
|
|
|
/* Re-paint if the button was updated.
|
|
|
|
* (note that it is intentional that SetScriptButtonColour is always called) */
|
2012-09-21 19:58:18 +00:00
|
|
|
dirty = SetScriptButtonColour(*button, dead, paused) || dirty;
|
2009-06-10 19:26:04 +00:00
|
|
|
|
2009-12-09 00:08:13 +00:00
|
|
|
/* Do we need a repaint? */
|
|
|
|
if (dirty) this->SetDirty();
|
|
|
|
/* Draw company icon only for valid AI companies */
|
|
|
|
if (!valid) continue;
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-03-25 21:35:53 +00:00
|
|
|
byte offset = (i == ai_debug_company) ? 1 : 0;
|
2011-12-16 16:27:45 +00:00
|
|
|
DrawCompanyIcon(i, button->pos_x + button->current_x / 2 - 7 + offset, this->GetWidget<NWidgetBase>(WID_AID_COMPANY_BUTTON_START + i)->pos_y + 2 + offset);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-21 17:07:17 +00:00
|
|
|
/* Set button colour for Game Script. */
|
|
|
|
GameInstance *game = Game::GetInstance();
|
|
|
|
bool dead = game != NULL && game->IsDead();
|
2012-09-21 19:58:18 +00:00
|
|
|
bool paused = game != NULL && game->IsPaused();
|
2012-08-21 17:07:17 +00:00
|
|
|
NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_AID_SCRIPT_GAME);
|
2012-09-21 19:58:18 +00:00
|
|
|
if (SetScriptButtonColour(*button, dead, paused)) {
|
2012-08-21 17:07:17 +00:00
|
|
|
/* Re-paint if the button was updated. */
|
|
|
|
this->SetWidgetDirty(WID_AID_SCRIPT_GAME);
|
|
|
|
}
|
|
|
|
|
2011-04-30 17:08:18 +00:00
|
|
|
/* If there are no active companies, don't display anything else. */
|
|
|
|
if (ai_debug_company == INVALID_COMPANY) return;
|
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptLog::LogData *log = this->GetLogPointer();
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2009-04-19 16:04:44 +00:00
|
|
|
int scroll_count = (log == NULL) ? 0 : log->used;
|
2010-08-12 08:37:01 +00:00
|
|
|
if (this->vscroll->GetCount() != scroll_count) {
|
|
|
|
this->vscroll->SetCount(scroll_count);
|
2009-04-19 16:04:44 +00:00
|
|
|
|
|
|
|
/* We need a repaint */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDirty(WID_AID_SCROLLBAR);
|
2009-04-19 16:04:44 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
if (log == NULL) return;
|
|
|
|
|
2009-04-19 14:42:03 +00:00
|
|
|
/* Detect when the user scrolls the window. Enable autoscroll when the
|
|
|
|
* bottom-most line becomes visible. */
|
2010-08-12 08:37:01 +00:00
|
|
|
if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
|
|
|
|
this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity();
|
2009-04-19 14:42:03 +00:00
|
|
|
}
|
2009-04-19 16:04:44 +00:00
|
|
|
if (this->autoscroll) {
|
2010-08-12 08:37:01 +00:00
|
|
|
int scroll_pos = max(0, log->used - this->vscroll->GetCapacity());
|
|
|
|
if (scroll_pos != this->vscroll->GetPosition()) {
|
|
|
|
this->vscroll->SetPosition(scroll_pos);
|
2009-04-19 16:04:44 +00:00
|
|
|
|
|
|
|
/* We need a repaint */
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDirty(WID_AID_SCROLLBAR);
|
|
|
|
this->SetWidgetDirty(WID_AID_LOG_PANEL);
|
2009-04-19 16:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-12 08:37:01 +00:00
|
|
|
this->last_vscroll_pos = this->vscroll->GetPosition();
|
2010-01-07 11:48:59 +00:00
|
|
|
}
|
2009-08-02 18:54:49 +00:00
|
|
|
|
2010-01-07 11:48:59 +00:00
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_NAME_TEXT:
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
const GameInfo *info = Game::GetInfo();
|
|
|
|
assert(info != NULL);
|
|
|
|
SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
|
|
|
|
SetDParamStr(1, info->GetName());
|
|
|
|
SetDParam(2, info->GetVersion());
|
|
|
|
} else if (ai_debug_company == INVALID_COMPANY || !Company::IsValidAiID(ai_debug_company)) {
|
2010-01-07 11:48:59 +00:00
|
|
|
SetDParam(0, STR_EMPTY);
|
|
|
|
} else {
|
|
|
|
const AIInfo *info = Company::Get(ai_debug_company)->ai_info;
|
|
|
|
assert(info != NULL);
|
|
|
|
SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION);
|
|
|
|
SetDParamStr(1, info->GetName());
|
|
|
|
SetDParam(2, info->GetVersion());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-08-02 18:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
if (ai_debug_company == INVALID_COMPANY) return;
|
|
|
|
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_LOG_PANEL: {
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptLog::LogData *log = this->GetLogPointer();
|
2009-08-02 18:54:49 +00:00
|
|
|
if (log == NULL) return;
|
|
|
|
|
2009-08-09 10:42:01 +00:00
|
|
|
int y = this->top_offset;
|
2010-08-12 08:37:01 +00:00
|
|
|
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) {
|
2010-04-02 17:35:20 +00:00
|
|
|
int pos = (i + log->pos + 1 - log->used + log->count) % log->count;
|
2009-08-02 18:54:49 +00:00
|
|
|
if (log->lines[pos] == NULL) break;
|
|
|
|
|
|
|
|
TextColour colour;
|
|
|
|
switch (log->type[pos]) {
|
2011-11-29 23:15:35 +00:00
|
|
|
case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break;
|
|
|
|
case ScriptLog::LOG_SQ_ERROR: colour = TC_RED; break;
|
|
|
|
case ScriptLog::LOG_INFO: colour = TC_BLACK; break;
|
|
|
|
case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break;
|
|
|
|
case ScriptLog::LOG_ERROR: colour = TC_RED; break;
|
2009-08-02 18:54:49 +00:00
|
|
|
default: colour = TC_BLACK; break;
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-04-02 17:35:20 +00:00
|
|
|
/* Check if the current line should be highlighted */
|
|
|
|
if (pos == this->highlight_row) {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + y, r.right - 1, r.top + y + this->resize.step_height - WD_PAR_VSEP_NORMAL, PC_BLACK);
|
2010-04-02 17:35:20 +00:00
|
|
|
if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
|
|
|
|
}
|
|
|
|
|
2009-08-02 18:54:49 +00:00
|
|
|
DrawString(r.left + 7, r.right - 7, r.top + y, log->lines[pos], colour, SA_LEFT | SA_FORCE);
|
|
|
|
y += this->resize.step_height;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-01 09:24:19 +00:00
|
|
|
/**
|
|
|
|
* Change all settings to select another AI.
|
|
|
|
* @param show_ai The new AI to show.
|
|
|
|
*/
|
2009-03-14 01:32:04 +00:00
|
|
|
void ChangeToAI(CompanyID show_ai)
|
|
|
|
{
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
this->RaiseWidget(WID_AID_SCRIPT_GAME);
|
|
|
|
} else {
|
|
|
|
this->RaiseWidget(ai_debug_company + WID_AID_COMPANY_BUTTON_START);
|
|
|
|
}
|
2009-03-14 01:32:04 +00:00
|
|
|
ai_debug_company = show_ai;
|
2009-09-02 07:01:25 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptLog::LogData *log = this->GetLogPointer();
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCount((log == NULL) ? 0 : log->used);
|
2009-09-02 07:01:25 +00:00
|
|
|
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
this->LowerWidget(WID_AID_SCRIPT_GAME);
|
2012-09-21 19:58:18 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, !Game::IsPaused());
|
2011-12-19 20:56:06 +00:00
|
|
|
} else {
|
|
|
|
this->LowerWidget(ai_debug_company + WID_AID_COMPANY_BUTTON_START);
|
2012-09-21 19:58:18 +00:00
|
|
|
this->SetWidgetDisabledState(WID_AID_CONTINUE_BTN, !AI::IsPaused(ai_debug_company));
|
2011-12-19 20:56:06 +00:00
|
|
|
}
|
|
|
|
|
2012-09-21 19:58:18 +00:00
|
|
|
this->highlight_row = -1; // The highlight of one AI make little sense for another AI.
|
2009-04-19 14:42:03 +00:00
|
|
|
this->autoscroll = true;
|
2010-08-12 08:37:01 +00:00
|
|
|
this->last_vscroll_pos = this->vscroll->GetPosition();
|
2009-03-14 01:32:04 +00:00
|
|
|
this->SetDirty();
|
2010-01-29 21:38:55 +00:00
|
|
|
/* Close AI settings window to prevent confusion */
|
|
|
|
DeleteWindowByClass(WC_AI_SETTINGS);
|
2009-03-14 01:32:04 +00:00
|
|
|
}
|
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2012-11-13 21:46:14 +00:00
|
|
|
/* Also called for hotkeys, so check for disabledness */
|
|
|
|
if (this->IsWidgetDisabled(widget)) return;
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Check which button is clicked */
|
2011-12-16 16:27:45 +00:00
|
|
|
if (IsInsideMM(widget, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END + 1)) {
|
2012-11-13 21:46:14 +00:00
|
|
|
ChangeToAI((CompanyID)(widget - WID_AID_COMPANY_BUTTON_START));
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2010-01-29 21:38:55 +00:00
|
|
|
|
|
|
|
switch (widget) {
|
2011-12-19 20:56:06 +00:00
|
|
|
case WID_AID_SCRIPT_GAME:
|
|
|
|
ChangeToAI(OWNER_DEITY);
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_RELOAD_TOGGLE:
|
2011-12-19 20:56:06 +00:00
|
|
|
if (ai_debug_company == OWNER_DEITY) break;
|
2010-01-29 21:38:55 +00:00
|
|
|
/* First kill the company of the AI, then start a new one. This should start the current AI again */
|
2011-10-15 20:42:32 +00:00
|
|
|
DoCommandP(0, 2 | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
|
2010-08-19 22:06:20 +00:00
|
|
|
DoCommandP(0, 1 | ai_debug_company << 16, 0, CMD_COMPANY_CTRL);
|
2010-01-29 21:38:55 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_SETTINGS:
|
2010-01-29 21:38:55 +00:00
|
|
|
ShowAISettingsWindow(ai_debug_company);
|
|
|
|
break;
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_BREAK_STR_ON_OFF_BTN:
|
2010-04-02 17:35:20 +00:00
|
|
|
this->break_check_enabled = !this->break_check_enabled;
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetLoweredState(WID_AID_BREAK_STR_ON_OFF_BTN, this->break_check_enabled);
|
|
|
|
this->SetWidgetDirty(WID_AID_BREAK_STR_ON_OFF_BTN);
|
2010-04-02 17:35:20 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_MATCH_CASE_BTN:
|
2010-04-02 17:35:20 +00:00
|
|
|
this->case_sensitive_break_check = !this->case_sensitive_break_check;
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetLoweredState(WID_AID_MATCH_CASE_BTN, this->case_sensitive_break_check);
|
2012-11-11 16:10:11 +00:00
|
|
|
this->SetWidgetDirty(WID_AID_MATCH_CASE_BTN);
|
2010-04-02 17:35:20 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_AID_CONTINUE_BTN:
|
2012-09-21 19:58:18 +00:00
|
|
|
/* Unpause current AI / game script and mark the corresponding script button dirty. */
|
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
Game::Unpause();
|
|
|
|
this->SetWidgetDirty(WID_AID_SCRIPT_GAME);
|
|
|
|
} else {
|
|
|
|
AI::Unpause(ai_debug_company);
|
|
|
|
this->SetWidgetDirty(WID_AID_COMPANY_BUTTON_START + ai_debug_company);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the last AI/Game Script is unpaused, unpause the game too. */
|
|
|
|
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_PAUSED_NORMAL) {
|
|
|
|
bool all_unpaused = !Game::IsPaused();
|
|
|
|
if (all_unpaused) {
|
|
|
|
Company *c;
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
if (c->is_ai && AI::IsPaused(c->index)) {
|
|
|
|
all_unpaused = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (all_unpaused) {
|
|
|
|
/* All scripts have been unpaused => unpause the game. */
|
|
|
|
DoCommandP(0, PM_PAUSED_NORMAL, 0, CMD_PAUSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->highlight_row = -1;
|
|
|
|
this->SetWidgetDirty(WID_AID_LOG_PANEL);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->DisableWidget(WID_AID_CONTINUE_BTN);
|
2010-04-02 17:35:20 +00:00
|
|
|
break;
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 17:35:20 +00:00
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
2010-07-14 12:03:30 +00:00
|
|
|
EventState state = ES_NOT_HANDLED;
|
2012-09-23 14:37:59 +00:00
|
|
|
switch (this->HandleEditBoxKey(WID_AID_BREAK_STR_EDIT_BOX, key, keycode, state)) {
|
|
|
|
case HEBR_CANCEL:
|
|
|
|
/* Unfocus the text box. */
|
|
|
|
this->UnfocusFocusedWidget();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HEBR_NOT_FOCUSED: {
|
|
|
|
/* Edit boxs is not globally foused => handle hotkeys of AI Debug window. */
|
|
|
|
int num = CheckHotkeyMatch(aidebug_hotkeys, keycode, this);
|
|
|
|
if (num == -1) return ES_NOT_HANDLED;
|
|
|
|
if (this->show_break_box && num == WID_AID_BREAK_STR_EDIT_BOX) {
|
|
|
|
this->SetFocusedWidget(WID_AID_BREAK_STR_EDIT_BOX);
|
|
|
|
SetFocusedWindow(this);
|
|
|
|
state = ES_HANDLED;
|
|
|
|
} else if (this->show_break_box || num < WID_AID_BREAK_STRING_WIDGETS) {
|
|
|
|
this->OnClick(Point(), num, 1);
|
|
|
|
state = ES_HANDLED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2010-04-02 17:35:20 +00:00
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:46:37 +00:00
|
|
|
virtual void OnOSKInput(int wid)
|
|
|
|
{
|
|
|
|
if (wid == WID_AID_BREAK_STR_EDIT_BOX) {
|
|
|
|
/* Save the current string to static member so it can be restored next time the window is opened. */
|
|
|
|
strecpy(this->break_string, this->edit_str_buf, lastof(this->break_string));
|
|
|
|
break_string_filter.SetFilterTerm(this->break_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (data == -1 || ai_debug_company == data) this->SetDirty();
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2011-03-13 21:32:40 +00:00
|
|
|
/* If the log message is related to the active company tab, check the break string.
|
|
|
|
* This needs to be done in gameloop-scope, so the AI is suspended immediately. */
|
2012-09-21 19:58:18 +00:00
|
|
|
if (!gui_scope && data == ai_debug_company && this->break_check_enabled && !this->break_string_filter.IsEmpty()) {
|
2010-04-02 17:35:20 +00:00
|
|
|
/* Get the log instance of the active company */
|
2011-12-19 20:56:06 +00:00
|
|
|
ScriptLog::LogData *log = this->GetLogPointer();
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2012-06-13 18:58:29 +00:00
|
|
|
if (log != NULL) {
|
|
|
|
this->break_string_filter.ResetState();
|
|
|
|
this->break_string_filter.AddLine(log->lines[log->pos]);
|
|
|
|
if (this->break_string_filter.GetState()) {
|
2012-09-21 19:58:18 +00:00
|
|
|
/* Pause execution of script. */
|
|
|
|
if (ai_debug_company == OWNER_DEITY) {
|
|
|
|
Game::Pause();
|
|
|
|
} else {
|
|
|
|
AI::Pause(ai_debug_company);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pause the game. */
|
2012-06-13 18:58:29 +00:00
|
|
|
if ((_pause_mode & PM_PAUSED_NORMAL) == PM_UNPAUSED) {
|
|
|
|
DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
|
|
|
}
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2012-06-13 18:58:29 +00:00
|
|
|
/* Make it possible to click on the continue button */
|
|
|
|
this->EnableWidget(WID_AID_CONTINUE_BTN);
|
|
|
|
this->SetWidgetDirty(WID_AID_CONTINUE_BTN);
|
2010-04-02 17:35:20 +00:00
|
|
|
|
2012-06-13 18:58:29 +00:00
|
|
|
/* Highlight row that matched */
|
|
|
|
this->highlight_row = log->pos;
|
|
|
|
}
|
2010-04-02 17:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll->SetCapacityFromWidget(this, WID_AID_LOG_PANEL);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2012-09-23 14:37:59 +00:00
|
|
|
|
|
|
|
static Hotkey<AIDebugWindow> aidebug_hotkeys[];
|
2009-01-12 17:11:45 +00:00
|
|
|
};
|
|
|
|
|
2009-08-09 10:42:01 +00:00
|
|
|
const int AIDebugWindow::top_offset = WD_FRAMERECT_TOP + 2;
|
|
|
|
const int AIDebugWindow::bottom_offset = WD_FRAMERECT_BOTTOM;
|
2009-01-12 17:11:45 +00:00
|
|
|
CompanyID AIDebugWindow::ai_debug_company = INVALID_COMPANY;
|
2010-04-02 17:35:20 +00:00
|
|
|
char AIDebugWindow::break_string[MAX_BREAK_STR_STRING_LENGTH] = "";
|
|
|
|
bool AIDebugWindow::break_check_enabled = true;
|
|
|
|
bool AIDebugWindow::case_sensitive_break_check = false;
|
2012-06-13 18:58:29 +00:00
|
|
|
StringFilter AIDebugWindow::break_string_filter(&AIDebugWindow::case_sensitive_break_check);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-08-19 12:56:31 +00:00
|
|
|
/** Make a number of rows with buttons for each company for the AI debug window. */
|
|
|
|
NWidgetBase *MakeCompanyButtonRowsAIDebug(int *biggest_index)
|
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
return MakeCompanyButtonRows(biggest_index, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END, 8, STR_AI_DEBUG_SELECT_AI_TOOLTIP);
|
2010-08-19 12:56:31 +00:00
|
|
|
}
|
|
|
|
|
2012-09-23 14:37:59 +00:00
|
|
|
Hotkey<AIDebugWindow> AIDebugWindow::aidebug_hotkeys[] = {
|
|
|
|
Hotkey<AIDebugWindow>('1', "company_1", WID_AID_COMPANY_BUTTON_START),
|
|
|
|
Hotkey<AIDebugWindow>('2', "company_2", WID_AID_COMPANY_BUTTON_START + 1),
|
|
|
|
Hotkey<AIDebugWindow>('3', "company_3", WID_AID_COMPANY_BUTTON_START + 2),
|
|
|
|
Hotkey<AIDebugWindow>('4', "company_4", WID_AID_COMPANY_BUTTON_START + 3),
|
|
|
|
Hotkey<AIDebugWindow>('5', "company_5", WID_AID_COMPANY_BUTTON_START + 4),
|
|
|
|
Hotkey<AIDebugWindow>('6', "company_6", WID_AID_COMPANY_BUTTON_START + 5),
|
|
|
|
Hotkey<AIDebugWindow>('7', "company_7", WID_AID_COMPANY_BUTTON_START + 6),
|
|
|
|
Hotkey<AIDebugWindow>('8', "company_8", WID_AID_COMPANY_BUTTON_START + 7),
|
|
|
|
Hotkey<AIDebugWindow>('9', "company_9", WID_AID_COMPANY_BUTTON_START + 8),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_10", WID_AID_COMPANY_BUTTON_START + 9),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_11", WID_AID_COMPANY_BUTTON_START + 10),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_12", WID_AID_COMPANY_BUTTON_START + 11),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_13", WID_AID_COMPANY_BUTTON_START + 12),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_14", WID_AID_COMPANY_BUTTON_START + 13),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "company_15", WID_AID_COMPANY_BUTTON_START + 14),
|
|
|
|
Hotkey<AIDebugWindow>('S', "settings", WID_AID_SETTINGS),
|
|
|
|
Hotkey<AIDebugWindow>('0', "game_script", WID_AID_SCRIPT_GAME),
|
|
|
|
Hotkey<AIDebugWindow>((uint16)0, "reload", WID_AID_RELOAD_TOGGLE),
|
|
|
|
Hotkey<AIDebugWindow>('B', "break_toggle", WID_AID_BREAK_STR_ON_OFF_BTN),
|
|
|
|
Hotkey<AIDebugWindow>('F', "break_string", WID_AID_BREAK_STR_EDIT_BOX),
|
|
|
|
Hotkey<AIDebugWindow>('C', "match_case", WID_AID_MATCH_CASE_BTN),
|
|
|
|
Hotkey<AIDebugWindow>(WKC_RETURN, "continue", WID_AID_CONTINUE_BTN),
|
|
|
|
HOTKEY_LIST_END(AIDebugWindow)
|
|
|
|
};
|
|
|
|
Hotkey<AIDebugWindow> *_aidebug_hotkeys = AIDebugWindow::aidebug_hotkeys;
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Widgets for the AI debug window. */
|
2009-03-25 21:35:53 +00:00
|
|
|
static const NWidgetPart _nested_ai_debug_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-12-21 16:24:29 +00:00
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_VIEW),
|
2010-08-19 12:56:31 +00:00
|
|
|
NWidgetFunction(MakeCompanyButtonRowsAIDebug), SetPadding(0, 2, 1, 2),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2012-11-11 16:10:11 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_SCRIPT_GAME), SetMinimalSize(100, 20), SetResize(1, 0), SetDataTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_NAME_TEXT), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_AI_DEBUG_NAME_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_SETTINGS), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetDataTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2010-04-02 17:35:20 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
/* Log panel */
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_AID_LOG_PANEL), SetMinimalSize(287, 180), SetResize(1, 1), SetScrollbar(WID_AID_SCROLLBAR),
|
2010-04-02 17:35:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
/* Break string widgets */
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_AID_BREAK_STRING_WIDGETS),
|
2010-04-03 17:22:24 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_AID_BREAK_STR_ON_OFF_BTN), SetFill(0, 1), SetDataTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
|
2010-04-03 17:22:24 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_LABEL, COLOUR_GREY), SetPadding(2, 2, 2, 4), SetDataTip(STR_AI_DEBUG_BREAK_ON_LABEL, 0x0),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_EDITBOX, COLOUR_WHITE, 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),
|
2010-04-03 17:22:24 +00:00
|
|
|
EndContainer(),
|
2010-04-02 17:35:20 +00:00
|
|
|
EndContainer(),
|
2012-11-11 16:10:11 +00:00
|
|
|
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AID_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_AID_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetDataTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
|
2010-04-02 17:35:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AID_SCROLLBAR),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-03-25 21:35:53 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/** Window definition for the AI debug window. */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _ai_debug_desc(
|
2010-01-21 17:13:09 +00:00
|
|
|
WDP_AUTO, 600, 450,
|
2009-01-12 17:11:45 +00:00
|
|
|
WC_AI_DEBUG, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2009-11-15 10:26:01 +00:00
|
|
|
_nested_ai_debug_widgets, lengthof(_nested_ai_debug_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2009-01-12 17:11:45 +00:00
|
|
|
|
2010-08-01 22:08:29 +00:00
|
|
|
/**
|
|
|
|
* Open the AI debug window and select the given company.
|
|
|
|
* @param show_company Display debug information about this AI company.
|
|
|
|
*/
|
2012-09-23 14:37:59 +00:00
|
|
|
Window *ShowAIDebugWindow(CompanyID show_company)
|
2009-01-12 17:11:45 +00:00
|
|
|
{
|
|
|
|
if (!_networking || _network_server) {
|
2009-03-14 01:32:04 +00:00
|
|
|
AIDebugWindow *w = (AIDebugWindow *)BringWindowToFrontById(WC_AI_DEBUG, 0);
|
|
|
|
if (w == NULL) w = new AIDebugWindow(&_ai_debug_desc, 0);
|
|
|
|
if (show_company != INVALID_COMPANY) w->ChangeToAI(show_company);
|
2012-09-23 14:37:59 +00:00
|
|
|
return w;
|
2009-01-12 17:11:45 +00:00
|
|
|
} else {
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_AI_DEBUG_SERVER_ONLY, INVALID_STRING_ID, WL_INFO);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2012-09-23 14:37:59 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for global AI debug window hotkeys.
|
|
|
|
*/
|
|
|
|
EventState AIDebugGlobalHotkeys(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
int num = CheckHotkeyMatch<AIDebugWindow>(_aidebug_hotkeys, keycode, NULL, true);
|
|
|
|
if (num == -1) return ES_NOT_HANDLED;
|
|
|
|
Window *w = ShowAIDebugWindow(INVALID_COMPANY);
|
|
|
|
if (w == NULL) return ES_NOT_HANDLED;
|
|
|
|
return w->OnKeyPress(key, keycode);
|
2009-01-12 17:11:45 +00:00
|
|
|
}
|
2010-03-11 21:55:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the AI windows to their initial state.
|
|
|
|
*/
|
|
|
|
void InitializeAIGui()
|
|
|
|
{
|
|
|
|
AIDebugWindow::ai_debug_company = INVALID_COMPANY;
|
|
|
|
}
|
2010-03-13 00:15:24 +00:00
|
|
|
|
|
|
|
/** Open the AI debug window if one of the AI scripts has crashed. */
|
|
|
|
void ShowAIDebugWindowIfAIError()
|
|
|
|
{
|
2010-03-30 22:37:45 +00:00
|
|
|
/* Network clients can't debug AIs. */
|
|
|
|
if (_networking && !_network_server) return;
|
|
|
|
|
2010-03-13 00:15:24 +00:00
|
|
|
Company *c;
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
if (c->is_ai && c->ai_instance->IsDead()) {
|
|
|
|
ShowAIDebugWindow(c->index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-02 22:44:28 +00:00
|
|
|
|
|
|
|
GameInstance *g = Game::GetGameInstance();
|
|
|
|
if (g != NULL && g->IsDead()) {
|
|
|
|
ShowAIDebugWindow(OWNER_DEITY);
|
|
|
|
}
|
2010-03-13 00:15:24 +00:00
|
|
|
}
|