OpenTTD Source 20250312-master-gcdcc6b491d
misc_gui.cpp File Reference

GUIs for a number of misc windows. More...

#include "stdafx.h"
#include "debug.h"
#include "landscape.h"
#include "error.h"
#include "gui.h"
#include "gfx_layout.h"
#include "command_func.h"
#include "company_func.h"
#include "town.h"
#include "string_func.h"
#include "company_base.h"
#include "texteff.hpp"
#include "strings_func.h"
#include "window_func.h"
#include "querystring_gui.h"
#include "core/geometry_func.hpp"
#include "newgrf_debug.h"
#include "zoom_func.h"
#include "viewport_func.h"
#include "landscape_cmd.h"
#include "rev.h"
#include "timer/timer.h"
#include "timer/timer_window.h"
#include "pathfinder/water_regions.h"
#include "widgets/misc_widget.h"
#include "table/strings.h"
#include <sstream>
#include <iomanip>
#include "safeguards.h"

Go to the source code of this file.

Data Structures

class  LandInfoWindow
 
struct  AboutWindow
 
struct  TooltipsWindow
 Window for displaying a tooltip. More...
 
struct  QueryStringWindow
 Class for the string query window. More...
 
struct  QueryWindow
 Window used for asking the user a YES/NO question. More...
 

Macros

#define LANDINFOD_LEVEL   1
 

Enumerations

enum  OskActivation : uint8_t { OSKA_DISABLED , OSKA_DOUBLE_CLICK , OSKA_SINGLE_CLICK , OSKA_IMMEDIATELY }
 Method to open the OSK. More...
 

Functions

void ShowLandInfo (TileIndex tile)
 Show land information window.
 
void ShowAboutWindow ()
 
void ShowEstimatedCostOrIncome (Money cost, int x, int y)
 Display estimated costs.
 
void ShowCostOrIncomeAnimation (int x, int y, int z, Money cost)
 Display animated income or costs on the map.
 
void ShowFeederIncomeAnimation (int x, int y, int z, Money transfer, Money income)
 Display animated feeder income.
 
TextEffectID ShowFillingPercent (int x, int y, int z, uint8_t percent, StringID string)
 Display vehicle loading indicators.
 
void UpdateFillingPercent (TextEffectID te_id, uint8_t percent, StringID string)
 Update vehicle loading indicators.
 
void HideFillingPercent (TextEffectID *te_id)
 Hide vehicle loading indicators.
 
