Loading
#openttdcoop - Paste
Archives
Trending
Docs
Login
ABAP
ActionScript
ActionScript 3
Ada
AIMMS3
ALGOL 68
Apache configuration
AppleScript
Apt sources
ARM ASSEMBLER
ASM
ASP
asymptote
Autoconf
Autohotkey
AutoIt
AviSynth
awk
BASCOM AVR
Bash
Basic4GL
BibTeX
BlitzBasic
bnf
Boo
Brainfuck
C
C#
C (LoadRunner)
C (Mac)
C (WinAPI)
C++
C++ (Qt)
C++ (WinAPI)
CAD DCL
CAD Lisp
CFDG
ChaiScript
Chapel
CIL
Clojure
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
Dart
DCL
DCPU-16 Assembly
DCS
Delphi
Diff
DIV
DOS
dot
E
ECMAScript
Eiffel
eMail (mbox)
EPC
Erlang
Euphoria
EZT
F#
Falcon
FO (abas-ERP)
Formula One
Fortran
FreeBasic
FreeSWITCH
GADV 4CS
GAMBAS
GDB
genero
Genie
glSlang
GML
GNU/Octave
GNU Gettext
GNU make
Gnuplot
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML
HTML5
Icon
INI
Inno
INTERCAL
Io
ISPF Panel
J
Java
Java(TM) 2 Platform Standard Edition 5.0
Javascript
JCL
jQuery
KiXtart
KLone C
KLone C++
LaTeX
LDIF
Liberty BASIC
Lisp
LLVM Intermediate Representation
Locomotive Basic
Logtalk
LOLcode
Lotus Notes @Formulas
LotusScript
LScript
LSL2
Lua
MagikSF
MapBasic
Matlab M
Microchip Assembler
Microsoft Registry
mIRC Scripting
MMIX
Modula-2
Modula-3
MOS 6502 (6510) ACME Cross Assembler format
MOS 6502 (6510) Kick Assembler format
MOS 6502 (6510) TASM/64TASS 1.46 Assembler format
Motorola 68000 - HiSoft Devpac ST 2 Assembler format
Motorola 68000 Assembler
MXML
MySQL
Nagios
NetRexx
newlisp
nginx
Nimrod
NML NewGRF Meta Language
NSIS
Oberon-2
Objeck Programming Language
Objective-C
OCaml
OCaml (brief)
ooRexx
OpenBSD Packet Filter
OpenOffice.org Basic
Oracle 8 SQL
Oracle 11 SQL
Oxygene
OZ
ParaSail
PARI/GP
Pascal
PCRE
per
Perl
Perl 6
PHP
PHP (brief)
PIC16
Pike
Pixel Bender 1.0
PL/I
PL/SQL
PostgreSQL
PostScript
POVRAY
PowerBuilder
PowerShell
ProFTPd configuration
Progress
Prolog
PROPERTIES
ProvideX
Puppet
PureBasic
Python
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
R / S+
Racket
Rails
RBScript
REBOL
rexx
robots.txt
RPM Specification File
Ruby
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
Squirrel Script
Squirrel Script with OpenTTD AI/GS
StandardML
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term Macro
Text
thinBasic
TypoScript
Unicon (Unified Extended Dialect of Icon)
Uno Idl
Unreal Script
UPC
Urbi
Vala
vb.net
VBScript
Vedit macro language
Verilog
VHDL
Vim Script
Visual Basic
Visual Fox Pro
Visual Prolog
Whitespace
Whois (RPSL format)
Winbatch
X++
XBasic
XML
Xorg configuration
YAML
ZiLOG Z80 Assembler
ZXBasic
typedef std::vector<const ScriptConfigItem *> VisibleSettingsList; static VisibleSettingsList BuildVisibleSettingsList(CompanyID slot) { VisibleSettingsList visible_settings; ///< List of visible AI settings ScriptConfig *config_list = GetConfig(slot); ScriptConfigItemList::const_iterator it = config_list->GetConfigList()->begin(); for (; it != config_list->GetConfigList()->end(); it++) { bool no_hide = (it->flags & SCRIPTCONFIG_DEVELOPER) == 0; if (no_hide || _settings_client.gui.ai_developer_tools) { visible_settings.push_back(&(*it)); } } return visible_settings; } ////BLA BLA CODE //// /** * Window for settings the parameters of an AI. */ struct AISettingsWindow : public Window { CompanyID slot; ///< The currently show company's setting. ScriptConfig *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. bool clicked_dropdown; ///< Whether the dropdown is open. bool closing_dropdown; ///< True, if the dropdown list is currently closing. GUITimer 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. VisibleSettingsList visible_settings; ///< List of visible AI settings /** * Constructor for the window. * @param desc The description of the window. * @param slot The company we're changing the settings for. */ AISettingsWindow(WindowDesc *desc, CompanyID slot) : Window(desc), slot(slot), clicked_button(-1), clicked_dropdown(false), closing_dropdown(false), timeout(0) { this->ai_config = GetConfig(slot); this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR); this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect. this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode == GM_EDITOR && !IsConsideredDead(this->slot)); this->RebuildVisibleSettings(); } 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; } } /** * Rebuilds the list of visible settings. AI settings with the flag * SCRIPTCONFIG_DEVELOPER set will only be visible if the client setting * gui.ai_developer_tools is enabled. */ void RebuildVisibleSettings() { this->ai_config = GetConfig(slot); visible_settings.clear(); visible_settings.swap(BuildVisibleSettingsList(slot)); this->vscroll->SetCount((int)this->visible_settings.size()); } virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { if (widget == WID_AIS_BACKGROUND) { this->line_height = max(SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL) + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; resize->width = 1; resize->height = this->line_height; size->height = 5 * this->line_height; } } virtual void DrawWidget(const Rect &r, int widget) const { if (widget != WID_AIS_BACKGROUND) return; ScriptConfig *config = this->ai_config; VisibleSettingsList::const_iterator it = this->visible_settings.begin(); int i = 0; for (; !this->vscroll->IsVisible(i); i++) it++; bool rtl = _current_text_dir == TD_RTL; 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); int y = r.top; int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2; for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) { const ScriptConfigItem &config_item = **it; int current_value = config->GetSetting((config_item).name); bool editable = this->IsEditableItem(config_item); StringID str; TextColour colour; uint idx = 0; if (StrEmpty(config_item.description)) { 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; } } else { str = STR_AI_SETTINGS_SETTING; colour = TC_LIGHT_BLUE; SetDParamStr(idx++, config_item.description); } if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) { DrawBoolButton(buttons_left, y + button_y_offset, current_value != 0, editable); SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON); } else { 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); } if (config_item.labels != NULL && config_item.labels->Contains(current_value)) { SetDParam(idx++, STR_JUST_RAW_STRING); SetDParamStr(idx++, config_item.labels->Find(current_value)->second); } else { SetDParam(idx++, STR_JUST_INT); SetDParam(idx++, current_value); } } DrawString(text_left, text_right, y + text_y_offset, str, colour); y += this->line_height; } } virtual void OnPaint() { if (this->closing_dropdown) { this->closing_dropdown = false; this->clicked_dropdown = false; } this->DrawWidgets(); } virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case WID_AIS_BACKGROUND: { const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_AIS_BACKGROUND); int num = (pt.y - wid->pos_y) / this->line_height + this->vscroll->GetPosition(); if (num >= (int)this->visible_settings.size()) break; VisibleSettingsList::const_iterator it = this->visible_settings.begin(); for (int i = 0; i < num; i++) it++; const ScriptConfigItem config_item = **it; if (!this->IsEditableItem(config_item)) return; if (this->clicked_row != num) { DeleteChildWindows(WC_QUERY_STRING); HideDropDownMenu(this); this->clicked_row = num; this->clicked_dropdown = false; } bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0; int x = pt.x - wid->pos_x; if (_current_text_dir == TD_RTL) x = wid->current_x - 1 - x; x -= 4; /* One of the arrows is clicked (or green/red rect in case of bool value) */ int old_val = this->ai_config->GetSetting(config_item.name); 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->Append() = 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)) { int new_val = old_val; if (bool_item) { new_val = !new_val; } else if (x >= SETTING_BUTTON_WIDTH / 2) { /* 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; } if (new_val != old_val) { this->ai_config->SetSetting(config_item.name, new_val); this->clicked_button = num; this->timeout.SetInterval(150); } } else if (!bool_item && !config_item.complete_labels) { /* Display a query box so users can enter a custom value. */ SetDParam(0, old_val); ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE); } this->SetDirty(); break; } case WID_AIS_ACCEPT: delete this; break; case WID_AIS_RESET: if (_game_mode != GM_EDITOR || IsConsideredDead(this->slot)) { this->ai_config->ResetSettingsGUI(IsConsideredDead(this->slot)); this->SetDirty(); } break; } } virtual void OnQueryTextFinished(char *str) { if (StrEmpty(str)) return; VisibleSettingsList::const_iterator it = this->visible_settings.begin(); for (int i = 0; i < this->clicked_row; i++) it++; const ScriptConfigItem config_item = **it; if (_game_mode != GM_MENU && !IsConsideredDead(this->slot) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return; int32 value = atoi(str); this->ai_config->SetSetting(config_item.name, value); this->SetDirty(); } virtual void OnDropdownSelect(int widget, int index) { assert(this->clicked_dropdown); VisibleSettingsList::const_iterator it = this->visible_settings.begin(); for (int i = 0; i < this->clicked_row; i++) it++; const ScriptConfigItem config_item = **it; if (_game_mode != GM_MENU && !IsConsideredDead(this->slot) && (config_item.flags & SCRIPTCONFIG_INGAME) == 0) return; this->ai_config->SetSetting(config_item.name, index); 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(); } virtual void OnResize() { this->vscroll->SetCapacityFromWidget(this, WID_AIS_BACKGROUND); } virtual void OnRealtimeTick(uint delta_ms) { if (this->timeout.Elapsed(delta_ms)) { this->clicked_button = -1; this->SetDirty(); } } /** * 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) { this->RebuildVisibleSettings(); HideDropDownMenu(this); DeleteChildWindows(WC_QUERY_STRING); } private: bool IsEditableItem(const ScriptConfigItem config_item) const { if (_game_mode == GM_MENU) return true; if (_game_mode == GM_NORMAL) { if (IsConsideredDead(slot)) return true; if (config_item.flags & SCRIPTCONFIG_INGAME) return true; } if (IsConsideredDead(slot)) { if (slot == OWNER_DEITY) { if (Game::GetInstance() == NULL) return true; } if (!Company::IsValidAiID(slot)) return true; if (Company::Get(slot)->ai_instance == NULL) return true; } return false; } };
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever