Go to the documentation of this file.
29 #include "table/strings.h"
59 SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
80 if (s->company == this->window_number) {
143 default: NOT_REACHED();
162 if (s->company == this->window_number) num++;
166 if (num == 0) num = 1;
176 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;
220 int progress_right = rtl ? x + progress_col_width : right;
248 if (s->progress !=
nullptr) {
250 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
252 if (str_width > max_width) max_width = str_width;
257 uint progress_col_width = std::min(max_width, wid->
current_x);
277 if (!gui_scope)
return;
300 NWidget(
WWT_EMPTY, COLOUR_GREY,
WID_GOAL_LIST),
SetResize(1, 1),
SetMinimalTextLines(2, 0),
SetFill(1, 1),
SetPadding(
WD_FRAMERECT_TOP, 2,
WD_FRAMETEXT_BOTTOM, 2),
324 AllocateWindowDescFront<GoalListWindow>(&_goals_list_desc, company);
343 this->button[n++] = bit;
347 assert(this->buttons < 4);
350 if (this->buttons == 0) {
354 this->GetWidget<NWidgetStacked>(
WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
362 free(this->question);
369 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
373 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
377 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
426 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
447 static const NWidgetPart _nested_goal_question_widgets_info[] = {
453 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
474 static const NWidgetPart _nested_goal_question_widgets_warning[] = {
480 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
501 static const NWidgetPart _nested_goal_question_widgets_error[] = {
507 NWidget(
WWT_EMPTY, INVALID_COLOUR,
WID_GQ_QUESTION),
SetMinimalSize(300, 0),
SetPadding(8, 8, 8, 8),
SetFill(1, 0),
528 static WindowDesc _goal_question_list_desc[] = {
539 _nested_goal_question_widgets_info,
lengthof(_nested_goal_question_widgets_info),
545 _nested_goal_question_widgets_warning,
lengthof(_nested_goal_question_widgets_warning),
551 _nested_goal_question_widgets_error,
lengthof(_nested_goal_question_widgets_error),
564 assert(type < GQT_END);
565 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.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
uint32 TileIndex
The index/ID of a Tile.
Struct about goals, current and completed.
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.
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.
@ SA_RIGHT
Right align the text (must be a single bit).
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.
@ WC_GOALS_LIST
Goals list; Window numbers:
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ SA_HOR_CENTER
Horizontally center the text.
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.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
@ GT_TOWN
Destination is a town.
High level window description.
@ SA_TOP
Top align the text.
int button[3]
Buttons to display.
@ GC_GOAL
Goal text column.
@ WDP_AUTO
Find a place automatically.
ResizeInfo resize
Resize information.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
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.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
@ CMD_GOAL_QUESTION_ANSWER
answer(s) to CMD_GOAL_QUESTION
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.
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.
@ GT_NONE
Destination is not linked.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
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.
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
GoalType type
Type of the goal.
@ WDP_CENTER
Center the window.
@ TD_RTL
Text is written right-to-left by default.
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
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.