OpenTTD Source 20260621-master-g720d10536d
goal_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 "industry.h"
12#include "town.h"
13#include "window_gui.h"
14#include "strings_func.h"
15#include "viewport_func.h"
16#include "gui.h"
17#include "goal_base.h"
18#include "goal_gui.h"
20#include "company_func.h"
21#include "company_base.h"
22#include "company_gui.h"
23#include "story_base.h"
24#include "command_func.h"
25#include "string_func.h"
26#include "goal_cmd.h"
27
28#include "widgets/goal_widget.h"
29
30#include "table/strings.h"
31
32#include "safeguards.h"
33
35enum GoalColumn : uint8_t {
36 GC_GOAL = 0,
38};
39
41struct GoalListWindow : public Window {
42 Scrollbar *vscroll = nullptr;
43
44 GoalListWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
45 {
46 this->CreateNestedTree();
47 this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
48 this->FinishInitNested(window_number);
49 this->owner = this->window_number;
51 wi->SetDisplayedPlane(window_number == CompanyID::Invalid() ? 1 : 0);
52 this->OnInvalidateData(0);
53 }
54
55 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
56 {
57 if (widget != WID_GOAL_CAPTION) return this->Window::GetWidgetString(widget, stringid);
58
59 if (this->window_number == CompanyID::Invalid()) {
60 return GetString(STR_GOALS_SPECTATOR_CAPTION);
61 }
62 return GetString(STR_GOALS_CAPTION, this->window_number);
63 }
64
65 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
66 {
67 switch (widget) {
69 ShowGoalsList(CompanyID::Invalid());
70 break;
71
74 break;
75
76 case WID_GOAL_LIST: {
77 int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.top);
78 for (const Goal *s : Goal::Iterate()) {
79 if (s->company == this->window_number) {
80 if (y == 0) {
81 this->HandleClick(s);
82 return;
83 }
84 y--;
85 }
86 }
87 break;
88 }
89
90 default:
91 break;
92 }
93 }
94
99 void HandleClick(const Goal *s)
100 {
101 /* Determine dst coordinate for goal and try to scroll to it. */
102 TileIndex xy;
103 switch (s->type) {
104 case GoalType::None: return;
105
107 /* s->dst here is not a tile, but a CompanyID.
108 * Show the window with the overview of the company instead. */
109 ShowCompany((CompanyID)s->dst);
110 return;
111
112 case GoalType::Tile:
113 if (!IsValidTile(s->dst)) return;
114 xy = TileIndex{s->dst};
115 break;
116
118 if (!Industry::IsValidID(s->dst)) return;
119 xy = Industry::Get(s->dst)->location.tile;
120 break;
121
122 case GoalType::Town:
123 if (!Town::IsValidID(s->dst)) return;
124 xy = Town::Get(s->dst)->xy;
125 break;
126
127 case GoalType::StoryPage: {
128 if (!StoryPage::IsValidID(s->dst)) return;
129
130 /* Verify that:
131 * - if global goal: story page must be global.
132 * - if company goal: story page must be global or of the same company.
133 */
134 CompanyID goal_company = s->company;
135 CompanyID story_company = StoryPage::Get(s->dst)->company;
136 if (goal_company == CompanyID::Invalid() ? story_company != CompanyID::Invalid() : story_company != CompanyID::Invalid() && story_company != goal_company) return;
137
138 ShowStoryBook(static_cast<CompanyID>(this->window_number), static_cast<StoryPageID>(s->dst));
139 return;
140 }
141
142 default: NOT_REACHED();
143 }
144
145 if (_ctrl_pressed) {
147 } else {
149 }
150 }
151
157 {
158 /* Count number of (non) awarded goals. */
159 uint num = 0;
160 for (const Goal *s : Goal::Iterate()) {
161 if (s->company == this->window_number) num++;
162 }
163
164 /* Count the 'none' lines. */
165 if (num == 0) num = 1;
166
167 return num;
168 }
169
170 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
171 {
172 if (widget != WID_GOAL_LIST) return;
173 Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
174
175 resize.width = 1;
176 fill.height = resize.height = d.height;
177
178 d.height *= 5;
179 d.width += WidgetDimensions::scaled.framerect.Horizontal();
180 d.height += WidgetDimensions::scaled.framerect.Vertical();
181 size = maxdim(size, d);
182 }
183
190 void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
191 {
192 /* Get column draw area. */
193 Rect r = wid->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
194 bool rtl = _current_text_dir == TD_RTL;
195
196 int pos = -this->vscroll->GetPosition();
197 const int cap = this->vscroll->GetCapacity();
198
199 uint num = 0;
200 for (const Goal *s : Goal::Iterate()) {
201 if (s->company == this->window_number) {
202 if (IsInsideMM(pos, 0, cap)) {
203 switch (column) {
204 case GC_GOAL: {
205 /* Display the goal. */
206 uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0;
207 DrawString(r.Indent(width_reduction, !rtl), GetString(STR_GOALS_TEXT, s->text.GetDecodedString()));
208 break;
209 }
210
211 case GC_PROGRESS:
212 if (!s->progress.empty()) {
213 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
214 DrawString(r.WithWidth(progress_col_width, !rtl), GetString(str, s->progress.GetDecodedString()), TextColour::FromString, SA_RIGHT | SA_FORCE);
215 }
216 break;
217 }
219 }
220 pos++;
221 num++;
222 }
223 }
224
225 if (num == 0) {
226 if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
227 DrawString(r, STR_GOALS_NONE);
228 }
229 }
230 }
231
232 void OnPaint() override
233 {
234 this->DrawWidgets();
235
236 if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
237
238 /* Calculate progress column width. */
239 uint max_width = 0;
240 for (const Goal *s : Goal::Iterate()) {
241 if (!s->progress.empty()) {
242 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
243 uint str_width = GetStringBoundingBox(GetString(str, s->progress.GetDecodedString())).width;
244 if (str_width > max_width) max_width = str_width;
245 }
246 }
247
249 uint progress_col_width = std::min(max_width, wid->current_x);
250
251 /* Draw goal list. */
252 this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
253 this->DrawListColumn(GC_GOAL, wid, progress_col_width);
254
255 }
256
257 void OnResize() override
258 {
259 this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.Vertical());
260 }
261
267 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
268 {
269 if (!gui_scope) return;
270 this->vscroll->SetCount(this->CountLines());
274 }
275};
276
299
302 WindowPosition::Automatic, "list_goals", 500, 127,
303 WindowClass::GoalList, WindowClass::None,
304 {},
306);
307
312void ShowGoalsList(CompanyID company)
313{
314 if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid();
315
317}
318
320struct GoalQuestionWindow : public Window {
324
335 {
336 assert(this->buttons.Count() < 4);
337
338 this->CreateNestedTree();
339 if (this->buttons.None()) {
341 } else {
342 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons.Count() - 1);
343 }
344 this->FinishInitNested(window_number);
345 }
346
347 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
348 {
349 switch (widget) {
350 case WID_GQ_BUTTON_1:
351 case WID_GQ_BUTTON_2:
352 case WID_GQ_BUTTON_3:
353 return GetString(STR_GOAL_QUESTION_BUTTON_CANCEL + to_underlying(this->buttons.GetNthSetBit(widget - WID_GQ_BUTTON_1).value_or(GoalQuestionButton::Cancel)));
354
355 default:
356 return this->Window::GetWidgetString(widget, stringid);
357 }
358 }
359
360 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
361 {
362 switch (widget) {
363 case WID_GQ_BUTTON_1:
364 case WID_GQ_BUTTON_2:
365 case WID_GQ_BUTTON_3:
366 Command<Commands::GoalQuestionAnswer>::Post(this->window_number, this->buttons.GetNthSetBit(widget - WID_GQ_BUTTON_1).value_or(GoalQuestionButton::Cancel));
367 this->Close();
368 break;
369 }
370 }
371
372 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
373 {
374 if (widget != WID_GQ_QUESTION) return;
375
376 size.height = GetStringHeight(this->question.GetDecodedString(), size.width);
377 }
378
379 void DrawWidget(const Rect &r, WidgetID widget) const override
380 {
381 if (widget != WID_GQ_QUESTION) return;
382
383 DrawStringMultiLine(r, this->question.GetDecodedString(), this->colour, SA_TOP | SA_HOR_CENTER);
384 }
385};
386
393template <Colours bg_colour, Colours btn_colour, StringID caption>
395 static constexpr auto widgetparts = {
397 NWidget(WWT_CLOSEBOX, bg_colour),
398 NWidget(WWT_CAPTION, bg_colour, WID_GQ_CAPTION), SetStringTip(caption, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
399 EndContainer(),
400 NWidget(WWT_PANEL, bg_colour),
405 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
406 EndContainer(),
408 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
409 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetFill(1, 0),
410 EndContainer(),
412 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
413 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetFill(1, 0),
414 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_3), SetFill(1, 0),
415 EndContainer(),
416 EndContainer(),
417 EndContainer(),
418 EndContainer(),
419 };
420};
421
422static constexpr auto _nested_goal_question_widgets_question = NestedGoalWidgets<Colours::LightBlue, Colours::LightBlue, STR_GOAL_QUESTION_CAPTION_QUESTION>::widgetparts;
423static constexpr auto _nested_goal_question_widgets_info = NestedGoalWidgets<Colours::LightBlue, Colours::LightBlue, STR_GOAL_QUESTION_CAPTION_INFORMATION>::widgetparts;
424static constexpr auto _nested_goal_question_widgets_warning = NestedGoalWidgets<Colours::Yellow, Colours::Yellow, STR_GOAL_QUESTION_CAPTION_WARNING>::widgetparts;
425static constexpr auto _nested_goal_question_widgets_error = NestedGoalWidgets<Colours::Red, Colours::Yellow, STR_GOAL_QUESTION_CAPTION_ERROR>::widgetparts;
426
429 {
430 WindowPosition::Center, {}, 0, 0,
431 WindowClass::GoalQuestion, WindowClass::None,
433 _nested_goal_question_widgets_question,
434 },
435 {
436 WindowPosition::Center, {}, 0, 0,
437 WindowClass::GoalQuestion, WindowClass::None,
439 _nested_goal_question_widgets_info,
440 },
441 {
442 WindowPosition::Center, {}, 0, 0,
443 WindowClass::GoalQuestion, WindowClass::None,
445 _nested_goal_question_widgets_warning,
446 },
447 {
448 WindowPosition::Center, {}, 0, 0,
449 WindowClass::GoalQuestion, WindowClass::None,
451 _nested_goal_question_widgets_error,
452 },
453}}};
454
462void ShowGoalQuestion(uint16_t id, GoalQuestionType type, GoalQuestionButtons buttons, const EncodedString &question)
463{
464 assert(type < GoalQuestionType::End);
466}
uint Count() const
Count the number of set bits.
constexpr bool None() const
Test if none of the values are set.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:207
Baseclass for nested widgets.
uint current_x
Current horizontal size (after resizing).
Stacked widgets, widgets all occupying the same space in the window.
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1452
Scrollbar data structure.
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.
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:2456
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:2530
size_type GetPosition() const
Gets the position of the first visible element in the list.
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:95
Functions related to commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
GUI Functions related to companies.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:716
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:899
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:787
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:668
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ SA_TOP
Top align the text.
Definition gfx_type.h:441
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:438
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:437
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:448
@ Invalid
Invalid marker.
Definition gfx_type.h:303
@ Brown
Brown.
Definition gfx_type.h:299
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:316
@ White
White colour.
Definition gfx_type.h:331
@ FromString
Marker for telling to use the colour from the string.
Definition gfx_type.h:318
@ Black
Black colour.
Definition gfx_type.h:335
Goal base class.
Command definitions related to goals.
void ShowGoalQuestion(uint16_t id, GoalQuestionType type, GoalQuestionButtons buttons, const EncodedString &question)
Display a goal question.
Definition goal_gui.cpp:462
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition goal_gui.cpp:312
GoalColumn
Goal list columns.
Definition goal_gui.cpp:35
@ GC_PROGRESS
Goal progress column.
Definition goal_gui.cpp:37
@ GC_GOAL
Goal text column.
Definition goal_gui.cpp:36
static constexpr std::initializer_list< NWidgetPart > _nested_goals_list_widgets
Widgets of the GoalListWindow.
Definition goal_gui.cpp:278
static WindowDesc _goals_list_desc(WindowPosition::Automatic, "list_goals", 500, 127, WindowClass::GoalList, WindowClass::None, {}, _nested_goals_list_widgets)
Window definition for the goal listing window.
static EnumIndexArray< WindowDesc, GoalQuestionType, GoalQuestionType::End > _goal_question_list_desc
Window definitions for the goal question windows.
Definition goal_gui.cpp:428
Goal GUI functions.
@ Company
Destination is a company.
Definition goal_type.h:56
@ Industry
Destination is an industry.
Definition goal_type.h:54
@ None
Destination is not linked.
Definition goal_type.h:52
@ StoryPage
Destination is a story page.
Definition goal_type.h:57
@ Town
Destination is a town.
Definition goal_type.h:55
@ Tile
Destination is a tile.
Definition goal_type.h:53
GoalQuestionType
Types of goal questions.
Definition goal_type.h:16
@ End
End marker.
Definition goal_type.h:21
@ Error
Showing an error; title: Error.
Definition goal_type.h:20
EnumBitSet< GoalQuestionButton, uint32_t, GoalQuestionButton::End > GoalQuestionButtons
Bitset of GoalQuestionButton elements.
Definition goal_type.h:48
@ Cancel
Cancel button.
Definition goal_type.h:26
Types related to the goal widgets.
@ WID_GQ_BUTTON_1
First button.
Definition goal_widget.h:29
@ WID_GQ_QUESTION
Question text.
Definition goal_widget.h:27
@ WID_GQ_BUTTON_2
Second button.
Definition goal_widget.h:30
@ WID_GQ_CAPTION
Caption of the window.
Definition goal_widget.h:26
@ WID_GQ_BUTTON_3
Third button.
Definition goal_widget.h:31
@ WID_GQ_BUTTONS
Buttons selection (between 1, 2 or 3).
Definition goal_widget.h:28
@ WID_GOAL_COMPANY_BUTTON
Button to show company goals.
Definition goal_widget.h:19
@ WID_GOAL_CAPTION
Caption of the window.
Definition goal_widget.h:16
@ WID_GOAL_SCROLLBAR
Scrollbar of the goal list.
Definition goal_widget.h:21
@ WID_GOAL_SELECT_BUTTONS
Selection widget for the title bar button.
Definition goal_widget.h:17
@ WID_GOAL_GLOBAL_BUTTON
Button to show global goals.
Definition goal_widget.h:18
@ WID_GOAL_LIST
Goal list.
Definition goal_widget.h:20
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
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 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.
GUI functions that shouldn't be here.
void ShowStoryBook(CompanyID company, StoryPageID page_id=StoryPageID::Invalid(), bool centered=false)
Raise or create the story book window for company, at page page_id.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Base of all industries.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
StoryPage base class.
PoolID< uint16_t, struct StoryPageIDTag, 64000, 0xFFFF > StoryPageID
ID of a story page.
Definition story_type.h:16
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:55
void OnResize() override
Called after the window got resized.
Definition goal_gui.cpp:257
uint CountLines()
Count the number of lines in this window.
Definition goal_gui.cpp:156
void OnPaint() override
The window must be repainted.
Definition goal_gui.cpp:232
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition goal_gui.cpp:99
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition goal_gui.cpp:65
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition goal_gui.cpp:267
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Definition goal_gui.cpp:190
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition goal_gui.cpp:42
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 goal_gui.cpp:170
Ask a question about a goal.
Definition goal_gui.cpp:320
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition goal_gui.cpp:379
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 goal_gui.cpp:372
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition goal_gui.cpp:360
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:347
EncodedString question
Question to ask (private copy).
Definition goal_gui.cpp:321
TextColour colour
Colour of the question text.
Definition goal_gui.cpp:323
GoalQuestionWindow(WindowDesc &desc, WindowNumber window_number, TextColour colour, GoalQuestionButtons buttons, const EncodedString &question)
Construct a new Goal Question Window.
Definition goal_gui.cpp:333
GoalQuestionButtons buttons
Buttons to display.
Definition goal_gui.cpp:322
Struct about goals, current and completed.
Definition goal_base.h:22
GoalType type
Type of the goal.
Definition goal_base.h:24
GoalTypeID dst
Index of type.
Definition goal_base.h:25
CompanyID company
Goal is for a specific company; CompanyID::Invalid() if it is global.
Definition goal_base.h:23
Widgets of the goal question window.
Definition goal_gui.cpp:394
static Pool::IterateWrapper< Goal > Iterate(size_t from=0)
static Industry * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
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.
High level window description.
Definition window_gui.h:172
Number to differentiate different windows of the same class.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1109
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1814
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:786
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:562
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:510
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1804
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:316
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:562
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1838
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:989
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:319
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:381
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
Base of the town class.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ 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_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
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ 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.
@ EqualSize
Containers should keep all their (resizing) children equally large.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:155
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:146
@ Center
Center the window.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:21