Go to the documentation of this file.
30 #include "table/strings.h"
60 SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
81 if (s->company == this->window_number) {
144 default: NOT_REACHED();
163 if (s->company == this->window_number) num++;
167 if (num == 0) num = 1;
178 resize->height = d.height;
204 if (s->company == this->window_number) {
216 if (s->progress !=
nullptr) {
218 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
246 if (s->progress !=
nullptr) {
248 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
250 if (str_width > max_width) max_width = str_width;
255 uint progress_col_width = std::min(max_width, wid->
current_x);
275 if (!gui_scope)
return;
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),
321 AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
339 this->button[n++] = bit;
343 assert(this->buttons < 4);
346 if (this->buttons == 0) {
350 this->GetWidget<NWidgetStacked>(
WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
358 free(this->question);
365 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
369 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
373 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
422 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
443 static const NWidgetPart _nested_goal_question_widgets_info[] = {
449 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
470 static const NWidgetPart _nested_goal_question_widgets_warning[] = {
476 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
497 static const NWidgetPart _nested_goal_question_widgets_error[] = {
503 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
524 static WindowDesc _goal_question_list_desc[] = {
535 _nested_goal_question_widgets_info,
lengthof(_nested_goal_question_widgets_info),
541 _nested_goal_question_widgets_warning,
lengthof(_nested_goal_question_widgets_warning),
547 _nested_goal_question_widgets_error,
lengthof(_nested_goal_question_widgets_error),
560 assert(type < GQT_END);
561 new GoalQuestionWindow(&_goal_question_list_desc[type],
id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
Window for displaying goals.
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.
Struct about goals, current and completed.
static constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void ShowGoalsList(CompanyID company)
Open a goal list window.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
GoalColumn
Goal list columns.
Dimensions (a width and height) of a rectangle in 2D.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
@ GT_INDUSTRY
Destination is an industry.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnPaint() override
The window must be repainted.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
@ GT_TILE
Destination is a tile.
void HandleClick(const Goal *s)
Handle clicking at a goal.
static const NWidgetPart _nested_goal_question_widgets_question[]
Widgets of the goal question window.
bool _ctrl_pressed
Is Ctrl pressed?
@ GC_PROGRESS
Goal progress column.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
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.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
int32 WindowNumber
Number to differentiate different windows of the same class.
GoalTypeID dst
Index of type.
@ SA_RIGHT
Right align the text (must be a single bit).
@ WC_GOALS_LIST
Goals list; Window numbers:
Ask a question about a goal.
Owner
Enum for all companies/owners.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
@ GT_TOWN
Destination is a town.
High level window description.
int button[3]
Buttons to display.
@ GC_GOAL
Goal text column.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
Iterable ensemble of each set bit in a value.
@ SA_TOP
Top align the text.
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.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint Horizontal() const
Get total horizontal padding of RectPadding.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Coordinates of a point in 2D.
Scrollbar * vscroll
Reference to the scrollbar widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
WindowNumber window_number
Window number within the window class.
uint CountLines()
Count the number of lines in this window.
uint Vertical() const
Get total vertical padding of RectPadding.
@ GT_NONE
Destination is not linked.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ SA_HOR_CENTER
Horizontally center the text.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
bool IsShaded() const
Is window shaded currently?
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
static const uint32 GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
@ GT_COMPANY
Destination is a company.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
@ COMPANY_SPECTATOR
The client is spectating.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
int buttons
Number of valid buttons in button.
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
@ GT_STORY_PAGE
Destination is a story page.
char * question
Question to ask (private copy).
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void OnResize() override
Called after the window got resized.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
#define lengthof(x)
Return the length of an fixed size array.
@ INVALID_COMPANY
An invalid company.
Data structure for an opened window.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void DrawWidgets() const
Paint all widgets of a window.
TextColour colour
Colour of the question text.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Specification of a rectangle with absolute coordinates of all edges.
static const NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
GoalType type
Type of the goal.
@ WDP_CENTER
Center the window.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question)
Display a goal question.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.