diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 64707259d3..c7be164ddb 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -702,10 +702,9 @@ public: if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false; if (Group::IsValidID(this->sel_group)) { - SetDParam(0, STR_REPLACE_REMOVE_WAGON_HELP); - GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, close_cond, 1); + GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_GROUP_HELP, close_cond, MakeParameters(STR_REPLACE_REMOVE_WAGON_HELP)); } else { - GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, close_cond); + GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, close_cond, MakeParameters()); } return true; } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index ae726c920b..aba2d3c312 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -885,10 +885,7 @@ struct DepotWindow : Window { details += GetString(STR_DEPOT_VEHICLE_TOOLTIP_CARGO); } - /* Show tooltip window */ - SetDParam(0, whole_chain ? num : v->engine_type); - SetDParamStr(1, details); - GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, TCC_RIGHT_CLICK, 2); + GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, TCC_RIGHT_CLICK, MakeParameters(whole_chain ? num : v->engine_type, details)); return true; } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 15c0c42094..1de7153292 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -3165,7 +3165,7 @@ struct IndustryCargoesWindow : public Window { case CFT_INDUSTRY: if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) { - GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond); + GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond, MakeParameters()); } return true; @@ -3174,8 +3174,7 @@ struct IndustryCargoesWindow : public Window { } if (IsValidCargoID(cid) && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) { const CargoSpec *csp = CargoSpec::Get(cid); - SetDParam(0, csp->name); - GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1); + GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, MakeParameters(csp->name)); return true; } diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index a1dfa0c8a8..7174426037 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -401,20 +401,15 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond) SetDParam(0, time); tooltip_extension += GetString(STR_LINKGRAPH_STATS_TOOLTIP_TIME_EXTENSION); } - SetDParam(0, link.cargo); - SetDParam(1, link.Usage()); - SetDParam(2, i->first); - SetDParam(3, j->first); - SetDParam(4, link.Usage() * 100 / (link.capacity + 1)); - SetDParamStr(5, tooltip_extension); + GuiShowTooltips(this->window, TimerGameEconomy::UsingWallclockUnits() ? STR_LINKGRAPH_STATS_TOOLTIP_MINUTE : STR_LINKGRAPH_STATS_TOOLTIP_MONTH, - close_cond, 7); + close_cond, MakeParameters(link.cargo, link.Usage(), i->first, j->first, link.Usage() * 100 / (link.capacity + 1), tooltip_extension)); return true; } } } - GuiShowTooltips(this->window, STR_NULL, close_cond); + GuiShowTooltips(this->window, STR_NULL, close_cond, MakeParameters()); return false; } @@ -646,17 +641,15 @@ bool LinkGraphLegendWindow::OnTooltip([[maybe_unused]] Point, WidgetID widget, T { if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) { if (this->IsWidgetDisabled(widget)) { - GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, close_cond); + GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, close_cond, MakeParameters()); } else { - SetDParam(0, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES); - SetDParam(1, (CompanyID)(widget - WID_LGL_COMPANY_FIRST)); - GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP, close_cond, 2); + GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP, close_cond, MakeParameters(STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, (CompanyID)(widget - WID_LGL_COMPANY_FIRST))); } return true; } if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) { const CargoSpec *cargo = _sorted_cargo_specs[widget - WID_LGL_CARGO_FIRST]; - GuiShowTooltips(this, cargo->name, close_cond); + GuiShowTooltips(this, cargo->name, close_cond, MakeParameters()); return true; } return false; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 07b441ce41..5bb0f07169 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -664,13 +664,14 @@ struct TooltipsWindow : public Window std::vector params; ///< The string parameters. TooltipCloseCondition close_cond; ///< Condition for closing the window. - TooltipsWindow(Window *parent, StringID str, uint paramcount, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc) + TooltipsWindow(Window *parent, StringID str, StringParameters &¶ms, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc) { this->parent = parent; this->string_id = str; - CopyOutDParam(this->params, paramcount); + CopyOutDParam(this->params, std::move(params)); this->close_cond = close_tooltip; + CopyInDParam(this->params); this->InitNested(); CLRBITS(this->flags, WF_WHITE_BORDER); @@ -748,15 +749,15 @@ struct TooltipsWindow : public Window * @param parent The window this tooltip is related to. * @param str String to be displayed * @param close_tooltip the condition under which the tooltip closes - * @param paramcount number of params to deal with + * @param params Parameters for the string. */ -void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount) +void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, StringParameters &¶ms) { CloseWindowById(WC_TOOLTIPS, 0); if (str == STR_NULL || !_cursor.in_window) return; - new TooltipsWindow(parent, str, paramcount, close_tooltip); + new TooltipsWindow(parent, str, std::move(params), close_tooltip); } void QueryString::HandleEditBox(Window *w, WidgetID wid) diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index e7a597b9b3..3fae07af1c 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1803,10 +1803,10 @@ public: if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) { if (index == this->player_self_index) { - GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, close_cond); + GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, close_cond, MakeParameters()); return true; } else if (index == this->player_host_index) { - GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, close_cond); + GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, close_cond, MakeParameters()); return true; } } @@ -1814,7 +1814,7 @@ public: ButtonCommon *button = this->GetButtonAtPoint(pt); if (button == nullptr) return false; - GuiShowTooltips(this, button->tooltip, close_cond); + GuiShowTooltips(this, button->tooltip, close_cond, MakeParameters()); return true; }; } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 4c09c32e8d..d73c9ccca9 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -458,7 +458,7 @@ struct BuildRailToolbarWindow : Window { if (std::find(std::begin(can_build_widgets), std::end(can_build_widgets), widget) == std::end(can_build_widgets)) return false; - GuiShowTooltips(this, STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE, close_cond); + GuiShowTooltips(this, STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE, close_cond, MakeParameters()); return true; } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index de0a11f11d..4d1df21501 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -2736,7 +2736,7 @@ struct VehicleDetailsWindow : Window { } else { tool_tip = widget == WID_VD_INCREASE_SERVICING_INTERVAL ? STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP_DAYS : STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP_DAYS; } - GuiShowTooltips(this, tool_tip, close_cond); + GuiShowTooltips(this, tool_tip, close_cond, MakeParameters()); return true; } diff --git a/src/viewport.cpp b/src/viewport.cpp index 77e93cb2ff..08a118f372 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2699,12 +2699,12 @@ void UpdateTileSelection() /** * Displays the measurement tooltips when selecting multiple tiles * @param str String to be displayed - * @param paramcount number of params to deal with + * @param params Parameters of the string. */ -static inline void ShowMeasurementTooltips(StringID str, uint paramcount) +static inline void ShowMeasurementTooltips(StringID str, StringParameters &¶ms) { if (!_settings_client.gui.measure_tooltip) return; - GuiShowTooltips(_thd.GetCallbackWnd(), str, TCC_EXIT_VIEWPORT, paramcount); + GuiShowTooltips(_thd.GetCallbackWnd(), str, TCC_EXIT_VIEWPORT, std::move(params)); } static void HideMeasurementTooltips() @@ -2780,8 +2780,7 @@ void VpSetPresizeRange(TileIndex from, TileIndex to) /* show measurement only if there is any length to speak of */ if (distance > 1) { - SetDParam(0, distance); - ShowMeasurementTooltips(STR_MEASURE_LENGTH, 1); + ShowMeasurementTooltips(STR_MEASURE_LENGTH, MakeParameters(distance)); } else { HideMeasurementTooltips(); } @@ -3168,7 +3167,8 @@ static void CalcRaildirsDrawstyle(int x, int y, int method) TileIndex t0 = TileVirtXY(_thd.selstart.x, _thd.selstart.y); TileIndex t1 = TileVirtXY(x, y); uint distance = DistanceManhattan(t0, t1) + 1; - byte index = 0; + auto params = MakeParameters(0, 0); + int index = 0; if (distance != 1) { int heightdiff = CalcHeightdiff(b, distance, t0, t1); @@ -3179,11 +3179,11 @@ static void CalcRaildirsDrawstyle(int x, int y, int method) distance = CeilDiv(distance, 2); } - SetDParam(index++, distance); - if (heightdiff != 0) SetDParam(index++, heightdiff); + params.SetParam(index++, distance); + if (heightdiff != 0) params.SetParam(index++, heightdiff); } - ShowMeasurementTooltips(measure_strings_length[index], index); + ShowMeasurementTooltips(measure_strings_length[index], std::move(params)); } _thd.selend.x = x; @@ -3264,6 +3264,7 @@ calc_heightdiff_single_direction:; TileIndex t0 = TileVirtXY(sx, sy); TileIndex t1 = TileVirtXY(x, y); uint distance = DistanceManhattan(t0, t1) + 1; + auto params = MakeParameters(0, 0); byte index = 0; if (distance != 1) { @@ -3274,11 +3275,11 @@ calc_heightdiff_single_direction:; * new_style := (_thd.next_drawstyle & HT_RECT) ? HT_LINE | style : _thd.next_drawstyle; */ int heightdiff = CalcHeightdiff(HT_LINE | style, 0, t0, t1); - SetDParam(index++, distance); - if (heightdiff != 0) SetDParam(index++, heightdiff); + params.SetParam(index++, distance); + if (heightdiff != 0) params.SetParam(index++, heightdiff); } - ShowMeasurementTooltips(measure_strings_length[index], index); + ShowMeasurementTooltips(measure_strings_length[index], std::move(params)); } break; @@ -3298,6 +3299,7 @@ calc_heightdiff_single_direction:; TileIndex t1 = TileVirtXY(x, y); uint dx = Delta(TileX(t0), TileX(t1)) + 1; uint dy = Delta(TileY(t0), TileY(t1)) + 1; + auto params = MakeParameters(0, 0, 0); byte index = 0; /* If dragging an area (eg dynamite tool) and it is actually a single @@ -3343,12 +3345,12 @@ calc_heightdiff_single_direction:; if (dx != 1 || dy != 1) { int heightdiff = CalcHeightdiff(style, 0, t0, t1); - SetDParam(index++, dx - (style & HT_POINT ? 1 : 0)); - SetDParam(index++, dy - (style & HT_POINT ? 1 : 0)); - if (heightdiff != 0) SetDParam(index++, heightdiff); + params.SetParam(index++, dx - (style & HT_POINT ? 1 : 0)); + params.SetParam(index++, dy - (style & HT_POINT ? 1 : 0)); + if (heightdiff != 0) params.SetParam(index++, heightdiff); } - ShowMeasurementTooltips(measure_strings_area[index], index); + ShowMeasurementTooltips(measure_strings_area[index], std::move(params)); } break; diff --git a/src/window.cpp b/src/window.cpp index a33c3c0177..65abb2aca8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -758,7 +758,7 @@ static void DispatchRightClickEvent(Window *w, int x, int y) /* Right-click close is enabled, but excluding sticky windows. */ w->Close(); } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) { - GuiShowTooltips(w, wid->tool_tip, TCC_RIGHT_CLICK); + GuiShowTooltips(w, wid->tool_tip, TCC_RIGHT_CLICK, MakeParameters()); } } @@ -779,7 +779,7 @@ static void DispatchHoverEvent(Window *w, int x, int y) /* Show the tooltip if there is any */ if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) { - GuiShowTooltips(w, wid->tool_tip, TCC_HOVER); + GuiShowTooltips(w, wid->tool_tip, TCC_HOVER, MakeParameters()); return; } diff --git a/src/window_gui.h b/src/window_gui.h index d4171070cf..55425031b6 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -1014,7 +1014,7 @@ Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_e void RelocateAllWindows(int neww, int newh); -void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount = 0); +void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, class StringParameters &¶ms); /* widget.cpp */ WidgetID GetWidgetFromPos(const Window *w, int x, int y);