mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: use SetDParam and CopyOutDParam for tooltips
This commit is contained in:
parent
ac0c932ce7
commit
836541b41c
|
@ -717,11 +717,10 @@ public:
|
||||||
if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
|
if (widget != WID_RV_TRAIN_WAGONREMOVE_TOGGLE) return false;
|
||||||
|
|
||||||
if (Group::IsValidID(this->sel_group)) {
|
if (Group::IsValidID(this->sel_group)) {
|
||||||
uint64 params[1];
|
SetDParam(0, STR_REPLACE_REMOVE_WAGON_HELP);
|
||||||
params[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, 1, params, close_cond);
|
|
||||||
} else {
|
} else {
|
||||||
GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, 0, nullptr, close_cond);
|
GuiShowTooltips(this, STR_REPLACE_REMOVE_WAGON_HELP, close_cond);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -889,10 +889,9 @@ struct DepotWindow : Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show tooltip window */
|
/* Show tooltip window */
|
||||||
uint64 args[2];
|
SetDParam(0, whole_chain ? num : v->engine_type);
|
||||||
args[0] = (whole_chain ? num : v->engine_type);
|
SetDParamStr(1, details);
|
||||||
args[1] = (uint64)(size_t)details.c_str();
|
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, 2, args, TCC_RIGHT_CLICK);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3129,7 +3129,7 @@ struct IndustryCargoesWindow : public Window {
|
||||||
|
|
||||||
case CFT_INDUSTRY:
|
case CFT_INDUSTRY:
|
||||||
if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
|
if (fld->u.industry.ind_type < NUM_INDUSTRYTYPES && (this->ind_cargo >= NUM_INDUSTRYTYPES || fieldxy.x != 2)) {
|
||||||
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, 0, nullptr, close_cond);
|
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_INDUSTRY_TOOLTIP, close_cond);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -3138,9 +3138,8 @@ struct IndustryCargoesWindow : public Window {
|
||||||
}
|
}
|
||||||
if (IsValidCargoID(cid) && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
|
if (IsValidCargoID(cid) && (this->ind_cargo < NUM_INDUSTRYTYPES || cid != this->ind_cargo - NUM_INDUSTRYTYPES)) {
|
||||||
const CargoSpec *csp = CargoSpec::Get(cid);
|
const CargoSpec *csp = CargoSpec::Get(cid);
|
||||||
uint64 params[5];
|
SetDParam(0, csp->name);
|
||||||
params[0] = csp->name;
|
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, close_cond, 1);
|
||||||
GuiShowTooltips(this, STR_INDUSTRY_CARGOES_CARGO_TOOLTIP, 1, params, close_cond);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -404,12 +404,12 @@ bool LinkGraphOverlay::ShowTooltip(Point pt, TooltipCloseCondition close_cond)
|
||||||
SetDParam(3, j->first);
|
SetDParam(3, j->first);
|
||||||
SetDParam(4, link.Usage() * 100 / (link.capacity + 1));
|
SetDParam(4, link.Usage() * 100 / (link.capacity + 1));
|
||||||
SetDParamStr(5, tooltip_extension);
|
SetDParamStr(5, tooltip_extension);
|
||||||
GuiShowTooltips(this->window, STR_LINKGRAPH_STATS_TOOLTIP, 7, nullptr, close_cond);
|
GuiShowTooltips(this->window, STR_LINKGRAPH_STATS_TOOLTIP, close_cond, 7);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GuiShowTooltips(this->window, STR_NULL, 0, nullptr, close_cond);
|
GuiShowTooltips(this->window, STR_NULL, close_cond);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,19 +642,17 @@ bool LinkGraphLegendWindow::OnTooltip(Point pt, int widget, TooltipCloseConditio
|
||||||
{
|
{
|
||||||
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
|
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
|
||||||
if (this->IsWidgetDisabled(widget)) {
|
if (this->IsWidgetDisabled(widget)) {
|
||||||
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, 0, nullptr, close_cond);
|
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES, close_cond);
|
||||||
} else {
|
} else {
|
||||||
uint64 params[2];
|
SetDParam(0, STR_LINKGRAPH_LEGEND_SELECT_COMPANIES);
|
||||||
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);
|
SetDParam(1, (CompanyID)(widget - WID_LGL_COMPANY_FIRST));
|
||||||
params[0] = STR_LINKGRAPH_LEGEND_SELECT_COMPANIES;
|
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP, close_cond, 2);
|
||||||
params[1] = cid;
|
|
||||||
GuiShowTooltips(this, STR_LINKGRAPH_LEGEND_COMPANY_TOOLTIP, 2, params, close_cond);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
|
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
|
||||||
const CargoSpec *cargo = _sorted_cargo_specs[widget - WID_LGL_CARGO_FIRST];
|
const CargoSpec *cargo = _sorted_cargo_specs[widget - WID_LGL_CARGO_FIRST];
|
||||||
GuiShowTooltips(this, cargo->name, 0, nullptr, close_cond);
|
GuiShowTooltips(this, cargo->name, close_cond);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -666,17 +666,13 @@ struct TooltipsWindow : public Window
|
||||||
uint64 params[8]; ///< The string parameters.
|
uint64 params[8]; ///< The string parameters.
|
||||||
TooltipCloseCondition close_cond; ///< Condition for closing the window.
|
TooltipCloseCondition close_cond; ///< Condition for closing the window.
|
||||||
|
|
||||||
TooltipsWindow(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
|
TooltipsWindow(Window *parent, StringID str, uint paramcount, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
|
||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
this->string_id = str;
|
this->string_id = str;
|
||||||
static_assert(sizeof(this->params[0]) == sizeof(params[0]));
|
|
||||||
assert(paramcount <= lengthof(this->params));
|
assert(paramcount <= lengthof(this->params));
|
||||||
if (params == nullptr) {
|
|
||||||
params = _global_string_params.GetPointerToOffset(0);
|
|
||||||
}
|
|
||||||
if (paramcount > 0) memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
|
|
||||||
this->paramcount = paramcount;
|
this->paramcount = paramcount;
|
||||||
|
if (paramcount > 0) CopyOutDParam(this->params, this->paramcount);
|
||||||
this->close_cond = close_tooltip;
|
this->close_cond = close_tooltip;
|
||||||
|
|
||||||
this->InitNested();
|
this->InitNested();
|
||||||
|
@ -757,17 +753,16 @@ struct TooltipsWindow : public Window
|
||||||
* Shows a tooltip
|
* Shows a tooltip
|
||||||
* @param parent The window this tooltip is related to.
|
* @param parent The window this tooltip is related to.
|
||||||
* @param str String to be displayed
|
* @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 paramcount number of params to deal with
|
||||||
* @param params (optional) up to 5 pieces of additional information that may be added to a tooltip
|
|
||||||
* @param close_tooltip when the left (true) or right (false) mouse button is released
|
|
||||||
*/
|
*/
|
||||||
void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
|
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
|
||||||
{
|
{
|
||||||
CloseWindowById(WC_TOOLTIPS, 0);
|
CloseWindowById(WC_TOOLTIPS, 0);
|
||||||
|
|
||||||
if (str == STR_NULL || !_cursor.in_window) return;
|
if (str == STR_NULL || !_cursor.in_window) return;
|
||||||
|
|
||||||
new TooltipsWindow(parent, str, paramcount, params, close_tooltip);
|
new TooltipsWindow(parent, str, paramcount, close_tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryString::HandleEditBox(Window *w, int wid)
|
void QueryString::HandleEditBox(Window *w, int wid)
|
||||||
|
|
|
@ -1849,10 +1849,10 @@ public:
|
||||||
|
|
||||||
if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) {
|
if (IsInsideMM(pt.x, player_icon_x, player_icon_x + d2.width)) {
|
||||||
if (index == this->player_self_index) {
|
if (index == this->player_self_index) {
|
||||||
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, 0, nullptr, close_cond);
|
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_SELF_TOOLTIP, close_cond);
|
||||||
return true;
|
return true;
|
||||||
} else if (index == this->player_host_index) {
|
} else if (index == this->player_host_index) {
|
||||||
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, 0, nullptr, close_cond);
|
GuiShowTooltips(this, STR_NETWORK_CLIENT_LIST_PLAYER_ICON_HOST_TOOLTIP, close_cond);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1860,7 +1860,7 @@ public:
|
||||||
ButtonCommon *button = this->GetButtonAtPoint(pt);
|
ButtonCommon *button = this->GetButtonAtPoint(pt);
|
||||||
if (button == nullptr) return false;
|
if (button == nullptr) return false;
|
||||||
|
|
||||||
GuiShowTooltips(this, button->tooltip, 0, nullptr, close_cond);
|
GuiShowTooltips(this, button->tooltip, close_cond);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2644,7 +2644,7 @@ void UpdateTileSelection()
|
||||||
static inline void ShowMeasurementTooltips(StringID str, uint paramcount)
|
static inline void ShowMeasurementTooltips(StringID str, uint paramcount)
|
||||||
{
|
{
|
||||||
if (!_settings_client.gui.measure_tooltip) return;
|
if (!_settings_client.gui.measure_tooltip) return;
|
||||||
GuiShowTooltips(_thd.GetCallbackWnd(), str, paramcount, nullptr, TCC_EXIT_VIEWPORT);
|
GuiShowTooltips(_thd.GetCallbackWnd(), str, TCC_EXIT_VIEWPORT, paramcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HideMeasurementTooltips()
|
static void HideMeasurementTooltips()
|
||||||
|
|
|
@ -823,7 +823,7 @@ static void DispatchRightClickEvent(Window *w, int x, int y)
|
||||||
if (_settings_client.gui.right_mouse_wnd_close && (w->window_desc->flags & WDF_NO_CLOSE) == 0) {
|
if (_settings_client.gui.right_mouse_wnd_close && (w->window_desc->flags & WDF_NO_CLOSE) == 0) {
|
||||||
w->Close();
|
w->Close();
|
||||||
} else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) {
|
} 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, 0, nullptr, TCC_RIGHT_CLICK);
|
GuiShowTooltips(w, wid->tool_tip, TCC_RIGHT_CLICK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,7 +844,7 @@ static void DispatchHoverEvent(Window *w, int x, int y)
|
||||||
|
|
||||||
/* Show the tooltip if there is any */
|
/* Show the tooltip if there is any */
|
||||||
if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
|
if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->tool_tip != 0) {
|
||||||
GuiShowTooltips(w, wid->tool_tip);
|
GuiShowTooltips(w, wid->tool_tip, TCC_HOVER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -898,7 +898,7 @@ Wcls *AllocateWindowDescFront(WindowDesc *desc, int window_number, bool return_e
|
||||||
|
|
||||||
void RelocateAllWindows(int neww, int newh);
|
void RelocateAllWindows(int neww, int newh);
|
||||||
|
|
||||||
void GuiShowTooltips(Window *parent, StringID str, uint paramcount = 0, const uint64 params[] = nullptr, TooltipCloseCondition close_tooltip = TCC_HOVER);
|
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount = 0);
|
||||||
|
|
||||||
/* widget.cpp */
|
/* widget.cpp */
|
||||||
int GetWidgetFromPos(const Window *w, int x, int y);
|
int GetWidgetFromPos(const Window *w, int x, int y);
|
||||||
|
|
Loading…
Reference in New Issue