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

refactor forward/backwards loop #54

Merged
merged 11 commits into from
Oct 24, 2024
2 changes: 2 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ L["None"] = "None"
L["Random"] = "Random"
L["ButtonText"] = "Show text"
L["ButtonText Tooltip"] = "When enabled, an abbreviated name of the dungeon will be added to dungeon teleports."
L["Reverse Mage Flyouts"] = "Reverse Mage Flyouts"
L["Reverse Mage Flyouts Tooltip"] = "Reverse order of flyouts for mage abilities to make most recent expansion teleports appear first"
2 changes: 1 addition & 1 deletion Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function tpm:LoadOptions()

do
local optionsKey = "reverseMageFlyouts"
local tooltip = L["Reverse order of flyouts for mage abilities to make most recent expansion teleports appear first"]
local tooltip = L["Reverse Mage Flyouts Tooltip"]
local setting = Settings.RegisterAddOnSetting(optionsCategory, "reverseMageFlyouts_Checkbox", optionsKey, db, type(defaultsDB[optionsKey]), L["Reverse Mage Flyouts"], defaultsDB[optionsKey])
Settings.SetOnValueChangedCallback("reverseMageFlyouts_Checkbox", OnSettingChanged)
Settings.CreateCheckbox(optionsCategory, setting, tooltip)
Expand Down
113 changes: 49 additions & 64 deletions TeleportMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ local tpTable = {
-- Engineering
{type = "wormholes", iconId = 4620673}, -- Engineering Wormholes
-- Class Teleports
{id = 1, type = "flyout", iconId = 237509}, -- Teleport (Mage)
{id = 8, type = "flyout", iconId = 237509}, -- Teleport (Mage)
{id = 11, type = "flyout", iconId = 135744}, -- Portals (Mage)
{id = 12, type = "flyout", iconId = 135748}, -- Portals (Mage)
{id = 1, type = "flyout", iconId = 237509, subtype = "mage"}, -- Teleport (Mage) (Horde)
{id = 8, type = "flyout", iconId = 237509, subtype = "mage"}, -- Teleport (Mage) (Alliance)
{id = 11, type = "flyout", iconId = 135744, subtype = "mage"}, -- Portals (Mage) (Horde)
{id = 12, type = "flyout", iconId = 135748, subtype = "mage"}, -- Portals (Mage) (Alliance)
{id = 126892, type = "spell"}, -- Zen Pilgrimage (Monk)
{id = 50977, type = "spell"}, -- Death Gate (Death Knight)
{id = 193753, type = "spell"}, -- Dreamwalk (Druid)
Expand Down Expand Up @@ -351,11 +351,11 @@ function tpm:checkQuestCompletion(quest)
end
end

function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
if db.showOnlySeasonalHerosPath and subtype == "path" then
function tpm:CreateFlyout(flyoutData, yOffset)
jetersen marked this conversation as resolved.
Show resolved Hide resolved
if db.showOnlySeasonalHerosPath and flyoutData.subtype == "path" then
return
end
local _, _, spells, flyoutKnown = GetFlyoutInfo(flyoutId)
local _, _, spells, flyoutKnown = GetFlyoutInfo(flyoutData.id)
if not flyoutKnown then
return
end
Expand All @@ -364,7 +364,7 @@ function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
yOffset = yOffset or -40 * TeleportMeButtonsFrame:GetButtonAmount()

button:SetSize(40, 40)
button:SetNormalTexture(iconId)
button:SetNormalTexture(flyoutData.iconId)
button:SetPoint("TOPLEFT", TeleportMeButtonsFrame, "TOPRIGHT", 0, yOffset)
button:EnableMouse(true)
button:RegisterForClicks("AnyDown", "AnyUp")
Expand All @@ -377,7 +377,7 @@ function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
tpm:setCombatTooltip(self)
return
end
tpm:setToolTip(self, "flyout", flyoutId)
tpm:setToolTip(self, "flyout", flyoutData.id)
self.flyOutFrame:Show()
end
)
Expand All @@ -388,11 +388,11 @@ function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
end
)

if db.buttonText == true and name then
if db.buttonText == true and flyoutData.name then
button.text = button:CreateFontString(nil, "OVERLAY")
button.text:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
button.text:SetPoint("BOTTOM", button, "BOTTOM", 0, 5)
button.text:SetText(name)
button.text:SetText(flyoutData.name)
button.text:SetTextColor(1, 1, 1, 1)
end

Expand All @@ -418,9 +418,6 @@ function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
local flyOutButtons = {}
local flyoutsCreated = 0

-- Check if reverseMageFlyouts is enabled
local reverseMageFlyouts = TeleportMenuDB.reverseMageFlyouts

-- Function to create a flyout button
local function createFlyOutButton(spellID, index)
local spellName = C_Spell.GetSpellName(spellID)
Expand Down Expand Up @@ -458,53 +455,37 @@ function tpm:CreateFlyout(flyoutId, iconId, yOffset, name)
return flyOutButton
end

