OpenTTD Source 20250924-master-gbec4e71d53
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 <http://www.gnu.org/licenses/>.
6 */
7
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"
19#include "company_func.h"
20#include "company_base.h"
21#include "company_gui.h"
22#include "story_base.h"
23#include "command_func.h"
24#include "string_func.h"
25#include "goal_cmd.h"
26
27#include "widgets/goal_widget.h"
28
29#include "table/strings.h"
30
31#include "safeguards.h"
32
34enum GoalColumn : uint8_t {
35 GC_GOAL = 0,
37};
38
40struct GoalListWindow : public Window {
41 Scrollbar *vscroll = nullptr;
42
44 {
45 this->CreateNestedTree();
46 this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
47 this->FinishInitNested(window_number);
48 this->owner = this->window_number;
49 NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
50 wi->SetDisplayedPlane(window_number == CompanyID::Invalid() ? 1 : 0);
51 this->OnInvalidateData(0);
52 }
53
54 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
55 {
56 if (widget != WID_GOAL_CAPTION) return this->Window::GetWidgetString(widget, stringid);
57
58 if (this->window_number == CompanyID::Invalid()) {
59 return GetString(STR_GOALS_SPECTATOR_CAPTION);
60 }
61 return GetString(STR_GOALS_CAPTION, this->window_number);
62 }
63
64 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
65 {
66 switch (widget) {
68 ShowGoalsList(CompanyID::Invalid());
69 break;
70
73 break;
74
75 case WID_GOAL_LIST: {
76 int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.top);
77 for (const Goal *s : Goal::Iterate()) {
78 if (s->company == this->window_number) {
79 if (y == 0) {
80 this->HandleClick(s);
81 return;
82 }
83 y--;
84 }
85 }
86 break;
87 }
88
89 default:
90 break;
91 }
92 }
93
98 void HandleClick(const Goal *s)
99 {
100 /* Determine dst coordinate for goal and try to scroll to it. */
101 TileIndex xy;
102 switch (s->type) {
103 case GT_NONE: return;
104
105 case GT_COMPANY:
106 /* s->dst here is not a tile, but a CompanyID.
107 * Show the window with the overview of the company instead. */
109 return;
110
111 case GT_TILE:
112 if (!IsValidTile(s->dst)) return;
113 xy = TileIndex{s->dst};
114 break;
115
116 case GT_INDUSTRY:
117 if (!Industry::IsValidID(s->dst)) return;
118 xy = Industry::Get(s->dst)->location.tile;
119 break;
120
121 case GT_TOWN:
122 if (!Town::IsValidID(s->dst)) return;
123 xy = Town::Get(s->dst)->xy;
124 break;
125
126 case GT_STORY_PAGE: {
127 if (!StoryPage::IsValidID(s->dst)) return;
128
129 /* Verify that:
130 * - if global goal: story page must be global.
131 * - if company goal: story page must be global or of the same company.
132 */
133 CompanyID goal_company = s->company;
134 CompanyID story_company = StoryPage::Get(s->dst)->company;
135 if (goal_company == CompanyID::Invalid() ? story_company != CompanyID::Invalid() : story_company != CompanyID::Invalid() && story_company != goal_company) return;
136
137 ShowStoryBook(static_cast<CompanyID>(this->window_number), static_cast<StoryPageID>(s->dst));
138 return;
139 }
140
141 default: NOT_REACHED();
142 }
143
144 if (_ctrl_pressed) {
146 } else {
148 }
149 }
150
156 {
157 /* Count number of (non) awarded goals. */
158 uint num = 0;
159 for (const Goal *s : Goal::Iterate()) {
160 if (s->company == this->window_number) num++;
161 }
162
163 /* Count the 'none' lines. */
164 if (num == 0) num = 1;
165
166 return num;
167 }
168
169 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
170 {
171 if (widget != WID_GOAL_LIST) return;
172 Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
173
174 resize.width = 1;
175 fill.height = resize.height = d.height;
176
177 d.height *= 5;
180 size = maxdim(size, d);
181 }
182
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()), TC_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
248 NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
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
280 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
281 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION),
283 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetStringTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
284 NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetStringTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
285 EndContainer(),
286 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
287 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
288 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
289 EndContainer(),
291 NWidget(WWT_PANEL, COLOUR_BROWN, WID_GOAL_LIST), SetToolTip(STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR), SetResize(1, 1), SetMinimalTextLines(2, 0),
292 EndContainer(),
295 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
296 EndContainer(),
297 EndContainer(),
298};
299
300static WindowDesc _goals_list_desc(
301 WDP_AUTO, "list_goals", 500, 127,
303 {},
305);
306
312{
313 if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid();
314
315 AllocateWindowDescFront<GoalListWindow>(_goals_list_desc, company);
316}
317
319struct GoalQuestionWindow : public Window {
321 int buttons = 0;
322 std::array<int, 3> button{};
324
326 {
327 this->question = question;
328
329 /* Figure out which buttons we have to enable. */
330 int n = 0;
331 for (uint bit : SetBitIterator(button_mask)) {
332 if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
333 this->button[n++] = bit;
334 if (n == 3) break;
335 }
336 this->buttons = n;
337 assert(this->buttons < 4);
338
339 this->CreateNestedTree();
340 if (this->buttons == 0) {
341 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
342 } else {
343 this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
344 }
345 this->FinishInitNested(window_number);
346 }
347
348
349 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
350 {
351 switch (widget) {
352 case WID_GQ_BUTTON_1:
353 return GetString(STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
354
355 case WID_GQ_BUTTON_2:
356 return GetString(STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
357
358 case WID_GQ_BUTTON_3:
359 return GetString(STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
360
361 default:
362 return this->Window::GetWidgetString(widget, stringid);
363 }
364 }
365
366 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
367 {
368 switch (widget) {
369 case WID_GQ_BUTTON_1:
370 Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[0]);
371 this->Close();
372 break;
373
374 case WID_GQ_BUTTON_2:
375 Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[1]);
376 this->Close();
377 break;
378
379 case WID_GQ_BUTTON_3:
380 Command<CMD_GOAL_QUESTION_ANSWER>::Post(this->window_number, this->button[2]);
381 this->Close();
382 break;
383 }
384 }
385
386 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
387 {
388 if (widget != WID_GQ_QUESTION) return;
389
390 size.height = GetStringHeight(this->question.GetDecodedString(), size.width);
391 }
392
393 void DrawWidget(const Rect &r, WidgetID widget) const override
394 {
395 if (widget != WID_GQ_QUESTION) return;
396
397 DrawStringMultiLine(r, this->question.GetDecodedString(), this->colour, SA_TOP | SA_HOR_CENTER);
398 }
399};
400
407template <Colours bg_colour, Colours btn_colour, StringID caption>
409 static constexpr auto widgetparts = {
411 NWidget(WWT_CLOSEBOX, bg_colour),
412 NWidget(WWT_CAPTION, bg_colour, WID_GQ_CAPTION), SetStringTip(caption, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
413 EndContainer(),
414 NWidget(WWT_PANEL, bg_colour),
416 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
417 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
419 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
420 EndContainer(),
422 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
423 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetFill(1, 0),
424 EndContainer(),
426 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
427 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetFill(1, 0),
428 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_3), SetFill(1, 0),
429 EndContainer(),
430 EndContainer(),
431 EndContainer(),
432 EndContainer(),
433 };
434};
435
438static constexpr auto _nested_goal_question_widgets_warning = NestedGoalWidgets<COLOUR_YELLOW, COLOUR_YELLOW, STR_GOAL_QUESTION_CAPTION_WARNING>::widgetparts;
439static constexpr auto _nested_goal_question_widgets_error = NestedGoalWidgets<COLOUR_RED, COLOUR_YELLOW, STR_GOAL_QUESTION_CAPTION_ERROR>::widgetparts;
440
441static WindowDesc _goal_question_list_desc[] = {
442 {
443 WDP_CENTER, {}, 0, 0,
446 _nested_goal_question_widgets_question,
447 },
448 {
449 WDP_CENTER, {}, 0, 0,
452 _nested_goal_question_widgets_info,
453 },
454 {
455 WDP_CENTER, {}, 0, 0,
458 _nested_goal_question_widgets_warning,
459 },
460 {
461 WDP_CENTER, {}, 0, 0,
464 _nested_goal_question_widgets_error,
465 },
466};
467
475void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question)
476{
477 assert(type < GQT_END);
478 new GoalQuestionWindow(_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
479}
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:1420
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:2423
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:2497
size_type GetPosition() const
Gets the position of the first visible element in the list.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
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:93
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.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
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:713
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:895
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:666
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:783
@ FS_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:393
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
Goal base class.
Command definitions related to goals.
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question)
Display a goal question.
Definition goal_gui.cpp:475
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition goal_gui.cpp:311
GoalColumn
Goal list columns.
Definition goal_gui.cpp:34
@ GC_PROGRESS
Goal progress column.
Definition goal_gui.cpp:36
@ GC_GOAL
Goal text column.
Definition goal_gui.cpp:35
static constexpr NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
Definition goal_gui.cpp:278
@ GT_INDUSTRY
Destination is an industry.
Definition goal_type.h:30
@ GT_STORY_PAGE
Destination is a story page.
Definition goal_type.h:33
@ GT_COMPANY
Destination is a company.
Definition goal_type.h:32
@ GT_NONE
Destination is not linked.
Definition goal_type.h:28
@ GT_TILE
Destination is a tile.
Definition goal_type.h:29
@ GT_TOWN
Destination is a town.
Definition goal_type.h:31
static const uint32_t GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition goal_type.h:16
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 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 SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
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.
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.
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.
Window for displaying goals.
Definition goal_gui.cpp:40
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:54
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:155
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:98
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:64
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:41
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:169
Ask a question about a goal.
Definition goal_gui.cpp:319
std::array< int, 3 > button
Buttons to display.
Definition goal_gui.cpp:322
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition goal_gui.cpp:393
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:386
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:366
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:349
int buttons
Number of valid buttons in button.
Definition goal_gui.cpp:321
EncodedString question
Question to ask (private copy).
Definition goal_gui.cpp:320
TextColour colour
Colour of the question text.
Definition goal_gui.cpp:323
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
Partial widget specification to allow NWidgets to be written nested.
Widgets of the goal question window.
Definition goal_gui.cpp:408
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
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.
Iterable ensemble of each set bit in a value.
High level window description.
Definition window_gui.h:167
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:273
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1102
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1789
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:764
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
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:1779
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:559
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
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
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:67
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:58
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:53
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:77
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:69
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:61
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:60
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:57
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:72
@ 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.
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
@ WC_GOALS_LIST
Goals list; Window numbers: