29 #include "table/strings.h"
54 void SetStringParameters(
WidgetID widget)
const override
59 SetDParam(0, STR_GOALS_SPECTATOR_CAPTION);
66 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
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;
203 if (s->company == this->window_number) {
215 if (!s->progress.empty()) {
217 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
245 if (!s->progress.empty()) {
247 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
249 if (str_width > max_width) max_width = str_width;
254 uint progress_col_width = std::min(max_width, wid->
current_x);
272 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
274 if (!gui_scope)
return;
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),
320 AllocateWindowDescFront<GoalListWindow>(_goals_list_desc, company);
338 this->button[n++] = bit;
342 assert(this->buttons < 4);
345 if (this->buttons == 0) {
348 this->GetWidget<NWidgetStacked>(
WID_GQ_BUTTONS)->SetDisplayedPlane(this->buttons - 1);
354 void SetStringParameters(
WidgetID widget)
const override
358 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[0]);
362 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[1]);
366 SetDParam(0, STR_GOAL_QUESTION_BUTTON_CANCEL + this->button[2]);
371 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
399 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
414 template <Colours bg_colour, Colours btn_colour, StringID caption>
416 static constexpr
auto widgetparts = {
448 static WindowDesc _goal_question_list_desc[] = {
453 _nested_goal_question_widgets_question,
459 _nested_goal_question_widgets_info,
465 _nested_goal_question_widgets_warning,
471 _nested_goal_question_widgets_error,
482 void ShowGoalQuestion(uint16_t
id, uint8_t type, uint32_t button_mask,
const std::string &question)
484 assert(type < GQT_END);
485 new GoalQuestionWindow(_goal_question_list_desc[type],
id, type == 3 ? TC_WHITE : TC_BLACK, button_mask, question);
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.
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.
@ INVALID_COMPANY
An invalid company.
@ COMPANY_SPECTATOR
The client is spectating.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
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.
@ SA_TOP
Top align the text.
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_HOR_CENTER
Horizontally center the text.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Command definitions related to goals.
void ShowGoalsList(CompanyID company)
Open a goal list window.
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const std::string &question)
Display a goal question.
GoalColumn
Goal list columns.
@ GC_PROGRESS
Goal progress column.
@ GC_GOAL
Goal text column.
static constexpr NWidgetPart _nested_goals_list_widgets[]
Widgets of the GoalListWindow.
@ GT_INDUSTRY
Destination is an industry.
@ GT_STORY_PAGE
Destination is a story page.
@ GT_COMPANY
Destination is a company.
@ GT_NONE
Destination is not linked.
@ GT_TILE
Destination is a tile.
@ GT_TOWN
Destination is a town.
static const uint32_t GOAL_QUESTION_BUTTON_COUNT
Amount of buttons available.
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.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
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.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to OTTD's strings.
@ TD_RTL
Text is written right-to-left by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Dimensions (a width and height) of a rectangle in 2D.
Window for displaying goals.
void OnResize() override
Called after the window got resized.
uint CountLines()
Count the number of lines in this window.
void OnPaint() override
The window must be repainted.
void HandleClick(const Goal *s)
Handle clicking at a goal.
void DrawListColumn(GoalColumn column, NWidgetBase *wid, uint progress_col_width) const
Draws a given column of the goal list.
Scrollbar * vscroll
Reference to the scrollbar widget.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Ask a question about a goal.
int button[3]
Buttons to display.
std::string question
Question to ask (private copy).
int buttons
Number of valid buttons in button.
TextColour colour
Colour of the question text.
Struct about goals, current and completed.
GoalType type
Type of the goal.
GoalTypeID dst
Index of type.
CompanyID company
Goal is for a specific company; INVALID_COMPANY if it is global.
Coordinates of a point in 2D.
static Titem * Get(size_t index)
Returns Titem with given index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
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.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
bool IsShaded() const
Is window shaded currently?
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
WindowNumber window_number
Window number within the window class.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Functions related to (drawing on) viewports.
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_CENTER
Center the window.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
@ WC_GOAL_QUESTION
Popup with a set of buttons, designed to ask the user a question from a GameScript.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_GOALS_LIST
Goals list; Window numbers: