summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2011-11-08 21:48:00 +0000
committeryexo <yexo@openttd.org>2011-11-08 21:48:00 +0000
commita256bd71e472fb6bd6ad91f464ee1d1a18a1823f (patch)
treeef338211b627ae164a9dd5bb705cf509123aaf88 /src
parent5c838ff1c312c240e44bb7da95e5450bcfeaeff6 (diff)
downloadopenttd-a256bd71e472fb6bd6ad91f464ee1d1a18a1823f.tar.xz
(svn r23169) -Feature: [NoAI] AICONFIG_AI_DEVELOPER flags to hide AI settings unless gui.ai_developer_tools is enabled (Zuu)
Diffstat (limited to 'src')
-rw-r--r--src/ai/ai_gui.cpp74
-rw-r--r--src/ai/ai_info.hpp9
-rw-r--r--src/ai/ai_scanner.cpp1
-rw-r--r--src/ai/api/ai_info_docs.hpp9
-rw-r--r--src/settings.cpp6
-rw-r--r--src/table/settings.ini2
6 files changed, 70 insertions, 31 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 243f96e6f..6e51eea1d 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -32,6 +32,8 @@
#include "table/strings.h"
+#include <vector>
+
/** Enum referring to the widgets of the AI list window */
enum AIListWindowWidgets {
AIL_WIDGET_LIST, ///< The matrix with all available AIs
@@ -262,14 +264,16 @@ enum AISettingsWindowWidgets {
* Window for settings the parameters of an AI.
*/
struct AISettingsWindow : public Window {
- CompanyID slot; ///< The currently show company's setting.
- AIConfig *ai_config; ///< The configuration we're modifying.
- int clicked_button; ///< The button we clicked.
- bool clicked_increase; ///< Whether we clicked the increase or decrease button.
- 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.
+ CompanyID slot; ///< The currently show company's setting.
+ AIConfig *ai_config; ///< The configuration we're modifying.
+ int clicked_button; ///< The button we clicked.
+ bool clicked_increase; ///< Whether we clicked the increase or decrease button.
+ 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.
+ typedef std::vector<const AIConfigItem *> VisibleSettingsList;
+ VisibleSettingsList visible_settings; ///< List of visible AI settings
/**
* Constructor for the window.
@@ -282,6 +286,7 @@ struct AISettingsWindow : public Window {
timeout(0)
{
this->ai_config = AIConfig::GetConfig(slot);
+ this->RebuildVisibleSettings();
this->CreateNestedTree(desc);
this->vscroll = this->GetScrollbar(AIS_WIDGET_SCROLLBAR);
@@ -289,7 +294,25 @@ struct AISettingsWindow : public Window {
this->SetWidgetDisabledState(AIS_WIDGET_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
- this->vscroll->SetCount((int)this->ai_config->GetConfigList()->size());
+ this->vscroll->SetCount(this->visible_settings.size());
+ }
+
+ /**
+ * 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();
+
+ AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
+ for (; it != this->ai_config->GetConfigList()->end(); it++) {
+ bool no_hide = (it->flags & AICONFIG_AI_DEVELOPER) == 0;
+ if (no_hide || _settings_client.gui.ai_developer_tools) {
+ visible_settings.push_back(&(*it));
+ }
+ }
}
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
@@ -308,7 +331,7 @@ struct AISettingsWindow : public Window {
if (widget != AIS_WIDGET_BACKGROUND) return;
AIConfig *config = this->ai_config;
- AIConfigItemList::const_iterator it = config->GetConfigList()->begin();
+ VisibleSettingsList::const_iterator it = this->visible_settings.begin();
int i = 0;
for (; !this->vscroll->IsVisible(i); i++) it++;
@@ -319,30 +342,31 @@ struct AISettingsWindow : public Window {
int y = r.top;
- for (; this->vscroll->IsVisible(i) && it != config->GetConfigList()->end(); i++, it++) {
- int current_value = config->GetSetting((*it).name);
- bool editable = _game_mode == GM_MENU || !Company::IsValidID(this->slot) || (it->flags & AICONFIG_INGAME) != 0;
+ for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
+ const AIConfigItem &config_item = **it;
+ int current_value = config->GetSetting((config_item).name);
+ bool editable = _game_mode == GM_MENU || !Company::IsValidID(this->slot) || (config_item.flags & AICONFIG_INGAME) != 0;
StringID str;
TextColour colour;
uint idx = 0;
- if (StrEmpty((*it).description)) {
+ if (StrEmpty(config_item.description)) {
str = STR_JUST_STRING;
colour = TC_ORANGE;
} else {
str = STR_AI_SETTINGS_SETTING;
colour = TC_LIGHT_BLUE;
- SetDParamStr(idx++, (*it).description);
+ SetDParamStr(idx++, config_item.description);
}
- if (((*it).flags & AICONFIG_BOOLEAN) != 0) {
+ if ((config_item.flags & AICONFIG_BOOLEAN) != 0) {
DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else {
- DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > (*it).min_value, editable && current_value < (*it).max_value);
- if (it->labels != NULL && it->labels->Contains(current_value)) {
+ DrawArrowButtons(buttons_left, y + 2, 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);
+ if (config_item.labels != NULL && config_item.labels->Contains(current_value)) {
SetDParam(idx++, STR_JUST_RAW_STRING);
- SetDParamStr(idx++, it->labels->Find(current_value)->second);
+ SetDParamStr(idx++, config_item.labels->Find(current_value)->second);
} else {
SetDParam(idx++, STR_JUST_INT);
SetDParam(idx++, current_value);
@@ -375,11 +399,11 @@ struct AISettingsWindow : public Window {
case AIS_WIDGET_BACKGROUND: {
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(AIS_WIDGET_BACKGROUND);
int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition();
- if (num >= (int)this->ai_config->GetConfigList()->size()) break;
+ if (num >= (int)this->visible_settings.size()) break;
- AIConfigItemList::const_iterator it = this->ai_config->GetConfigList()->begin();
+ VisibleSettingsList::const_iterator it = this->visible_settings.begin();
for (int i = 0; i < num; i++) it++;
- AIConfigItem config_item = *it;
+ const AIConfigItem config_item = **it;
if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot) && (config_item.flags & AICONFIG_INGAME) == 0) return;
bool bool_item = (config_item.flags & AICONFIG_BOOLEAN) != 0;
@@ -469,7 +493,11 @@ struct AISettingsWindow : public Window {
*/
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{
- if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) delete this;
+ if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
+ delete this;
+ } else {
+ this->RebuildVisibleSettings();
+ }
}
};
diff --git a/src/ai/ai_info.hpp b/src/ai/ai_info.hpp
index 936237418..c618930d9 100644
--- a/src/ai/ai_info.hpp
+++ b/src/ai/ai_info.hpp
@@ -20,10 +20,11 @@
/** Bitmask of flags for AI settings. */
enum AIConfigFlags {
- AICONFIG_NONE = 0x0, ///< No flags set.
- AICONFIG_RANDOM = 0x1, ///< When randomizing the AI, pick any value between min_value and max_value when on custom difficulty setting.
- AICONFIG_BOOLEAN = 0x2, ///< This value is a boolean (either 0 (false) or 1 (true) ).
- AICONFIG_INGAME = 0x4, ///< This setting can be changed while the AI is running.
+ AICONFIG_NONE = 0x0, ///< No flags set.
+ AICONFIG_RANDOM = 0x1, ///< When randomizing the AI, pick any value between min_value and max_value when on custom difficulty setting.
+ AICONFIG_BOOLEAN = 0x2, ///< This value is a boolean (either 0 (false) or 1 (true) ).
+ AICONFIG_INGAME = 0x4, ///< This setting can be changed while the AI is running.
+ AICONFIG_AI_DEVELOPER = 0x8, ///< This setting will only be visible when the ai development tools are active.
};
typedef SmallMap<int, char *> LabelMapping; ///< Map-type used to map the setting numbers to labels.
diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp
index df989630f..9e752c010 100644
--- a/src/ai/ai_scanner.cpp
+++ b/src/ai/ai_scanner.cpp
@@ -42,6 +42,7 @@ AIScanner::AIScanner() :
SQAIInfo.DefSQConst(engine, AICONFIG_RANDOM, "AICONFIG_RANDOM");
SQAIInfo.DefSQConst(engine, AICONFIG_BOOLEAN, "AICONFIG_BOOLEAN");
SQAIInfo.DefSQConst(engine, AICONFIG_INGAME, "AICONFIG_INGAME");
+ SQAIInfo.DefSQConst(engine, AICONFIG_AI_DEVELOPER, "AICONFIG_AI_DEVELOPER");
SQAIInfo.PostRegister(engine);
this->engine->AddMethod("RegisterAI", &AIInfo::Constructor, 2, "tx");
this->engine->AddMethod("RegisterDummyAI", &AIInfo::DummyConstructor, 2, "tx");
diff --git a/src/ai/api/ai_info_docs.hpp b/src/ai/api/ai_info_docs.hpp
index c0c68935e..f821b43f6 100644
--- a/src/ai/api/ai_info_docs.hpp
+++ b/src/ai/api/ai_info_docs.hpp
@@ -183,10 +183,11 @@ public:
/** Miscellaneous flags for AI settings. */
enum AIConfigFlags {
- AICONFIG_NONE, ///< Normal setting.
- AICONFIG_RANDOM, ///< When randomizing the AI, pick any value between min_value and max_value.
- AICONFIG_BOOLEAN, ///< This value is a boolean (either 0 (false) or 1 (true) ).
- AICONFIG_INGAME, ///< This setting can be changed while the AI is running.
+ AICONFIG_NONE, ///< Normal setting.
+ AICONFIG_RANDOM, ///< When randomizing the AI, pick any value between min_value and max_value.
+ AICONFIG_BOOLEAN, ///< This value is a boolean (either 0 (false) or 1 (true) ).
+ AICONFIG_INGAME, ///< This setting can be changed while the AI is running.
+ AICONFIG_AI_DEVELOPER, ///< This setting will only be visible when the ai development tools are active.
};
/**
diff --git a/src/settings.cpp b/src/settings.cpp
index a688fc5aa..cd6003cdc 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -920,6 +920,12 @@ static bool InvalidateIndustryViewWindow(int32 p1)
return true;
}
+static bool InvalidateAISettingsWindow(int32 p1)
+{
+ InvalidateWindowClassesData(WC_AI_SETTINGS);
+ return true;
+}
+
/**
* Update the town authority window after a town authority setting change.
* @param p1 Unused.
diff --git a/src/table/settings.ini b/src/table/settings.ini
index 6370a43c6..65edeea2c 100644
--- a/src/table/settings.ini
+++ b/src/table/settings.ini
@@ -37,6 +37,7 @@ static bool InvalidateVehTimetableWindow(int32 p1);
static bool InvalidateCompanyLiveryWindow(int32 p1);
static bool InvalidateNewGRFChangeWindows(int32 p1);
static bool InvalidateIndustryViewWindow(int32 p1);
+static bool InvalidateAISettingsWindow(int32 p1);
static bool RedrawTownAuthority(int32 p1);
extern bool UpdateNewGRFConfigPalette(int32 p1);
@@ -2422,6 +2423,7 @@ proc = InvalidateNewGRFChangeWindows
var = gui.ai_developer_tools
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
def = false
+proc = InvalidateAISettingsWindow
[SDTC_BOOL]
var = gui.scenario_developer