OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "../stdafx.h"
11#include "../table/sprites.h"
12#include "../error.h"
13#include "../settings_gui.h"
14#include "../querystring_gui.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 "../textbuf_gui.h"
27#include "../textfile_gui.h"
28#include "../timer/timer.h"
31
32#include "script_gui.h"
33#include "script_scanner.hpp"
34#include "script_config.hpp"
35#include "../ai/ai.hpp"
36#include "../ai/ai_config.hpp"
37#include "../ai/ai_info.hpp"
38#include "../ai/ai_instance.hpp"
39#include "../game/game.hpp"
41#include "../game/game_info.hpp"
43
46
47#include "table/strings.h"
48
49#include "../safeguards.h"
50
51
52static ScriptConfig *GetConfig(CompanyID slot)
53{
54 if (slot == OWNER_DEITY) return GameConfig::GetConfig();
55 return AIConfig::GetConfig(slot);
56}
57
61struct ScriptListWindow : public Window {
62 const ScriptInfoList *info_list = nullptr;
63 int selected = -1;
64 CompanyID slot{};
65 int line_height = 0;
66 Scrollbar *vscroll = nullptr;
67 bool show_all = false;
68
75 ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all) : Window(desc),
77 {
78 if (this->slot == OWNER_DEITY) {
79 this->info_list = this->show_all ? Game::GetInfoList() : Game::GetUniqueInfoList();
80 } else {
81 this->info_list = this->show_all ? AI::GetInfoList() : AI::GetUniqueInfoList();
82 }
83
84 this->CreateNestedTree();
85 this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR);
86 this->FinishInitNested(); // Initializes 'this->line_height' as side effect.
87
88 this->vscroll->SetCount(this->info_list->size() + 1);
89
90 /* Try if we can find the currently selected AI */
91 if (GetConfig(this->slot)->HasScript()) {
92 ScriptInfo *info = GetConfig(this->slot)->GetInfo();
93 int i = 0;
94 for (const auto &item : *this->info_list) {
95 if (item.second == info) {
96 this->selected = i;
97 break;
98 }
99
100 i++;
101 }
102 }
103 }
104
105 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
106 {
107 if (widget != WID_SCRL_CAPTION) return this->Window::GetWidgetString(widget, stringid);
108
109 return GetString(STR_AI_LIST_CAPTION, (this->slot == OWNER_DEITY) ? STR_AI_LIST_CAPTION_GAMESCRIPT : STR_AI_LIST_CAPTION_AI);
110 }
111
112 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
113 {
114 if (widget != WID_SCRL_LIST) return;
115
116 this->line_height = GetCharacterHeight(FontSize::Normal) + padding.height;
117
118 resize.width = 1;
119 fill.height = resize.height = this->line_height;
120 size.height = 5 * this->line_height;
121 }
122
123 void DrawWidget(const Rect &r, WidgetID widget) const override
124 {
125 switch (widget) {
126 case WID_SCRL_LIST: {
127 /* Draw a list of all available Scripts. */
128 Rect tr = r.Shrink(WidgetDimensions::scaled.matrix);
129 /* First AI in the list is hardcoded to random */
130 if (this->vscroll->IsVisible(0)) {
131 DrawString(tr, this->slot == OWNER_DEITY ? STR_AI_CONFIG_NONE : STR_AI_CONFIG_RANDOM_AI, this->selected == -1 ? TextColour::White : TextColour::Orange);
132 tr.top += this->line_height;
133 }
134 int i = 0;
135 for (const auto &item : *this->info_list) {
136 i++;
137 if (this->vscroll->IsVisible(i)) {
138 DrawString(tr, this->show_all ? GetString(STR_AI_CONFIG_NAME_VERSION, item.second->GetName(), item.second->GetVersion()) : item.second->GetName(), (this->selected == i - 1) ? TextColour::White : TextColour::Orange);
139 tr.top += this->line_height;
140 }
141 }
142 break;
143 }
144 case WID_SCRL_INFO_BG: {
145 ScriptInfo *selected_info = nullptr;
146 int i = 0;
147 for (const auto &item : *this->info_list) {
148 i++;
149 if (this->selected == i - 1) selected_info = static_cast<ScriptInfo *>(item.second);
150 }
151 /* Some info about the currently selected Script. */
152 if (selected_info != nullptr) {
154 DrawString(tr, GetString(STR_AI_LIST_AUTHOR, selected_info->GetAuthor()));
156 DrawString(tr, GetString(STR_AI_LIST_VERSION, selected_info->GetVersion()));
158 if (!selected_info->GetURL().empty()) {
159 DrawString(tr, GetString(STR_AI_LIST_URL, selected_info->GetURL()));
161 }
163 }
164 break;
165 }
166 }
167 }
168
173 {
174 if (this->selected == -1) {
175 GetConfig(this->slot)->Change(std::nullopt);
176 } else {
177 ScriptInfoList::const_iterator it = this->info_list->cbegin();
178 std::advance(it, this->selected);
179 GetConfig(this->slot)->Change(it->second->GetName(), it->second->GetVersion());
180 }
181 if (_game_mode == GameMode::Editor) {
182 if (this->slot == OWNER_DEITY) {
183 if (Game::GetInstance() != nullptr) Game::ResetInstance();
185 } else {
186 Company *c = Company::GetIfValid(this->slot);
187 if (c != nullptr && c->ai_instance != nullptr) {
188 c->ai_instance.reset();
189 AI::StartNew(this->slot);
190 }
191 }
192 }
194 InvalidateWindowClassesData(WindowClass::ScriptSettings);
195 InvalidateWindowClassesData(WindowClass::ScriptDebug, -1);
196 CloseWindowByClass(WindowClass::QueryString);
197 InvalidateWindowClassesData(WindowClass::Textfile);
198 }
199
200 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
201 {
202 switch (widget) {
203 case WID_SCRL_LIST: { // Select one of the Scripts
204 int sel = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCRL_LIST) - 1;
205 if (sel < static_cast<int>(this->info_list->size())) {
206 this->selected = sel;
207 this->SetDirty();
208 if (click_count > 1) {
209 this->ChangeScript();
210 this->Close();
211 }
212 }
213 break;
214 }
215
216 case WID_SCRL_ACCEPT: {
217 this->ChangeScript();
218 this->Close();
219 break;
220 }
221 }
222 }
223
224 void OnResize() override
225 {
226 this->vscroll->SetCapacityFromWidget(this, WID_SCRL_LIST);
227 }
228
234 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
235 {
236 if (_game_mode == GameMode::Normal && Company::IsValidID(this->slot)) {
237 this->Close();
238 return;
239 }
240
241 if (!gui_scope) return;
242
243 this->vscroll->SetCount(this->info_list->size() + 1);
244
245 /* selected goes from -1 .. length of ai list - 1. */
246 this->selected = std::min(this->selected, this->vscroll->GetCount() - 2);
247 }
248};
249
268
271 WindowPosition::Center, "settings_script_list", 200, 234,
272 WindowClass::ScriptList, WindowClass::None,
273 {},
275);
276
282void ShowScriptListWindow(CompanyID slot, bool show_all)
283{
284 CloseWindowByClass(WindowClass::ScriptList);
285 new ScriptListWindow(_script_list_desc, slot, show_all);
286}
287
288
293 CompanyID slot{};
295 int clicked_button = -1;
296 bool clicked_increase = false;
297 bool clicked_dropdown = false;
298 bool closing_dropdown = false;
299 int clicked_row = 0;
300 int line_height = 0;
301 Scrollbar *vscroll = nullptr;
302 typedef std::vector<const ScriptConfigItem *> VisibleSettingsList;
304
311 {
312 this->CreateNestedTree();
313 this->vscroll = this->GetScrollbar(WID_SCRS_SCROLLBAR);
314 this->FinishInitNested(this->slot); // Initializes 'this->line_height' as side effect.
315
316 this->OnInvalidateData();
317 }
318
325 {
326 this->visible_settings.clear();
327
328 for (const auto &item : *this->script_config->GetConfigList()) {
329 bool no_hide = !item.flags.Test(ScriptConfigFlag::Developer);
330 if (no_hide || _settings_client.gui.ai_developer_tools) {
331 this->visible_settings.push_back(&item);
332 }
333 }
334
335 this->vscroll->SetCount(this->visible_settings.size());
336 }
337
338 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
339 {
340 if (widget != WID_SCRS_CAPTION) return this->Window::GetWidgetString(widget, stringid);
341
342 return GetString((this->slot == OWNER_DEITY) ? STR_AI_SETTINGS_CAPTION_GAMESCRIPT : STR_AI_SETTINGS_CAPTION_AI);
343 }
344
345 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
346 {
347 if (widget != WID_SCRS_BACKGROUND) return;
348
349 this->line_height = std::max(SETTING_BUTTON_HEIGHT, GetCharacterHeight(FontSize::Normal)) + padding.height;
350
351 resize.width = 1;
352 fill.height = resize.height = this->line_height;
353 size.height = 5 * this->line_height;
354 }
355
356 void DrawWidget(const Rect &r, WidgetID widget) const override
357 {
358 if (widget != WID_SCRS_BACKGROUND) return;
359
360 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
361 bool rtl = _current_text_dir == TD_RTL;
362 Rect br = ir.WithWidth(SETTING_BUTTON_WIDTH, rtl);
364
365 int y = r.top;
366 int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
367 int text_y_offset = (this->line_height - GetCharacterHeight(FontSize::Normal)) / 2;
368
369 const auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->visible_settings);
370 for (auto it = first; it != last; ++it) {
371 const ScriptConfigItem &config_item = **it;
372 int current_value = this->script_config->GetSetting(config_item.name);
373 bool editable = this->IsEditableItem(config_item);
374
375 if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
376 DrawBoolButton(br.left, y + button_y_offset, Colours::Yellow, Colours::Mauve, current_value != 0, editable);
377 } else {
378 int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
379 if (config_item.complete_labels) {
380 DrawDropDownButton(br.left, y + button_y_offset, Colours::Yellow, this->clicked_row == i && this->clicked_dropdown, editable);
381 } else {
382 DrawArrowButtons(br.left, y + button_y_offset, Colours::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);
383 }
384 }
385
386 DrawString(tr.left, tr.right, y + text_y_offset, config_item.GetString(current_value), config_item.GetColour());
387 y += this->line_height;
388 }
389 }
390
391 void OnPaint() override
392 {
393 if (this->closing_dropdown) {
394 this->closing_dropdown = false;
395 this->clicked_dropdown = false;
396 }
397 this->DrawWidgets();
398 }
399
400 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
401 {
402 switch (widget) {
403 case WID_SCRS_BACKGROUND: {
404 auto it = this->vscroll->GetScrolledItemFromWidget(this->visible_settings, pt.y, this, widget);
405 if (it == this->visible_settings.end()) break;
406
407 const ScriptConfigItem &config_item = **it;
408 if (!this->IsEditableItem(config_item)) return;
409
410 int num = it - this->visible_settings.begin();
411 if (this->clicked_row != num) {
412 this->CloseChildWindows(WindowClass::QueryString);
413 this->CloseChildWindows(WindowClass::DropdownMenu);
414 this->clicked_row = num;
415 this->clicked_dropdown = false;
416 }
417
418 bool bool_item = config_item.flags.Test(ScriptConfigFlag::Boolean);
419
420 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext, RectPadding::zero);
421 int x = pt.x - r.left;
422 if (_current_text_dir == TD_RTL) x = r.Width() - 1 - x;
423
424 /* One of the arrows is clicked (or green/red rect in case of bool value) */
425 int old_val = this->script_config->GetSetting(config_item.name);
426 if (!bool_item && IsInsideMM(x, 0, SETTING_BUTTON_WIDTH) && config_item.complete_labels) {
427 if (this->clicked_dropdown) {
428 /* unclick the dropdown */
429 this->CloseChildWindows(WindowClass::DropdownMenu);
430 this->clicked_dropdown = false;
431 this->closing_dropdown = false;
432 } else {
433 int rel_y = (pt.y - r.top) % this->line_height;
434
435 Rect wi_rect;
436 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
437 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
438 wi_rect.top = pt.y - rel_y + (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
439 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
440
441 /* If the mouse is still held but dragged outside of the dropdown list, keep the dropdown open */
442 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
443 this->clicked_dropdown = true;
444 this->closing_dropdown = false;
445
446 DropDownList list;
447 for (int i = config_item.min_value; i <= config_item.max_value; i++) {
448 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_RAW_STRING, config_item.labels.find(i)->second), i));
449 }
450
451 ShowDropDownListAt(this, std::move(list), old_val, WID_SCRS_SETTING_DROPDOWN, wi_rect, Colours::Orange);
452 }
453 }
454 } else if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
455 int new_val = old_val;
456 if (bool_item) {
457 new_val = !new_val;
458 } else if (x >= SETTING_BUTTON_WIDTH / 2) {
459 /* Increase button clicked */
460 new_val += config_item.step_size;
461 if (new_val > config_item.max_value) new_val = config_item.max_value;
462 this->clicked_increase = true;
463 } else {
464 /* Decrease button clicked */
465 new_val -= config_item.step_size;
466 if (new_val < config_item.min_value) new_val = config_item.min_value;
467 this->clicked_increase = false;
468 }
469
470 if (new_val != old_val) {
471 this->script_config->SetSetting(config_item.name, new_val);
472 this->clicked_button = num;
473 this->unclick_timeout.Reset();
474 }
475 } else if (!bool_item && !config_item.complete_labels) {
476 /* Display a query box so users can enter a custom value. */
477 ShowQueryString(GetString(STR_JUST_INT, old_val), STR_CONFIG_SETTING_QUERY_CAPTION, INT32_DIGITS_WITH_SIGN_AND_TERMINATION, this, CS_NUMERAL_SIGNED, {});
478 }
479 this->SetDirty();
480 break;
481 }
482
483 case WID_SCRS_RESET:
484 this->script_config->ResetEditableSettings(_game_mode == GameMode::Menu || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
485 this->SetDirty();
486 break;
487 }
488 }
489
490 void OnQueryTextFinished(std::optional<std::string> str) override
491 {
492 if (!str.has_value()) return;
493 auto value = ParseInteger<int32_t>(*str, 10, true);
494 if (!value.has_value()) return;
495 this->SetValue(*value);
496 }
497
498 void OnDropdownSelect(WidgetID widget, int index, int) override
499 {
500 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
501 assert(this->clicked_dropdown);
502 this->SetValue(index);
503 }
504
505 void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
506 {
507 if (widget != WID_SCRS_SETTING_DROPDOWN) return;
508 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
509 * the same dropdown button was clicked again, and then not open the dropdown again.
510 * So, we only remember that it was closed, and process it on the next OnPaint, which is
511 * after OnClick. */
512 assert(this->clicked_dropdown);
513 this->closing_dropdown = true;
514 this->SetDirty();
515 }
516
517 void OnResize() override
518 {
519 this->vscroll->SetCapacityFromWidget(this, WID_SCRS_BACKGROUND);
520 }
521
523 TimeoutTimer<TimerWindow> unclick_timeout = {std::chrono::milliseconds(150), [this]() {
524 this->clicked_button = -1;
525 this->SetDirty();
526 }};
527
533 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
534 {
535 this->script_config = GetConfig(this->slot);
536 if (this->script_config->GetConfigList()->empty()) this->Close();
538 this->CloseChildWindows(WindowClass::DropdownMenu);
539 this->CloseChildWindows(WindowClass::QueryString);
540 }
541
542private:
543 bool IsEditableItem(const ScriptConfigItem &config_item) const
544 {
545 return _game_mode == GameMode::Menu
546 || _game_mode == GameMode::Editor
547 || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot))
548 || config_item.flags.Test(ScriptConfigFlag::InGame)
549 || _settings_client.gui.ai_developer_tools;
550 }
551
552 void SetValue(int value)
553 {
554 const ScriptConfigItem &config_item = *this->visible_settings[this->clicked_row];
555 if (_game_mode == GameMode::Normal && ((this->slot == OWNER_DEITY) || Company::IsValidID(this->slot)) && !config_item.flags.Test(ScriptConfigFlag::InGame)) return;
556 this->script_config->SetSetting(config_item.name, value);
557 this->SetDirty();
558 }
559};
560
579
582 WindowPosition::Center, "settings_script", 500, 208,
583 WindowClass::ScriptSettings, WindowClass::None,
584 {},
586);
587
592void ShowScriptSettingsWindow(CompanyID slot)
593{
594 CloseWindowByClass(WindowClass::ScriptList);
595 CloseWindowByClass(WindowClass::ScriptSettings);
597}
598
599
601struct ScriptTextfileWindow : public TextfileWindow {
602 CompanyID slot{};
603
605 {
606 this->ConstructWindow();
607 this->OnInvalidateData();
608 }
609
610 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
611 {
612 if (widget == WID_TF_CAPTION) {
613 return GetString(stringid, (this->slot == OWNER_DEITY) ? STR_CONTENT_TYPE_GAME_SCRIPT : STR_CONTENT_TYPE_AI, GetConfig(this->slot)->GetInfo()->GetName());
614 }
615
616 return this->Window::GetWidgetString(widget, stringid);
617 }
618
619 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
620 {
621 auto textfile = GetConfig(this->slot)->GetTextfile(file_type, this->slot);
622 if (!textfile.has_value()) {
623 this->Close();
624 } else {
625 this->LoadTextfile(textfile.value(), (this->slot == OWNER_DEITY) ? Subdirectory::Gs : Subdirectory::Ai);
626 }
627 }
628};
629
636void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
637{
638 parent->CloseChildWindowById(WindowClass::Textfile, file_type);
639 new ScriptTextfileWindow(parent, file_type, slot);
640}
641
642
651static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
652{
653 /* Dead scripts are indicated with red background and
654 * paused scripts are indicated with yellow background. */
655 Colours colour = dead ? Colours::Red :
656 (paused ? Colours::Yellow : Colours::Grey);
657 if (button.colour != colour) {
658 button.colour = colour;
659 return true;
660 }
661 return false;
662}
663
667struct ScriptDebugWindow : public Window {
668 static const uint MAX_BREAK_STR_STRING_LENGTH = 256;
669
676
677 static inline FilterState initial_state = {
678 "",
679 CompanyID::Invalid(),
680 true,
681 false,
682 };
683
685 bool autoscroll = true;
686 bool show_break_box = false;
689 int highlight_row = -1;
690 Scrollbar *vscroll = nullptr;
691 Scrollbar *hscroll = nullptr;
692 FilterState filter{};
693
694 ScriptLogTypes::LogData &GetLogData() const
695 {
696 if (this->filter.script_debug_company == OWNER_DEITY) return Game::GetInstance()->GetLogData();
697 return Company::Get(this->filter.script_debug_company)->ai_instance->GetLogData();
698 }
699
704 bool IsDead() const
705 {
706 if (this->filter.script_debug_company == OWNER_DEITY) {
708 return game == nullptr || game->IsDead();
709 }
710 return !Company::IsValidAiID(this->filter.script_debug_company) || Company::Get(this->filter.script_debug_company)->ai_instance->IsDead();
711 }
712
718 bool IsValidDebugCompany(CompanyID company) const
719 {
720 switch (company.base()) {
721 case CompanyID::Invalid().base(): return false;
722 case OWNER_DEITY.base(): return Game::GetInstance() != nullptr;
723 default: return Company::IsValidAiID(company);
724 }
725 }
726
732 {
733 /* Check if the currently selected company is still active. */
734 if (this->IsValidDebugCompany(this->filter.script_debug_company)) return;
735
736 this->filter.script_debug_company = CompanyID::Invalid();
737
738 for (const Company *c : Company::Iterate()) {
739 if (c->is_ai) {
740 this->ChangeToScript(c->index);
741 return;
742 }
743 }
744
745 /* If no AI is available, see if there is a game script. */
746 if (Game::GetInstance() != nullptr) this->ChangeToScript(OWNER_DEITY);
747 }
748
756 {
757 this->filter = ScriptDebugWindow::initial_state;
758 this->break_string_filter = {&this->filter.case_sensitive_break_check, false};
759
760 this->CreateNestedTree();
761 this->vscroll = this->GetScrollbar(WID_SCRD_VSCROLLBAR);
762 this->hscroll = this->GetScrollbar(WID_SCRD_HSCROLLBAR);
763 this->FinishInitNested(number);
764
765 this->querystrings[WID_SCRD_BREAK_STR_EDIT_BOX] = &this->break_editbox;
766
767 /* Restore the break string value from static variable, and enable the filter. */
768 this->break_editbox.text.Assign(this->filter.break_string);
769 this->break_string_filter.SetFilterTerm(this->filter.break_string);
770
771 if (show_company == CompanyID::Invalid()) {
773 } else {
774 this->ChangeToScript(show_company);
775 }
776 }
777
778 void OnInit() override
779 {
780 this->hscroll->SetStepSize(GetCharacterHeight(FontSize::Normal)); // Speed up horizontal scrollbar
781
782 this->show_break_box = _settings_client.gui.ai_developer_tools;
783 this->GetWidget<NWidgetStacked>(WID_SCRD_BREAK_STRING_WIDGETS)->SetDisplayedPlane(this->show_break_box ? 0 : SZSP_HORIZONTAL);
784 if (!this->show_break_box) this->filter.break_check_enabled = false;
786
787 this->InvalidateData(-1);
788 }
789
792 {
793 ScriptDebugWindow::initial_state = this->filter;
794 }
795
796 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
797 {
798 if (widget == WID_SCRD_LOG_PANEL) {
799 fill.height = resize.height = GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
800 size.height = 14 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
801 }
802 }
803
804 void OnPaint() override
805 {
807 this->UpdateLogScroll();
808
809 /* Draw standard stuff */
810 this->DrawWidgets();
811 }
812
813 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
814 {
815 if (widget != WID_SCRD_NAME_TEXT) return this->Window::GetWidgetString(widget, stringid);
816
817 if (this->filter.script_debug_company == OWNER_DEITY) {
818 const GameInfo *info = Game::GetInfo();
819 assert(info != nullptr);
820 return GetString(STR_AI_DEBUG_NAME_AND_VERSION, info->GetName(), info->GetVersion());
821 }
822 if (this->filter.script_debug_company == CompanyID::Invalid() || !Company::IsValidAiID(this->filter.script_debug_company)) {
823 return {};
824 }
825
826 const AIInfo *info = Company::Get(this->filter.script_debug_company)->ai_info;
827 return GetString(STR_AI_DEBUG_NAME_AND_VERSION, info->GetName(), info->GetVersion());
828 }
829
830 void DrawWidget(const Rect &r, WidgetID widget) const override
831 {
832 switch (widget) {
834 this->DrawWidgetLog(r);
835 break;
836
837 default:
838 if (IsInsideBS(widget, WID_SCRD_COMPANY_BUTTON_START, MAX_COMPANIES)) {
840 }
841 break;
842 }
843 }
844
851 void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
852 {
853 if (this->IsWidgetDisabled(widget)) return;
854 CompanyID cid = static_cast<CompanyID>(widget - start);
856 DrawCompanyIcon(cid, CentreBounds(r.left, r.right, sprite_size.width), CentreBounds(r.top, r.bottom, sprite_size.height));
857 }
858
863 void DrawWidgetLog(const Rect &r) const
864 {
865 if (this->filter.script_debug_company == CompanyID::Invalid()) return;
866
867 const ScriptLogTypes::LogData &log = this->GetLogData();
868 if (log.empty()) return;
869
870 Rect fr = r.Shrink(WidgetDimensions::scaled.framerect);
871
872 /* Setup a clipping rectangle... */
873 DrawPixelInfo tmp_dpi;
874 if (!FillDrawPixelInfo(&tmp_dpi, fr)) return;
875 /* ...but keep coordinates relative to the window. */
876 tmp_dpi.left += fr.left;
877 tmp_dpi.top += fr.top;
878
879 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
880
881 fr = ScrollRect(fr, *this->hscroll, 1);
882
883 auto [first, last] = this->vscroll->GetVisibleRangeIterators(log);
884 for (auto it = first; it != last; ++it) {
885 const ScriptLogTypes::LogLine &line = *it;
886
887 TextColour colour;
888 switch (line.type) {
889 case ScriptLogTypes::LOG_SQ_INFO: colour = TextColour::Black; break;
890 case ScriptLogTypes::LOG_SQ_ERROR: colour = TextColour::White; break;
891 case ScriptLogTypes::LOG_INFO: colour = TextColour::Black; break;
892 case ScriptLogTypes::LOG_WARNING: colour = TextColour::Yellow; break;
893 case ScriptLogTypes::LOG_ERROR: colour = TextColour::Red; break;
894 default: colour = TextColour::Black; break;
895 }
896
897 /* Check if the current line should be highlighted */
898 if (std::distance(std::begin(log), it) == this->highlight_row) {
899 fr.bottom = fr.top + this->resize.step_height - 1;
901 if (colour == TextColour::Black) colour = TextColour::White; // Make black text readable by inverting it to white.
902 }
903
904 DrawString(fr, line.text, colour, AlignmentH::ForceLeft);
905 fr.top += this->resize.step_height;
906 }
907 }
908
913 {
914 this->SetWidgetsDisabledState(this->filter.script_debug_company == CompanyID::Invalid(), WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR);
915 if (this->filter.script_debug_company == CompanyID::Invalid()) return;
916
917 ScriptLogTypes::LogData &log = this->GetLogData();
918
919 int scroll_count = static_cast<int>(log.size());
920 if (this->vscroll->GetCount() != scroll_count) {
921 this->vscroll->SetCount(scroll_count);
922
923 /* We need a repaint */
925 }
926
927 if (log.empty()) return;
928
929 /* Detect when the user scrolls the window. Enable autoscroll when the bottom-most line becomes visible. */
930 if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
931 this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= static_cast<int>(log.size());
932 }
933
934 if (this->autoscroll && this->vscroll->SetPosition(static_cast<int>(log.size()))) {
935 /* We need a repaint */
938 }
939
940 this->last_vscroll_pos = this->vscroll->GetPosition();
941 }
942
947 {
948 /* Update company buttons */
949 for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) {
950 /* Mark dead/paused AIs by setting the background colour. */
951 bool valid = Company::IsValidAiID(i);
952 bool dead = valid && Company::Get(i)->ai_instance->IsDead();
953 bool paused = valid && Company::Get(i)->ai_instance->IsPaused();
954
956 button->SetDisabled(!valid);
957 button->SetLowered(this->filter.script_debug_company == i);
958 SetScriptButtonColour(*button, dead, paused);
959 }
960 }
961
966 {
968 bool valid = game != nullptr;
969 bool dead = valid && game->IsDead();
970 bool paused = valid && game->IsPaused();
971
973 button->SetDisabled(!valid);
974 button->SetLowered(this->filter.script_debug_company == OWNER_DEITY);
975 SetScriptButtonColour(*button, dead, paused);
976 }
977
983 void ChangeToScript(CompanyID show_script, bool new_window = false)
984 {
985 if (!this->IsValidDebugCompany(show_script)) return;
986
987 if (new_window) {
988 ScriptDebugWindow::initial_state = this->filter;
989 ShowScriptDebugWindow(show_script, true);
990 return;
991 }
992
993 this->filter.script_debug_company = show_script;
994
995 this->highlight_row = -1; // The highlight of one Script make little sense for another Script.
996
997 /* Close AI settings window to prevent confusion */
998 CloseWindowByClass(WindowClass::ScriptSettings);
999
1000 this->InvalidateData(-1);
1001
1002 this->autoscroll = true;
1003 this->last_vscroll_pos = this->vscroll->GetPosition();
1004 }
1005
1006 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1007 {
1008 /* Also called for hotkeys, so check for disabledness */
1009 if (this->IsWidgetDisabled(widget)) return;
1010
1011 /* Check which button is clicked */
1013 this->ChangeToScript(static_cast<CompanyID>(widget - WID_SCRD_COMPANY_BUTTON_START), IsCtrlPressed());
1014 }
1015
1016 switch (widget) {
1019 break;
1020
1022 if (this->filter.script_debug_company == OWNER_DEITY) break;
1023 /* First kill the company of the AI, then start a new one. This should start the current AI again */
1024 Command<Commands::CompanyControl>::Post(CompanyCtrlAction::Delete, this->filter.script_debug_company, CompanyRemoveReason::Manual, ClientID::Invalid);
1025 Command<Commands::CompanyControl>::Post(CompanyCtrlAction::NewAI, this->filter.script_debug_company, CompanyRemoveReason::None, ClientID::Invalid);
1026 break;
1027
1028 case WID_SCRD_SETTINGS:
1030 break;
1031
1033 this->filter.break_check_enabled = !this->filter.break_check_enabled;
1034 this->InvalidateData(-1);
1035 break;
1036
1038 this->filter.case_sensitive_break_check = !this->filter.case_sensitive_break_check;
1039 this->InvalidateData(-1);
1040 break;
1041
1043 /* Unpause current AI / game script and mark the corresponding script button dirty. */
1044 if (!this->IsDead()) {
1045 if (this->filter.script_debug_company == OWNER_DEITY) {
1046 Game::Unpause();
1047 } else {
1048 AI::Unpause(this->filter.script_debug_company);
1049 }
1050 }
1051
1052 /* If the last AI/Game Script is unpaused, unpause the game too. */
1053 if (_pause_mode.Test(PauseMode::Normal)) {
1054 bool all_unpaused = !Game::IsPaused();
1055 if (all_unpaused) {
1056 for (const Company *c : Company::Iterate()) {
1057 if (c->is_ai && AI::IsPaused(c->index)) {
1058 all_unpaused = false;
1059 break;
1060 }
1061 }
1062 if (all_unpaused) {
1063 /* All scripts have been unpaused => unpause the game. */
1064 Command<Commands::Pause>::Post(PauseMode::Normal, false);
1065 }
1066 }
1067 }
1068
1069 this->highlight_row = -1;
1070 this->InvalidateData(-1);
1071 break;
1072 }
1073 }
1074
1075 void OnEditboxChanged(WidgetID wid) override
1076 {
1077 if (wid != WID_SCRD_BREAK_STR_EDIT_BOX) return;
1078
1079 /* Save the current string to static member so it can be restored next time the window is opened. */
1080 this->filter.break_string = this->break_editbox.text.GetText();
1081 this->break_string_filter.SetFilterTerm(this->filter.break_string);
1082 }
1083
1090 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1091 {
1092 if (this->show_break_box != _settings_client.gui.ai_developer_tools) this->ReInit();
1093
1094 /* If the log message is related to the active company tab, check the break string.
1095 * This needs to be done in gameloop-scope, so the AI is suspended immediately. */
1096 if (!gui_scope && data == this->filter.script_debug_company &&
1097 this->IsValidDebugCompany(this->filter.script_debug_company) &&
1098 this->filter.break_check_enabled && !this->break_string_filter.IsEmpty()) {
1099 /* Get the log instance of the active company */
1100 ScriptLogTypes::LogData &log = this->GetLogData();
1101
1102 if (!log.empty()) {
1103 this->break_string_filter.ResetState();
1104 this->break_string_filter.AddLine(log.back().text);
1105 if (this->break_string_filter.GetState()) {
1106 /* Pause execution of script. */
1107 if (!this->IsDead()) {
1108 if (this->filter.script_debug_company == OWNER_DEITY) {
1109 Game::Pause();
1110 } else {
1111 AI::Pause(this->filter.script_debug_company);
1112 }
1113 }
1114
1115 /* Pause the game. */
1116 if (!_pause_mode.Test(PauseMode::Normal)) {
1117 Command<Commands::Pause>::Post(PauseMode::Normal, true);
1118 }
1119
1120 /* Highlight row that matched */
1121 this->highlight_row = static_cast<int>(log.size() - 1);
1122 }
1123 }
1124 }
1125
1126 if (!gui_scope) return;
1127
1129
1130 uint max_width = 0;
1131 if (this->filter.script_debug_company != CompanyID::Invalid()) {
1132 for (auto &line : this->GetLogData()) {
1133 if (line.width == 0 || data == -1) line.width = GetStringBoundingBox(line.text).width;
1134 max_width = std::max(max_width, line.width);
1135 }
1136 }
1137
1138 this->vscroll->SetCount(this->filter.script_debug_company != CompanyID::Invalid() ? this->GetLogData().size() : 0);
1139 this->hscroll->SetCount(max_width + WidgetDimensions::scaled.frametext.Horizontal());
1140
1141 this->UpdateAIButtonsState();
1142 this->UpdateGSButtonState();
1143
1146
1147 this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == CompanyID::Invalid() ||
1148 GetConfig(this->filter.script_debug_company)->GetConfigList()->empty());
1149 extern CompanyID _local_company;
1151 this->filter.script_debug_company == CompanyID::Invalid() ||
1152 this->filter.script_debug_company == OWNER_DEITY ||
1153 this->filter.script_debug_company == _local_company);
1154 this->SetWidgetDisabledState(WID_SCRD_CONTINUE_BTN, this->filter.script_debug_company == CompanyID::Invalid() ||
1155 (this->filter.script_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(this->filter.script_debug_company)));
1156 }
1157
1158 void OnResize() override
1159 {
1160 this->vscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Vertical());
1161 this->hscroll->SetCapacityFromWidget(this, WID_SCRD_LOG_PANEL, WidgetDimensions::scaled.framerect.Horizontal());
1162 }
1163
1170 {
1171 if (_game_mode != GameMode::Normal) return EventState::NotHandled;
1172 Window *w = ShowScriptDebugWindow(CompanyID::Invalid());
1173 if (w == nullptr) return EventState::NotHandled;
1174 return w->OnHotkey(hotkey);
1175 }
1176
1177 static inline HotkeyList hotkeys{"aidebug", {
1178 Hotkey('1', "company_1", WID_SCRD_COMPANY_BUTTON_START),
1179 Hotkey('2', "company_2", WID_SCRD_COMPANY_BUTTON_START + 1),
1180 Hotkey('3', "company_3", WID_SCRD_COMPANY_BUTTON_START + 2),
1181 Hotkey('4', "company_4", WID_SCRD_COMPANY_BUTTON_START + 3),
1182 Hotkey('5', "company_5", WID_SCRD_COMPANY_BUTTON_START + 4),
1183 Hotkey('6', "company_6", WID_SCRD_COMPANY_BUTTON_START + 5),
1184 Hotkey('7', "company_7", WID_SCRD_COMPANY_BUTTON_START + 6),
1185 Hotkey('8', "company_8", WID_SCRD_COMPANY_BUTTON_START + 7),
1186 Hotkey('9', "company_9", WID_SCRD_COMPANY_BUTTON_START + 8),
1187 Hotkey(0, "company_10", WID_SCRD_COMPANY_BUTTON_START + 9),
1188 Hotkey(0, "company_11", WID_SCRD_COMPANY_BUTTON_START + 10),
1189 Hotkey(0, "company_12", WID_SCRD_COMPANY_BUTTON_START + 11),
1190 Hotkey(0, "company_13", WID_SCRD_COMPANY_BUTTON_START + 12),
1191 Hotkey(0, "company_14", WID_SCRD_COMPANY_BUTTON_START + 13),
1192 Hotkey(0, "company_15", WID_SCRD_COMPANY_BUTTON_START + 14),
1193 Hotkey('S', "settings", WID_SCRD_SETTINGS),
1194 Hotkey('0', "game_script", WID_SCRD_SCRIPT_GAME),
1195 Hotkey(0, "reload", WID_SCRD_RELOAD_TOGGLE),
1196 Hotkey('B', "break_toggle", WID_SCRD_BREAK_STR_ON_OFF_BTN),
1197 Hotkey('F', "break_string", WID_SCRD_BREAK_STR_EDIT_BOX),
1198 Hotkey('C', "match_case", WID_SCRD_MATCH_CASE_BTN),
1199 Hotkey(WKC_RETURN, "continue", WID_SCRD_CONTINUE_BTN),
1201};
1202
1204std::unique_ptr<NWidgetBase> MakeCompanyButtonRowsScriptDebug()
1205{
1206 return MakeCompanyButtonRows(WID_SCRD_COMPANY_BUTTON_START, WID_SCRD_COMPANY_BUTTON_END, Colours::Grey, 5, STR_AI_DEBUG_SELECT_AI_TOOLTIP, false);
1207}
1208
1210static constexpr std::initializer_list<NWidgetPart> _nested_script_debug_widgets = {
1213 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_AI_DEBUG, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1217 EndContainer(),
1221 EndContainer(),
1222 NWidget(WWT_TEXTBTN, Colours::Grey, WID_SCRD_SCRIPT_GAME), SetMinimalSize(100, 20), SetStringTip(STR_AI_GAME_SCRIPT, STR_AI_GAME_SCRIPT_TOOLTIP),
1223 NWidget(WWT_TEXTBTN, Colours::Grey, WID_SCRD_NAME_TEXT), SetResize(1, 0), SetToolTip(STR_AI_DEBUG_NAME_TOOLTIP),
1225 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SCRD_SETTINGS), SetMinimalSize(100, 20), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_SETTINGS, STR_AI_DEBUG_SETTINGS_TOOLTIP),
1226 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SCRD_RELOAD_TOGGLE), SetMinimalSize(100, 20), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_RELOAD, STR_AI_DEBUG_RELOAD_TOOLTIP),
1227 EndContainer(),
1228 EndContainer(),
1231 /* Log panel */
1233 EndContainer(),
1234 /* Break string widgets */
1237 NWidget(WWT_IMGBTN_2, Colours::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),
1240 NWidget(WWT_LABEL, Colours::Invalid), SetPadding(2, 2, 2, 4), SetStringTip(STR_AI_DEBUG_BREAK_ON_LABEL),
1241 NWidget(WWT_EDITBOX, Colours::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),
1242 EndContainer(),
1243 EndContainer(),
1244 NWidget(WWT_TEXTBTN, Colours::Grey, WID_SCRD_MATCH_CASE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_MATCH_CASE, STR_AI_DEBUG_MATCH_CASE_TOOLTIP),
1245 NWidget(WWT_PUSHTXTBTN, Colours::Grey, WID_SCRD_CONTINUE_BTN), SetMinimalSize(100, 0), SetFill(0, 1), SetStringTip(STR_AI_DEBUG_CONTINUE, STR_AI_DEBUG_CONTINUE_TOOLTIP),
1246 EndContainer(),
1247 EndContainer(),
1249 EndContainer(),
1253 EndContainer(),
1254EndContainer(),
1255};
1256
1259 WindowPosition::Automatic, "script_debug", 600, 450,
1260 WindowClass::ScriptDebug, WindowClass::None,
1261 {},
1263 &ScriptDebugWindow::hotkeys
1264);
1265
1272Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window)
1273{
1274 if (!_networking || _network_server) {
1275 int i = 0;
1276 if (new_window) {
1277 /* find next free window number for script debug */
1278 while (FindWindowById(WindowClass::ScriptDebug, i) != nullptr) i++;
1279 } else {
1280 /* Find existing window showing show_company. */
1281 for (Window *w : Window::Iterate()) {
1282 if (w->window_class == WindowClass::ScriptDebug && static_cast<ScriptDebugWindow *>(w)->filter.script_debug_company == show_company) {
1283 return BringWindowToFrontById(w->window_class, w->window_number);
1284 }
1285 }
1286
1287 /* Maybe there's a window showing a different company which can be switched. */
1288 ScriptDebugWindow *w = static_cast<ScriptDebugWindow *>(FindWindowByClass(WindowClass::ScriptDebug));
1289 if (w != nullptr) {
1291 w->ChangeToScript(show_company);
1292 return w;
1293 }
1294 }
1295 return new ScriptDebugWindow(_script_debug_desc, i, show_company);
1296 } else {
1297 ShowErrorMessage(GetEncodedString(STR_ERROR_AI_DEBUG_SERVER_ONLY), {}, WarningLevel::Info);
1298 }
1299
1300 return nullptr;
1301}
1302
1307{
1308 ScriptDebugWindow::initial_state.script_debug_company = CompanyID::Invalid();
1309}
1310
1313{
1314 /* Network clients can't debug AIs. */
1315 if (_networking && !_network_server) return;
1316
1317 for (const Company *c : Company::Iterate()) {
1318 if (c->is_ai && c->ai_instance->IsDead()) {
1319 ShowScriptDebugWindow(c->index);
1320 break;
1321 }
1322 }
1323
1325 if (g != nullptr && g->IsDead()) {
1327 }
1328}
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
AIInfo keeps track of all information of an AI, like Author, Description, ...
The AIInstance tracks an AI.
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=ScriptSettingSource::Default)
Get the AI configuration of specific company.
Definition ai_config.cpp:20
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
static void Pause(CompanyID company)
Suspend the AI and then pause execution of the script.
Definition ai_core.cpp:128
static void StartNew(CompanyID company)
Start a new AI company.
Definition ai_core.cpp:36
static const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
Definition ai_core.cpp:297
static bool IsPaused(CompanyID company)
Checks if the AI is paused.
Definition ai_core.cpp:145
static void Unpause(CompanyID company)
Resume execution of the AI.
Definition ai_core.cpp:139
static const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
Definition ai_core.cpp:292
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
static GameConfig * GetConfig(ScriptSettingSource source=ScriptSettingSource::Default)
Get the script configuration.
All static information from an Game like name, version, etc.
Definition game_info.hpp:16
Runtime information about a game script like a pointer to the squirrel vm and the current state.
static void StartNew()
Start up a new GameScript.
Definition game_core.cpp:70
static class GameInfo * GetInfo()
Get the current GameInfo.
Definition game.hpp:72
static void Unpause()
Resume execution of the Game Script.
static bool IsPaused()
Checks if the Game Script is paused.
static void ResetInstance()
Reset the current active instance.
static const ScriptInfoList * GetUniqueInfoList()
Get the list of the latest version of all registered scripts.
static void Pause()
Suspends the Game Script and then pause the execution of the script.
static class GameInstance * GetInstance()
Get the current active instance.
Definition game.hpp:108
static const ScriptInfoList * GetInfoList()
Get the list of all registered scripts.
Base class for a 'real' widget.
Colours colour
Colour of this widget.
void SetLowered(bool lowered)
Lower or raise the widget.
void SetDisabled(bool disabled)
Disable (grey-out) or enable the widget.
Script settings.
void SetSetting(std::string_view name, int value)
Set the value of a setting for this config.
const ScriptConfigItemList * GetConfigList()
Get the config list for this ScriptConfig.
int GetSetting(const std::string &name) const
Get the value of a setting for this config.
void ResetEditableSettings(bool yet_to_start)
Reset only editable and visible settings to their default value.
All static information from an Script like name, version, etc.
const std::string & GetName() const
Get the Name of the script.
const std::string & GetAuthor() const
Get the Author of the script.
const std::string & GetURL() const
Get the website for this script.
int GetVersion() const
Get the version of the script.
const std::string & GetDescription() const
Get the description of the script.
bool IsPaused()
Checks if the script is paused.
ScriptLogTypes::LogData & GetLogData()
Get the log pointer of this script.
bool IsDead() const
Return the "this script died" value.
Scrollbar data structure.
bool IsVisible(size_type item) const
Checks whether given current item is visible in the list.
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
void SetCount(size_t num)
Sets the number of elements in the list.
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.
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:2474
bool SetPosition(size_type position)
Sets the position of the first visible element.
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:2548
size_type GetCount() const
Gets the number of elements in the list.
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
size_type GetPosition() const
Gets the position of the first visible element in the list.
A timeout timer will fire once after the interval.
Definition timer.h:116
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Definition of stuff that is very close to a company, like the company struct itself.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Command definitions related to companies.
GUI Functions related to companies.
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
@ NewAI
Create a new AI company.
@ Delete
Delete a company.
@ None
Dummy reason for actions that don't need one.
@ Manual
The company is manually removed.
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:574
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:22
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ Ai
Subdirectory for all AI files.
Definition fileio_type.h:98
@ Gs
Subdirectory for all game scripts.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
GameInfo keeps track of all information of an Game, like Author, Description, ...
The GameInstance tracks games.
@ ForceLeft
Force align to the left.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
PauseModes _pause_mode
The current pause mode.
Definition gfx.cpp:46
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:111
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
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:1567
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
Colours
One of 16 base colours used for companies and windows/widgets.
Definition gfx_type.h:283
@ Mauve
Mauve.
Definition gfx_type.h:295
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Yellow
Yellow.
Definition gfx_type.h:288
@ Orange
Orange.
Definition gfx_type.h:297
@ Grey
Grey.
Definition gfx_type.h:299
@ Red
Red.
Definition gfx_type.h:289
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:315
@ White
White colour.
Definition gfx_type.h:330
@ Yellow
Yellow colour.
Definition gfx_type.h:326
@ Orange
Orange colour.
Definition gfx_type.h:324
@ Black
Black colour.
Definition gfx_type.h:334
@ Red
Red colour.
Definition gfx_type.h:321
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
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.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
Hotkey related functions.
#define Point
Macro that prevents name conflicts between included headers.
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.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Miscellaneous command definitions.
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.
Types related to the misc widgets.
@ WID_TF_CAPTION
The caption of the window.
Definition misc_widget.h:53
bool _networking
are we in networking mode?
Definition network.cpp:63
bool _network_server
network-server is active
Definition network.cpp:64
Basic functions/variables used all over the place.
@ Invalid
Client is not part of anything.
@ Normal
A game normally paused.
Definition openttd.h:72
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
@ Menu
In the main menu.
Definition openttd.h:19
static constexpr PixelColour PC_BLACK
Black palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
ScriptConfig stores the configuration settings of every Script.
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'.
@ Boolean
This value is a boolean (either 0 (false) or 1 (true) ).
@ Developer
This setting will only be visible when the Script development tools are active.
@ InGame
This setting can be changed while the Script is running.
static constexpr std::initializer_list< NWidgetPart > _nested_script_list_widgets
Widgets for the AI list window.
void ShowScriptDebugWindowIfScriptError()
Open the AI debug window if one of the AI scripts has crashed.
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
static WindowDesc _script_settings_desc(WindowPosition::Center, "settings_script", 500, 208, WindowClass::ScriptSettings, WindowClass::None, {}, _nested_script_settings_widgets)
Window definition for the Script settings window.
std::unique_ptr< NWidgetBase > MakeCompanyButtonRowsScriptDebug()
Make a number of rows with buttons for each company for the Script debug window.
static bool SetScriptButtonColour(NWidgetCore &button, bool dead, bool paused)
Set the widget colour of a button based on the state of the script.
static constexpr std::initializer_list< NWidgetPart > _nested_script_debug_widgets
Widgets for the Script debug window.
void ShowScriptSettingsWindow(CompanyID slot)
Open the Script settings window to change the Script settings for a Script.
void ShowScriptTextfileWindow(Window *parent, TextfileType file_type, CompanyID slot)
Open the Script version of the textfile window.
static constexpr std::initializer_list< NWidgetPart > _nested_script_settings_widgets
Widgets for the Script settings window.
static WindowDesc _script_debug_desc(WindowPosition::Automatic, "script_debug", 600, 450, WindowClass::ScriptDebug, WindowClass::None, {}, _nested_script_debug_widgets, &ScriptDebugWindow::hotkeys)
Window definition for the Script debug window.
static WindowDesc _script_list_desc(WindowPosition::Center, "settings_script_list", 200, 234, WindowClass::ScriptList, WindowClass::None, {}, _nested_script_list_widgets)
Window definition for the ai list window.
void ShowScriptListWindow(CompanyID slot, bool show_all)
Open the Script list window to chose a script for the given company slot.
void InitializeScriptGui()
Reset the Script windows to their initial state.
Window for configuring the scripts.
Declarations of the class for the script scanner.
std::map< std::string, class ScriptInfo *, CaseInsensitiveComparator > ScriptInfoList
Type for the list of scripts.
Types related to the script widgets.
@ WID_SCRD_NAME_TEXT
Name of the current selected.
@ WID_SCRD_BREAK_STRING_WIDGETS
The panel to handle the breaking on string.
@ WID_SCRD_SCRIPT_GAME
Game Script button.
@ WID_SCRD_RELOAD_TOGGLE
Reload button.
@ WID_SCRD_HSCROLLBAR
Horizontal scrollbar of the log panel.
@ WID_SCRD_SETTINGS
Settings button.
@ WID_SCRD_BREAK_STR_EDIT_BOX
Edit box for the string to break on.
@ WID_SCRD_COMPANY_BUTTON_START
Buttons in the VIEW.
@ WID_SCRD_VIEW
The row of company buttons.
@ WID_SCRD_MATCH_CASE_BTN
Checkbox to use match caching or not.
@ WID_SCRD_BREAK_STR_ON_OFF_BTN
Enable breaking on string.
@ WID_SCRD_VSCROLLBAR
Vertical scrollbar of the log panel.
@ WID_SCRD_LOG_PANEL
Panel where the log is in.
@ WID_SCRD_CONTINUE_BTN
Continue button.
@ WID_SCRD_COMPANY_BUTTON_END
Last possible button in the VIEW.
@ WID_SCRL_ACCEPT
Accept button.
@ WID_SCRL_INFO_BG
Panel to draw some Script information on.
@ WID_SCRL_CAPTION
Caption of the window.
@ WID_SCRL_LIST
The matrix with all available Scripts.
@ WID_SCRL_SCROLLBAR
Scrollbar next to the Script list.
@ WID_SCRS_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
@ WID_SCRS_BACKGROUND
Panel to draw the settings on.
@ WID_SCRS_SCROLLBAR
Scrollbar to scroll through all settings.
@ WID_SCRS_RESET
Reset button.
@ WID_SCRS_CAPTION
Caption of the window.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
This file contains all sprite-related enums and defines.
static const SpriteID SPR_COMPANY_ICON
Icon showing company colour.
Definition sprites.h:386
static const SpriteID SPR_FLAG_VEH_STOPPED
Vehicle sprite-flags (red/green).
Definition sprites.h:1098
Definition of base types and functions in a cross-platform compatible way.
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
Searching and filtering using a stringterm.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
static bool IsValidAiID(auto index)
Is this company a valid company, controlled by the computer (a NoAI program)?
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Data about how and where to blit pixels.
Definition gfx_type.h:157
List of hotkeys for a window.
Definition hotkeys.h:44
All data for a single hotkey.
Definition hotkeys.h:20
static Pool::IterateWrapper< Company > Iterate(size_t from=0)
static Company * Get(auto index)
static Company * GetIfValid(auto index)
Data stored about a string that can be modified in the GUI.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Info about a single Script setting.
ScriptConfigFlags flags
Flags for the configuration setting.
std::string GetString(int value) const
Get string to display this setting in the configuration interface.
LabelMapping labels
Text labels for the integer values.
std::string name
The name of the configuration setting.
int min_value
The minimal value this configuration setting can have.
int max_value
The maximal value this configuration setting can have.
int step_size
The step size in the gui.
bool complete_labels
True if all values have a label.
TextColour GetColour() const
Get text colour to display this setting in the configuration interface.
bool break_check_enabled
Stop an AI when it prints a matching string.
bool case_sensitive_break_check
Is the matching done case-sensitive.
std::string break_string
The string to match to the AI output.
CompanyID script_debug_company
The AI that is (was last) being debugged.
Window with everything an AI prints via ScriptLog.
void UpdateAIButtonsState()
Update state of all Company (AI) buttons.
void DrawWidgetLog(const Rect &r) const
Draw the AI/GS log.
void UpdateGSButtonState()
Update state of game script button.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
static EventState ScriptDebugGlobalHotkeys(int hotkey)
Handler for global hotkeys of the ScriptDebugWindow.
void SelectValidDebugCompany()
Ensure that script_debug_company refers to a valid AI company or GS, or is set to CompanyID::Invalid(...
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
int last_vscroll_pos
Last position of the scrolling.
void DrawWidgetCompanyButton(const Rect &r, WidgetID widget, int start) const
Draw a company button icon.
static const uint MAX_BREAK_STR_STRING_LENGTH
Maximum length of the break string.
QueryString break_editbox
Break editbox.
void OnPaint() override
The window must be repainted.
Scrollbar * hscroll
Cache of the horizontal scrollbar.
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.
void OnResize() override
Called after the window got resized.
int highlight_row
The output row that matches the given string, or -1.
ScriptDebugWindow(WindowDesc &desc, WindowNumber number, Owner show_company)
Constructor for the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void UpdateLogScroll()
Update the scrollbar and scroll position of the log panel.
StringFilter break_string_filter
Log filter for break.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
bool autoscroll
Whether automatically scrolling should be enabled or not.
bool IsDead() const
Check whether the currently selected AI/GS is dead.
bool IsValidDebugCompany(CompanyID company) const
Check whether a company is a valid AI company or GS.
void ChangeToScript(CompanyID show_script, bool new_window=false)
Change all settings to select another Script.
Scrollbar * vscroll
Cache of the vertical scrollbar.
~ScriptDebugWindow() override
Save the last sorting state.
bool show_break_box
Whether the break/debug box is visible.
Window that let you choose an available Script.
int line_height
Height of a row in the matrix widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
bool show_all
Whether to show all available versions.
void OnResize() override
Called after the window got resized.
CompanyID slot
The company we're selecting a new Script for.
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.
int selected
The currently selected Script.
Scrollbar * vscroll
Cache of the vertical scrollbar.
ScriptListWindow(WindowDesc &desc, CompanyID slot, bool show_all)
Constructor for the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void ChangeScript()
Changes the Script of the current slot.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
const ScriptInfoList * info_list
The list of Scripts.
Window for settings the parameters of an AI.
int clicked_row
The clicked row of settings.
void OnPaint() override
The window must be repainted.
std::vector< const ScriptConfigItem * > VisibleSettingsList
typedef for a vector of script settings
int clicked_button
The button we clicked.
void OnResize() override
Called after the window got resized.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void RebuildVisibleSettings()
Rebuilds the list of visible settings.
CompanyID slot
The currently show company's setting.
int line_height
Height of a row in the matrix widget.
ScriptSettingsWindow(WindowDesc &desc, CompanyID slot)
Constructor for the window.
bool clicked_dropdown
Whether the dropdown is open.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
TimeoutTimer< TimerWindow > unclick_timeout
When reset, unclick the button after a small timeout.
bool clicked_increase
Whether we clicked the increase or decrease button.
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.
ScriptConfig * script_config
The configuration we're modifying.
VisibleSettingsList visible_settings
List of visible AI settings.
void OnDropdownClose(Point, WidgetID widget, int, int, bool) override
A dropdown window associated to this window has been closed.
bool closing_dropdown
True, if the dropdown list is currently closing.
Scrollbar * vscroll
Cache of the vertical scrollbar.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Window for displaying the textfile of a AI.
CompanyID slot
View the textfile of this CompanyID slot.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
String filter and state.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:283
void Assign(std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:419
Window for displaying a textfile.
TextfileType file_type
Type of textfile to view.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
High level window description.
Definition window_gui.h:171
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:319
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
Window * parent
Parent window.
Definition window_gui.h:327
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
WindowClass window_class
Window class.
Definition window_gui.h:300
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1137
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:409
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:579
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
Definition window_gui.h:959
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
Stuff related to the text buffer GUI.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
Definition of Interval and OneShot timers.
Definition of the Window system.
Rect ScrollRect(Rect r, const Scrollbar &sb, int resize_step)
Apply 'scroll' to a rect to be drawn in.
Definition widget.cpp:2565
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:3492
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:42
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition widget_type.h:75
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ 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
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Window * FindWindowByClass(WindowClass cls)
Find any window by its class.
Definition window.cpp:1214
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
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:3377
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1199
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:3395
Window functions not directly related to making/drawing windows.
@ Automatic
Find a place automatically.
Definition window_gui.h:145
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ NotHandled
The passed event is not handled.