30#include "table/strings.h"
41struct GoalListWindow :
public Window {
49 this->
owner = this->window_number;
60 return GetString(STR_GOALS_SPECTATOR_CAPTION);
79 if (s->company == this->window_number) {
134 CompanyID goal_company = s->
company;
136 if (goal_company == CompanyID::Invalid() ? story_company != CompanyID::Invalid() : story_company != CompanyID::Invalid() && story_company != goal_company)
return;
142 default: NOT_REACHED();
161 if (s->company == this->window_number) num++;
165 if (num == 0) num = 1;
176 fill.height =
resize.height = d.height;
201 if (s->company == this->window_number) {
206 uint width_reduction = progress_col_width > 0 ? progress_col_width +
WidgetDimensions::scaled.framerect.Horizontal() : 0;
212 if (!s->progress.empty()) {
213 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
241 if (!s->progress.empty()) {
242 StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
244 if (str_width > max_width) max_width = str_width;
249 uint progress_col_width = std::min(max_width, wid->
current_x);
267 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
269 if (!gui_scope)
return;
303 WindowClass::GoalList, WindowClass::None,
336 assert(this->buttons.
Count() < 4);
339 if (this->buttons.
None()) {
393template <Colours bg_colour, Colours btn_colour, StringID caption>
395 static constexpr auto widgetparts = {
422static constexpr auto _nested_goal_question_widgets_question = NestedGoalWidgets<Colours::LightBlue, Colours::LightBlue, STR_GOAL_QUESTION_CAPTION_QUESTION>::widgetparts;
423static constexpr auto _nested_goal_question_widgets_info = NestedGoalWidgets<Colours::LightBlue, Colours::LightBlue, STR_GOAL_QUESTION_CAPTION_INFORMATION>::widgetparts;
424static constexpr auto _nested_goal_question_widgets_warning = NestedGoalWidgets<Colours::Yellow, Colours::Yellow, STR_GOAL_QUESTION_CAPTION_WARNING>::widgetparts;
425static constexpr auto _nested_goal_question_widgets_error = NestedGoalWidgets<Colours::Red, Colours::Yellow, STR_GOAL_QUESTION_CAPTION_ERROR>::widgetparts;
431 WindowClass::GoalQuestion, WindowClass::None,
433 _nested_goal_question_widgets_question,
437 WindowClass::GoalQuestion, WindowClass::None,
439 _nested_goal_question_widgets_info,
443 WindowClass::GoalQuestion, WindowClass::None,
445 _nested_goal_question_widgets_warning,
449 WindowClass::GoalQuestion, WindowClass::None,
451 _nested_goal_question_widgets_error,
uint Count() const
Count the number of set bits.
constexpr bool None() const
Test if none of the values are set.
std::optional< Tvalue_type > GetNthSetBit(uint n) const
Get the value of the Nth set bit.
Container for an encoded string, created by GetEncodedString.
std::string GetDecodedString() const
Decode the encoded string.
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.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
EnumClassIndexContainer< std::array< T, to_underlying(N)>, Index > EnumIndexArray
A typedef for EnumClassIndexContainer using std::array as the backing container type.
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.
bool _ctrl_pressed
Is Ctrl pressed?
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
@ Normal
Index of the normal font in the font tables.
@ 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.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ FromString
Marker for telling to use the colour from the string.
Command definitions related to goals.
void ShowGoalQuestion(uint16_t id, GoalQuestionType type, GoalQuestionButtons buttons, const EncodedString &question)
Display a goal question.
void ShowGoalsList(CompanyID company)
Open a goal list window.
GoalColumn
Goal list columns.
@ GC_PROGRESS
Goal progress column.
@ GC_GOAL
Goal text column.
static constexpr std::initializer_list< NWidgetPart > _nested_goals_list_widgets
Widgets of the GoalListWindow.
static WindowDesc _goals_list_desc(WindowPosition::Automatic, "list_goals", 500, 127, WindowClass::GoalList, WindowClass::None, {}, _nested_goals_list_widgets)
Window definition for the goal listing window.
static EnumIndexArray< WindowDesc, GoalQuestionType, GoalQuestionType::End > _goal_question_list_desc
Window definitions for the goal question windows.
@ Company
Destination is a company.
@ Industry
Destination is an industry.
@ None
Destination is not linked.
@ StoryPage
Destination is a story page.
@ Town
Destination is a town.
@ Tile
Destination is a tile.
GoalQuestionType
Types of goal questions.
@ Error
Showing an error; title: Error.
EnumBitSet< GoalQuestionButton, uint32_t, GoalQuestionButton::End > GoalQuestionButtons
Bitset of GoalQuestionButton elements.
GUI functions that shouldn't be here.
void ShowStoryBook(CompanyID company, StoryPageID page_id=StoryPageID::Invalid(), bool centered=false)
Raise or create the story book window for company, at page page_id.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
#define Point
Macro that prevents name conflicts between included headers.
constexpr bool IsInsideMM(const size_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.
PoolID< uint16_t, struct StoryPageIDTag, 64000, 0xFFFF > StoryPageID
ID of a story page.
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Dimensions (a width and height) of a rectangle in 2D.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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 OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
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 UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Ask a question about a goal.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
EncodedString question
Question to ask (private copy).
TextColour colour
Colour of the question text.
GoalQuestionWindow(WindowDesc &desc, WindowNumber window_number, TextColour colour, GoalQuestionButtons buttons, const EncodedString &question)
Construct a new Goal Question Window.
GoalQuestionButtons buttons
Buttons to display.
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; CompanyID::Invalid() if it is global.
static Pool::IterateWrapper< Goal > Iterate(size_t from=0)
static Industry * Get(auto index)
static bool IsValidID(auto index)
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.
High level window description.
Number to differentiate different windows of the same class.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
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?
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
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.
@ Construction
This window is used for construction; close it whenever changing company.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
@ Center
Center the window.