Engine:UI Macro

Revision as of 10:58, 24 February 2024 by Firstgnome (talk | contribs) (MagePortal)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

-- 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)