OpenTTD Source: src/goal_gui.cpp Source File

OpenTTD Source 15.3

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
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 "core/geometry_func.hpp"
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
34 enum GoalColumn : uint8_t {
35 GC_GOAL = 0,
36 GC_PROGRESS,
37};
38
40 struct GoalListWindow : public Window {
41 Scrollbar *vscroll = nullptr;
42
43 GoalListWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
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) {
67 case WID_GOAL_GLOBAL_BUTTON:
68 ShowGoalsList(CompanyID::Invalid());
69 break;
70
71 case WID_GOAL_COMPANY_BUTTON:
72 ShowGoalsList(_local_company);
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. */
108 ShowCompany((CompanyID)s->dst);
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) {
145 ShowExtraViewportWindow(xy);
146 } else {
147 ScrollMainWindowToTile(xy);
148 }
149 }
150
155 uint CountLines()
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;
178 d.width += WidgetDimensions::scaled.framerect.Horizontal();
179 d.height += WidgetDimensions::scaled.framerect.Vertical();
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 }
218 r.top += GetCharacterHeight(FS_NORMAL);
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());
271 this->SetWidgetDisabledState(WID_GOAL_COMPANY_BUTTON, _local_company == COMPANY_SPECTATOR);
272 this->SetWidgetDirty(WID_GOAL_COMPANY_BUTTON);
273 this->SetWidgetDirty(WID_GOAL_LIST);
274 }
275};
276
278 static constexpr std::initializer_list<NWidgetPart> _nested_goals_list_widgets = {
279 NWidget(NWID_HORIZONTAL),
280 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
281 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION),
282 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GOAL_SELECT_BUTTONS),
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(),
290 NWidget(NWID_HORIZONTAL),
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(),
293 NWidget(NWID_VERTICAL),
294 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_GOAL_SCROLLBAR),
295 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
296 EndContainer(),
297 EndContainer(),
298};
299
300static WindowDesc _goals_list_desc(
301 WDP_AUTO, "list_goals", 500, 127,
302 WC_GOALS_LIST, WC_NONE,
303 {},
304 _nested_goals_list_widgets
305);
306
311 void ShowGoalsList(CompanyID company)
312{
313 if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid();
314
315 AllocateWindowDescFront<GoalListWindow>(_goals_list_desc, company);
316}
317
319 struct GoalQuestionWindow : public Window {
320 EncodedString question{};
321 int buttons = 0;
322 std::array<int, 3> button{};
323 TextColour colour{};
324
325 GoalQuestionWindow(WindowDesc &desc, WindowNumber window_number, TextColour colour, uint32_t button_mask, const EncodedString &question) : Window(desc), colour(colour)
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>
408 struct NestedGoalWidgets {
409 static constexpr auto widgetparts = {
410 NWidget(NWID_HORIZONTAL),
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),
415 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.modalpopup), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
416 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
417 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
418 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(85, WidgetDimensions::unscaled.hsep_wide, 85),
419 NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetFill(1, 0),
420 EndContainer(),
421 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(65, WidgetDimensions::unscaled.hsep_wide, 65),
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(),
425 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize), SetPIP(25, WidgetDimensions::unscaled.hsep_wide, 25),
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
436static constexpr auto _nested_goal_question_widgets_question = NestedGoalWidgets<COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE, STR_GOAL_QUESTION_CAPTION_QUESTION>::widgetparts;
437static constexpr auto _nested_goal_question_widgets_info = NestedGoalWidgets<COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE, STR_GOAL_QUESTION_CAPTION_INFORMATION>::widgetparts;
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,
444 WC_GOAL_QUESTION, WC_NONE,
445 WindowDefaultFlag::Construction,
446 _nested_goal_question_widgets_question,
447 },
448 {
449 WDP_CENTER, {}, 0, 0,
450 WC_GOAL_QUESTION, WC_NONE,
451 WindowDefaultFlag::Construction,
452 _nested_goal_question_widgets_info,
453 },
454 {
455 WDP_CENTER, {}, 0, 0,
456 WC_GOAL_QUESTION, WC_NONE,
457 WindowDefaultFlag::Construction,
458 _nested_goal_question_widgets_warning,
459 },
460 {
461 WDP_CENTER, {}, 0, 0,
462 WC_GOAL_QUESTION, WC_NONE,
463 WindowDefaultFlag::Construction,
464 _nested_goal_question_widgets_error,
465 },
466};
467
475 void 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}
EncodedString
Container for an encoded string, created by GetEncodedString.
Definition strings_type.h:98
EncodedString::GetDecodedString
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:207
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:137
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition widget_type.h:238
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition widget_type.h:524
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition widget.cpp:1450
Scrollbar
Scrollbar data structure.
Definition widget_type.h:711
Scrollbar::GetCapacity
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition widget_type.h:746
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:795
Scrollbar::GetScrolledRowFromWidget
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2453
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2527
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:755
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
command_func.h
Functions related to commands.
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
company_func.h
Functions related to companies.
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition company_gui.cpp:2307
company_gui.h
GUI Functions related to companies.
COMPANY_SPECTATOR
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
Definition company_type.h:21
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:715
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:897
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:668
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:785
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_TOP
@ SA_TOP
Top align the text.
Definition gfx_type.h:393
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition gfx_type.h:400
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
goal_base.h
Goal base class.
goal_cmd.h
Command definitions related to goals.
ShowGoalQuestion
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question)
Display a goal question.
Definition goal_gui.cpp:475
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition goal_gui.cpp:311
GoalColumn
GoalColumn
Goal list columns.
Definition goal_gui.cpp:34
GC_PROGRESS
@ GC_PROGRESS
Goal progress column.
Definition goal_gui.cpp:36
GC_GOAL
@ GC_GOAL
Goal text column.
Definition goal_gui.cpp:35
_nested_goals_list_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_goals_list_widgets
Widgets of the GoalListWindow.
Definition goal_gui.cpp:278
GT_INDUSTRY
@ GT_INDUSTRY
Destination is an industry.
Definition goal_type.h:29
GT_STORY_PAGE
@ GT_STORY_PAGE
Destination is a story page.
Definition goal_type.h:32
GT_COMPANY
@ GT_COMPANY
Destination is a company.
Definition goal_type.h:31
GT_NONE
@ GT_NONE
Destination is not linked.
Definition goal_type.h:27
GT_TILE
@ GT_TILE
Destination is a tile.
Definition goal_type.h:28
GT_TOWN
@ GT_TOWN
Destination is a town.
Definition goal_type.h:30
GOAL_QUESTION_BUTTON_COUNT
static const uint32_t GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition goal_type.h:15
goal_widget.h
Types related to the goal widgets.
WID_GQ_BUTTON_1
@ WID_GQ_BUTTON_1
First button.
Definition goal_widget.h:29
WID_GQ_QUESTION
@ WID_GQ_QUESTION
Question text.
Definition goal_widget.h:27
WID_GQ_BUTTON_2
@ WID_GQ_BUTTON_2
Second button.
Definition goal_widget.h:30
WID_GQ_CAPTION
@ WID_GQ_CAPTION
Caption of the window.
Definition goal_widget.h:26
WID_GQ_BUTTON_3
@ WID_GQ_BUTTON_3
Third button.
Definition goal_widget.h:31
WID_GQ_BUTTONS
@ WID_GQ_BUTTONS
Buttons selection (between 1, 2 or 3).
Definition goal_widget.h:28
WID_GOAL_COMPANY_BUTTON
@ WID_GOAL_COMPANY_BUTTON
Button to show company goals.
Definition goal_widget.h:19
WID_GOAL_CAPTION
@ WID_GOAL_CAPTION
Caption of the window.
Definition goal_widget.h:16
WID_GOAL_SCROLLBAR
@ WID_GOAL_SCROLLBAR
Scrollbar of the goal list.
Definition goal_widget.h:21
WID_GOAL_SELECT_BUTTONS
@ WID_GOAL_SELECT_BUTTONS
Selection widget for the title bar button.
Definition goal_widget.h:17
WID_GOAL_GLOBAL_BUTTON
@ WID_GOAL_GLOBAL_BUTTON
Button to show global goals.
Definition goal_widget.h:18
WID_GOAL_LIST
@ WID_GOAL_LIST
Goal list.
Definition goal_widget.h:20
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1222
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1378
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1402
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1335
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1243
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1159
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1321
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1232
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1427
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1190
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1148
gui.h
GUI functions that shouldn't be here.
ShowStoryBook
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.
Definition story_gui.cpp:1043
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition viewport_gui.cpp:159
industry.h
Base of all industries.
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
story_base.h
StoryPage base class.
string_func.h
Functions related to low-level strings.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:27
CommandHelper
Definition command_func.h:84
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
GoalListWindow
Window for displaying goals.
Definition goal_gui.cpp:40
GoalListWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:54
GoalListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition goal_gui.cpp:257
GoalListWindow::CountLines
uint CountLines()
Count the number of lines in this window.
Definition goal_gui.cpp:155
GoalListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition goal_gui.cpp:232
GoalListWindow::HandleClick
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition goal_gui.cpp:98
GoalListWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition goal_gui.cpp:64
GoalListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition goal_gui.cpp:267
GoalListWindow::DrawListColumn
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Definition goal_gui.cpp:190
GoalListWindow::vscroll
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition goal_gui.cpp:41
GoalListWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition goal_gui.cpp:169
GoalQuestionWindow
Ask a question about a goal.
Definition goal_gui.cpp:319
GoalQuestionWindow::button
std::array< int, 3 > button
Buttons to display.
Definition goal_gui.cpp:322
GoalQuestionWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition goal_gui.cpp:393
GoalQuestionWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition goal_gui.cpp:386
GoalQuestionWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition goal_gui.cpp:366
GoalQuestionWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition goal_gui.cpp:349
GoalQuestionWindow::buttons
int buttons
Number of valid buttons in button.
Definition goal_gui.cpp:321
GoalQuestionWindow::question
EncodedString question
Question to ask (private copy).
Definition goal_gui.cpp:320
GoalQuestionWindow::colour
TextColour colour
Colour of the question text.
Definition goal_gui.cpp:323
Goal
Struct about goals, current and completed.
Definition goal_base.h:22
Goal::type
GoalType type
Type of the goal.
Definition goal_base.h:24
Goal::dst
GoalTypeID dst
Index of type.
Definition goal_base.h:25
Goal::company
CompanyID company
Goal is for a specific company; CompanyID::Invalid() if it is global.
Definition goal_base.h:23
NestedGoalWidgets
Widgets of the goal question window.
Definition goal_gui.cpp:408
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem<&_goal_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_industry_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:89
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:211
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:224
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:277
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1104
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1809
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:784
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:558
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:506
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1799
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition window_gui.h:317
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:560
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:315
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
town.h
Base of the town class.
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2592
viewport_func.h
Functions related to (drawing on) viewports.
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:105
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:508
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:544
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
WC_GOAL_QUESTION
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
Definition window_type.h:142
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_GOALS_LIST
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition window_type.h:295