Skip to content

Commit

Permalink
fix(ui): more stable skyriding buttons for low level chars [cf#118](h…
Browse files Browse the repository at this point in the history
  • Loading branch information
exochron committed Aug 5, 2024
1 parent 2026754 commit 7448e33
Showing 1 changed file with 54 additions and 41 deletions.
95 changes: 54 additions & 41 deletions UI/SkyridingButtons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ EventRegistry:RegisterCallback(
)

local function UpdateToggleTrait(self)
self.spellId = nil
local configId = C_Traits.GetConfigIDBySystemID(Constants.MountDynamicFlightConsts.TRAIT_SYSTEM_ID)
local nodeInfo = C_Traits.GetNodeInfo(configId, self.nodeId)
local entryInfo = C_Traits.GetEntryInfo(configId, nodeInfo.activeEntry.entryID)
local definitionInfo = C_Traits.GetDefinitionInfo(entryInfo.definitionID)
local spellIcon = C_Spell.GetSpellTexture(definitionInfo.spellID)
self.texture:SetTexture(spellIcon)
self.spellId = definitionInfo.spellID
if configId then
local nodeInfo = C_Traits.GetNodeInfo(configId, self.nodeId)
if nodeInfo and nodeInfo.activeEntry then
local entryInfo = C_Traits.GetEntryInfo(configId, nodeInfo.activeEntry.entryID)
local definitionInfo = C_Traits.GetDefinitionInfo(entryInfo.definitionID)
local spellIcon = C_Spell.GetSpellTexture(definitionInfo.spellID)
self.texture:SetTexture(spellIcon)
self.spellId = definitionInfo.spellID
end
end
end

local function DisplayTooltip(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetSpellByID(self.spellId)
GameTooltip:Show()
if self.spellId then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetSpellByID(self.spellId)
GameTooltip:Show()
end
end

local function BuildTraitToggle(nodeId)
Expand All @@ -50,18 +57,20 @@ local function BuildTraitToggle(nodeId)
button:HookScript("OnClick", function(self)
local configId = C_Traits.GetConfigIDBySystemID(Constants.MountDynamicFlightConsts.TRAIT_SYSTEM_ID)

local nodeInfo = C_Traits.GetNodeInfo(configId, nodeId)
if #nodeInfo.entryIDs == 2 and nodeInfo.activeEntry then
local toggleEntryIndex = nodeInfo.entryIDs[1] == nodeInfo.activeEntry.entryID and 2 or 1
if configId then
local nodeInfo = C_Traits.GetNodeInfo(configId, nodeId)
if nodeInfo and #nodeInfo.entryIDs == 2 and nodeInfo.activeEntry then
local toggleEntryIndex = nodeInfo.entryIDs[1] == nodeInfo.activeEntry.entryID and 2 or 1

C_Traits.SetSelection(configId, nodeId, nodeInfo.entryIDs[toggleEntryIndex])
C_Traits.CommitConfig(configId)
if GenericTraitFrame then
GenericTraitFrame:MarkNodeInfoCacheDirty(nodeId)
end
C_Traits.SetSelection(configId, nodeId, nodeInfo.entryIDs[toggleEntryIndex])
C_Traits.CommitConfig(configId)
if GenericTraitFrame then
GenericTraitFrame:MarkNodeInfoCacheDirty(nodeId)
end

UpdateToggleTrait(self)
DisplayTooltip(self)
UpdateToggleTrait(self)
DisplayTooltip(self)
end
end
end)
button:HookScript("OnShow", UpdateToggleTrait)
Expand All @@ -78,16 +87,18 @@ local function checkInitialTraitSelection()
local configId = C_Traits.GetConfigIDBySystemID(Constants.MountDynamicFlightConsts.TRAIT_SYSTEM_ID)
local hasUpdate = false

local nodeInfo = C_Traits.GetNodeInfo(configId, RIDING_ALONG_NODE_ID)
if not nodeInfo.activeEntry then
C_Traits.SetSelection(configId, RIDING_ALONG_NODE_ID, nodeInfo.entryIDs[1])
hasUpdate = true
end
if configId then
local nodeInfo = C_Traits.GetNodeInfo(configId, RIDING_ALONG_NODE_ID)
if nodeInfo and not nodeInfo.activeEntry then
C_Traits.SetSelection(configId, RIDING_ALONG_NODE_ID, nodeInfo.entryIDs[1])
hasUpdate = true
end

nodeInfo = C_Traits.GetNodeInfo(configId, WHIRLING_SURGE_NODE_ID)
if not nodeInfo.activeEntry then
C_Traits.SetSelection(configId, WHIRLING_SURGE_NODE_ID, nodeInfo.entryIDs[1])
hasUpdate = true
nodeInfo = C_Traits.GetNodeInfo(configId, WHIRLING_SURGE_NODE_ID)
if nodeInfo and not nodeInfo.activeEntry then
C_Traits.SetSelection(configId, WHIRLING_SURGE_NODE_ID, nodeInfo.entryIDs[1])
hasUpdate = true
end
end

if hasUpdate then
Expand All @@ -97,17 +108,19 @@ end

ADDON.Events:RegisterCallback("loadUI", function()
-- make sure first node in traits are selected
checkInitialTraitSelection()

ADDON.UI:RegisterToolbarGroup(
'05-skyriding',
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton,
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton,
BuildTraitToggle(RIDING_ALONG_NODE_ID),
BuildTraitToggle(WHIRLING_SURGE_NODE_ID)
)
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton:SetParent(MountJournal)
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton:Show()
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton:SetParent(MountJournal)
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton:Show()
if C_MountJournal.IsDragonridingUnlocked() then
checkInitialTraitSelection()

ADDON.UI:RegisterToolbarGroup(
'05-skyriding',
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton,
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton,
BuildTraitToggle(RIDING_ALONG_NODE_ID),
BuildTraitToggle(WHIRLING_SURGE_NODE_ID)
)
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton:SetParent(MountJournal)
MountJournal.DynamicFlightFlyout.OpenDynamicFlightSkillTreeButton:Show()
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton:SetParent(MountJournal)
MountJournal.DynamicFlightFlyout.DynamicFlightModeButton:Show()
end
end, 'skyriding' )

0 comments on commit 7448e33

Please sign in to comment.