Guest User

xanAchievementMover

a guest
Jun 28th, 2015
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local L = XANACHIEVEMENTMOVER_L
  3.  
  4. local f = CreateFrame("frame","xanAchievementMover",UIParent)
  5. f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
  6.  
  7. UIPARENT_MANAGED_FRAME_POSITIONS["AchievementAlertFrame1"] = nil;
  8. UIPARENT_MANAGED_FRAME_POSITIONS["AchievementAlertFrame2"] = nil;
  9. UIPARENT_MANAGED_FRAME_POSITIONS["DungeonCompletionAlertFrame1"] = nil;
  10. UIPARENT_MANAGED_FRAME_POSITIONS["GuildChallengeAlertFrame"] = nil;
  11. UIPARENT_MANAGED_FRAME_POSITIONS["AlertFrame"] = nil;
  12. UIPARENT_MANAGED_FRAME_POSITIONS["ChallengeModeAlertFrame1"] = nil;
  13. UIPARENT_MANAGED_FRAME_POSITIONS["ScenarioAlertFrame1"] = nil;
  14. UIPARENT_MANAGED_FRAME_POSITIONS["GarrisonFollowerAlertFrame"] = nil;
  15. UIPARENT_MANAGED_FRAME_POSITIONS["GarrisonMissionAlertFrame"] = nil;
  16. UIPARENT_MANAGED_FRAME_POSITIONS["GarrisonBuildingAlertFrame"] = nil;
  17. UIPARENT_MANAGED_FRAME_POSITIONS["StorePurchaseAlertFrame"] = nil;
  18. UIPARENT_MANAGED_FRAME_POSITIONS["MoneyWonAlertFrame1"] = nil;
  19. UIPARENT_MANAGED_FRAME_POSITIONS["GarrisonShipMissionAlertFrame"] = nil;
  20. UIPARENT_MANAGED_FRAME_POSITIONS["GarrisonShipFollowerAlertFrame"] = nil;
  21.  
  22. for i=1, MAX_ACHIEVEMENT_ALERTS do
  23.     UIPARENT_MANAGED_FRAME_POSITIONS["AchievementAlertFrame"..i] = nil;
  24. end
  25.  
  26. for i=1, MAX_ACHIEVEMENT_ALERTS do
  27.     UIPARENT_MANAGED_FRAME_POSITIONS["CriteriaAlertFrame"..i] = nil;
  28. end
  29.  
  30. ----------------------
  31. --  POSITION FIX    --
  32. ----------------------
  33.  
  34. local function customFixAnchors(...)
  35.  
  36.     local frame = AchievementAlertFrame1
  37.     local frameTwo = AchievementAlertFrame2
  38.     local frameD = DungeonCompletionAlertFrame1
  39.     local frameG = GuildChallengeAlertFrame
  40.     local frameA = AlertFrame
  41.     local frameC = ChallengeModeAlertFrame1
  42.     local frameS = ScenarioAlertFrame1
  43.     local frameGF = GarrisonFollowerAlertFrame
  44.     local frameGM = GarrisonMissionAlertFrame
  45.     local frameGB = GarrisonBuildingAlertFrame
  46.     local frameSP = StorePurchaseAlertFrame
  47.     local frameMW = MoneyWonAlertFrame1
  48.     local frameNM = GarrisonShipMissionAlertFrame
  49.     local frameNF = GarrisonShipFollowerAlertFrame
  50.    
  51.    
  52.     --check for dungeon shown
  53.     if (frameD and frameD:IsShown()) then
  54.         f:LoadPositionHook("DungeonCompletionAlertFrame1", "xanAchievementMover_Anchor")
  55.     end
  56.    
  57.     --check for guild challenge shown
  58.     if (frameG and frameG:IsShown()) then
  59.         f:LoadPositionHook("GuildChallengeAlertFrame", "xanAchievementMover_Anchor")
  60.     end
  61.    
  62.     --check for dungeon challenge shown
  63.     if (frameC and frameC:IsShown()) then
  64.         f:LoadPositionHook("ChallengeModeAlertFrame1", "xanAchievementMover_Anchor")
  65.     end
  66.    
  67.     --check for scenario complete shown
  68.     if (frameS and frameS:IsShown()) then
  69.         f:LoadPositionHook("ScenarioAlertFrame1", "xanAchievementMover_Anchor")
  70.     end
  71.    
  72.     --check for garrison frames
  73.     if (frameGF and frameGF:IsShown()) then
  74.         f:LoadPositionHook("GarrisonFollowerAlertFrame", "xanAchievementMover_Anchor")
  75.     end
  76.     if (frameGM and frameGM:IsShown()) then
  77.         f:LoadPositionHook("GarrisonMissionAlertFrame", "xanAchievementMover_Anchor")
  78.     end
  79.    
  80.     if (frameNM and frameNM:IsShown()) then
  81.     f:LoadPositionHook("GarrisonShipMissionAlertFrame", "xanAchievementMover_Anchor")
  82.     end
  83.  
  84.     if (frameNF and frameNF:IsShown()) then
  85.     f:LoadPositionHook("GarrisonShipFollowerAlertFrame", "xanAchievementMover_Anchor")
  86.     end
  87.    
  88.     if (frameGB and frameGB:IsShown()) then
  89.         f:LoadPositionHook("GarrisonBuildingAlertFrame", "xanAchievementMover_Anchor")
  90.     end
  91.    
  92.     --check for Money & Store frames
  93.     if (frameMW and frameMW:IsShown()) then
  94.         f:LoadPositionHook("MoneyWonAlertFrame1", "xanAchievementMover_Anchor")
  95.     end
  96.     if (frameSP and frameSP:IsShown()) then
  97.         f:LoadPositionHook("StorePurchaseAlertFrame", "xanAchievementMover_Anchor")
  98.     end
  99.    
  100.     --position the achievements
  101.     for i=1, MAX_ACHIEVEMENT_ALERTS do
  102.         local achframe = _G["AchievementAlertFrame"..i];
  103.         if ( achframe and achframe:IsShown() ) then
  104.             achframe:ClearAllPoints()
  105.             if i == 1 then
  106.                 f:LoadPositionHook("AchievementAlertFrame1", "xanAchievementMover_Ach1")
  107.             elseif _G["AchievementAlertFrame"..(i-1)] then
  108.                 achframe:SetPoint("TOPLEFT", _G["AchievementAlertFrame"..(i-1)], "BOTTOMLEFT", 0, 4)
  109.             end
  110.         end
  111.     end
  112.  
  113.     --position the criteria alerts
  114.     for i=1, MAX_ACHIEVEMENT_ALERTS do
  115.         local achframe = _G["CriteriaAlertFrame"..i];
  116.         if ( achframe and achframe:IsShown() ) then
  117.             achframe:ClearAllPoints()
  118.             if i == 1 then
  119.                 f:LoadPositionHook("CriteriaAlertFrame1", "xanAchievementMover_Ach1")
  120.             elseif _G["CriteriaAlertFrame"..(i-1)] then
  121.                 achframe:SetPoint("TOPLEFT", _G["CriteriaAlertFrame"..(i-1)], "BOTTOMLEFT", 0, 4)
  122.             end
  123.         end
  124.     end
  125.    
  126. end
  127.  
  128. hooksecurefunc("AlertFrame_FixAnchors", customFixAnchors)
  129.  
  130. ----------------------
  131. --      Enable      --
  132. ----------------------
  133.  
  134. function f:PLAYER_LOGIN()
  135.  
  136.     if not XanAM_DB then XanAM_DB = {} end
  137.    
  138.     self:DrawAnchor()
  139.     self:RestoreLayout("xanAchievementMover_Anchor")
  140.  
  141.     SLASH_XANACHIEVEMENTMOVER1 = "/xanam";
  142.     SlashCmdList["XANACHIEVEMENTMOVER"] = xanAchievementMover_SlashCommand;
  143.    
  144.     local ver = GetAddOnMetadata("xanAchievementMover","Version") or '1.0'
  145. --  DEFAULT_CHAT_FRAME:AddMessage(string.format(L["|cFF99CC33%s|r [v|cFFDF2B2B%s|r] loaded:   /xanam"], "xanAchievementMover", ver or "1.0"))
  146.    
  147.     self:UnregisterEvent("PLAYER_LOGIN")
  148.     self.PLAYER_LOGIN = nil
  149. end
  150.  
  151. function xanAchievementMover_SlashCommand(cmd)
  152.     if not _G["xanAchievementMover_Anchor"] then return end
  153.     _G["xanAchievementMover_Anchor"]:Show()
  154. end
  155.  
  156. function f:DrawAnchor()
  157.  
  158.     --lets do the dungeon one first ;)
  159.     local frame = CreateFrame("Frame", "xanAchievementMover_Anchor", UIParent)
  160.  
  161.     frame:SetFrameStrata("DIALOG")
  162.     frame:SetWidth(DungeonCompletionAlertFrame1:GetWidth())
  163.     frame:SetHeight(DungeonCompletionAlertFrame1:GetHeight())
  164.  
  165.     frame:EnableMouse(true)
  166.     frame:SetMovable(true)
  167.  
  168.     frame:SetScript("OnMouseDown",function(self, button)
  169.         if button == "LeftButton" then
  170.             self.isMoving = true
  171.             self:StartMoving()
  172.         else
  173.             self:Hide()
  174.         end
  175.        
  176.     end)
  177.     frame:SetScript("OnMouseUp",function(self)
  178.         if( self.isMoving ) then
  179.             self.isMoving = nil
  180.             self:StopMovingOrSizing()
  181.  
  182.             f:SaveLayout(self:GetName())
  183.             f:SaveLayout("xanAchievementMover_Ach1")
  184.         end
  185.     end)
  186.  
  187.     local stringA = frame:CreateFontString()
  188.     stringA:SetAllPoints(frame)
  189.     stringA:SetFontObject("GameFontNormalSmall")
  190.     stringA:SetText(L["xanAchievementMover [DUNGEON POPUP]\n\nRight click when finished dragging"])
  191.  
  192.     frame:SetBackdrop({
  193.             edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  194.             tile = true,
  195.             tileSize = 16,
  196.             edgeSize = 16,
  197.             insets = { left = 5, right = 5, top = 5, bottom = 5 }
  198.     })
  199.     frame:SetBackdropColor(0.15, 0.49, 1, 1)
  200.     frame:SetBackdropBorderColor(0.15, 0.49, 1, 1)
  201.  
  202.     frame.bg = frame:CreateTexture(nil, "BACKGROUND")
  203.     frame.bg:SetTexCoord(0, 0.546875, 0.28515, 0.5664)
  204.     frame.bg:SetWidth(70)
  205.     frame.bg:SetHeight(72)
  206.     frame.bg:SetTexture("Interface\\LFGFrame\\UI-LFG-DUNGEONTOAST")
  207.     frame.bg:SetPoint("BOTTOMLEFT")
  208.  
  209.     frame.bg1 = frame:CreateTexture(nil, "BACKGROUND")
  210.     frame.bg1:SetTexCoord(0.5546875, 0.671875, 0.28515, 0.5664)
  211.     frame.bg1:SetWidth(15)
  212.     frame.bg1:SetHeight(72)
  213.     frame.bg1:SetTexture("Interface\\LFGFrame\\UI-LFG-DUNGEONTOAST")
  214.     frame.bg1:SetPoint("BOTTOMRIGHT")
  215.  
  216.     frame.bg2 = frame:CreateTexture(nil, "BACKGROUND")
  217.     frame.bg2:SetTexCoord(0, 0.9921875, 0, 0.28125)
  218.     frame.bg2:SetWidth(127)
  219.     frame.bg2:SetHeight(72)
  220.     frame.bg2:SetTexture("Interface\\LFGFrame\\UI-LFG-DUNGEONTOAST")
  221.     frame.bg2:SetPoint("BOTTOMLEFT", 69, 0)
  222.  
  223.     frame.bg3 = frame:CreateTexture(nil, "BACKGROUND")
  224.     frame.bg3:SetTexCoord(0, 0.9921875, 0.58203, 0.86328)
  225.     frame.bg3:SetWidth(127)
  226.     frame.bg3:SetHeight(72)
  227.     frame.bg3:SetTexture("Interface\\LFGFrame\\UI-LFG-DUNGEONTOAST")
  228.     frame.bg3:SetPoint("BOTTOMRIGHT", -14, 0)
  229.  
  230.    
  231.     --achievement popup 1
  232.     local frameAch1 = CreateFrame("Frame", "xanAchievementMover_Ach1", xanAchievementMover_Anchor)
  233.  
  234.     frameAch1:SetFrameStrata("DIALOG")
  235.     frameAch1:SetWidth(300)
  236.     frameAch1:SetHeight(88)
  237.     frameAch1:ClearAllPoints()
  238.     frameAch1:SetPoint("CENTER", xanAchievementMover_Anchor, "BOTTOM", 0, -(frame:GetHeight()/2 + 4) )
  239.            
  240.     frameAch1:EnableMouse(true)
  241.     frameAch1:SetMovable(true)
  242.  
  243.     frameAch1:SetScript("OnMouseDown",function(self, button)
  244.         if button == "LeftButton" then
  245.             self:GetParent().isMoving = true
  246.             self:GetParent():StartMoving()
  247.         end
  248.        
  249.     end)
  250.     frameAch1:SetScript("OnMouseUp",function(self)
  251.         if( self:GetParent().isMoving ) then
  252.             self:GetParent().isMoving = nil
  253.             self:GetParent():StopMovingOrSizing()
  254.             f:SaveLayout(self:GetParent():GetName())
  255.             f:SaveLayout("xanAchievementMover_Ach1")
  256.         end
  257.     end)
  258.  
  259.     local stringAch1 = frameAch1:CreateFontString()
  260.     stringAch1:SetAllPoints(frameAch1)
  261.     stringAch1:SetFontObject("GameFontNormalSmall")
  262.     stringAch1:SetText(L["xanAchievementMover [ACHIEVEMENT 1]"])
  263.  
  264.     frameAch1:SetBackdrop({
  265.             edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  266.             tile = true,
  267.             tileSize = 16,
  268.             edgeSize = 16,
  269.             insets = { left = 5, right = 5, top = 5, bottom = 5 }
  270.     })
  271.     frameAch1:SetBackdropColor(153/255, 204/255, 51/255, 1)
  272.     frameAch1:SetBackdropBorderColor(153/255, 204/255, 51/255, 1)
  273.    
  274.     frameAch1.bg = frameAch1:CreateTexture(nil, "BACKGROUND")
  275.     frameAch1.bg:SetTexCoord(0, .605, 0, .703)
  276.     frameAch1.bg:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Alert-Background")
  277.     frameAch1.bg:SetAllPoints(true)
  278.  
  279.     --achievement popup 2
  280.     local frameAch2 = CreateFrame("Frame", "xanAchievementMover_Ach2", xanAchievementMover_Anchor)
  281.  
  282.     frameAch2:SetFrameStrata("DIALOG")
  283.     frameAch2:SetWidth(300)
  284.     frameAch2:SetHeight(88)
  285.     frameAch2:ClearAllPoints()
  286.     frameAch2:SetPoint("TOPLEFT", frameAch1, "BOTTOMLEFT", 0, 4)
  287.            
  288.     frameAch2:EnableMouse(true)
  289.     frameAch2:SetMovable(true)
  290.  
  291.     frameAch2:SetScript("OnMouseDown",function(self, button)
  292.         if button == "LeftButton" then
  293.             self:GetParent().isMoving = true
  294.             self:GetParent():StartMoving()
  295.         end
  296.        
  297.     end)
  298.     frameAch2:SetScript("OnMouseUp",function(self)
  299.         if( self:GetParent().isMoving ) then
  300.             self:GetParent().isMoving = nil
  301.             self:GetParent():StopMovingOrSizing()
  302.             f:SaveLayout(self:GetParent():GetName())
  303.             f:SaveLayout("xanAchievementMover_Ach1")
  304.         end
  305.     end)
  306.  
  307.     local stringAch2 = frameAch2:CreateFontString()
  308.     stringAch2:SetAllPoints(frameAch2)
  309.     stringAch2:SetFontObject("GameFontNormalSmall")
  310.     stringAch2:SetText(L["xanAchievementMover [ACHIEVEMENT 2]"])
  311.  
  312.     frameAch2:SetBackdrop({
  313.             edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  314.             tile = true,
  315.             tileSize = 16,
  316.             edgeSize = 16,
  317.             insets = { left = 5, right = 5, top = 5, bottom = 5 }
  318.     })
  319.     frameAch2:SetBackdropColor(153/255, 204/255, 51/255, 1)
  320.     frameAch2:SetBackdropBorderColor(153/255, 204/255, 51/255, 1)
  321.    
  322.     frameAch2.bg = frameAch2:CreateTexture(nil, "BACKGROUND")
  323.     frameAch2.bg:SetTexCoord(0, .605, 0, .703)
  324.     frameAch2.bg:SetTexture("Interface\\AchievementFrame\\UI-Achievement-Alert-Background")
  325.     frameAch2.bg:SetAllPoints(true)
  326.    
  327.     frame:Hide()   
  328. end
  329.  
  330. function f:SaveLayout(frame)
  331.     if type(frame) ~= "string" then return end
  332.     if not _G[frame] then return end
  333.     if not XanAM_DB then XanAM_DB = {} end
  334.    
  335.     local opt = XanAM_DB[frame] or nil
  336.  
  337.     if not opt then
  338.         XanAM_DB[frame] = {
  339.             ["point"] = "CENTER",
  340.             ["relativePoint"] = "CENTER",
  341.             ["xOfs"] = 0,
  342.             ["yOfs"] = 0,
  343.         }
  344.         opt = XanAM_DB[frame]
  345.         return
  346.     end
  347.  
  348.     local point, relativeTo, relativePoint, xOfs, yOfs = _G[frame]:GetPoint()
  349.     opt.point = point
  350.     opt.relativePoint = relativePoint
  351.     opt.xOfs = xOfs
  352.     opt.yOfs = yOfs
  353. end
  354.  
  355. function f:RestoreLayout(frame)
  356.     if type(frame) ~= "string" then return end
  357.     if not _G[frame] then return end
  358.     if not XanAM_DB then XanAM_DB = {} end
  359.  
  360.     local opt = XanAM_DB[frame] or nil
  361.  
  362.     if not opt then
  363.         XanAM_DB[frame] = {
  364.             ["point"] = "CENTER",
  365.             ["relativePoint"] = "CENTER",
  366.             ["xOfs"] = 0,
  367.             ["yOfs"] = 0,
  368.         }
  369.         opt = XanAM_DB[frame]
  370.     end
  371.  
  372.     _G[frame]:ClearAllPoints()
  373.     _G[frame]:SetPoint(opt.point, UIParent, opt.relativePoint, opt.xOfs, opt.yOfs)
  374. end
  375.  
  376. function f:LoadPositionHook(frame, frameAttach)
  377.     if type(frame) ~= "string" then return end
  378.     if type(frameAttach) ~= "string" then return end
  379.     if not _G[frame] then return end
  380.     if not _G[frameAttach] then return end
  381.     if not XanAM_DB then XanAM_DB = {} end
  382.  
  383.     local opt = XanAM_DB[frame] or nil
  384.  
  385.     if not opt then
  386.         XanAM_DB[frame] = {
  387.             ["point"] = "CENTER",
  388.             ["relativePoint"] = "CENTER",
  389.             ["xOfs"] = 0,
  390.             ["yOfs"] = 0,
  391.         }
  392.         opt = XanAM_DB[frame]
  393.     end
  394.  
  395.     _G[frame]:ClearAllPoints()
  396.     _G[frame]:SetPoint(opt.point, _G[frameAttach], opt.relativePoint, opt.xOfs, opt.yOfs)
  397.    
  398. end
  399.  
  400. ------------------------------
  401. --      Event Handlers      --
  402. ------------------------------
  403.  
  404. if IsLoggedIn() then f:PLAYER_LOGIN() else f:RegisterEvent("PLAYER_LOGIN") end
RAW Paste Data