diff --git a/src/widget.cpp b/src/widget.cpp index 8ddd77ed6d..53559743cf 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1154,6 +1154,15 @@ void NWidgetCore::SetToolTip(StringID tool_tip) this->tool_tip = tool_tip; } +/** + * Get the tool tip of the nested widget. + * @return The tool tip string. + */ +StringID NWidgetCore::GetToolTip() const +{ + return this->tool_tip; +} + /** * Set the text/image alignment of the nested widget. * @param align Alignment to use. diff --git a/src/widget_type.h b/src/widget_type.h index a4325df4f4..5fd2fedc01 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -377,6 +377,7 @@ public: void SetSpriteTip(SpriteID sprite, StringID tool_tip) { this->SetDataTip(sprite, tool_tip); } void SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip) { this->SetDataTip(static_cast((rows << MAT_ROW_START) | (cols << MAT_COL_START)), tip); } void SetToolTip(StringID tool_tip); + StringID GetToolTip() const; void SetTextStyle(TextColour colour, FontSize size); void SetAlignment(StringAlignment align); diff --git a/src/window.cpp b/src/window.cpp index c97a27e257..99a87da82a 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -756,8 +756,8 @@ static void DispatchRightClickEvent(Window *w, int x, int y) } else if (_settings_client.gui.right_click_wnd_close == RCC_YES_EXCEPT_STICKY && (w->flags & WF_STICKY) == 0 && (w->window_desc.flags & WDF_NO_CLOSE) == 0) { /* 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); + } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->GetToolTip() != STR_NULL) { + GuiShowTooltips(w, wid->GetToolTip(), TCC_RIGHT_CLICK); } } @@ -777,8 +777,8 @@ static void DispatchHoverEvent(Window *w, int x, int y) Point pt = { x, 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); + if (!w->OnTooltip(pt, wid->index, TCC_HOVER) && wid->GetToolTip() != STR_NULL) { + GuiShowTooltips(w, wid->GetToolTip(), TCC_HOVER); return; }