diff --git a/UI/SkyridingButtons.lua b/UI/SkyridingButtons.lua index 8861c29..89f1d1d 100644 --- a/UI/SkyridingButtons.lua +++ b/UI/SkyridingButtons.lua @@ -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) @@ -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) @@ -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 @@ -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' )