void GuiShowTooltips (Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
 Shows a tooltip.
 
static int GetCaretWidth ()
 
static Rect ScrollEditBoxTextRect (Rect r, const Textbuf &tb)
 Reposition edit text box rect based on textbuf length can caret position.
 
void ShowQueryString (std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
 Show a query popup window with a textbox in it.
 
void ShowQuery (EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
 Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre of its parent.
 

Variables

static constexpr NWidgetPart _nested_land_info_widgets []
 
static WindowDesc _land_info_desc (WDP_AUTO, nullptr, 0, 0, WC_LAND_INFO, WC_NONE, {}, _nested_land_info_widgets)
 
static constexpr NWidgetPart _nested_about_widgets []
 
static WindowDesc _about_desc (WDP_CENTER, nullptr, 0, 0, WC_GAME_OPTIONS, WC_NONE, {}, _nested_about_widgets)
 
static const std::initializer_list< const std::string_view > _credits
 
static constexpr NWidgetPart _nested_tooltips_widgets []
 
static WindowDesc _tool_tips_desc (WDP_MANUAL, nullptr, 0, 0, WC_TOOLTIPS, WC_NONE, {WindowDefaultFlag::NoFocus, WindowDefaultFlag::NoClose}, _nested_tooltips_widgets)
 
static constexpr NWidgetPart _nested_query_string_widgets []
 
static WindowDesc _query_string_desc (WDP_CENTER, nullptr, 0, 0, WC_QUERY_STRING, WC_NONE, {}, _nested_query_string_widgets)
 
static constexpr NWidgetPart _nested_query_widgets []
 
static WindowDesc _query_desc (WDP_CENTER, nullptr, 0, 0, WC_CONFIRM_POPUP_QUERY, WC_NONE, WindowDefaultFlag::Modal, _nested_query_widgets)
 

Detailed Description

GUIs for a number of misc windows.

Definition in file misc_gui.cpp.

Enumeration Type Documentation

◆ OskActivation

enum OskActivation : uint8_t

Method to open the OSK.

Enumerator
OSKA_DISABLED 

The OSK shall not be activated at all.

OSKA_DOUBLE_CLICK 

Double click on the edit box opens OSK.

OSKA_SINGLE_CLICK 

Single click after focus click opens OSK.

OSKA_IMMEDIATELY 

Focusing click already opens OSK.

Definition at line 45 of file misc_gui.cpp.

Function Documentation

◆ GetCaretWidth()

static int GetCaretWidth ( )
static

Definition at line 709 of file misc_gui.cpp.

◆ GuiShowTooltips()

void GuiShowTooltips ( Window parent,
EncodedString &&  text,
TooltipCloseCondition  close_tooltip 
)

Shows a tooltip.

Parameters
parentThe window this tooltip is related to.
textString to be displayed. May include encoded parameters.
close_tooltipthe condition under which the tooltip closes

Definition at line 690 of file misc_gui.cpp.

References CloseWindowById(), CursorVars::in_window, and WC_TOOLTIPS.

Referenced by DispatchHoverEvent(), DispatchRightClickEvent(), DepotWindow::OnRightClick(), ReplaceVehicleWindow::OnTooltip(), CheatWindow::OnTooltip(), IndustryCargoesWindow::OnTooltip(), LinkGraphLegendWindow::OnTooltip(), NetworkClientListWindow::OnTooltip(), BuildRailToolbarWindow::OnTooltip(), TextfileWindow::OnTooltip(), VehicleDetailsWindow::OnTooltip(), and ShowMeasurementTooltips().

◆ HideFillingPercent()

void HideFillingPercent ( TextEffectID *  te_id)

Hide vehicle loading indicators.

Parameters
*te_idTextEffectID which is supposed to be hidden.

Definition at line 583 of file misc_gui.cpp.

Referenced by CmdReverseTrainDirection(), Train::Crash(), Vehicle::LeaveStation(), and Vehicle::PreDestructor().

◆ ScrollEditBoxTextRect()

static Rect ScrollEditBoxTextRect ( Rect  r,
const Textbuf tb 
)
static

Reposition edit text box rect based on textbuf length can caret position.

Parameters
rInitial rect of edit text box.
tbThe Textbuf being processed.
Returns
Updated rect.

Definition at line 720 of file misc_gui.cpp.

References Textbuf::caretxoffs, Textbuf::pixels, Rect::Translate(), Rect::Width(), and Rect::WithWidth().

Referenced by QueryString::GetBoundingRect(), QueryString::GetCaretPosition(), and QueryString::GetCharAtPosition().

◆ ShowAboutWindow()

void ShowAboutWindow ( )

Definition at line 480 of file misc_gui.cpp.

◆ ShowCostOrIncomeAnimation()

void ShowCostOrIncomeAnimation ( int  x,
int  y,
int  z,
Money  cost 
)

Display animated income or costs on the map.

Does nothing if cost is zero.

Parameters
xWorld X position of the animation location.
yWorld Y position of the animation location.
zWorld Z position of the animation location.
costEstimated cost (or income if negative).

Definition at line 510 of file misc_gui.cpp.

References Ticks::DAY_TICKS, GetEncodedString(), RemapCoords(), and TE_RISING.

Referenced by CmdChangeBankBalance(), CommandHelperBase::InternalPostResult(), and VehicleEnterDepot().

◆ ShowEstimatedCostOrIncome()

void ShowEstimatedCostOrIncome ( Money  cost,
int  x,
int  y 
)

Display estimated costs.

Parameters
costEstimated cost (or income if negative).
xX position of the notification window.
yY position of the notification window.

Definition at line 492 of file misc_gui.cpp.

References GetEncodedString(), ShowErrorMessage(), and WL_INFO.

Referenced by CommandHelperBase::InternalPostResult().

◆ ShowFeederIncomeAnimation()

void ShowFeederIncomeAnimation ( int  x,
int  y,
int  z,
Money  transfer,
Money  income 
)

Display animated feeder income.

Parameters
xWorld X position of the animation location.
yWorld Y position of the animation location.
zWorld Z position of the animation location.
transferEstimated feeder income.
incomeReal income from goods being delivered to their final destination.

Definition at line 533 of file misc_gui.cpp.

References Ticks::DAY_TICKS, GetEncodedString(), RemapCoords(), and TE_RISING.

◆ ShowFillingPercent()

TextEffectID ShowFillingPercent ( int  x,
int  y,
int  z,
uint8_t  percent,
StringID  string 
)

Display vehicle loading indicators.

Parameters
xWorld X position of the animation location.
yWorld Y position of the animation location.
zWorld Z position of the animation location.
percentEstimated feeder income.
stringString which is drawn on the map.
Returns
TextEffectID to be used for future updates of the loading indicators.

Definition at line 558 of file misc_gui.cpp.

References GetEncodedString(), RemapCoords(), and TE_STATIC.

Referenced by LoadUnloadVehicle().

◆ ShowLandInfo()

void ShowLandInfo ( TileIndex  tile)

Show land information window.

Parameters
tileThe tile to show information about.

Definition at line 319 of file misc_gui.cpp.

References CloseWindowById(), and WC_LAND_INFO.

Referenced by MainToolbarWindow::OnPlaceObject(), and ScenarioEditorToolbarWindow::OnPlaceObject().

◆ ShowQuery()

void ShowQuery ( EncodedString &&  caption,
EncodedString &&  message,
Window parent,
QueryCallbackProc callback,
bool  focus 
)

Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre of its parent.

Parameters
captionstring shown as window caption
messagestring that will be shown for the window
parentpointer to parent window, if this pointer is nullptr the parent becomes the main window WC_MAIN_WINDOW
callbackcallback function pointer to set in the window descriptor
focuswhether the window should be focussed (by default false)

Definition at line 1151 of file misc_gui.cpp.

References QueryWindow::Close(), GetMainWindow(), Window::parent, QueryWindow::proc, SetFocusedWindow(), WC_CONFIRM_POPUP_QUERY, and Window::window_class.

Referenced by CmdPause(), MakeScreenshotWithConfirm(), DepotWindow::OnClick(), GenerateLandscapeWindow::OnClick(), GenerateProgressWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildIndustryWindow::OnClick(), NetworkContentListWindow::OnClick(), NewGRFWindow::OnClick(), GameSettingsWindow::OnClick(), ScenarioEditorLandscapeGenerationWindow::OnClick(), NetworkClientListWindow::OnDropdownSelect(), and SaveLoadWindow::OnTimeout().

◆ ShowQueryString()

void ShowQueryString ( std::string_view  str,
StringID  caption,
uint  maxsize,
Window parent,
CharSetFilter  afilter,
QueryStringFlags  flags 
)

◆ UpdateFillingPercent()

void UpdateFillingPercent ( TextEffectID  te_id,
uint8_t  percent,
StringID  string 
)

Update vehicle loading indicators.

Parameters
te_idTextEffectID to be updated.
stringString which is printed.

Definition at line 572 of file misc_gui.cpp.

References GetEncodedString().

Referenced by LoadUnloadVehicle().

Variable Documentation

◆ _credits

const std::initializer_list<const std::string_view> _credits
static

Definition at line 348 of file misc_gui.cpp.

◆ _nested_about_widgets

constexpr NWidgetPart _nested_about_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_ABOUT_ORIGINAL_COPYRIGHT),
NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_ABOUT_VERSION),
NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
NWidget(WWT_LABEL, INVALID_COLOUR, WID_A_WEBSITE),
NWidget(WWT_LABEL, INVALID_COLOUR, WID_A_COPYRIGHT),
}
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
@ WID_A_WEBSITE
URL of OpenTTD website.
Definition misc_widget.h:27
@ WID_A_COPYRIGHT
Copyright string.
Definition misc_widget.h:28
@ WID_A_SCROLLING_TEXT
The actually scrolling text.
Definition misc_widget.h:26
@ WWT_LABEL
Centered label.
Definition widget_type.h:47
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_FRAME
Frame.
Definition widget_type.h:50
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38

