OpenTTD Source  20241120-master-g6d3adc6169
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"
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 {
35  GC_GOAL = 0,
37 };
38 
40 struct GoalListWindow : public Window {
42 
44  {
45  this->CreateNestedTree();
46  this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
47  this->FinishInitNested(window_number);
48  this->owner = (Owner)this->window_number;
49  NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
51  this->OnInvalidateData(0);
52  }
53 
54  void SetStringParameters(WidgetID widget) const override
55  {
56  if (widget != WID_GOAL_CAPTION) return;
57 
58  if (this->window_number == INVALID_COMPANY) {
59  SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
60  } else {
61  SetDParam(0, STR_GOALS_CAPTION);
62  SetDParam(1, this->window_number);
63  }
64  }
65 
66  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
67  {
68  switch (widget) {
71  break;
72 
75  break;
76 
77  case WID_GOAL_LIST: {
78  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.top);
79  for (const Goal *s : Goal::Iterate()) {
80  if (s->company == this->window_number) {
81  if (y == 0) {
82  this->HandleClick(s);
83  return;
84  }
85  y--;
86  }
87  }
88  break;
89  }
90 
91  default:
92  break;
93  }
94  }
95 
100  void HandleClick(const Goal *s)
101  {
102  /* Determine dst coordinate for goal and try to scroll to it. */
103  TileIndex xy;
104  switch (s->type) {
105  case GT_NONE: return;
106 
107  case GT_COMPANY:
108  /* s->dst here is not a tile, but a CompanyID.
109  * Show the window with the overview of the company instead. */
111  return;
112 
113  case GT_TILE:
114  if (!IsValidTile(s->dst)) return;
115  xy = s->dst;
116  break;
117 
118  case GT_INDUSTRY:
119  if (!Industry::IsValidID(s->dst)) return;
120  xy = Industry::Get(s->dst)->location.tile;
121  break;
122 
123  case GT_TOWN:
124  if (!Town::IsValidID(s->dst)) return;
125  xy = Town::Get(s->dst)->xy;
126  break;
127 
128  case GT_STORY_PAGE: {
129  if (!StoryPage::IsValidID(s->dst)) return;
130 
131  /* Verify that:
132  * - if global goal: story page must be global.
133  * - if company goal: story page must be global or of the same company.
134  */
135  CompanyID goal_company = s->company;
136  CompanyID story_company = StoryPage::Get(s->dst)->company;
137  if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
138 
140  return;
141  }
142 
143  default: NOT_REACHED();
144  }
145 
146  if (_ctrl_pressed) {
148  } else {
150  }
151  }
152 
157  uint CountLines()
158  {
159  /* Count number of (non) awarded goals. */
160  uint num = 0;
161  for (const Goal *s : Goal::Iterate()) {
162  if (s->company == this->window_number) num++;
163  }
164 
165  /* Count the 'none' lines. */
166  if (num == 0) num = 1;
167 
168  return num;
169  }
170 
171  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
172  {
173  if (widget != WID_GOAL_LIST) return;
174  Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
175 
176  resize.width = 1;
177  resize.height = d.height;
178 
179  d.height *= 5;
182  size = maxdim(size, d);
183  }
184 
192  void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
193  {
194  /* Get column draw area. */
195  Rect r = wid->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
196  bool rtl = _current_text_dir == TD_RTL;
197 
198  int pos = -this->vscroll->GetPosition();
199  const int cap = this->vscroll->GetCapacity();
200 
201  uint num = 0;
202  for (const Goal *s : Goal::Iterate()) {
203  if (s->company == this->window_number) {
204  if (IsInsideMM(pos, 0, cap)) {
205  switch (column) {
206  case GC_GOAL: {
207  /* Display the goal. */
208  SetDParamStr(0, s->text);
209  uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0;
210  DrawString(r.Indent(width_reduction, !rtl), STR_GOALS_TEXT);
211  break;
212  }
213 
214  case GC_PROGRESS:
215  if (!s->progress.empty()) {
216  SetDParamStr(0, s->progress);
217  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
218  DrawString(r.WithWidth(progress_col_width, !rtl), str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
219  }
220  break;
221  }
222  r.top += GetCharacterHeight(FS_NORMAL);
223  }
224  pos++;
225  num++;
226  }
227  }
228 
229  if (num == 0) {
230  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
231  DrawString(r, STR_GOALS_NONE);
232  }
233  }
234  }
235 
236  void OnPaint() override
237  {
238  this->DrawWidgets();
239 
240  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
241 
242  /* Calculate progress column width. */
243  uint max_width = 0;
244  for (const Goal *s : Goal::Iterate()) {
245  if (!s->progress.empty()) {
246  SetDParamStr(0, s->progress);
247  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
248  uint str_width = GetStringBoundingBox(str).width;
249  if (str_width > max_width) max_width = str_width;
250  }
251  }
252 
253  NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
254  uint progress_col_width = std::min(max_width, wid->current_x);
255 
256  /* Draw goal list. */
257  this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
258  this->DrawListColumn(GC_GOAL, wid, progress_col_width);
259 
260  }
261 
262  void OnResize() override
263  {
264  this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.Vertical());
265  }
266 
272  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
273  {
274  if (!gui_scope) return;
275  this->vscroll->SetCount(this->CountLines());
279  }
280 };
281 
285  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
286  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING1, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
288  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
289  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
290  EndContainer(),
291  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
292  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
293  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
294  EndContainer(),
296  NWidget(WWT_PANEL, COLOUR_BROWN, WID_GOAL_LIST), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR), SetResize(1, 1), SetMinimalTextLines(2, 0),
297  EndContainer(),
300  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
301  EndContainer(),
302  EndContainer(),
303 };
304 
305 static WindowDesc _goals_list_desc(
306  WDP_AUTO, "list_goals", 500, 127,
308  0,
310 );
311 
317 {
318  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
319 
320  AllocateWindowDescFront<GoalListWindow>(_goals_list_desc, company);
321 }
322 
324 struct GoalQuestionWindow : public Window {
325  std::string question;
326  int buttons;
327  int button[3];
329 
330  GoalQuestionWindow(WindowDesc &desc, WindowNumber window_number, TextColour colour, uint32_t button_mask, const std::string &question) : Window(desc), colour(colour)
331  {
332  this->question = question;
333 
334  /* Figure out which buttons we have to enable. */
335  int n = 0;
336  for (uint bit : SetBitIterator(button_mask)) {
337  if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
338  this->button[n++] = bit;
339  if (n == 3) break;
340  }
341  this->buttons = n;
342  assert(this->buttons < 4);
343 
344  this->CreateNestedTree();
345  if (this->buttons == 0) {
346  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
347  } else {
348  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
349  }
350  this->FinishInitNested(window_number);
351  }
352 
353 
354  void SetStringParameters(WidgetID widget) const override
355  {
356  switch (widget) {
357  case WID_GQ_BUTTON_1:
358  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
359  break;
360 
361  case WID_GQ_BUTTON_2:
362  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
363  break;
364 
365  case WID_GQ_BUTTON_3:
366  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
367  break;
368  }
369  }
370 
371  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
372  {
373  switch (widget) {
374  case WID_GQ_BUTTON_1:
376  this->Close();
377  break;
378 
379  case WID_GQ_BUTTON_2:
381  this->Close();
382  break;
383 
384  case WID_GQ_BUTTON_3:
386  this->Close();
387  break;
388  }
389  }
390 
391  void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
392  {
393  if (widget != WID_GQ_QUESTION) return;
394 
395  SetDParamStr(0, this->question);
396  size.height = GetStringHeight(STR_JUST_RAW_STRING, size.width);
397  }
398 
399  void DrawWidget(const Rect &r, WidgetID widget) const override
400  {
401  if (widget != WID_GQ_QUESTION) return;
402 
403  SetDParamStr(0, this->question);
404  DrawStringMultiLine(r, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
405  }
406 };
407 
414 template <Colours bg_colour, Colours btn_colour, StringID caption>
416  static constexpr auto widgetparts = {
418  NWidget(WWT_CLOSEBOX, bg_colour),
419  NWidget(WWT_CAPTION, bg_colour, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
420  EndContainer(),
421  NWidget(WWT_PANEL, bg_colour),
423  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetFill(1, 0),
424  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
426  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
427  EndContainer(),
429  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
430  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
431  EndContainer(),
433  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_1), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
434  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_2), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
435  NWidget(WWT_PUSHTXTBTN, btn_colour, WID_GQ_BUTTON_3), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
436  EndContainer(),
437  EndContainer(),
438  EndContainer(),
439  EndContainer(),
440  };
441 };
442 
443 static constexpr auto _nested_goal_question_widgets_question = NestedGoalWidgets<COLOUR_LIGHT_BLUE, COLOUR_LIGHT_BLUE, STR_GOAL_QUESTION_CAPTION_QUESTION>::widgetparts;
445 static constexpr auto _nested_goal_question_widgets_warning = NestedGoalWidgets<COLOUR_YELLOW, COLOUR_YELLOW, STR_GOAL_QUESTION_CAPTION_WARNING>::widgetparts;
446 static constexpr auto _nested_goal_question_widgets_error = NestedGoalWidgets<COLOUR_RED, COLOUR_YELLOW, STR_GOAL_QUESTION_CAPTION_ERROR>::widgetparts;
447 
448 static WindowDesc _goal_question_list_desc[] = {
449  {
450  WDP_CENTER, nullptr, 0, 0,
453  _nested_goal_question_widgets_question,
454  },
455  {
456  WDP_CENTER, nullptr, 0, 0,
459  _nested_goal_question_widgets_info,
460  },
461  {
462  WDP_CENTER, nullptr, 0, 0,
465  _nested_goal_question_widgets_warning,
466  },
467  {
468  WDP_CENTER, nullptr, 0, 0,
471  _nested_goal_question_widgets_error,
472  },
473 };
474 
482 void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const std::string &question)
483 {
484  assert(type < GQT_END);
485  new GoalQuestionWindow(_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
486 }
Baseclass for nested widgets.
Definition: widget_type.h:144
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:243
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:498
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1342
Scrollbar data structure.
Definition: widget_type.h:694
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:731
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:780
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:2320
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:2394
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:740
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
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.
Definition: company_cmd.cpp:52
Functions related to companies.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
GUI Functions related to companies.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:77
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:704
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:851
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:657
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
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:774
@ SA_TOP
Top align the text.
Definition: gfx_type.h:348
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:345
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:344
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:355
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:209
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
Goal base class.
Command definitions related to goals.
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:316
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const std::string &question)
Display a goal question.
Definition: goal_gui.cpp:482
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:283
@ GT_INDUSTRY
Destination is an industry.
Definition: goal_type.h:29
@ GT_STORY_PAGE
Destination is a story page.
Definition: goal_type.h:32
@ GT_COMPANY
Destination is a company.
Definition: goal_type.h:31
@ GT_NONE
Destination is not linked.
Definition: goal_type.h:27
@ GT_TILE
Destination is a tile.
Definition: goal_type.h:28
@ GT_TOWN
Destination is a town.
Definition: goal_type.h:30
static const uint32_t GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition: goal_type.h:15
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.
Definition: widget_type.h:1181
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:1260
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1284
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:1228
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1202
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1137
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1309
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1191
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:1149
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1126
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
void ShowStoryBook(CompanyID company, uint16_t page_id=INVALID_STORY_PAGE, bool centered=false)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:1051
Base of all industries.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:357
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Dimensions (a width and height) of a rectangle in 2D.
Window for displaying goals.
Definition: goal_gui.cpp:40
void OnResize() override
Called after the window got resized.
Definition: goal_gui.cpp:262
uint CountLines()
Count the number of lines in this window.
Definition: goal_gui.cpp:157
void OnPaint() override
The window must be repainted.
Definition: goal_gui.cpp:236
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition: goal_gui.cpp:100
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Definition: goal_gui.cpp:192
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition: goal_gui.cpp:41
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: goal_gui.cpp:272
Ask a question about a goal.
Definition: goal_gui.cpp:324
int button[3]
Buttons to display.
Definition: goal_gui.cpp:327
std::string question
Question to ask (private copy).
Definition: goal_gui.cpp:325
int buttons
Number of valid buttons in button.
Definition: goal_gui.cpp:326
TextColour colour
Colour of the question text.
Definition: goal_gui.cpp:328
Struct about goals, current and completed.
Definition: goal_base.h:21
GoalType type
Type of the goal.
Definition: goal_base.h:23
GoalTypeID dst
Index of type.
Definition: goal_base.h:24
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
Definition: goal_base.h:22
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1075
Widgets of the goal question window.
Definition: goal_gui.cpp:415
Coordinates of a point in 2D.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
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:159
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:1047
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1733
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:551
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:1723
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:563
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:314
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:387
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.
Definition: viewport.cpp:2515
Functions related to (drawing on) viewports.
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:482
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:524
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:112
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:77
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:69
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:48
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:65
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:203
@ WDP_CENTER
Center the window.
Definition: window_gui.h:148
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:147
int WidgetID
Widget ID.
Definition: window_type.h:18
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:737
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
Definition: window_type.h:137
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition: window_type.h:290