OpenTTD
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 "date_func.h"
16 #include "viewport_func.h"
17 #include "gui.h"
18 #include "goal_base.h"
19 #include "core/geometry_func.hpp"
20 #include "company_func.h"
21 #include "company_base.h"
22 #include "story_base.h"
23 #include "command_func.h"
24 #include "string_func.h"
25 
26 #include "widgets/goal_widget.h"
27 
28 #include "table/strings.h"
29 
30 #include "safeguards.h"
31 
33 enum GoalColumn {
34  GC_GOAL = 0,
36 };
37 
39 struct GoalListWindow : public Window {
41 
43  {
44  this->CreateNestedTree();
45  this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
46  this->FinishInitNested(window_number);
47  this->owner = (Owner)this->window_number;
48  this->OnInvalidateData(0);
49  }
50 
51  void SetStringParameters(int widget) const override
52  {
53  if (widget != WID_GOAL_CAPTION) return;
54 
55  if (this->window_number == INVALID_COMPANY) {
56  SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
57  } else {
58  SetDParam(0, STR_GOALS_CAPTION);
59  SetDParam(1, this->window_number);
60  }
61  }
62 
63  void OnClick(Point pt, int widget, int click_count) override
64  {
65  if (widget != WID_GOAL_LIST) return;
66 
67  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
68  int num = 0;
69  for (const Goal *s : Goal::Iterate()) {
70  if (s->company == INVALID_COMPANY) {
71  y--;
72  if (y == 0) {
73  this->HandleClick(s);
74  return;
75  }
76  num++;
77  }
78  }
79 
80  if (num == 0) {
81  y--; // "None" line.
82  if (y < 0) return;
83  }
84 
85  y -= 2; // "Company specific goals:" line.
86  if (y < 0) return;
87 
88  for (const Goal *s : Goal::Iterate()) {
89  if (s->company == this->window_number) {
90  y--;
91  if (y == 0) {
92  this->HandleClick(s);
93  return;
94  }
95  }
96  }
97  }
98 
103  void HandleClick(const Goal *s)
104  {
105  /* Determine dst coordinate for goal and try to scroll to it. */
106  TileIndex xy;
107  switch (s->type) {
108  case GT_NONE: return;
109  case GT_COMPANY: return;
110 
111  case GT_TILE:
112  if (!IsValidTile(s->dst)) return;
113  xy = 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 == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
136 
138  return;
139  }
140 
141  default: NOT_REACHED();
142  }
143 
144  if (_ctrl_pressed) {
146  } else {
148  }
149  }
150 
155  uint CountLines()
156  {
157  /* Count number of (non) awarded goals. */
158  uint num_global = 0;
159  uint num_company = 0;
160  for (const Goal *s : Goal::Iterate()) {
161  if (s->company == INVALID_COMPANY) {
162  num_global++;
163  } else if (s->company == this->window_number) {
164  num_company++;
165  }
166  }
167 
168  /* Count the 'none' lines. */
169  if (num_global == 0) num_global = 1;
170  if (num_company == 0) num_company = 1;
171 
172  /* Global, company and an empty line before the accepted ones. */
173  return 3 + num_global + num_company;
174  }
175 
176  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
177  {
178  if (widget != WID_GOAL_LIST) return;
179  Dimension d = maxdim(GetStringBoundingBox(STR_GOALS_GLOBAL_TITLE), GetStringBoundingBox(STR_GOALS_COMPANY_TITLE));
180 
181  resize->height = d.height;
182 
183  d.height *= 5;
184  d.width += padding.width + WD_FRAMERECT_RIGHT + WD_FRAMERECT_LEFT;
185  d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
186  *size = maxdim(*size, d);
187  }
188 
200  void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
201  {
202  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
203  pos++;
204 
205  bool rtl = _current_text_dir == TD_RTL;
206 
207  uint num = 0;
208  for (const Goal *s : Goal::Iterate()) {
209  if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
210  if (IsInsideMM(pos, 0, cap)) {
211  switch (column) {
212  case GC_GOAL: {
213  /* Display the goal. */
214  SetDParamStr(0, s->text);
215  uint width_reduction = progress_col_width > 0 ? progress_col_width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT : 0;
216  DrawString(x + (rtl ? width_reduction : 0), right - (rtl ? 0 : width_reduction), y + pos * FONT_HEIGHT_NORMAL, STR_GOALS_TEXT);
217  break;
218  }
219 
220  case GC_PROGRESS:
221  if (s->progress != nullptr) {
222  SetDParamStr(0, s->progress);
223  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
224  int progress_x = x;
225  int progress_right = rtl ? x + progress_col_width : right;
226  DrawString(progress_x, progress_right, y + pos * FONT_HEIGHT_NORMAL, str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
227  }
228  break;
229  }
230  }
231  pos++;
232  num++;
233  }
234  }
235 
236  if (num == 0) {
237  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
238  StringID str = !global_section && this->window_number == INVALID_COMPANY ? STR_GOALS_SPECTATOR_NONE : STR_GOALS_NONE;
239  DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, str);
240  }
241  pos++;
242  }
243  }
244 
252  void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
253  {
254  /* Get column draw area. */
255  int y = wid->pos_y + WD_FRAMERECT_TOP;
256  int x = wid->pos_x + WD_FRAMERECT_LEFT;
257  int right = x + wid->current_x - WD_FRAMERECT_RIGHT;
258 
259  int pos = -this->vscroll->GetPosition();
260  const int cap = this->vscroll->GetCapacity();
261 
262  /* Draw partial list with global goals. */
263  DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, true, column);
264 
265  /* Draw partial list with company goals. */
266  pos++;
267  DrawPartialGoalList(pos, cap, x, y, right, progress_col_width, false, column);
268  }
269 
270  void OnPaint() override
271  {
272  this->DrawWidgets();
273 
274  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
275 
276  /* Calculate progress column width. */
277  uint max_width = 0;
278  for (const Goal *s : Goal::Iterate()) {
279  if (s->progress != nullptr) {
280  SetDParamStr(0, s->progress);
281  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
282  uint str_width = GetStringBoundingBox(str).width;
283  if (str_width > max_width) max_width = str_width;
284  }
285  }
286 
287  NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
288  uint progress_col_width = min(max_width, wid->current_x);
289 
290  /* Draw goal list. */
291  this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
292  this->DrawListColumn(GC_GOAL, wid, progress_col_width);
293 
294  }
295 
296  void OnResize() override
297  {
298  this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST);
299  }
300 
306  void OnInvalidateData(int data = 0, bool gui_scope = true) override
307  {
308  if (!gui_scope) return;
309  this->vscroll->SetCount(this->CountLines());
311  }
312 };
313 
317  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
318  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
319  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
320  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
321  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
322  EndContainer(),
324  NWidget(WWT_PANEL, COLOUR_BROWN), SetDataTip(0x0, STR_GOALS_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetScrollbar(WID_GOAL_SCROLLBAR),
326  EndContainer(),
329  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
330  EndContainer(),
331  EndContainer(),
332 };
333 
334 static WindowDesc _goals_list_desc(
335  WDP_AUTO, "list_goals", 500, 127,
337  0,
338  _nested_goals_list_widgets, lengthof(_nested_goals_list_widgets)
339 );
340 
346 {
347  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
348 
349  AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
350 }
351 
353 struct GoalQuestionWindow : public Window {
354  char *question;
355  int buttons;
356  int button[3];
357  byte type;
358 
359  GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, byte type, uint32 button_mask, const char *question) : Window(desc), type(type)
360  {
361  assert(type < GOAL_QUESTION_TYPE_COUNT);
362  this->question = stredup(question);
363 
364  /* Figure out which buttons we have to enable. */
365  uint bit;
366  int n = 0;
367  FOR_EACH_SET_BIT(bit, button_mask) {
368  if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
369  this->button[n++] = bit;
370  if (n == 3) break;
371  }
372  this->buttons = n;
373  assert(this->buttons > 0 && this->buttons < 4);
374 
375  this->CreateNestedTree();
376  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
377  this->FinishInitNested(window_number);
378  }
379 
381  {
382  free(this->question);
383  }
384 
385  void SetStringParameters(int widget) const override
386  {
387  switch (widget) {
388  case WID_GQ_CAPTION:
389  SetDParam(0, STR_GOAL_QUESTION_CAPTION_QUESTION + this->type);
390  break;
391 
392  case WID_GQ_BUTTON_1:
393  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
394  break;
395 
396  case WID_GQ_BUTTON_2:
397  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
398  break;
399 
400  case WID_GQ_BUTTON_3:
401  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
402  break;
403  }
404  }
405 
406  void OnClick(Point pt, int widget, int click_count) override
407  {
408  switch (widget) {
409  case WID_GQ_BUTTON_1:
410  DoCommandP(0, this->window_number, this->button[0], CMD_GOAL_QUESTION_ANSWER);
411  delete this;
412  break;
413 
414  case WID_GQ_BUTTON_2:
415  DoCommandP(0, this->window_number, this->button[1], CMD_GOAL_QUESTION_ANSWER);
416  delete this;
417  break;
418 
419  case WID_GQ_BUTTON_3:
420  DoCommandP(0, this->window_number, this->button[2], CMD_GOAL_QUESTION_ANSWER);
421  delete this;
422  break;
423  }
424  }
425 
426  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
427  {
428  if (widget != WID_GQ_QUESTION) return;
429 
430  SetDParamStr(0, this->question);
431  size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WD_PAR_VSEP_WIDE;
432  }
433 
434  void DrawWidget(const Rect &r, int widget) const override
435  {
436  if (widget != WID_GQ_QUESTION) return;
437 
438  SetDParamStr(0, this->question);
439  DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK, SA_TOP | SA_HOR_CENTER);
440  }
441 };
442 
446  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
447  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
448  EndContainer(),
449  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
450  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
451  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
453  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
454  EndContainer(),
456  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
457  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
458  EndContainer(),
460  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
461  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
462  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
463  EndContainer(),
464  EndContainer(),
466  EndContainer(),
467 };
468 
469 static WindowDesc _goal_question_list_desc(
470  WDP_CENTER, nullptr, 0, 0,
473  _nested_goal_question_widgets, lengthof(_nested_goal_question_widgets)
474 );
475 
483 void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
484 {
485  new GoalQuestionWindow(&_goal_question_list_desc, id, type, button_mask, question);
486 }
Functions related to OTTD&#39;s strings.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
Destination is an industry.
Definition: goal_type.h:22
Definition of stuff that is very close to a company, like the company struct itself.
Horizontally center the text.
Definition: gfx_func.h:95
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
Caption of the window.
Definition: goal_widget.h:16
Buttons selection (between 1, 2 or 3).
Definition: goal_widget.h:25
High level window description.
Definition: window_gui.h:166
Goal progress column.
Definition: goal_gui.cpp:35
static const NWidgetPart _nested_goal_question_widgets[]
Widgets of the goal question window.
Definition: goal_gui.cpp:444
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
Functions related to dates.
Scrollbar data structure.
Definition: widget_type.h:587
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
Horizontal container.
Definition: widget_type.h:73
Popup with a set of buttons, designed to ask the user a question from a GameScript.
Definition: window_type.h:130
void DrawPartialGoalList(int &pos, const int cap, int x, int y, int right, uint progress_col_width, bool global_section, GoalColumn column) const
Draws either the global goals or the company goal section.
Definition: goal_gui.cpp:200
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:385
char * question
Question to ask (private copy).
Definition: goal_gui.cpp:354
Window for displaying goals.
Definition: goal_gui.cpp:39
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
Struct about goals, current and completed.
Definition: goal_base.h:21
Goals list; Window numbers:
Definition: window_type.h:283
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:345
Third button.
Definition: goal_widget.h:28
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:547
Close box (at top-left of a window)
Definition: widget_type.h:67
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:963
Ask a question about a goal.
Definition: goal_gui.cpp:353
First button.
Definition: goal_widget.h:26
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
byte type
Type of question.
Definition: goal_gui.cpp:357
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1828
void UpdateWidgetSize(int 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:426
Large amount of vertical space between two paragraphs of text.
Definition: window_gui.h:138
void OnResize() override
Called after the window got resized.
Definition: goal_gui.cpp:296
Functions, definitions and such used only by the GUI.
Caption of the window.
Definition: goal_widget.h:23
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:668
Force the alignment, i.e. don&#39;t swap for RTL languages.
Definition: gfx_func.h:106
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Functions related to (drawing on) viewports.
GoalTypeID dst
Index of type.
Definition: goal_base.h:24
Data structure for an opened window.
Definition: window_gui.h:276
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1844
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1044
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:264
Destination is a tile.
Definition: goal_type.h:21
void UpdateWidgetSize(int 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:176
Bottom offset of the text of the frame.
Definition: window_gui.h:73
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
Functions related to low-level strings.
Invisible widget that takes some space.
Definition: widget_type.h:77
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1957
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
Destination is a town.
Definition: goal_type.h:23
Definition of base types and functions in a cross-platform compatible way.
Top align the text.
Definition: gfx_func.h:99
static const NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
Definition: goal_gui.cpp:315
A number of safeguards to prevent using unsafe methods.
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
Geometry functions.
Simple depressed panel.
Definition: widget_type.h:48
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:136
Goal list.
Definition: goal_widget.h:17
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
Center the window.
Definition: window_gui.h:155
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
Baseclass for nested widgets.
Definition: widget_type.h:124
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:498
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: goal_gui.cpp:306
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:406
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Destination is not linked.
Definition: goal_type.h:20
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition: goal_gui.cpp:40
void OnPaint() override
The window must be repainted.
Definition: goal_gui.cpp:270
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
Functions related to companies.
Scrollbar of the goal list.
Definition: goal_widget.h:18
An invalid company.
Definition: company_type.h:30
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Types related to the goal widgets.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
Vertical container.
Definition: widget_type.h:75
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
Display a goal question.
Definition: goal_gui.cpp:483
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
Second button.
Definition: goal_widget.h:27
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
Goal base class.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2396
Functions related to commands.
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:750
Coordinates of a point in 2D.
Destination is a company.
Definition: goal_type.h:24
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
Destination is a story page.
Definition: goal_type.h:25
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:620
uint CountLines()
Count the number of lines in this window.
Definition: goal_gui.cpp:155
Goal text column.
Definition: goal_gui.cpp:34
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition: goal_gui.cpp:103
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:324
StoryPage base class.
Base of all industries.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
Definition: goal_base.h:22
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
static const uint32 GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition: goal_type.h:15
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: goal_gui.cpp:63
GoalColumn
Goal list columns.
Definition: goal_gui.cpp:33
Base of the town class.
answer(s) to CMD_GOAL_QUESTION
Definition: command_type.h:286
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:705
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1971
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:82
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:524
Text is written right-to-left by default.
Definition: strings_type.h:24
Right align the text (must be a single bit).
Definition: gfx_func.h:96
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
static const byte GOAL_QUESTION_TYPE_COUNT
Amount of question types.
Definition: goal_type.h:16
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:51
Find a place automatically.
Definition: window_gui.h:154
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
GUI functions that shouldn&#39;t be here.
int buttons
Number of valid buttons in button.
Definition: goal_gui.cpp:355
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: goal_gui.cpp:434
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1093
Question text.
Definition: goal_widget.h:24
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
GoalType type
Type of the goal.
Definition: goal_base.h:23
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:621
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:629
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Definition: goal_gui.cpp:252