OpenTTD Source  13.2.1
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 "company_gui.h"
23 #include "story_base.h"
24 #include "command_func.h"
25 #include "string_func.h"
26 #include "goal_cmd.h"
27 
28 #include "widgets/goal_widget.h"
29 
30 #include "table/strings.h"
31 
32 #include "safeguards.h"
33 
35 enum GoalColumn {
36  GC_GOAL = 0,
38 };
39 
41 struct GoalListWindow : public Window {
43 
45  {
46  this->CreateNestedTree();
47  this->vscroll = this->GetScrollbar(WID_GOAL_SCROLLBAR);
48  this->FinishInitNested(window_number);
49  this->owner = (Owner)this->window_number;
50  NWidgetStacked *wi = this->GetWidget<NWidgetStacked>(WID_GOAL_SELECT_BUTTONS);
52  this->OnInvalidateData(0);
53  }
54 
55  void SetStringParameters(int widget) const override
56  {
57  if (widget != WID_GOAL_CAPTION) return;
58 
59  if (this->window_number == INVALID_COMPANY) {
60  SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
61  } else {
62  SetDParam(0, STR_GOALS_CAPTION);
63  SetDParam(1, this->window_number);
64  }
65  }
66 
67  void OnClick(Point pt, int widget, int click_count) override
68  {
69  switch (widget) {
72  break;
73 
76  break;
77 
78  case WID_GOAL_LIST: {
79  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.top);
80  for (const Goal *s : Goal::Iterate()) {
81  if (s->company == this->window_number) {
82  if (y == 0) {
83  this->HandleClick(s);
84  return;
85  }
86  y--;
87  }
88  }
89  break;
90  }
91 
92  default:
93  break;
94  }
95  }
96 
101  void HandleClick(const Goal *s)
102  {
103  /* Determine dst coordinate for goal and try to scroll to it. */
104  TileIndex xy;
105  switch (s->type) {
106  case GT_NONE: return;
107 
108  case GT_COMPANY:
109  /* s->dst here is not a tile, but a CompanyID.
110  * Show the window with the overview of the company instead. */
112  return;
113 
114  case GT_TILE:
115  if (!IsValidTile(s->dst)) return;
116  xy = s->dst;
117  break;
118 
119  case GT_INDUSTRY:
120  if (!Industry::IsValidID(s->dst)) return;
121  xy = Industry::Get(s->dst)->location.tile;
122  break;
123 
124  case GT_TOWN:
125  if (!Town::IsValidID(s->dst)) return;
126  xy = Town::Get(s->dst)->xy;
127  break;
128 
129  case GT_STORY_PAGE: {
130  if (!StoryPage::IsValidID(s->dst)) return;
131 
132  /* Verify that:
133  * - if global goal: story page must be global.
134  * - if company goal: story page must be global or of the same company.
135  */
136  CompanyID goal_company = s->company;
137  CompanyID story_company = StoryPage::Get(s->dst)->company;
138  if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return;
139 
141  return;
142  }
143 
144  default: NOT_REACHED();
145  }
146 
147  if (_ctrl_pressed) {
149  } else {
151  }
152  }
153 
158  uint CountLines()
159  {
160  /* Count number of (non) awarded goals. */
161  uint num = 0;
162  for (const Goal *s : Goal::Iterate()) {
163  if (s->company == this->window_number) num++;
164  }
165 
166  /* Count the 'none' lines. */
167  if (num == 0) num = 1;
168 
169  return num;
170  }
171 
172  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
173  {
174  if (widget != WID_GOAL_LIST) return;
175  Dimension d = GetStringBoundingBox(STR_GOALS_NONE);
176 
177  resize->width = 1;
178  resize->height = d.height;
179 
180  d.height *= 5;
183  *size = maxdim(*size, d);
184  }
185 
193  void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
194  {
195  /* Get column draw area. */
196  Rect r = wid->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
197  bool rtl = _current_text_dir == TD_RTL;
198 
199  int pos = -this->vscroll->GetPosition();
200  const int cap = this->vscroll->GetCapacity();
201 
202  uint num = 0;
203  for (const Goal *s : Goal::Iterate()) {
204  if (s->company == this->window_number) {
205  if (IsInsideMM(pos, 0, cap)) {
206  switch (column) {
207  case GC_GOAL: {
208  /* Display the goal. */
209  SetDParamStr(0, s->text);
210  uint width_reduction = progress_col_width > 0 ? progress_col_width + WidgetDimensions::scaled.framerect.Horizontal() : 0;
211  DrawString(r.Indent(width_reduction, !rtl), STR_GOALS_TEXT);
212  break;
213  }
214 
215  case GC_PROGRESS:
216  if (s->progress != nullptr) {
217  SetDParamStr(0, s->progress);
218  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
219  DrawString(r.WithWidth(progress_col_width, !rtl), str, TC_FROMSTRING, SA_RIGHT | SA_FORCE);
220  }
221  break;
222  }
223  r.top += FONT_HEIGHT_NORMAL;
224  }
225  pos++;
226  num++;
227  }
228  }
229 
230  if (num == 0) {
231  if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) {
232  DrawString(r, STR_GOALS_NONE);
233  }
234  }
235  }
236 
237  void OnPaint() override
238  {
239  this->DrawWidgets();
240 
241  if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
242 
243  /* Calculate progress column width. */
244  uint max_width = 0;
245  for (const Goal *s : Goal::Iterate()) {
246  if (s->progress != nullptr) {
247  SetDParamStr(0, s->progress);
248  StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
249  uint str_width = GetStringBoundingBox(str).width;
250  if (str_width > max_width) max_width = str_width;
251  }
252  }
253 
254  NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GOAL_LIST);
255  uint progress_col_width = std::min(max_width, wid->current_x);
256 
257  /* Draw goal list. */
258  this->DrawListColumn(GC_PROGRESS, wid, progress_col_width);
259  this->DrawListColumn(GC_GOAL, wid, progress_col_width);
260 
261  }
262 
263  void OnResize() override
264  {
265  this->vscroll->SetCapacityFromWidget(this, WID_GOAL_LIST, WidgetDimensions::scaled.framerect.Vertical());
266  }
267 
273  void OnInvalidateData(int data = 0, bool gui_scope = true) override
274  {
275  if (!gui_scope) return;
276  this->vscroll->SetCount(this->CountLines());
280  }
281 };
282 
286  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
287  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_GOAL_CAPTION), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
289  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_GLOBAL_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WidgetDimensions::unscaled.captiontext.Vertical()), SetDataTip(STR_GOALS_GLOBAL_BUTTON, STR_GOALS_GLOBAL_BUTTON_HELPTEXT),
290  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_GOAL_COMPANY_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WidgetDimensions::unscaled.captiontext.Vertical()), SetDataTip(STR_GOALS_COMPANY_BUTTON, STR_GOALS_COMPANY_BUTTON_HELPTEXT),
291  EndContainer(),
292  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
293  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
294  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
295  EndContainer(),
297  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),
298  EndContainer(),
301  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
302  EndContainer(),
303  EndContainer(),
304 };
305 
306 static WindowDesc _goals_list_desc(
307  WDP_AUTO, "list_goals", 500, 127,
309  0,
311 );
312 
318 {
319  if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY;
320 
321  AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
322 }
323 
325 struct GoalQuestionWindow : public Window {
326  char *question;
327  int buttons;
328  int button[3];
330 
331  GoalQuestionWindow(WindowDesc *desc, WindowNumber window_number, TextColour colour, uint32 button_mask, const char *question) : Window(desc), colour(colour)
332  {
333  this->question = stredup(question);
334 
335  /* Figure out which buttons we have to enable. */
336  int n = 0;
337  for (uint bit : SetBitIterator(button_mask)) {
338  if (bit >= GOAL_QUESTION_BUTTON_COUNT) break;
339  this->button[n++] = bit;
340  if (n == 3) break;
341  }
342  this->buttons = n;
343  assert(this->buttons < 4);
344 
345  this->CreateNestedTree();
346  if (this->buttons == 0) {
347  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(SZSP_HORIZONTAL);
348  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(SZSP_HORIZONTAL);
349  } else {
350  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
351  this->GetWidget<NWidgetStacked>(WID_GQ_BUTTON_SPACER)->SetDisplayedPlane(0);
352  }
353  this->FinishInitNested(window_number);
354  }
355 
357  {
358  free(this->question);
359  }
360 
361  void SetStringParameters(int widget) const override
362  {
363  switch (widget) {
364  case WID_GQ_BUTTON_1:
365  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
366  break;
367 
368  case WID_GQ_BUTTON_2:
369  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
370  break;
371 
372  case WID_GQ_BUTTON_3:
373  SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
374  break;
375  }
376  }
377 
378  void OnClick(Point pt, int widget, int click_count) override
379  {
380  switch (widget) {
381  case WID_GQ_BUTTON_1:
383  this->Close();
384  break;
385 
386  case WID_GQ_BUTTON_2:
388  this->Close();
389  break;
390 
391  case WID_GQ_BUTTON_3:
393  this->Close();
394  break;
395  }
396  }
397 
398  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
399  {
400  if (widget != WID_GQ_QUESTION) return;
401 
402  SetDParamStr(0, this->question);
403  size->height = GetStringHeight(STR_JUST_RAW_STRING, size->width) + WidgetDimensions::scaled.vsep_wide;
404  }
405 
406  void DrawWidget(const Rect &r, int widget) const override
407  {
408  if (widget != WID_GQ_QUESTION) return;
409 
410  SetDParamStr(0, this->question);
411  DrawStringMultiLine(r, STR_JUST_RAW_STRING, this->colour, SA_TOP | SA_HOR_CENTER);
412  }
413 };
414 
418  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
419  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_QUESTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
420  EndContainer(),
421  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
422  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
423  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
425  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
426  EndContainer(),
428  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
429  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
430  EndContainer(),
432  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
433  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
434  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
435  EndContainer(),
436  EndContainer(),
437  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
439  EndContainer(),
440  EndContainer(),
441 };
442 
443 static const NWidgetPart _nested_goal_question_widgets_info[] = {
445  NWidget(WWT_CLOSEBOX, COLOUR_LIGHT_BLUE),
446  NWidget(WWT_CAPTION, COLOUR_LIGHT_BLUE, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_INFORMATION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
447  EndContainer(),
448  NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE),
449  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
450  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
452  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
453  EndContainer(),
455  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
456  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
457  EndContainer(),
459  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
460  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
461  NWidget(WWT_PUSHTXTBTN, COLOUR_LIGHT_BLUE, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
462  EndContainer(),
463  EndContainer(),
464  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
466  EndContainer(),
467  EndContainer(),
468 };
469 
470 static const NWidgetPart _nested_goal_question_widgets_warning[] = {
472  NWidget(WWT_CLOSEBOX, COLOUR_YELLOW),
473  NWidget(WWT_CAPTION, COLOUR_YELLOW, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_WARNING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
474  EndContainer(),
475  NWidget(WWT_PANEL, COLOUR_YELLOW),
476  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
477  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
479  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
480  EndContainer(),
482  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
483  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
484  EndContainer(),
486  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
487  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
488  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
489  EndContainer(),
490  EndContainer(),
491  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
493  EndContainer(),
494  EndContainer(),
495 };
496 
497 static const NWidgetPart _nested_goal_question_widgets_error[] = {
499  NWidget(WWT_CLOSEBOX, COLOUR_RED),
500  NWidget(WWT_CAPTION, COLOUR_RED, WID_GQ_CAPTION), SetDataTip(STR_GOAL_QUESTION_CAPTION_ERROR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
501  EndContainer(),
502  NWidget(WWT_PANEL, COLOUR_RED),
503  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GQ_QUESTION), SetMinimalSize(300, 0), SetPadding(8, 8, 8, 8), SetFill(1, 0),
504  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTONS),
506  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
507  EndContainer(),
509  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
510  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
511  EndContainer(),
513  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_1), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
514  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_2), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
515  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GQ_BUTTON_3), SetDataTip(STR_BLACK_STRING, STR_NULL), SetFill(1, 0),
516  EndContainer(),
517  EndContainer(),
518  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GQ_BUTTON_SPACER),
520  EndContainer(),
521  EndContainer(),
522 };
523 
524 static WindowDesc _goal_question_list_desc[] = {
525  {
526  WDP_CENTER, nullptr, 0, 0,
530  },
531  {
532  WDP_CENTER, nullptr, 0, 0,
535  _nested_goal_question_widgets_info, lengthof(_nested_goal_question_widgets_info),
536  },
537  {
538  WDP_CENTER, nullptr, 0, 0,
541  _nested_goal_question_widgets_warning, lengthof(_nested_goal_question_widgets_warning),
542  },
543  {
544  WDP_CENTER, nullptr, 0, 0,
547  _nested_goal_question_widgets_error, lengthof(_nested_goal_question_widgets_error),
548  },
549 };
550 
558 void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
559 {
560  assert(type < GQT_END);
561  new GoalQuestionWindow(&_goal_question_list_desc[type], id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
562 }
GoalListWindow
Window for displaying goals.
Definition: goal_gui.cpp:41
GoalListWindow::UpdateWidgetSize
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:172
Goal
Struct about goals, current and completed.
Definition: goal_base.h:21
IsInsideMM
static 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:230
Pool::PoolItem<&_industry_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2456
ShowGoalsList
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:317
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1210
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:168
GoalColumn
GoalColumn
Goal list columns.
Definition: goal_gui.cpp:35
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:669
command_func.h
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
SetPadding
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:1143
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:319
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:144
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
ShowStoryBook
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:1057
GT_INDUSTRY
@ GT_INDUSTRY
Destination is an industry.
Definition: goal_type.h:29
company_base.h
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
WID_GQ_BUTTONS
@ WID_GQ_BUTTONS
Buttons selection (between 1, 2 or 3).
Definition: goal_widget.h:28
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
GoalListWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: goal_gui.cpp:273
company_gui.h
GoalListWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: goal_gui.cpp:237
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1775
WID_GQ_CAPTION
@ WID_GQ_CAPTION
Caption of the window.
Definition: goal_widget.h:26
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
GT_TILE
@ GT_TILE
Destination is a tile.
Definition: goal_type.h:28
GoalListWindow::HandleClick
void HandleClick(const Goal *s)
Handle clicking at a goal.
Definition: goal_gui.cpp:101
_nested_goal_question_widgets_question
static const NWidgetPart _nested_goal_question_widgets_question[]
Widgets of the goal question window.
Definition: goal_gui.cpp:416
TileIndex
The index/ID of a Tile.
Definition: tile_type.h:85
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
WID_GOAL_SCROLLBAR
@ WID_GOAL_SCROLLBAR
Scrollbar of the goal list.
Definition: goal_widget.h:21
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:38
GC_PROGRESS
@ GC_PROGRESS
Goal progress column.
Definition: goal_gui.cpp:37
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:997
goal_base.h
DrawString
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:644
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:427
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
town.h
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:253
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
Goal::dst
GoalTypeID dst
Index of type.
Definition: goal_base.h:24
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
WC_GOALS_LIST
@ WC_GOALS_LIST
Goals list; Window numbers:
Definition: window_type.h:283
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2353
WID_GQ_BUTTON_3
@ WID_GQ_BUTTON_3
Third button.
Definition: goal_widget.h:31
GoalQuestionWindow
Ask a question about a goal.
Definition: goal_gui.cpp:325
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
SetDParam
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:196
WID_GQ_QUESTION
@ WID_GQ_QUESTION
Question text.
Definition: goal_widget.h:27
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1111
WID_GQ_BUTTON_2
@ WID_GQ_BUTTON_2
Second button.
Definition: goal_widget.h:30
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
DrawStringMultiLine
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:789
GT_TOWN
@ GT_TOWN
Destination is a town.
Definition: goal_type.h:30
WindowDesc
High level window description.
Definition: window_gui.h:102
window_gui.h
goal_widget.h
GoalQuestionWindow::button
int button[3]
Buttons to display.
Definition: goal_gui.cpp:328
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
GC_GOAL
@ GC_GOAL
Goal text column.
Definition: goal_gui.cpp:36
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:90
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:251
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:329
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
GoalQuestionWindow::UpdateWidgetSize
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:398
GoalListWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:55
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
WID_GQ_BUTTON_SPACER
@ WID_GQ_BUTTON_SPACER
Selection to hide extra padding if there are no buttons.
Definition: goal_widget.h:32
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:321
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
industry.h
safeguards.h
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
GoalListWindow::vscroll
Scrollbar * vscroll
Reference to the scrollbar widget.
Definition: goal_gui.cpp:42
GoalListWindow::OnClick
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:67
date_func.h
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
GoalListWindow::CountLines
uint CountLines()
Count the number of lines in this window.
Definition: goal_gui.cpp:158
WID_GOAL_GLOBAL_BUTTON
@ WID_GOAL_GLOBAL_BUTTON
Button to show global goals.
Definition: goal_widget.h:18
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
WID_GOAL_COMPANY_BUTTON
@ WID_GOAL_COMPANY_BUTTON
Button to show company goals.
Definition: goal_widget.h:19
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1409
viewport_func.h
GT_NONE
@ GT_NONE
Destination is not linked.
Definition: goal_type.h:27
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:443
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:715
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_GOAL_LIST
@ WID_GOAL_LIST
Goal list.
Definition: goal_widget.h:20
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1096
GoalQuestionWindow::OnClick
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:378
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:386
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:455
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:193
GOAL_QUESTION_BUTTON_COUNT
static const uint32 GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
Definition: goal_type.h:15
GT_COMPANY
@ GT_COMPANY
Destination is a company.
Definition: goal_type.h:31
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1229
COMPANY_SPECTATOR
@ COMPANY_SPECTATOR
The client is spectating.
Definition: company_type.h:35
geometry_func.hpp
GoalQuestionWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: goal_gui.cpp:361
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
Goal::company
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
Definition: goal_base.h:22
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_GQ_BUTTON_1
@ WID_GQ_BUTTON_1
First button.
Definition: goal_widget.h:29
GoalQuestionWindow::buttons
int buttons
Number of valid buttons in button.
Definition: goal_gui.cpp:327
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:130
goal_cmd.h
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
GT_STORY_PAGE
@ GT_STORY_PAGE
Destination is a story page.
Definition: goal_type.h:32
GoalQuestionWindow::question
char * question
Question to ask (private copy).
Definition: goal_gui.cpp:326
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
company_func.h
GoalListWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: goal_gui.cpp:263
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
CommandHelper
Definition: command_func.h:94
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Scrollbar::SetCapacityFromWidget
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:2427
WID_GOAL_CAPTION
@ WID_GOAL_CAPTION
Caption of the window.
Definition: goal_widget.h:16
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1191
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1080
gui.h
Window
Data structure for an opened window.
Definition: window_gui.h:213
Pool::PoolItem<&_industry_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:326
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
GoalQuestionWindow::colour
TextColour colour
Colour of the question text.
Definition: goal_gui.cpp:329
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:470
story_base.h
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition: company_gui.cpp:2763
GoalQuestionWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: goal_gui.cpp:406
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
_nested_goals_list_widgets
static const NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
Definition: goal_gui.cpp:284
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
Goal::type
GoalType type
Type of the goal.
Definition: goal_base.h:23
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:91
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:297
WID_GOAL_SELECT_BUTTONS
@ WID_GOAL_SELECT_BUTTONS
Selection widget for the title bar button.
Definition: goal_widget.h:17
ShowGoalQuestion
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
Display a goal question.
Definition: goal_gui.cpp:558
SetMinimalTextLines
static NWidgetPart SetMinimalTextLines(uint8 lines, uint8 spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition: widget_type.h:1032
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1107