WoW:User snippets/MagePortal: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Created page with "-- Create a frame to hold mage portal icons local portalFrame = CreateFrame("Frame", "MagePortalFrame", UIParent) portalFrame:SetSize(200, 300) portalFrame:SetPoint("RIGHT") portalFrame:Hide() -- Hide the frame by default -- Function to create a portal button local button = CreateFrame("Button", ADDON_NAME .. "CraftButton", frame, "UIPanelButtonTemplate") button:SetText("Craft") button:SetSize(100, 25) button:SetPoint("BOTTOM", frame, "BOTTOM", 0, 10) button:SetScript("O...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Created by AddOn Studio wiki user Firstgnome on 02:58, 24 February 2024
<lua>
-- Create a frame to hold mage portal icons
-- Create a frame to hold mage portal icons
local portalFrame = CreateFrame("Frame", "MagePortalFrame", UIParent)
local portalFrame = CreateFrame("Frame", "MagePortalFrame", UIParent)
Line 63: Line 65:
     end
     end
end)
end)
</lua>

Latest revision as of 21:26, 2 August 2025

Created by AddOn Studio wiki user Firstgnome on 02:58, 24 February 2024

-- Create a frame to hold mage portal icons
local portalFrame = CreateFrame("Frame", "MagePortalFrame", UIParent)
portalFrame:SetSize(200, 300)
portalFrame:SetPoint("RIGHT")
portalFrame:Hide() -- Hide the frame by default
-- Function to create a portal button
local button = CreateFrame("Button", ADDON_NAME .. "CraftButton", frame, "UIPanelButtonTemplate")
button:SetText("Craft")
button:SetSize(100, 25)
button:SetPoint("BOTTOM", frame, "BOTTOM", 0, 10)
button:SetScript("OnClick", function()
    if selectedItem then
        local itemName = selectedItem:GetText()
        if itemName then
            SendChatMessage("/cast " .. portalName, "SAY")
        end
    end
end)
-- Create portal buttons
local function CreatePortalButtons()
    local faction = UnitFactionGroup("player")
    local portals = {
        {portalName= "Portal: Orgrimmar", texturePath = "Interface\\Icons\\Spell_Arcane_PortalOrgrimmar", faction = "Horde"},
        {portalName = "Portal: Stormwind", texturePath = "Interface\\Icons\\Spell_Arcane_PortalStormwind", faction = "Alliance"},
        {portalName = "Portal: Ironforge", texturePath = "Interface\\Icons\\Spell_Arcane_PortalIronForge", faction = "Alliance"},
        {portalName = "Portal: Darnassus", texturePath = "Interface\\Icons\\Spell_Arcane_PortalDarnassus", faction = "Alliance"},
        {portalName = "Portal: Thunder Bluff", texturePath = "Interface\\Icons\\Spell_Arcane_PortalThunderBluff", faction = "Horde"},
        {portalName = "Portal: Undercity", texturePath = "Interface\\Icons\\Spell_Arcane_PortalUnderCity", faction = "Horde"},
        {portalName = "Portal: Silvermoon", texturePath = "Interface\\Icons\\Spell_Arcane_PortalSilvermoon", faction = "Horde"},
        {portalName = "Portal: Exodar", texturePath = "Interface\\Icons\\Spell_Arcane_PortalExodar", faction = "Alliance"},
        {portalName = "Portal: Shattrath", texturePath = "Interface\\Icons\\Spell_Arcane_PortalShattrath", faction = "Neutral"},
        {portalName = "Portal: Dalaran - Northrend", texturePath = "Interface\\Icons\\Spell_Arcane_PortalDalaran", faction = "Neutral"}
    }
    local yOffset = -10
    for _, portal in ipairs(portals) do
        if portal.faction == faction or portal.faction == "Neutral" then
            local button = CreatePortalButton(portal.portalName, portal.texturePath)
            button:SetPoint("TOP", 0, yOffset)
            yOffset = yOffset - 50
        end
    end
end
-- Toggle frame visibility function
local function ToggleFrameVisibility()
    if portalFrame:IsVisible() then
        portalFrame:Hide()
    else
        portalFrame:Show()
    end
end
-- Create a button to toggle frame visibility on minimap
local toggleButton = CreateFrame("Button", nil, Minimap)
toggleButton:SetSize(20, 20)
toggleButton:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 0, 0)
toggleButton:SetNormalTexture("Interface\\Icons\\Ability_Hunter_BeastTaming")
toggleButton:SetScript("OnClick", ToggleFrameVisibility)
-- Initialize addon
local addon = CreateFrame("Frame")
addon:RegisterEvent("ADDON_LOADED")
addon:SetScript("OnEvent", function(self, event, addonName)
    if addonName == "MagePortal" then
        CreatePortalButtons()
    end
end)