Definition at line 325 of file misc_gui.cpp.

◆ _nested_land_info_widgets

constexpr NWidgetPart _nested_land_info_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_LI_LOCATION), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetSpriteTip(SPR_GOTO_LOCATION, STR_LAND_AREA_INFORMATION_LOCATION_TOOLTIP),
NWidget(WWT_DEBUGBOX, COLOUR_GREY),
}
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
@ WID_LI_BACKGROUND
Background of the window.
Definition misc_widget.h:16
@ WID_LI_LOCATION
Scroll to location.
Definition misc_widget.h:15
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition widget_type.h:53

Definition at line 53 of file misc_gui.cpp.

◆ _nested_query_string_widgets

constexpr NWidgetPart _nested_query_string_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
NWidget(WWT_CAPTION, COLOUR_GREY, WID_QS_CAPTION), SetTextStyle(TC_WHITE),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 0), SetFill(1, 0), SetPadding(2, 2, 2, 2),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_DEFAULT),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_CANCEL),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetStringTip(STR_BUTTON_OK),
}
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
@ WID_QS_DEFAULT
Default button.
Definition misc_widget.h:35
@ WID_QS_CAPTION
Caption of the window.
Definition misc_widget.h:33
@ WID_QS_TEXT
Text of the query.
Definition misc_widget.h:34
@ WID_QS_CANCEL
Cancel button.
Definition misc_widget.h:36
@ WID_QS_OK
OK button.
Definition misc_widget.h:37
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:61
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ EqualSize
Containers should keep all their (resizing) children equally large.

Definition at line 980 of file misc_gui.cpp.

◆ _nested_query_widgets

constexpr NWidgetPart _nested_query_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_CLOSEBOX, COLOUR_RED),
NWidget(WWT_PANEL, COLOUR_RED),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_Q_TEXT), SetMinimalSize(200, 12),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_QUIT_NO),
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetStringTip(STR_QUIT_YES),
}
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
@ WID_Q_NO
Yes button.
Definition misc_widget.h:44
@ WID_Q_YES
No button.
Definition misc_widget.h:45
@ WID_Q_CAPTION
Caption of the window.
Definition misc_widget.h:42
@ WID_Q_TEXT
Text of the query.
Definition misc_widget.h:43
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:48

Definition at line 1118 of file misc_gui.cpp.

◆ _nested_tooltips_widgets

constexpr NWidgetPart _nested_tooltips_widgets[]
staticconstexpr
Initial value:
= {
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_TT_BACKGROUND),
}
@ WID_TT_BACKGROUND
Background of the window.
Definition misc_widget.h:21

Definition at line 591 of file misc_gui.cpp.