Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order button tooltips not disappearing on mouse exit #6654

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/snippets/fix.6654.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6654) Fix order button tooltips not disappearing when the mouse is moved off the order button.
10 changes: 10 additions & 0 deletions lua/ui/controls.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
-----------------------------------------------------------------
-- File: lua/ui/controls.lua
-- Author: Crotalus
-- Summary: Let this file have all references to UI controls to make UI behave better
-- when hot-reloading lua files
-----------------------------------------------------------------

local controls = {}

--- Returns a table that persists between file reloads.
---@param key? string # key for the table. Defaults to the source of the calling file.
---@return table
function Get(key)
if not key then
key = debug.getinfo(2, "S").source
Expand Down
82 changes: 34 additions & 48 deletions lua/ui/game/orders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,6 @@ local function CreateAutoBuildEffect(parent)
return glow
end

function CreateMouseoverDisplay(parent, ID)
if controls.mouseoverDisplay then
controls.mouseoverDisplay:Destroy()
controls.mouseoverDisplay = false
end

if not Prefs.GetOption('tooltips') then return end

local createDelay = Prefs.GetOption('tooltip_delay') or 0
local text = TooltipInfo['Tooltips'][ID]['title'] or ID
local desc = TooltipInfo['Tooltips'][ID]['description'] or ID

if not text or not desc then
return
end

controls.mouseoverDisplay = Tooltip.CreateMouseoverDisplay(parent, {["text"] = text, ["body"] = desc}, nil, true)
end

local function CreateOrderButtonGrid()
controls.orderButtonGrid = Grid(controls.bg, GameCommon.iconWidth, GameCommon.iconHeight)
controls.orderButtonGrid:SetName("Orders Grid")
Expand Down Expand Up @@ -382,9 +363,7 @@ local function BuildOrderBehavior(self, modifiers)
self._curHelpText = self._data.helpText
self.autoBuildEffect:Destroy()
end
if controls.mouseoverDisplay.text then
controls.mouseoverDisplay.text:SetText(self._curHelpText)
end
Tooltip.SetTooltipText(self._curHelpText)
SetAutoMode(currentSelection, self:IsChecked())
end
end
Expand Down Expand Up @@ -451,9 +430,7 @@ local function DiveOrderBehavior(self, modifiers)
self.autoModeIcon:SetAlpha(1)
self._isAutoMode = true
end
if controls.mouseoverDisplay.text then
controls.mouseoverDisplay.text:SetText(self._curHelpText)
end
Tooltip.SetTooltipText(self._curHelpText)
SetAutoSurfaceMode(currentSelection, self._isAutoMode)
end
end
Expand Down Expand Up @@ -587,9 +564,7 @@ local function ScriptButtonOrderBehavior(self, modifiers, subState)
ToggleScriptBit(currentSelection, self._data.extraInfo, state)
end

if controls.mouseoverDisplay.text then
controls.mouseoverDisplay.text:SetText(self._curHelpText)
end
Tooltip.SetTooltipText(self._curHelpText)
if subState == nil then
Checkbox.OnClick(self)
end
Expand Down Expand Up @@ -642,9 +617,7 @@ local function StatToggleOrderBehavior(self, modifiers, subState)
SimCallback( { Func="SetStatByCallback", Args= {[self._data.statToggle] = not state}}, true)
end

if controls.mouseoverDisplay.text then
controls.mouseoverDisplay.text:SetText(self._curHelpText)
end
Tooltip.SetTooltipText(self._curHelpText)
if subState == nil then
Checkbox.OnClick(self)
else
Expand Down Expand Up @@ -796,12 +769,9 @@ local function CreateFirestatePopup(parent, selected)
btn.index = index
btn.HandleEvent = function(control, event)
if event.Type == 'MouseEnter' then
CreateMouseoverDisplay(control, control.info.helpText, 1)
Tooltip.CreateMouseoverDisplay(control, control.info.helpText, nil, true)
elseif event.Type == 'MouseExit' then
if controls.mouseoverDisplay then
controls.mouseoverDisplay:Destroy()
controls.mouseoverDisplay = false
end
Tooltip.DestroyMouseoverDisplay()
end
return Checkbox.HandleEvent(control, event)
end
Expand Down Expand Up @@ -1021,9 +991,7 @@ function OverchargeBehavior(self, modifiers)
self._isAutoMode = true
end

if controls.mouseoverDisplay.text then
controls.mouseoverDisplay.text:SetText(self._curHelpText)
end
Tooltip.SetTooltipText(self._curHelpText)

SimCallback({Func = 'AutoOvercharge', Args = {auto = self._isAutoMode == true} }, true)
end
Expand Down Expand Up @@ -1293,7 +1261,7 @@ local function AddOrder(orderInfo, slot, batchMode)
-- Set up tooltips
checkbox.HandleEvent = function(self, event)
if event.Type == 'MouseEnter' then
CreateMouseoverDisplay(self, self._curHelpText, 1)
Tooltip.CreateMouseoverDisplay(self, self._curHelpText, nil, true)

if not self:IsDisabled() then
if controls.orderGlow then
Expand All @@ -1303,10 +1271,7 @@ local function AddOrder(orderInfo, slot, batchMode)
glowThread = CreateOrderGlow(self)
end
elseif event.Type == 'MouseExit' then
if controls.mouseoverDisplay then
controls.mouseoverDisplay:Destroy()
controls.mouseoverDisplay = false
end
Tooltip.DestroyMouseoverDisplay()
if controls.orderGlow then
controls.orderGlow:Destroy()
controls.orderGlow = false
Expand Down Expand Up @@ -1699,10 +1664,7 @@ function SetAvailableOrders(availableOrders, availableToggles, newSelection)
end

function CreateControls()
if controls.mouseoverDisplay then
controls.mouseoverDisplay:Destroy()
controls.mouseoverDisplay = false
end
Tooltip.DestroyMouseoverDisplay()
if not controls.bg then
controls.bg = Bitmap(controls.controlClusterGroup)
end
Expand Down Expand Up @@ -1790,3 +1752,27 @@ function Expand()
controls.bg:Hide()
end
end

--#region Backwards compatibility
function CreateMouseoverDisplay(parent, ID)
Tooltip.CreateMouseoverDisplay(parent, ID, nil, true)
end
local _mouseoverDisplay = setmetatable({}, { __index = { Destroy = Tooltip.DestroyMouseoverDisplay, text = { SetText = Tooltip.SetTooltipText } }, __newindex = function() end })
setmetatable(controls, {
__index = function(t, k)
if k == 'mouseoverDisplay' then
LOG('__index')
return _mouseoverDisplay
else
return rawget(t, k)
end
end,
__newindex = function(t, k, v)
if k == 'mouseoverDisplay' then
LOG('__newindex')
return
else
rawset(t, k, v)
end
end,
})
3 changes: 2 additions & 1 deletion lua/ui/game/tooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local createThread = false

-- creates a tooltip box from ID table and with optional parameters
---@param ID table e.g. { text = 'tooltip header', body = 'tooltip description' }
---@param delay? number minimum delay compared against the prefs `tooltip_delay` option
---@param extended? boolean indicates whether to just create tooltip header or also tooltip description
---@param width? number is optional width of tooltip or it is auto calculated based on length of header/description
---@param forced? boolean determine if the tooltip should override hiding tooltips set in game options
Expand All @@ -37,7 +38,7 @@ function CreateMouseoverDisplay(parent, ID, delay, extended, width, forced, padd
local text = ""
local body = ""
if not position then position = 'center' end

-- remove previous instance
if mouseoverDisplay then
mouseoverDisplay:Destroy()
Expand Down
Loading