OpenTTD Source: src/script/script_gui.cpp Source File

OpenTTD Source 15.0-RC2

script_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "../stdafx.h"
11#include "../table/sprites.h"
12#include "../error.h"
13#include "../settings_gui.h"
14#include "../querystring_gui.h"
15#include "../stringfilter_type.h"
16#include "../company_base.h"
17#include "../company_gui.h"
18#include "../dropdown_type.h"
19#include "../dropdown_func.h"
20#include "../window_func.h"
21#include "../network/network.h"
22#include "../hotkeys.h"
23#include "../company_cmd.h"
24#include "../misc_cmd.h"
25#include "../strings_func.h"
26#include "../timer/timer.h"
27#include "../timer/timer_window.h"
28#include "../core/string_consumer.hpp"
29
30#include "script_gui.h"
31#include "script_log.hpp"
32#include "script_scanner.hpp"
33#include "script_config.hpp"
34#include "../ai/ai.hpp"
35#include "../ai/ai_config.hpp"
36#include "../ai/ai_info.hpp"
37#include "../ai/ai_instance.hpp"
38#include "../game/game.hpp"
39#include "../game/game_config.hpp"
40#include "../game/game_info.hpp"
41#include "../game/game_instance.hpp"
42
43#include "table/strings.h"
44
45#include "../safeguards.h"
46
47
48static ScriptConfig *GetConfig(CompanyID slot)
49{
50 if (slot == OWNER_DEITY) return GameConfig::GetConfig();
51 return AIConfig::GetConfig(slot);
52}
53
57 struct ScriptListWindow : public Window {
58 const ScriptInfoList *info_list = nullptr;
59 int selected = -1;
60 CompanyID slot{};
61 int line_height = 0;
62 Scrollbar *vscroll = nullptr;
63 bool show_all = false;
64
71 ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all) : Window(desc),
72 slot(slot), show_all(show_all)
73 {
74 if (this->slot == OWNER_DEITY) {
75 this->info_list = this->show_all ? Game::GetInfoList() : Game::GetUniqueInfoList();
76 } else {
77 this->info_list = this->show_all ? AI::GetInfoList() : AI::GetUniqueInfoList();
78 }
79
80 this->CreateNestedTree();
81 this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR);
82 this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
83
84 this->vscroll->SetCount(this->info_list->size() + 1);
85
86 /* Try if we can find the currently selected AI */
87 if (GetConfig(this->slot)->HasScript()) {
88 ScriptInfo *info = GetConfig(this->slot)->GetInfo();
89 int i = 0;
90 for (const auto &item : *this->info_list) {
91 if (item.second == info) {
92 this->selected = i;
93 break;
94 }
95
96 i++;
97 }
98 }
99 }
100
101 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
102 {
103 if (widget != WID_SCRL_CAPTION) return this->Window::GetWidgetString(widget, stringid);
104
105 return GetString(STR_AI_LIST_CAPTION, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
106 }
107
108 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
109 {
110 if (widget != WID_SCRL_LIST) return;
111
112 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
113
114 resize.width = 1;
115 fill.height = resize.height = this->line_height;
116 size.height = 5 * this->line_height;
117 }
118
119 void DrawWidget(const Rect &r, WidgetID widget) const override
120 {
121 switch (widget) {
122 case WID_SCRL_LIST: {
123 /* Draw a list of all available Scripts. */
124 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
125 /* First AI in the list is hardcoded to random */
126 if (this->vscroll->IsVisible(0)) {
127 DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TC_WHITE : TC_ORANGE);
128 tr.top += this->line_height;
129 }
130 int i = 0;
131 for (const auto &item : *this->info_list) {
132 i++;
133 if (this->vscroll->IsVisible(i)) {
134 DrawString(tr, this->show_all ? GetString(STR_AI_CONFIG_NAME_VERSION, item.second->GetName(), item.second->GetVersion()) : item.second->GetName(), (this->selected == i - 1) ? TC_WHITE : TC_ORANGE);
135 tr.top += this->line_height;
136 }
137 }
138 break;
139 }
140 case WID_SCRL_INFO_BG: {
141 ScriptInfo *selected_info = nullptr;
142 int i = 0;
143 for (const auto &item : *this->info_list) {
144 i++;
145 if (this->selected == i - 1) selected_info = static_cast<ScriptInfo *>(item.second);
146 }
147 /* Some info about the currently selected Script. */
148 if (selected_info != nullptr) {
149 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
150 DrawString(tr, GetString(STR_AI_LIST_AUTHOR, selected_info->GetAuthor()));
151 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
152 DrawString(tr, GetString(STR_AI_LIST_VERSION, selected_info->GetVersion()));
153 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
154 if (!selected_info->GetURL().empty()) {
155 DrawString(tr, GetString(STR_AI_LIST_URL, selected_info->GetURL()));
156 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
157 }
158 DrawStringMultiLine(tr, selected_info->GetDescription(), TC_WHITE);
159 }
160 break;
161 }
162 }
163 }
164
168 void ChangeScript()
169 {
170 if (this->selected == -1) {
171 GetConfig(this->slot)->Change(std::nullopt);
172 } else {
173 ScriptInfoList::const_iterator it = this->info_list->cbegin();
174 std::advance(it, this->selected);
175 GetConfig(this->slot)->Change(it->second->GetName(), it->second->GetVersion());
176 }
177 if (_game_mode == GM_EDITOR) {
178 if (this->slot == OWNER_DEITY) {
179 if (Game::GetInstance() != nullptr) Game::ResetInstance();
180 Game::StartNew();
181 } else {
182 Company *c = Company::GetIfValid(this->slot);
183 if (c != nullptr && c->ai_instance != nullptr) {
184 c->ai_instance.reset();
185 AI::StartNew(this->slot);
186 }
187 }
188 }
189 InvalidateWindowData(WC_GAME_OPTIONS, this->slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI);
190 InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
191 InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
192 CloseWindowByClass(WC_QUERY_STRING);
193 InvalidateWindowClassesData(WC_TEXTFILE);
194 }
195
196 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
197 {
198 switch (widget) {
199 case WID_SCRL_LIST: { // Select one of the Scripts
200 int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCRL_LIST) - 1;
201 if (sel < static_cast<int>(this->info_list->size())) {
202 this->selected = sel;
203 this->SetDirty();
204 if (click_count > 1) {
205 this->ChangeScript();
206 this->Close();
207 }
208 }
209 break;
210 }
211
212 case WID_SCRL_ACCEPT: {
213 this->ChangeScript();
214 this->Close();
215 break;
216 }
217 }
218 }
219
220 void OnResize() override
221 {
222 this->vscroll->SetCapacityFromWidget(this, WID_SCRL_LIST);
223 }
224
230 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
231 {
232 if (_game_mode == GM_NORMAL && Company::IsValidID(this->slot)) {
233 this->Close();
234 return;
235 }
236
237 if (!gui_scope) return;
238
239 this->vscroll->SetCount(this->info_list->size() + 1);
240
241 /* selected goes from -1 .. length of ai list - 1. */
242 this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
243 }
244};
245
247 static constexpr std::initializer_list<NWidgetPart> _nested_script_list_widgets = {
248 NWidget(NWID_HORIZONTAL),
249 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
250 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRL_CAPTION),
251 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
252 EndContainer(),
253 NWidget(NWID_HORIZONTAL),
254 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_SCRL_LIST), SetMinimalSize(188, 112), SetFill(1, 1), SetResize(1, 1), SetMatrixDataTip(1, 0, STR_AI_LIST_TOOLTIP), SetScrollbar(WID_SCRL_SCROLLBAR),
255 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRL_SCROLLBAR),
256 EndContainer(),
257 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_SCRL_INFO_BG), SetMinimalTextLines(8, WidgetDimensions::unscaled.framerect.Vertical() + WidgetDimensions::unscaled.vsep_normal * 3), SetResize(1, 0),
258 EndContainer(),
259 NWidget(NWID_HORIZONTAL),
260 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRL_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_AI_LIST_ACCEPT, STR_AI_LIST_ACCEPT_TOOLTIP),
261 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
262 EndContainer(),
263};
264
266 static WindowDesc _script_list_desc(
267 WDP_CENTER, "settings_script_list", 200, 234,
268 WC_SCRIPT_LIST, WC_NONE,
269 {},
270 _nested_script_list_widgets
271);
272
278 void ShowScriptListWindow(CompanyID slot, bool show_all)
279{
280 CloseWindowByClass(WC_SCRIPT_LIST);
281 new ScriptListWindow(_script_list_desc, slot, show_all);
282}
283
284
288 struct ScriptSettingsWindow : public Window {
289 CompanyID slot{};
290 ScriptConfig *script_config = nullptr;
291 int clicked_button = -1;
292 bool clicked_increase = false;
293 bool clicked_dropdown = false;
294 bool closing_dropdown = false;
295 int clicked_row = 0;
296 int line_height = 0;
297 Scrollbar *vscroll = nullptr;
298 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
299 VisibleSettingsList visible_settings{};
300
306 ScriptSettingsWindow(WindowDesc &desc, CompanyID slot) : Window(desc), slot(slot)
307 {
308 this->CreateNestedTree();
309 this->vscroll = this->GetScrollbar(WID_SCRS_SCROLLBAR);
310 this->FinishInitNested(this->slot); // Initializes 'this->line_height' as side effect.
311
312 this->OnInvalidateData();
313 }
314
320 void RebuildVisibleSettings()
321 {
322 this->visible_settings.clear();
323
324 for (const auto &item : *this->script_config->GetConfigList()) {
325 bool no_hide = !item.flags.Test(ScriptConfigFlag::Developer);
326 if (no_hide || _settings_client.gui.ai_developer_tools) {
327 this->visible_settings.push_back(&item);
328 }
329 }
330
331 this->vscroll->SetCount(this->visible_settings.size());
332 }
333
334 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
335 {
336 if (widget != WID_SCRS_CAPTION) return this->Window::GetWidgetString(widget, stringid);
337
338 return GetString((this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
339 }
340
341 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
342 {
343 if (widget != WID_SCRS_BACKGROUND) return;
344
345 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)) + padding.height;
346
347 resize.width = 1;
348 fill.height = resize.height = this->line_height;
349 size.height = 5 * this->line_height;
350 }
351
352 void DrawWidget(const Rect &r, WidgetID widget) const override
353 {
354 if (widget != WID_SCRS_BACKGROUND) return;
355
356 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
357 bool rtl = _current_text_dir == TD_RTL;
358 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
359 Rect tr = ir.Indent(SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide, rtl);
360
361 int y = r.top;
362 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
363 int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2;
364
365 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
366 for (auto it = first; it != last; ++it) {
367 const ScriptConfigItem &config_item = **it;
368 int current_value = this->script_config->GetSetting(config_item.name);
369 bool editable = this->IsEditableItem(config_item);
370
371 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
372 DrawBoolButton(br.left, y + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, editable);
373 } else {
374 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
375 if (config_item.complete_labels) {
376 DrawDropDownButton(br.left, y + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, editable);
377 } else {
378 DrawArrowButtons(br.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);
379 }
380 }
381
382 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
383 y += this->line_height;
384 }
385 }
386
387 void OnPaint() override
388 {
389 if (this->closing_dropdown) {
390 this->closing_dropdown = false;
391 this->clicked_dropdown = false;
392 }
393 this->DrawWidgets();
394 }
395
396 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
397 {
398 switch (widget) {
399 case WID_SCRS_BACKGROUND: {
400 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
401 if (it == this->visible_settings.end()) break;
402
403 const ScriptConfigItem &config_item = **it;
404 if (!this->IsEditableItem(config_item)) return;
405
406 int num = it - this->visible_settings.begin();
407 if (this->clicked_row != num) {
408 this->CloseChildWindows(WC_QUERY_STRING);
409 this->CloseChildWindows(WC_DROPDOWN_MENU);
410 this->clicked_row = num;
411 this->clicked_dropdown = false;
412 }
413
414 bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean);
415
416 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
417 int x = pt.x - r.left;
418 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
419
420 /* One of the arrows is clicked (or green/red rect in case of bool value) */
421 int old_val = this->script_config->GetSetting(config_item.name);
422 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
423 if (this->clicked_dropdown) {
424 /* unclick the dropdown */
425 this->CloseChildWindows(WC_DROPDOWN_MENU);
426 this->clicked_dropdown = false;
427 this->closing_dropdown = false;
428 } else {
429 int rel_y = (pt.y - r.top) % this->line_height;
430
431 Rect wi_rect;
432 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
433 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
434 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
435 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
436
437 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
438 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
439 this->clicked_dropdown = true;
440 this->closing_dropdown = false;
441
442 DropDownList list;
443 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
444 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i));
445 }
446
447 ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
448 }
449 }
450 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
451 int new_val = old_val;
452 if (bool_item) {
453 new_val = !new_val;
454 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
455 /* Increase button clicked */
456 new_val += config_item.step_size;
457 if (new_val > config_item.max_value) new_val = config_item.max_value;
458 this->clicked_increase = true;
459 } else {
460 /* Decrease button clicked */
461 new_val -= config_item.step_size;
462 if (new_val < config_item.min_value) new_val = config_item.min_value;
463 this->clicked_increase = false;
464 }
465
466 if (new_val != old_val) {
467 this->script_config->SetSetting(config_item.name, new_val);
468 this->clicked_button = num;
469 this->unclick_timeout.Reset();
470 }
471 } else if (!bool_item && !config_item.complete_labels) {
472 /* Display a query box so users can enter a custom value. */
473 ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
474 }
475 this->SetDirty();
476 break;
477 }
478
479 case WID_SCRS_RESET:
480 this->script_config->ResetEditableSettings(_game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
481 this->SetDirty();
482 break;
483 }
484 }
485
486 void OnQueryTextFinished(std::optional<std::string> str) override
487 {
488 if (!str.has_value()) return;
489 auto value = ParseInteger<int32_t>(*str, 10, true);
490 if (!value.has_value()) return;
491 this->SetValue(*value);
492 }
493
494 void OnDropdownSelect(WidgetID widget, int index, int) override
495 {
496 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
497 assert(this->clicked_dropdown);
498 this->SetValue(index);
499 }
500
501 void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
502 {
503 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
504 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
505 * the same dropdown button was clicked again, and then not open the dropdown again.
506 * So, we only remember that it was closed, and process it on the next OnPaint, which is
507 * after OnClick. */
508 assert(this->clicked_dropdown);
509 this->closing_dropdown = true;
510 this->SetDirty();
511 }
512
513 void OnResize() override
514 {
515 this->vscroll->SetCapacityFromWidget(this, WID_SCRS_BACKGROUND);
516 }
517
519 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
520 this->clicked_button = -1;
521 this->SetDirty();
522 }};
523
529 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
530 {
531 this->script_config = GetConfig(this->slot);
532 if (this->script_config->GetConfigList()->empty()) this->Close();
533 this->RebuildVisibleSettings();
534 this->CloseChildWindows(WC_DROPDOWN_MENU);
535 this->CloseChildWindows(WC_QUERY_STRING);
536 }
537
538private:
539 bool IsEditableItem(const ScriptConfigItem &config_item) const
540 {
541 return _game_mode == GM_MENU
542 || _game_mode == GM_EDITOR
543 || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot))
544 || config_item.flags.Test(ScriptConfigFlag::InGame)
545 || _settings_client.gui.ai_developer_tools;
546 }
547
548 void SetValue(int value)
549 {
550 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
551 if (_game_mode == GM_NORMAL && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
552 this->script_config->SetSetting(config_item.name, value);
553 this->SetDirty();
554 }
555};
556
558 static constexpr std::initializer_list<NWidgetPart> _nested_script_settings_widgets = {
559 NWidget(NWID_HORIZONTAL),
560 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
561 NWidget(WWT_CAPTION, COLOUR_MAUVE, WID_SCRS_CAPTION),
562 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
563 EndContainer(),
564 NWidget(NWID_HORIZONTAL),
565 NWidget(WWT_MATRIX, COLOUR_MAUVE, WID_SCRS_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetMatrixDataTip(1, 0), SetScrollbar(WID_SCRS_SCROLLBAR),
566 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_SCRS_SCROLLBAR),
567 EndContainer(),
568 NWidget(NWID_HORIZONTAL),
569 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_SCRS_RESET), SetStringTip(STR_AI_SETTINGS_RESET),
570 NWidget(WWT_PANEL, COLOUR_MAUVE), SetResize(1, 0), SetFill(1, 0),
571 EndContainer(),
572 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
573 EndContainer(),
574};
575
577 static WindowDesc _script_settings_desc(
578 WDP_CENTER, "settings_script", 500, 208,
579 WC_SCRIPT_SETTINGS, WC_NONE,
580 {},
581 _nested_script_settings_widgets
582);
583
588 void ShowScriptSettingsWindow(CompanyID slot)
589{
590 CloseWindowByClass(WC_SCRIPT_LIST);
591 CloseWindowByClass(WC_SCRIPT_SETTINGS);
592 new ScriptSettingsWindow(_script_settings_desc, slot);
593}
594
595
597 struct ScriptTextfileWindow : public TextfileWindow {
598 CompanyID slot{};
599
600 ScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot) : TextfileWindow(parent, file_type), slot(slot)
601 {
602 this->ConstructWindow();
603 this->OnInvalidateData();
604 }
605
606 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
607 {
608 if (widget == WID_TF_CAPTION) {
609 return GetString(stringid, (this->slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI, GetConfig(this->slot)->GetInfo()->GetName());
610 }
611
612 return this->Window::GetWidgetString(widget, stringid);
613 }
614
615 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
616 {
617 auto textfile = GetConfig(this->slot)->GetTextfile(file_type, this->slot);
618 if (!textfile.has_value()) {
619 this->Close();
620 } else {
621 this->LoadTextfile(textfile.value(), (this->slot == OWNER_DEITY) ? GAME_DIR : AI_DIR);
622 }
623 }
624};
625
631 void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
632{
633 parent->CloseChildWindowById(WC_TEXTFILE, file_type);
634 new ScriptTextfileWindow(parent, file_type, slot);
635}
636
637
646 static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
647{
648 /* Dead scripts are indicated with red background and
649 * paused scripts are indicated with yellow background. */
650 Colours colour = dead ? COLOUR_RED :
651 (paused ? COLOUR_YELLOW : COLOUR_GREY);
652 if (button.colour != colour) {
653 button.colour = colour;
654 return true;
655 }
656 return false;
657}
658
662 struct ScriptDebugWindow : public Window {
663 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
664
665 struct FilterState {
666 std::string break_string;
667 CompanyID script_debug_company;
668 bool break_check_enabled;
669 bool case_sensitive_break_check;
670 };
671
672 static inline FilterState initial_state = {
673 "",
674 CompanyID::Invalid(),
675 true,
676 false,
677 };
678
679 int last_vscroll_pos = 0;
680 bool autoscroll = true;
681 bool show_break_box = false;
682 QueryString break_editbox;
683 StringFilter break_string_filter{};
684 int highlight_row = -1;
685 Scrollbar *vscroll = nullptr;
686 Scrollbar *hscroll = nullptr;
687 FilterState filter{};
688
689 ScriptLogTypes::LogData &GetLogData() const
690 {
691 if (this->filter.script_debug_company == OWNER_DEITY) return Game::GetInstance()->GetLogData();
692 return Company::Get(this->filter.script_debug_company)->ai_instance->GetLogData();
693 }
694
699 bool IsDead() const
700 {
701 if (this->filter.script_debug_company == OWNER_DEITY) {
702 GameInstance *game = Game::GetInstance();
703 return game == nullptr || game->IsDead();
704 }
705 return !Company::IsValidAiID(this->filter.script_debug_company) || Company::Get(this->filter.script_debug_company)->ai_instance->IsDead();
706 }
707
713 bool IsValidDebugCompany(CompanyID company) const
714 {
715 switch (company.base()) {
716 case CompanyID::Invalid().base(): return false;
717 case OWNER_DEITY.base(): return Game::GetInstance() != nullptr;
718 default: return Company::IsValidAiID(company);
719 }
720 }
721
726 void SelectValidDebugCompany()
727 {
728 /* Check if the currently selected company is still active. */
729 if (this->IsValidDebugCompany(this->filter.script_debug_company)) return;
730
731 this->filter.script_debug_company = CompanyID::Invalid();
732
733 for (const Company *c : Company::Iterate()) {
734 if (c->is_ai) {
735 this->ChangeToScript(c->index);
736 return;
737 }
738 }
739
740 /* If no AI is available, see if there is a game script. */
741 if (Game::GetInstance() != nullptr) this->ChangeToScript(OWNER_DEITY);
742 }
743
749 ScriptDebugWindow(WindowDesc &desc, WindowNumber number, Owner show_company) : Window(desc), break_editbox(MAX_BREAK_STR_STRING_LENGTH)
750 {
751 this->filter = ScriptDebugWindow::initial_state;
752 this->break_string_filter = {&this->filter.case_sensitive_break_check, false};
753
754 this->CreateNestedTree();
755 this->vscroll = this->GetScrollbar(WID_SCRD_VSCROLLBAR);
756 this->hscroll = this->GetScrollbar(WID_SCRD_HSCROLLBAR);
757 this->FinishInitNested(number);
758
759 this->querystrings[WID_SCRD_BREAK_STR_EDIT_BOX] = &this->break_editbox;
760
761 this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar
762
763 /* Restore the break string value from static variable, and enable the filter. */
764 this->break_editbox.text.Assign(this->filter.break_string);
765 this->break_string_filter.SetFilterTerm(this->filter.break_string);
766
767 if (show_company == CompanyID::Invalid()) {
768 this->SelectValidDebugCompany();
769 } else {
770 this->ChangeToScript(show_company);
771 }
772 }
773
774 void OnInit() override
775 {
776 this->show_break_box = _settings_client.gui.ai_developer_tools;
777 this->GetWidget<NWidgetStacked>(WID_SCRD_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
778 if (!this->show_break_box) this->filter.break_check_enabled = false;
779 SetWidgetsDisabledState(!this->show_break_box, WID_SCRD_BREAK_STR_ON_OFF_BTN, WID_SCRD_BREAK_STR_EDIT_BOX, WID_SCRD_MATCH_CASE_BTN);
780
781 this->InvalidateData(-1);
782 }
783
784 ~ScriptDebugWindow()
785 {
786 ScriptDebugWindow::initial_state = this->filter;
787 }
788
789 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
790 {
791 if (widget == WID_SCRD_LOG_PANEL) {
792 fill.height = resize.height = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
793 size.height = 14 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
794 }
795 }
796
797 void OnPaint() override
798 {
799 this->SelectValidDebugCompany();
800 this->UpdateLogScroll();
801
802 /* Draw standard stuff */
803 this->DrawWidgets();
804 }
805
806 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
807 {
808 if (widget != WID_SCRD_NAME_TEXT) return this->Window::GetWidgetString(widget, stringid);
809
810 if (this->filter.script_debug_company == OWNER_DEITY) {
811 const GameInfo *info = Game::GetInfo();
812 assert(info != nullptr);
813 return GetString(STR_AI_DEBUG_NAME_AND_VERSION, info->GetName(), info->GetVersion());
814 }
815 if (this->filter.script_debug_company == CompanyID::Invalid() || !Company::IsValidAiID(this->filter.script_debug_company)) {
816 return {};
817 }
818
819 const AIInfo *info = Company::Get(this->filter.script_debug_company)->ai_info;
820 return GetString(STR_AI_DEBUG_NAME_AND_VERSION, info->GetName(), info->GetVersion());
821 }
822
823 void DrawWidget(const Rect &r, WidgetID widget) const override
824 {
825 switch (widget) {
826 case WID_SCRD_LOG_PANEL:
827 this->DrawWidgetLog(r);
828 break;
829
830 default:
831 if (IsInsideBS(widget, WID_SCRD_COMPANY_BUTTON_START, MAX_COMPANIES)) {
832 this->DrawWidgetCompanyButton(r, widget, WID_SCRD_COMPANY_BUTTON_START);
833 }
834 break;
835 }
836 }
837
844 void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
845 {
846 if (this->IsWidgetDisabled(widget)) return;
847 CompanyID cid = static_cast<CompanyID>(widget - start);
848 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
849 DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height));
850 }
851
856 void DrawWidgetLog(const Rect &r) const
857 {
858 if (this->filter.script_debug_company == CompanyID::Invalid()) return;
859
860 const ScriptLogTypes::LogData &log = this->GetLogData();
861 if (log.empty()) return;
862
863 Rect fr = r.Shrink(WidgetDimensions::scaled.framerect);
864
865 /* Setup a clipping rectangle... */
866 DrawPixelInfo tmp_dpi;
867 if (!FillDrawPixelInfo(&tmp_dpi, fr)) return;
868 /* ...but keep coordinates relative to the window. */
869 tmp_dpi.left += fr.left;
870 tmp_dpi.top += fr.top;
871
872 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
873
874 fr = ScrollRect(fr, *this->hscroll, 1);
875
876 auto [first, last] = this->vscroll->GetVisibleRangeIterators(log);
877 for (auto it = first; it != last; ++it) {
878 const ScriptLogTypes::LogLine &line = *it;
879
880 TextColour colour;
881 switch (line.type) {
882 case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break;
883 case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break;
884 case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break;
885 case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break;
886 case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break;
887 default: colour = TC_BLACK; break;
888 }
889
890 /* Check if the current line should be highlighted */
891 if (std::distance(std::begin(log), it) == this->highlight_row) {
892 fr.bottom = fr.top + this->resize.step_height - 1;
893 GfxFillRect(fr, PC_BLACK);
894 if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white.
895 }
896
897 DrawString(fr, line.text, colour, SA_LEFT | SA_FORCE);
898 fr.top += this->resize.step_height;
899 }
900 }
901
905 void UpdateLogScroll()
906 {
907 this->SetWidgetsDisabledState(this->filter.script_debug_company == CompanyID::Invalid(), WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR);
908 if (this->filter.script_debug_company == CompanyID::Invalid()) return;
909
910 ScriptLogTypes::LogData &log = this->GetLogData();
911
912 int scroll_count = static_cast<int>(log.size());
913 if (this->vscroll->GetCount() != scroll_count) {
914 this->vscroll->SetCount(scroll_count);
915
916 /* We need a repaint */
917 this->SetWidgetDirty(WID_SCRD_VSCROLLBAR);
918 }
919
920 if (log.empty()) return;
921
922 /* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */
923 if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
924 this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= static_cast<int>(log.size());
925 }
926
927 if (this->autoscroll && this->vscroll->SetPosition(static_cast<int>(log.size()))) {
928 /* We need a repaint */
929 this->SetWidgetDirty(WID_SCRD_VSCROLLBAR);
930 this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
931 }
932
933 this->last_vscroll_pos = this->vscroll->GetPosition();
934 }
935
939 void UpdateAIButtonsState()
940 {
941 /* Update company buttons */
942 for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) {
943 /* Mark dead/paused AIs by setting the background colour. */
944 bool valid = Company::IsValidAiID(i);
945 bool dead = valid && Company::Get(i)->ai_instance->IsDead();
946 bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
947
948 NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_SCRD_COMPANY_BUTTON_START + i);
949 button->SetDisabled(!valid);
950 button->SetLowered(this->filter.script_debug_company == i);
951 SetScriptButtonColour(*button, dead, paused);
952 }
953 }
954
958 void UpdateGSButtonState()
959 {
960 GameInstance *game = Game::GetInstance();
961 bool valid = game != nullptr;
962 bool dead = valid && game->IsDead();
963 bool paused = valid && game->IsPaused();
964
965 NWidgetCore *button = this->GetWidget<NWidgetCore>(WID_SCRD_SCRIPT_GAME);
966 button->SetDisabled(!valid);
967 button->SetLowered(this->filter.script_debug_company == OWNER_DEITY);
968 SetScriptButtonColour(*button, dead, paused);
969 }
970
976 void ChangeToScript(CompanyID show_script, bool new_window = false)
977 {
978 if (!this->IsValidDebugCompany(show_script)) return;
979
980 if (new_window) {
981 ScriptDebugWindow::initial_state = this->filter;
982 ShowScriptDebugWindow(show_script, true);
983 return;
984 }
985
986 this->filter.script_debug_company = show_script;
987
988 this->highlight_row = -1; // The highlight of one Script make little sense for another Script.
989
990 /* Close AI settings window to prevent confusion */
991 CloseWindowByClass(WC_SCRIPT_SETTINGS);
992
993 this->InvalidateData(-1);
994
995 this->autoscroll = true;
996 this->last_vscroll_pos = this->vscroll->GetPosition();
997 }
998
999 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1000 {
1001 /* Also called for hotkeys, so check for disabledness */
1002 if (this->IsWidgetDisabled(widget)) return;
1003
1004 /* Check which button is clicked */
1005 if (IsInsideMM(widget, WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END + 1)) {
1006 this->ChangeToScript(static_cast<CompanyID>(widget - WID_SCRD_COMPANY_BUTTON_START), _ctrl_pressed);
1007 }
1008
1009 switch (widget) {
1010 case WID_SCRD_SCRIPT_GAME:
1011 this->ChangeToScript(OWNER_DEITY, _ctrl_pressed);
1012 break;
1013
1014 case WID_SCRD_RELOAD_TOGGLE:
1015 if (this->filter.script_debug_company == OWNER_DEITY) break;
1016 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1017 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, this->filter.script_debug_company, CRR_MANUAL, INVALID_CLIENT_ID);
1018 Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, this->filter.script_debug_company, CRR_NONE, INVALID_CLIENT_ID);
1019 break;
1020
1021 case WID_SCRD_SETTINGS:
1022 ShowScriptSettingsWindow(this->filter.script_debug_company);
1023 break;
1024
1025 case WID_SCRD_BREAK_STR_ON_OFF_BTN:
1026 this->filter.break_check_enabled = !this->filter.break_check_enabled;
1027 this->InvalidateData(-1);
1028 break;
1029
1030 case WID_SCRD_MATCH_CASE_BTN:
1031 this->filter.case_sensitive_break_check = !this->filter.case_sensitive_break_check;
1032 this->InvalidateData(-1);
1033 break;
1034
1035 case WID_SCRD_CONTINUE_BTN:
1036 /* Unpause current AI / game script and mark the corresponding script button dirty. */
1037 if (!this->IsDead()) {
1038 if (this->filter.script_debug_company == OWNER_DEITY) {
1039 Game::Unpause();
1040 } else {
1041 AI::Unpause(this->filter.script_debug_company);
1042 }
1043 }
1044
1045 /* If the last AI/Game Script is unpaused, unpause the game too. */
1046 if (_pause_mode.Test(PauseMode::Normal)) {
1047 bool all_unpaused = !Game::IsPaused();
1048 if (all_unpaused) {
1049 for (const Company *c : Company::Iterate()) {
1050 if (c->is_ai && AI::IsPaused(c->index)) {
1051 all_unpaused = false;
1052 break;
1053 }
1054 }
1055 if (all_unpaused) {
1056 /* All scripts have been unpaused => unpause the game. */
1057 Command<CMD_PAUSE>::Post(PauseMode::Normal, false);
1058 }
1059 }
1060 }
1061
1062 this->highlight_row = -1;
1063 this->InvalidateData(-1);
1064 break;
1065 }
1066 }
1067
1068 void OnEditboxChanged(WidgetID wid) override
1069 {
1070 if (wid != WID_SCRD_BREAK_STR_EDIT_BOX) return;
1071
1072 /* Save the current string to static member so it can be restored next time the window is opened. */
1073 this->filter.break_string = this->break_editbox.text.GetText();
1074 this->break_string_filter.SetFilterTerm(this->filter.break_string);
1075 }
1076
1083 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1084 {
1085 if (this->show_break_box != _settings_client.gui.ai_developer_tools) this->ReInit();
1086
1087 /* If the log message is related to the active company tab, check the break string.
1088 * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1089 if (!gui_scope && data == this->filter.script_debug_company &&
1090 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1091 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1092 /* Get the log instance of the active company */
1093 ScriptLogTypes::LogData &log = this->GetLogData();
1094
1095 if (!log.empty()) {
1096 this->break_string_filter.ResetState();
1097 this->break_string_filter.AddLine(log.back().text);
1098 if (this->break_string_filter.GetState()) {
1099 /* Pause execution of script. */
1100 if (!this->IsDead()) {
1101 if (this->filter.script_debug_company == OWNER_DEITY) {
1102 Game::Pause();
1103 } else {
1104 AI::Pause(this->filter.script_debug_company);
1105 }
1106 }
1107
1108 /* Pause the game. */
1109 if (!_pause_mode.Test(PauseMode::Normal)) {
1110 Command<CMD_PAUSE>::Post(PauseMode::Normal, true);
1111 }
1112
1113 /* Highlight row that matched */
1114 this->highlight_row = static_cast<int>(log.size() - 1);
1115 }
1116 }
1117 }
1118
1119 if (!gui_scope) return;
1120
1121 this->SelectValidDebugCompany();
1122
1123 uint max_width = 0;
1124 if (this->filter.script_debug_company != CompanyID::Invalid()) {
1125 for (auto &line : this->GetLogData()) {
1126 if (line.width == 0 || data == -1) line.width = GetStringBoundingBox(line.text).width;
1127 max_width = std::max(max_width, line.width);
1128 }
1129 }
1130
1131 this->vscroll->SetCount(this->filter.script_debug_company != CompanyID::Invalid() ? this->GetLogData().size() : 0);
1132 this->hscroll->SetCount(max_width + WidgetDimensions::scaled.frametext.Horizontal());
1133
1134 this->UpdateAIButtonsState();
1135 this->UpdateGSButtonState();
1136
1137 this->SetWidgetLoweredState(WID_SCRD_BREAK_STR_ON_OFF_BTN, this->filter.break_check_enabled);
1138 this->SetWidgetLoweredState(WID_SCRD_MATCH_CASE_BTN, this->filter.case_sensitive_break_check);
1139
1140 this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == CompanyID::Invalid() ||
1141 GetConfig(this->filter.script_debug_company)->GetConfigList()->empty());
1142 extern CompanyID _local_company;
1143 this->SetWidgetDisabledState(WID_SCRD_RELOAD_TOGGLE,
1144 this->filter.script_debug_company == CompanyID::Invalid() ||
1145 this->filter.script_debug_company == OWNER_DEITY ||
1146 this->filter.script_debug_company == _local_company);
1147 this->SetWidgetDisabledState(WID_SCRD_CONTINUE_BTN, this->filter.script_debug_company == CompanyID::Invalid() ||
1148 (this->filter.script_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(this->filter.script_debug_company)));
1149 }
1150
1151 void OnResize() override
1152 {
1153 this->vscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Vertical());
1154 this->hscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Horizontal());
1155 }
1156
1162 static EventState ScriptDebugGlobalHotkeys(int hotkey)
1163 {
1164 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
1165 Window *w = ShowScriptDebugWindow(CompanyID::Invalid());
1166 if (w == nullptr) return ES_NOT_HANDLED;
1167 return w->OnHotkey(hotkey);
1168 }
1169
1170 static inline HotkeyList hotkeys{"aidebug", {
1171 Hotkey('1', "company_1", WID_SCRD_COMPANY_BUTTON_START),
1172 Hotkey('2', "company_2", WID_SCRD_COMPANY_BUTTON_START + 1),
1173 Hotkey('3', "company_3", WID_SCRD_COMPANY_BUTTON_START + 2),
1174 Hotkey('4', "company_4", WID_SCRD_COMPANY_BUTTON_START + 3),
1175 Hotkey('5', "company_5", WID_SCRD_COMPANY_BUTTON_START + 4),
1176 Hotkey('6', "company_6", WID_SCRD_COMPANY_BUTTON_START + 5),
1177 Hotkey('7', "company_7", WID_SCRD_COMPANY_BUTTON_START + 6),
1178 Hotkey('8', "company_8", WID_SCRD_COMPANY_BUTTON_START + 7),
1179 Hotkey('9', "company_9", WID_SCRD_COMPANY_BUTTON_START + 8),
1180 Hotkey(0, "company_10", WID_SCRD_COMPANY_BUTTON_START + 9),
1181 Hotkey(0, "company_11", WID_SCRD_COMPANY_BUTTON_START + 10),
1182 Hotkey(0, "company_12", WID_SCRD_COMPANY_BUTTON_START + 11),
1183 Hotkey(0, "company_13", WID_SCRD_COMPANY_BUTTON_START + 12),
1184 Hotkey(0, "company_14", WID_SCRD_COMPANY_BUTTON_START + 13),
1185 Hotkey(0, "company_15", WID_SCRD_COMPANY_BUTTON_START + 14),
1186 Hotkey('S', "settings", WID_SCRD_SETTINGS),
1187 Hotkey('0', "game_script", WID_SCRD_SCRIPT_GAME),
1188 Hotkey(0, "reload", WID_SCRD_RELOAD_TOGGLE),
1189 Hotkey('B', "break_toggle", WID_SCRD_BREAK_STR_ON_OFF_BTN),
1190 Hotkey('F', "break_string", WID_SCRD_BREAK_STR_EDIT_BOX),
1191 Hotkey('C', "match_case", WID_SCRD_MATCH_CASE_BTN),
1192 Hotkey(WKC_RETURN, "continue", WID_SCRD_CONTINUE_BTN),
1193 }, ScriptDebugGlobalHotkeys};
1194};
1195
1197std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsScriptDebug()
1198{
1199 return MakeCompanyButtonRows(WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END, COLOUR_GREY, 5, STR_AI_DEBUG_SELECT_AI_TOOLTIP, false);
1200}
1201
1203 static constexpr std::initializer_list<NWidgetPart> _nested_script_debug_widgets = {
1204 NWidget(NWID_HORIZONTAL),
1205 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1206 NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1207 NWidget(WWT_SHADEBOX, COLOUR_GREY),
1208 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
1209 NWidget(WWT_STICKYBOX, COLOUR_GREY),
1210 EndContainer(),
1211 NWidget(NWID_HORIZONTAL),
1212 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_VIEW),
1213 NWidgetFunction(MakeCompanyButtonRowsScriptDebug), SetPadding(0, 2, 1, 2),
1214 EndContainer(),
1215 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_SCRIPT_GAME), SetMinimalSize(100, 20), SetStringTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
1216 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_NAME_TEXT), SetResize(1, 0), SetToolTip(STR_AI_DEBUG_NAME_TOOLTIP),
1217 NWidget(NWID_VERTICAL),
1218 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_SETTINGS), SetMinimalSize(100, 20), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1219 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1220 EndContainer(),
1221 EndContainer(),
1222 NWidget(NWID_HORIZONTAL),
1223 NWidget(NWID_VERTICAL),
1224 /* Log panel */
1225 NWidget(WWT_PANEL, COLOUR_GREY, WID_SCRD_LOG_PANEL), SetMinimalSize(287, 180), SetResize(1, 1), SetScrollbar(WID_SCRD_VSCROLLBAR),
1226 EndContainer(),
1227 /* Break string widgets */
1228 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SCRD_BREAK_STRING_WIDGETS),
1229 NWidget(NWID_HORIZONTAL),
1230 NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_SCRD_BREAK_STR_ON_OFF_BTN), SetAspect(WidgetDimensions::ASPECT_VEHICLE_FLAG), SetFill(0, 1), SetSpriteTip(SPR_FLAG_VEH_STOPPED, STR_AI_DEBUG_BREAK_STR_ON_OFF_TOOLTIP),
1231 NWidget(WWT_PANEL, COLOUR_GREY),
1232 NWidget(NWID_HORIZONTAL),
1233 NWidget(WWT_LABEL, INVALID_COLOUR), SetPadding(2, 2, 2, 4), SetStringTip(STR_AI_DEBUG_BREAK_ON_LABEL),
1234 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SCRD_BREAK_STR_EDIT_BOX), SetFill(1, 1), SetResize(1, 0), SetPadding(2, 2, 2, 2), SetStringTip(STR_AI_DEBUG_BREAK_STR_OSKTITLE, STR_AI_DEBUG_BREAK_STR_TOOLTIP),
1235 EndContainer(),
1236 EndContainer(),
1237 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SCRD_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
1238 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SCRD_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
1239 EndContainer(),
1240 EndContainer(),
1241 NWidget(NWID_HSCROLLBAR, COLOUR_GREY, WID_SCRD_HSCROLLBAR),
1242 EndContainer(),
1243 NWidget(NWID_VERTICAL),
1244 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SCRD_VSCROLLBAR),
1245 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
1246 EndContainer(),
1247 EndContainer(),
1248};
1249
1251 static WindowDesc _script_debug_desc(
1252 WDP_AUTO, "script_debug", 600, 450,
1253 WC_SCRIPT_DEBUG, WC_NONE,
1254 {},
1255 _nested_script_debug_widgets,
1256 &ScriptDebugWindow::hotkeys
1257);
1258
1264 Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window)
1265{
1266 if (!_networking || _network_server) {
1267 int i = 0;
1268 if (new_window) {
1269 /* find next free window number for script debug */
1270 while (FindWindowById(WC_SCRIPT_DEBUG, i) != nullptr) i++;
1271 } else {
1272 /* Find existing window showing show_company. */
1273 for (Window *w : Window::Iterate()) {
1274 if (w->window_class == WC_SCRIPT_DEBUG && static_cast<ScriptDebugWindow *>(w)->filter.script_debug_company == show_company) {
1275 return BringWindowToFrontById(w->window_class, w->window_number);
1276 }
1277 }
1278
1279 /* Maybe there's a window showing a different company which can be switched. */
1280 ScriptDebugWindow *w = static_cast<ScriptDebugWindow *>(FindWindowByClass(WC_SCRIPT_DEBUG));
1281 if (w != nullptr) {
1282 BringWindowToFrontById(w->window_class, w->window_number);
1283 w->ChangeToScript(show_company);
1284 return w;
1285 }
1286 }
1287 return new ScriptDebugWindow(_script_debug_desc, i, show_company);
1288 } else {
1289 ShowErrorMessage(GetEncodedString(STR_ERROR_AI_DEBUG_SERVER_ONLY), {}, WL_INFO);
1290 }
1291
1292 return nullptr;
1293}
1294
1298 void InitializeScriptGui()
1299{
1300 ScriptDebugWindow::initial_state.script_debug_company = CompanyID::Invalid();
1301}
1302
1304 void ShowScriptDebugWindowIfScriptError()
1305{
1306 /* Network clients can't debug AIs. */
1307 if (_networking && !_network_server) return;
1308
1309 for (const Company *c : Company::Iterate()) {
1310 if (c->is_ai && c->ai_instance->IsDead()) {
1311 ShowScriptDebugWindow(c->index);
1312 break;
1313 }
1314 }
1315
1316 GameInstance *g = Game::GetInstance();
1317 if (g != nullptr && g->IsDead()) {
1318 ShowScriptDebugWindow(OWNER_DEITY);
1319 }
1320}
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition ai_config.cpp:20
AIInfo
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
AI::Pause
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition ai_core.cpp:124
AI::StartNew
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
AI::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for AIScanner::GetUniqueAIInfoList.
Definition ai_core.cpp:303
AI::IsPaused
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition ai_core.cpp:145
AI::Unpause
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition ai_core.cpp:137
AI::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for AIScanner::GetAIInfoList.
Definition ai_core.cpp:298
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition game_config.cpp:18
GameInfo
All static information from an Game like name, version, etc.
Definition game_info.hpp:16
GameInstance
Runtime information about a game script like a pointer to the squirrel vm and the current state.
Definition game_instance.hpp:16
Game::StartNew
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:72
Game::GetInfo
static class GameInfo * GetInfo()
Get the current GameInfo.
Definition game.hpp:70
Game::Unpause
static void Unpause()
Resume execution of the Game Script.
Definition game_core.cpp:126
Game::IsPaused
static bool IsPaused()
Checks if the Game Script is paused.
Definition game_core.cpp:131
Game::ResetInstance
static void ResetInstance()
Reset the current active instance.
Definition game_core.cpp:233
Game::GetUniqueInfoList
static const ScriptInfoList * GetUniqueInfoList()
Wrapper function for GameScanner::GetUniqueInfoList.
Definition game_core.cpp:218
Game::Pause
static void Pause()
Suspends the Game Script and then pause the execution of the script.
Definition game_core.cpp:121
Game::GetInstance
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:96
Game::GetInfoList
static const ScriptInfoList * GetInfoList()
Wrapper function for GameScanner::GetInfoList.
Definition game_core.cpp:213
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:368
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition widget_type.h:400
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition widget_type.h:440
NWidgetCore::SetDisabled
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Definition widget_type.h:455
ScriptConfig
Script settings.
Definition script_config.hpp:53
ScriptConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type, CompanyID slot) const
Search a textfile file next to this script.
Definition script_config.cpp:178
ScriptConfig::SetSetting
void SetSetting(std::string_view name, int value)
Set the value of a setting for this config.
Definition script_config.cpp:90
ScriptConfig::Change
void Change(std::optional< std::string_view > name, int version=-1, bool force_exact_match=false)
Set another Script to be loaded in this slot.
Definition script_config.cpp:22
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition script_config.cpp:55
ScriptConfig::GetConfigList
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
Definition script_config.cpp:60
ScriptConfig::GetSetting
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
Definition script_config.cpp:83
ScriptConfig::ResetEditableSettings
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
Definition script_config.cpp:108
ScriptInfo
All static information from an Script like name, version, etc.
Definition script_info.hpp:30
ScriptInfo::GetName
const std::string & GetName() const
Get the Name of the script.
Definition script_info.hpp:40
ScriptInfo::GetAuthor
const std::string & GetAuthor() const
Get the Author of the script.
Definition script_info.hpp:35
ScriptInfo::GetURL
const std::string & GetURL() const
Get the website for this script.
Definition script_info.hpp:70
ScriptInfo::GetVersion
int GetVersion() const
Get the version of the script.
Definition script_info.hpp:55
ScriptInfo::GetDescription
const std::string & GetDescription() const
Get the description of the script.
Definition script_info.hpp:50
ScriptInstance::IsPaused
bool IsPaused()
Checks if the script is paused.
Definition script_instance.cpp:595
ScriptInstance::GetLogData
ScriptLogTypes::LogData & GetLogData()
Get the log pointer of this script.
Definition script_instance.cpp:335
ScriptInstance::IsDead
bool IsDead() const
Return the "this script died" value.
Definition script_instance.hpp:158
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::IsVisible
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
Definition widget_type.h:762
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition widget_type.h:743
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:891
Scrollbar::GetScrolledRowFromWidget
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2425
Scrollbar::SetPosition
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition widget_type.h:822
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2499
Scrollbar::GetCount
size_type GetCount() const
Gets the number of elements in the list.
Definition widget_type.h:734
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
Scrollbar::SetStepSize
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition widget_type.h:780
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:752
TimeoutTimer
A timeout timer will fire once after the interval.
Definition timer.h:116
TimeoutTimer::Reset
void Reset()
Reset the timer, so it will fire again after the timeout.
Definition timer.h:140
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition company_cmd.cpp:175
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
OWNER_DEITY
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:28
CCA_NEW_AI
@ CCA_NEW_AI
Create a new AI company.
Definition company_type.h:73
CCA_DELETE
@ CCA_DELETE
Delete a company.
Definition company_type.h:74
CRR_NONE
@ CRR_NONE
Dummy reason for actions that don't need one.
Definition company_type.h:67
CRR_MANUAL
@ CRR_MANUAL
The company is manually removed.
Definition company_type.h:61
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options)
Show a drop down list.
Definition dropdown.cpp:402
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:24
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
AI_DIR
@ AI_DIR
Subdirectory for all AI files.
Definition fileio_type.h:99
GAME_DIR
@ GAME_DIR
Subdirectory for all game scripts.
Definition fileio_type.h:101
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:965
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:665
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
_pause_mode
PauseModes _pause_mode
The current pause mode.
Definition gfx.cpp:50
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition gfx.cpp:1565
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_LEFT
@ SA_LEFT
Left align the text.
Definition gfx_type.h:388
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1308
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1445
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1410
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1156
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1187
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition math_func.hpp:252
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
ShowQueryString
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition misc_gui.cpp:1062
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition misc_widget.h:53
_networking
bool _networking
are we in networking mode?
Definition network.cpp:66
_network_server
bool _network_server
network-server is active
Definition network.cpp:67
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition network_type.h:44
PauseMode::Normal
@ Normal
A game normally paused.
PC_BLACK
static constexpr PixelColour PC_BLACK
Black palette colour.
Definition palette_func.h:96
script_config.hpp
ScriptConfig stores the configuration settings of every Script.
INT32_DIGITS_WITH_SIGN_AND_TERMINATION
static const int INT32_DIGITS_WITH_SIGN_AND_TERMINATION
Maximum of 10 digits for MIN / MAX_INT32, 1 for the sign and 1 for '\0'.
Definition script_config.hpp:18
ScriptConfigFlag::Boolean
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
ScriptConfigFlag::Developer
@ Developer
This setting will only be visible when the Script development tools are active.
ScriptConfigFlag::InGame
@ InGame
This setting can be changed while the Script is running.
_nested_script_list_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_script_list_widgets
Widgets for the AI list window.
Definition script_gui.cpp:247
ShowScriptDebugWindowIfScriptError
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
Definition script_gui.cpp:1304
ShowScriptDebugWindow
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
Definition script_gui.cpp:1264
_script_debug_desc
static WindowDesc _script_debug_desc(WDP_AUTO, "script_debug", 600, 450, WC_SCRIPT_DEBUG, WC_NONE, {}, _nested_script_debug_widgets, &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
MakeCompanyButtonRowsScriptDebug
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
Definition script_gui.cpp:1197
SetScriptButtonColour
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
Definition script_gui.cpp:646
_nested_script_debug_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_script_debug_widgets
Widgets for the Script debug window.
Definition script_gui.cpp:1203
_script_list_desc
static WindowDesc _script_list_desc(WDP_CENTER, "settings_script_list", 200, 234, WC_SCRIPT_LIST, WC_NONE, {}, _nested_script_list_widgets)
Window definition for the ai list window.
ShowScriptSettingsWindow
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
Definition script_gui.cpp:588
_script_settings_desc
static WindowDesc _script_settings_desc(WDP_CENTER, "settings_script", 500, 208, WC_SCRIPT_SETTINGS, WC_NONE, {}, _nested_script_settings_widgets)
Window definition for the Script settings window.
ShowScriptTextfileWindow
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
Definition script_gui.cpp:631
_nested_script_settings_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_script_settings_widgets
Widgets for the Script settings window.
Definition script_gui.cpp:558
ShowScriptListWindow
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
Definition script_gui.cpp:278
InitializeScriptGui
void InitializeScriptGui()
Reset the Script windows to their initial state.
Definition script_gui.cpp:1298
script_scanner.hpp
Declarations of the class for the script scanner.
ScriptInfoList
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Definition script_scanner.hpp:16
WID_SCRD_NAME_TEXT
@ WID_SCRD_NAME_TEXT
Name of the current selected.
Definition script_widget.h:37
WID_SCRD_BREAK_STRING_WIDGETS
@ WID_SCRD_BREAK_STRING_WIDGETS
The panel to handle the breaking on string.
Definition script_widget.h:45
WID_SCRD_SCRIPT_GAME
@ WID_SCRD_SCRIPT_GAME
Game Script button.
Definition script_widget.h:39
WID_SCRD_RELOAD_TOGGLE
@ WID_SCRD_RELOAD_TOGGLE
Reload button.
Definition script_widget.h:40
WID_SCRD_HSCROLLBAR
@ WID_SCRD_HSCROLLBAR
Horizontal scrollbar of the log panel.
Definition script_widget.h:50
WID_SCRD_SETTINGS
@ WID_SCRD_SETTINGS
Settings button.
Definition script_widget.h:38
WID_SCRD_BREAK_STR_EDIT_BOX
@ WID_SCRD_BREAK_STR_EDIT_BOX
Edit box for the string to break on.
Definition script_widget.h:47
WID_SCRD_COMPANY_BUTTON_START
@ WID_SCRD_COMPANY_BUTTON_START
Buttons in the VIEW.
Definition script_widget.h:43
WID_SCRD_VIEW
@ WID_SCRD_VIEW
The row of company buttons.
Definition script_widget.h:36
WID_SCRD_MATCH_CASE_BTN
@ WID_SCRD_MATCH_CASE_BTN
Checkbox to use match caching or not.
Definition script_widget.h:48
WID_SCRD_BREAK_STR_ON_OFF_BTN
@ WID_SCRD_BREAK_STR_ON_OFF_BTN
Enable breaking on string.
Definition script_widget.h:46
WID_SCRD_VSCROLLBAR
@ WID_SCRD_VSCROLLBAR
Vertical scrollbar of the log panel.
Definition script_widget.h:42
WID_SCRD_LOG_PANEL
@ WID_SCRD_LOG_PANEL
Panel where the log is in.
Definition script_widget.h:41
WID_SCRD_CONTINUE_BTN
@ WID_SCRD_CONTINUE_BTN
Continue button.
Definition script_widget.h:49
WID_SCRD_COMPANY_BUTTON_END
@ WID_SCRD_COMPANY_BUTTON_END
Last possible button in the VIEW.
Definition script_widget.h:44
WID_SCRL_ACCEPT
@ WID_SCRL_ACCEPT
Accept button.
Definition script_widget.h:21
WID_SCRL_INFO_BG
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
Definition script_widget.h:20
WID_SCRL_CAPTION
@ WID_SCRL_CAPTION
Caption of the window.
Definition script_widget.h:17
WID_SCRL_LIST
@ WID_SCRL_LIST
The matrix with all available Scripts.
Definition script_widget.h:18
WID_SCRL_SCROLLBAR
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
Definition script_widget.h:19
WID_SCRS_SETTING_DROPDOWN
@ WID_SCRS_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
Definition script_widget.h:31
WID_SCRS_BACKGROUND
@ WID_SCRS_BACKGROUND
Panel to draw the settings on.
Definition script_widget.h:27
WID_SCRS_SCROLLBAR
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
Definition script_widget.h:28
WID_SCRS_RESET
@ WID_SCRS_RESET
Reset button.
Definition script_widget.h:29
WID_SCRS_CAPTION
@ WID_SCRS_CAPTION
Caption of the window.
Definition script_widget.h:26
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition settings_gui.cpp:1866
DrawBoolButton
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
Definition settings_gui.cpp:1947
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition settings_gui.cpp:1924
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition settings_gui.h:17
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition settings_gui.h:19
CS_NUMERAL_SIGNED
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition backup_type.hpp:150
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:83
Company
Definition company_base.h:127
Company::IsValidAiID
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Definition company_base.h:153
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
DrawPixelInfo
Data about how and where to blit pixels.
Definition gfx_type.h:157
GUISettings::ai_developer_tools
bool ai_developer_tools
activate AI/GS developer tools
Definition settings_type.h:252
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Definition pool_type.hpp:398
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Width
int Width() const
Get width of Rect.
Definition geometry_type.hpp:111
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:213
ScriptConfigItem
Info about a single Script setting.
Definition script_config.hpp:33
ScriptConfigItem::flags
ScriptConfigFlags flags
Flags for the configuration setting.
Definition script_config.hpp:40
ScriptConfigItem::GetString
std::string GetString(int value) const
Get string to display this setting in the configuration interface.
Definition script_config.cpp:210
ScriptConfigItem::labels
LabelMapping labels
Text labels for the integer values.
Definition script_config.hpp:41
ScriptConfigItem::name
std::string name
The name of the configuration setting.
Definition script_config.hpp:34
ScriptConfigItem::min_value
int min_value
The minimal value this configuration setting can have.
Definition script_config.hpp:36
ScriptConfigItem::max_value
int max_value
The maximal value this configuration setting can have.
Definition script_config.hpp:37
ScriptConfigItem::step_size
int step_size
The step size in the gui.
Definition script_config.hpp:39
ScriptConfigItem::complete_labels
bool complete_labels
True if all values have a label.
Definition script_config.hpp:42
ScriptConfigItem::GetColour
TextColour GetColour() const
Get text colour to display this setting in the configuration interface.
Definition script_config.cpp:222
ScriptDebugWindow::FilterState
Definition script_gui.cpp:665
ScriptDebugWindow::FilterState::break_check_enabled
bool break_check_enabled
Stop an AI when it prints a matching string.
Definition script_gui.cpp:668
ScriptDebugWindow::FilterState::case_sensitive_break_check
bool case_sensitive_break_check
Is the matching done case-sensitive.
Definition script_gui.cpp:669
ScriptDebugWindow::FilterState::break_string
std::string break_string
The string to match to the AI output.
Definition script_gui.cpp:666
ScriptDebugWindow::FilterState::script_debug_company
CompanyID script_debug_company
The AI that is (was last) being debugged.
Definition script_gui.cpp:667
ScriptDebugWindow
Window with everything an AI prints via ScriptLog.
Definition script_gui.cpp:662
ScriptDebugWindow::UpdateAIButtonsState
void UpdateAIButtonsState()
Update state of all Company (AI) buttons.
Definition script_gui.cpp:939
ScriptDebugWindow::DrawWidgetLog
void DrawWidgetLog(const Rect &r) const
Draw the AI/GS log.
Definition script_gui.cpp:856
ScriptDebugWindow::UpdateGSButtonState
void UpdateGSButtonState()
Update state of game script button.
Definition script_gui.cpp:958
ScriptDebugWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition script_gui.cpp:823
ScriptDebugWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition script_gui.cpp:1083
ScriptDebugWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition script_gui.cpp:774
ScriptDebugWindow::ScriptDebugGlobalHotkeys
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
Definition script_gui.cpp:1162
ScriptDebugWindow::SelectValidDebugCompany
void SelectValidDebugCompany()
Ensure that script_debug_company refers to a valid AI company or GS, or is set to CompanyID::Invalid(...
Definition script_gui.cpp:726
ScriptDebugWindow::OnEditboxChanged
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
Definition script_gui.cpp:1068
ScriptDebugWindow::last_vscroll_pos
int last_vscroll_pos
Last position of the scrolling.
Definition script_gui.cpp:679
ScriptDebugWindow::DrawWidgetCompanyButton
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
Draw a company button icon.
Definition script_gui.cpp:844
ScriptDebugWindow::MAX_BREAK_STR_STRING_LENGTH
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
Definition script_gui.cpp:663
ScriptDebugWindow::break_editbox
QueryString break_editbox
Break editbox.
Definition script_gui.cpp:682
ScriptDebugWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition script_gui.cpp:797
ScriptDebugWindow::hscroll
Scrollbar * hscroll
Cache of the horizontal scrollbar.
Definition script_gui.cpp:686
ScriptDebugWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition script_gui.cpp:789
ScriptDebugWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition script_gui.cpp:1151
ScriptDebugWindow::highlight_row
int highlight_row
The output row that matches the given string, or -1.
Definition script_gui.cpp:684
ScriptDebugWindow::ScriptDebugWindow
ScriptDebugWindow(WindowDesc &desc, WindowNumber number, Owner show_company)
Constructor for the window.
Definition script_gui.cpp:749
ScriptDebugWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition script_gui.cpp:806
ScriptDebugWindow::UpdateLogScroll
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
Definition script_gui.cpp:905
ScriptDebugWindow::break_string_filter
StringFilter break_string_filter
Log filter for break.
Definition script_gui.cpp:683
ScriptDebugWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition script_gui.cpp:999
ScriptDebugWindow::autoscroll
bool autoscroll
Whether automatically scrolling should be enabled or not.
Definition script_gui.cpp:680
ScriptDebugWindow::IsDead
bool IsDead() const
Check whether the currently selected AI/GS is dead.
Definition script_gui.cpp:699
ScriptDebugWindow::IsValidDebugCompany
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
Definition script_gui.cpp:713
ScriptDebugWindow::ChangeToScript
void ChangeToScript(CompanyID show_script, bool new_window=false)
Change all settings to select another Script.
Definition script_gui.cpp:976
ScriptDebugWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition script_gui.cpp:685
ScriptDebugWindow::show_break_box
bool show_break_box
Whether the break/debug box is visible.
Definition script_gui.cpp:681
ScriptListWindow
Window that let you choose an available Script.
Definition script_gui.cpp:57
ScriptListWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition script_gui.cpp:61
ScriptListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition script_gui.cpp:230
ScriptListWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition script_gui.cpp:119
ScriptListWindow::show_all
bool show_all
Whether to show all available versions.
Definition script_gui.cpp:63
ScriptListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition script_gui.cpp:220
ScriptListWindow::slot
CompanyID slot
The company we're selecting a new Script for.
Definition script_gui.cpp:60
ScriptListWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition script_gui.cpp:108
ScriptListWindow::selected
int selected
The currently selected Script.
Definition script_gui.cpp:59
ScriptListWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition script_gui.cpp:62
ScriptListWindow::ScriptListWindow
ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all)
Constructor for the window.
Definition script_gui.cpp:71
ScriptListWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition script_gui.cpp:101
ScriptListWindow::ChangeScript
void ChangeScript()
Changes the Script of the current slot.
Definition script_gui.cpp:168
ScriptListWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition script_gui.cpp:196
ScriptListWindow::info_list
const ScriptInfoList * info_list
The list of Scripts.
Definition script_gui.cpp:58
ScriptSettingsWindow
Window for settings the parameters of an AI.
Definition script_gui.cpp:288
ScriptSettingsWindow::clicked_row
int clicked_row
The clicked row of settings.
Definition script_gui.cpp:295
ScriptSettingsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition script_gui.cpp:387
ScriptSettingsWindow::VisibleSettingsList
std::vector< const ScriptConfigItem * > VisibleSettingsList
typdef for a vector of script settings
Definition script_gui.cpp:298
ScriptSettingsWindow::clicked_button
int clicked_button
The button we clicked.
Definition script_gui.cpp:291
ScriptSettingsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition script_gui.cpp:513
ScriptSettingsWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition script_gui.cpp:494
ScriptSettingsWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition script_gui.cpp:352
ScriptSettingsWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition script_gui.cpp:334
ScriptSettingsWindow::RebuildVisibleSettings
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
Definition script_gui.cpp:320
ScriptSettingsWindow::slot
CompanyID slot
The currently show company's setting.
Definition script_gui.cpp:289
ScriptSettingsWindow::line_height
int line_height
Height of a row in the matrix widget.
Definition script_gui.cpp:296
ScriptSettingsWindow::ScriptSettingsWindow
ScriptSettingsWindow(WindowDesc &desc, CompanyID slot)
Constructor for the window.
Definition script_gui.cpp:306
ScriptSettingsWindow::clicked_dropdown
bool clicked_dropdown
Whether the dropdown is open.
Definition script_gui.cpp:293
ScriptSettingsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition script_gui.cpp:529
ScriptSettingsWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition script_gui.cpp:396
ScriptSettingsWindow::unclick_timeout
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
Definition script_gui.cpp:519
ScriptSettingsWindow::clicked_increase
bool clicked_increase
Whether we clicked the increase or decrease button.
Definition script_gui.cpp:292
ScriptSettingsWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition script_gui.cpp:341
ScriptSettingsWindow::script_config
ScriptConfig * script_config
The configuration we're modifying.
Definition script_gui.cpp:290
ScriptSettingsWindow::visible_settings
VisibleSettingsList visible_settings
List of visible AI settings.
Definition script_gui.cpp:299
ScriptSettingsWindow::OnDropdownClose
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
Definition script_gui.cpp:501
ScriptSettingsWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition script_gui.cpp:294
ScriptSettingsWindow::vscroll
Scrollbar * vscroll
Cache of the vertical scrollbar.
Definition script_gui.cpp:297
ScriptSettingsWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition script_gui.cpp:486
ScriptTextfileWindow
Window for displaying the textfile of a AI.
Definition script_gui.cpp:597
ScriptTextfileWindow::slot
CompanyID slot
View the textfile of this CompanyID slot.
Definition script_gui.cpp:598
ScriptTextfileWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition script_gui.cpp:615
ScriptTextfileWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition script_gui.cpp:606
StringFilter
String filter and state.
Definition stringfilter_type.h:30
StringFilter::SetFilterTerm
void SetFilterTerm(std::string_view str)
Set the term to filter on.
Definition stringfilter.cpp:29
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition stringfilter.cpp:80
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition stringfilter_type.h:67
Textbuf::GetText
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
Textbuf::Assign
void Assign(std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:420
TextfileWindow
Window for displaying a textfile.
Definition textfile_gui.h:22
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition textfile_gui.h:23
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition textfile_gui.cpp:851
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:978
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1102
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3234
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
Window::CloseChildWindows
void CloseChildWindows(WindowClass wc=WC_INVALID) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1075
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::window_class
WindowClass window_class
Window class.
Definition window_gui.h:302
Window::CloseChildWindowById
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1090
Window::IsWidgetDisabled
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:570
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::Iterate
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
Definition window_gui.h:933
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition textfile_type.h:14
ScrollRect
Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step)
Apply 'scroll' to a rect to be drawn in.
Definition widget.cpp:2516
MakeCompanyButtonRows
std::unique_ptr< NWidgetBase > MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition widget.cpp:3435
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:42
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition widget_type.h:75
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:505
FindWindowByClass
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1166
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1205
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3294
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1276
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1151
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3311
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WN_GAME_OPTIONS_GS
@ WN_GAME_OPTIONS_GS
GS settings.
Definition window_type.h:28
WN_GAME_OPTIONS_AI
@ WN_GAME_OPTIONS_AI
AI settings.
Definition window_type.h:27
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
WC_SCRIPT_SETTINGS
@ WC_SCRIPT_SETTINGS
Script settings; Window numbers:
Definition window_type.h:180
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_SCRIPT_LIST
@ WC_SCRIPT_LIST
Scripts list; Window numbers:
Definition window_type.h:289
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition window_type.h:635
WC_SCRIPT_DEBUG
@ WC_SCRIPT_DEBUG
Script debug window; Window numbers:
Definition window_type.h:685
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition window_type.h:192
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition window_type.h:161
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition window_type.h:128