Skip to content

Commit

Permalink
Split out logic from method
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Dec 31, 2024
1 parent 1c2eeb1 commit 39b1a15
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ local function tooltipHook(tooltip, item)
end
end

local function tooltipShow(self)
if self:GetRight() >= GetScreenWidth() / 2 then
GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
else
GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
end

if self.itemLink then
GameTooltip:SetHyperlink(self.itemLink)
else
GameTooltip:SetBagItem(self:GetAttribute('target-bag'), self:GetAttribute('target-slot'))
end

if addon:IsRetail() then
if self.spellID then
local spellName = (C_Spell.GetSpellName or GetSpellInfo)(self.spellID)
tooltipHelp((('\n'):split(NPEV2_CASTER_ABILITYINITIAL:gsub(' %%s ', '%s'))):format('|A:NPE_LeftClick:18:18|a', '|cff0090ff' .. spellName .. '|r'))
elseif self.itemID then
tooltipHelp(NPEV2_ABILITYINITIAL:format('|A:NPE_LeftClick:18:18|a', '|cff0090ff' .. C_Item.GetItemNameByID(self.itemID) .. '|r'))
end
end

GameTooltip:Show()
end

function addon:OnLogin()
-- load late so our hooks are added late, that way our tooltip lines are more
-- likely to render at the bottom of the tooltip (but no guarantee)
Expand Down Expand Up @@ -194,30 +219,7 @@ end)

-- tooltips
Molinari:HookScript('OnLeave', GameTooltip_Hide)
Molinari:HookScript('OnEnter', function(self)
if self:GetRight() >= GetScreenWidth() / 2 then
GameTooltip:SetOwner(self, 'ANCHOR_LEFT')
else
GameTooltip:SetOwner(self, 'ANCHOR_RIGHT')
end

if self.itemLink then
GameTooltip:SetHyperlink(self.itemLink)
else
GameTooltip:SetBagItem(self:GetAttribute('target-bag'), self:GetAttribute('target-slot'))
end

if addon:IsRetail() then
if self.spellID then
local spellName = (C_Spell.GetSpellName or GetSpellInfo)(self.spellID)
tooltipHelp((('\n'):split(NPEV2_CASTER_ABILITYINITIAL:gsub(' %%s ', '%s'))):format('|A:NPE_LeftClick:18:18|a', '|cff0090ff' .. spellName .. '|r'))
elseif self.itemID then
tooltipHelp(NPEV2_ABILITYINITIAL:format('|A:NPE_LeftClick:18:18|a', '|cff0090ff' .. C_Item.GetItemNameByID(self.itemID) .. '|r'))
end
end

GameTooltip:Show()
end)
Molinari:HookScript('OnEnter', tooltipShow)

-- hide whenever a bag update occurs
function addon:BAG_UPDATE_DELAYED()
Expand All @@ -229,7 +231,7 @@ end
-- force-update tooltip whenever a modifier changes, as the state driver doesn't handle OnEnter
function addon:MODIFIER_STATE_CHANGED()
if Molinari:IsShown() then
Molinari:GetScript('OnEnter')(Molinari)
tooltipShow(Molinari)

if modifier == 'CTRL' and not IsControlKeyDown() then
addon:DeferMethod(Molinari, 'Hide')
Expand Down

0 comments on commit 39b1a15

Please sign in to comment.