-- Check if reverseMageFlyouts is enabled
-- Loop through spells, either forwards or backwards based on the setting
if reverseMageFlyouts and (flyoutId == 1 or flyoutId == 8 or flyoutId == 11 or flyoutId == 12) then
for i = spells, 1, -1 do
local flyname = nil
local spellID = select(1, GetFlyoutSlotInfo(flyoutId, i))
if IsSpellKnown(spellID) then
for _, v in pairs(dungeons) do
if v.id == spellID then
flyname = v.name
end
end
flyoutsCreated = flyoutsCreated + 1
local flyOutButton = createFlyOutButton(spellID, flyoutsCreated)
if db.buttonText == true and flyname then
flyOutButton.text = flyOutButton:CreateFontString(nil, "OVERLAY")
flyOutButton.text:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
flyOutButton.text:SetPoint("BOTTOM", flyOutButton, "BOTTOM", 0, 5)
flyOutButton.text:SetText(flyname)
flyOutButton.text:SetTextColor(1, 1, 1, 1)
end
table.insert(flyOutButtons, flyOutButton)
end
end
local start, stop, step
if TeleportMenuDB.reverseMageFlyouts and flyoutData.subtype == "mage" then
start, stop, step = spells, 1, -1
else
for i = 1, spells do
local flyname = nil
local spellID = select(1, GetFlyoutSlotInfo(flyoutId, i))
if IsSpellKnown(spellID) then
for _, v in pairs(dungeons) do
if v.id == spellID then
flyname = v.name
end
end
if not flyname then
print(APPEND .. "No short name found for spellID " .. spellID ..", please report this on GitHub")
end
flyoutsCreated = flyoutsCreated + 1
local flyOutButton = createFlyOutButton(spellID, flyoutsCreated)
if db.buttonText == true and flyname then
flyOutButton.text = flyOutButton:CreateFontString(nil, "OVERLAY")
flyOutButton.text:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
flyOutButton.text:SetPoint("BOTTOM", flyOutButton, "BOTTOM", 0, 5)
flyOutButton.text:SetText(flyname)
flyOutButton.text:SetTextColor(1, 1, 1, 1)
start, stop, step = 1, spells, 1
end

for i = start, stop, step do
local flyname = nil
local spellID = select(1, GetFlyoutSlotInfo(flyoutData.id, i))
if IsSpellKnown(spellID) then
for _, v in pairs(dungeons) do
if v.id == spellID then
flyname = v.name
end
table.insert(flyOutButtons, flyOutButton)
end
if not flyname then
print(APPEND .. "No short name found for spellID " .. spellID ..", please report this on GitHub")
end
flyoutsCreated = flyoutsCreated + 1
local flyOutButton = createFlyOutButton(spellID, flyoutsCreated)
if db.buttonText == true and flyname then
flyOutButton.text = flyOutButton:CreateFontString(nil, "OVERLAY")
flyOutButton.text:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
flyOutButton.text:SetPoint("BOTTOM", flyOutButton, "BOTTOM", 0, 5)
flyOutButton.text:SetText(flyname)
flyOutButton.text:SetTextColor(1, 1, 1, 1)
end
table.insert(flyOutButtons, flyOutButton)
end
end

Expand All @@ -516,15 +497,19 @@ end
function tpm:updateMageFlyouts()
local teleportButton = TeleportMeButtonsFrame.mageTeleportButton
local portalButton = TeleportMeButtonsFrame.magePortalButton
if not teleportButton or not portalButton then
return
end
local _, _, _, _, teleportYOffset = teleportButton:GetPoint()
local _, _, _, _, portalYOffset = portalButton:GetPoint()

if select(4, GetFlyoutInfo(12)) then -- Player is Alliance
local updatedTeleportButton = tpm:CreateFlyout(1, 237509, teleportYOffset)
local updatedPortalButton = tpm:CreateFlyout(11, 135748, portalYOffset)
jetersen marked this conversation as resolved.
Show resolved Hide resolved
else -- Player is Horde
local updatedTeleportButton = tpm:CreateFlyout(8, 237509, teleportYOffset)
local updatedPortalButton = tpm:CreateFlyout(12, 135748, portalYOffset)
local updatedTeleportButton, updatedPortalButton
if select(4, GetFlyoutInfo(1)) then -- Player is Horde
jetersen marked this conversation as resolved.
Show resolved Hide resolved
updatedTeleportButton = tpm:CreateFlyout(tpTable[7], teleportYOffset)
updatedPortalButton = tpm:CreateFlyout(tpTable[9], portalYOffset)
else -- Player is Alliance
updatedTeleportButton = tpm:CreateFlyout(tpTable[8], teleportYOffset)
updatedPortalButton = tpm:CreateFlyout(tpTable[10], portalYOffset)
jetersen marked this conversation as resolved.
Show resolved Hide resolved
end

TeleportMeButtonsFrame.mageTeleportButton = updatedTeleportButton
Expand Down Expand Up @@ -1083,7 +1068,7 @@ local function createAnchors()
TeleportMeButtonsFrame:IncrementButtons()
end
elseif teleport.type == "flyout" then
local created = tpm:CreateFlyout(teleport.id, teleport.iconId, nil, teleport.name or nil)
local created = tpm:CreateFlyout(teleport, nil)
if created then
-- Save Teleport button for replacement later
if teleport.id == 1 or teleport.id == 8 then
Expand Down