Advertisement
Guest User

Unlock.lua

a guest
Jun 27th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Azurah = _G['Azurah'] -- grab addon table from global
  2. local L = Azurah:GetLocale()
  3.  
  4. -- UPVALUES --
  5. local strformat            = string.format
  6.  
  7. local uiFrames = {
  8.    ['ZO_PlayerAttributeHealth']           = {1, L.Health},
  9.    ['ZO_PlayerAttributeSiegeHealth']      = {2, L.HealthSiege},
  10.    ['ZO_PlayerAttributeMagicka']          = {1, L.Magicka},
  11.    ['ZO_PlayerAttributeWerewolf']         = {2, L.Werewolf},
  12.    ['ZO_PlayerAttributeStamina']          = {1, L.Stamina},
  13.    ['ZO_PlayerAttributeMountStamina']     = {2, L.StaminaMount},
  14.    ['ZO_PlayerProgressBar']               = {1, L.Experience},
  15.    ['ZO_SynergyTopLevelContainer']        = {1, L.Synergy},
  16.    ['ZO_CompassFrame']                    = {1, L.Compass},
  17.    ['ZO_TargetUnitFramereticleover']      = {1, L.ReticleOver},
  18.    ['ZO_ActionBar1']                      = {1, L.ActionBar},
  19.    ['ZO_SmallGroupAnchorFrame']           = {1, L.Group},
  20.    ['ZO_LargeGroupAnchorFrame1']          = {1, L.Raid1},
  21.    ['ZO_LargeGroupAnchorFrame2']          = {1, L.Raid2},
  22.    ['ZO_LargeGroupAnchorFrame3']          = {1, L.Raid3},
  23.    ['ZO_LargeGroupAnchorFrame4']          = {1, L.Raid4},
  24.    ['ZO_LargeGroupAnchorFrame5']          = {1, L.Raid5},
  25.    ['ZO_LargeGroupAnchorFrame6']          = {1, L.Raid6},
  26.    ['ZO_FocusedQuestTrackerPanel']        = {1, L.FocusedQuest},
  27.    ['ZO_PlayerToPlayerAreaPromptContainer'] = {1, L.PlayerPrompt},
  28.    ['ZO_AlertTextNotification']           = {1, L.AlertText},
  29. }
  30. local defaultUIData = {}
  31. local uiPanel
  32.  
  33. -- --------------------------------------------
  34. -- DEFAULT ------------------------------------
  35. -- --------------------------------------------
  36.  
  37. function Azurah:RecordDefaultData()
  38.    for frame in pairs(uiFrames) do -- record default position data
  39.       local _, point, rel, relPoint, x, y = _G[frame]:GetAnchor()
  40.  
  41.       defaultUIData[frame] = {
  42.          ['point']      = point,
  43.          ['rel']        = rel,
  44.          ['relPoint']   = relPoint,
  45.          ['x']       = x,
  46.          ['y']       = y,
  47.          ['scale']      = _G[frame]:GetScale()
  48.       }
  49.    end
  50. end
  51.  
  52. function Azurah:RestoreDefaultData() -- reset all frames to default positions
  53.    local data, obj
  54.  
  55.    for frame in pairs(uiFrames) do
  56.       obj, data = _G[frame], defaultUIData[frame]
  57.  
  58.       if (self.db.uiData[frame]) then
  59.          self.db.uiData[frame] = nil -- cleanse user data
  60.       end
  61.  
  62.       obj:ClearAnchors()
  63.       obj:SetAnchor(data.point, data.rel, data.relPoint, data.x, data.y)
  64.       obj:SetScale(data.scale)
  65.  
  66.       self.movers[obj]:Sync() -- reset attachments to new frame positions
  67.    end
  68.  
  69.    AZ_MOVED_COMPASS  = false  -- GLOBALS FOR WYKKYD
  70.    AZ_MOVED_TARGET      = false  -- GLOBALS FOR WYKKYD
  71. end
  72.  
  73. -- --------------------------------------------
  74. -- USER ---------------------------------------
  75. -- --------------------------------------------
  76.  
  77. function Azurah:RecordUserData(frame, point, x, y, scale)
  78.    if (not self.db.uiData[frame]) then
  79.       self.db.uiData[frame] = {}
  80.    end
  81.  
  82.    self.db.uiData[frame].point      = point
  83.    self.db.uiData[frame].x       = x
  84.    self.db.uiData[frame].y       = y
  85.    self.db.uiData[frame].scale      = scale
  86.  
  87.    -- special cases
  88.    if (frame == 'ZO_CompassframeName') then
  89.       AZ_MOVED_COMPASS = true -- GLOBALS FOR WYKKYD
  90.    end
  91.  
  92.    if (frame == 'ZO_TargetUnitFramereticleover') then
  93.       AZ_MOVED_TARGET = true  -- GLOBALS FOR WYKKYD
  94.    end
  95.  
  96.    if (frame == 'ZO_PlayerAttributeHealth') then -- scale attached bar
  97.       ZO_PlayerAttributeSiegeHealth:SetScale(scale)
  98.    end
  99.  
  100.    if (frame == 'ZO_PlayerAttributeMagicka') then -- scale attached bar
  101.       ZO_PlayerAttributeWerewolf:SetScale(scale)
  102.    end
  103.  
  104.    if (frame == 'ZO_PlayerAttributeStamina') then -- scale attached bar
  105.       ZO_PlayerAttributeMountStamina:SetScale(scale)
  106.    end
  107. end
  108.  
  109. function Azurah:RestoreUserData()
  110.    local obj
  111.  
  112.    for frame, data in pairs(self.db.uiData) do
  113.       if frame == "ZO_ExperienceBar" then
  114.          self.db.uiData["ZO_PlayerProgressBar"] = data
  115.          self.db.uiData["ZO_ExperienceBar"] = nil
  116.          frame = "ZO_PlayerProgressBar"
  117.       end
  118.        
  119.       obj = _G[frame]
  120.  
  121.       -- special casse
  122.       if (frame == 'ZO_CompassFrame') then
  123.          AZ_MOVED_COMPASS = true -- GLOBALS FOR WYKKYD
  124.       end
  125.  
  126.       if (frame == 'ZO_TargetUnitFramereticleover') then
  127.          AZ_MOVED_TARGET = true  -- GLOBALS FOR WYKKYD
  128.       end
  129.  
  130.       if (frame == 'ZO_AlertTextNotification') then  -- set an actual size for positioning
  131.          ZO_AlertTextNotification:SetDimensions(600, 56)
  132.       end
  133.  
  134.       if (frame == 'ZO_PlayerToPlayerAreaPromptContainer') then -- special case, has no height
  135.          ZO_PlayerToPlayerAreaPromptContainer:SetHeight(100)
  136.       end
  137.  
  138.       if (frame == 'ZO_FocusedQuestTrackerPanel') then
  139.          ZO_FocusedQuestTrackerPanel:SetHeight(200)
  140.       end
  141.  
  142.       if (frame == 'ZO_PlayerAttributeHealth') then -- scale attached bar
  143.          ZO_PlayerAttributeSiegeHealth:SetScale(data.scale)
  144.       end
  145.  
  146.       if (frame == 'ZO_PlayerAttributeMagicka') then -- scale attached bar
  147.          ZO_PlayerAttributeWerewolf:SetScale(data.scale)
  148.       end
  149.  
  150.       if (frame == 'ZO_PlayerAttributeStamina') then -- scale attached bar
  151.          ZO_PlayerAttributeMountStamina:SetScale(data.scale)
  152.       end
  153.  
  154.       obj:ClearAnchors()
  155.       obj:SetAnchor(data.point, GuiRoot, data.point, data.x, data.y)
  156.       obj:SetScale(data.scale)
  157.    end
  158. end
  159.  
  160. -- --------------------------------------------
  161. -- UNLOCK PANEL -------------------------------
  162. -- --------------------------------------------
  163.  
  164. local function CreateButton(text, anchor, yOffset)
  165.    local btn = WINDOW_MANAGER:CreateControlFromVirtual(nil, uiPanel, 'ZO_DefaultButton')
  166.    btn:SetAnchor(TOP, anchor, BOTTOM, 0, yOffset)
  167.    btn:SetWidth(180)
  168.    btn:SetHeight(24)
  169.    btn:SetFont('ZoFontAnnounceSmall')
  170.    btn:SetText(text)
  171.    return btn
  172. end
  173.  
  174. local function BuildUnlockPanel()
  175.    -- base frame setup
  176.    uiPanel = WINDOW_MANAGER:CreateControl(nil, GuiRoot, CT_TOPLEVELCONTROL)
  177.    uiPanel:SetDimensions(180, 130)
  178.    uiPanel:SetAnchor(CENTER)
  179.    uiPanel:SetMouseEnabled(true)
  180.    uiPanel:SetMovable(true)
  181.    uiPanel:SetClampedToScreen(true)
  182.    -- background
  183.    uiPanel.bg = WINDOW_MANAGER:CreateControl(nil, uiPanel, CT_BACKDROP)
  184.    uiPanel.bg:SetAnchorFill(uiPanel)
  185.    uiPanel.bg:SetCenterColor(0, 0, 0, 0.5)
  186.    uiPanel.bg:SetEdgeColor(0,0,0,1)
  187.    uiPanel.bg:SetEdgeTexture('', 8, 8, 1, 0)
  188.    uiPanel.bg:SetInsets(3,3,-3,-3)
  189.    -- header
  190.    uiPanel.header = WINDOW_MANAGER:CreateControl(nil, uiPanel, CT_LABEL)
  191.    uiPanel.header:SetAnchor(TOP, uiPanel, TOP, 0, 4)
  192.    uiPanel.header:SetFont('ZoFontWinH4')
  193.    uiPanel.header:SetText(L.Azurah .. ' - ' .. L.UnlockHeader)
  194.    -- snap button
  195.    uiPanel.snap = CreateButton(L.UnlockGridDisable, uiPanel.header, 2)
  196.    uiPanel.snap:SetHandler('OnClicked', function()
  197.       Azurah.snapToGrid = not Azurah.snapToGrid
  198.       uiPanel.snap:SetText(Azurah.snapToGrid and L.UnlockGridDisable or L.UnlockGridEnable)
  199.    end)
  200.    -- lock button
  201.    uiPanel.lock = CreateButton(L.UnlockLockFrames, uiPanel.snap, 6)
  202.    uiPanel.lock:SetHandler('OnClicked', function()
  203.       Azurah:LockUI()
  204.    end)
  205.    -- reset to defaults button
  206.    uiPanel.reset = CreateButton(L.UnlockReset, uiPanel.lock, 16)
  207.    uiPanel.reset:SetHandler('OnClicked', function()
  208.       uiPanel.confirm:SetHidden(false)
  209.       uiPanel.reset:SetHidden(true)
  210.    end)
  211.    -- reset to defaults confirm button
  212.    uiPanel.confirm = CreateButton(L.UnlockResetConfirm, uiPanel.lock, 16)
  213.    uiPanel.confirm:SetHandler('OnClicked', function()
  214.       Azurah:RestoreDefaultData()
  215.       uiPanel.reset:SetHidden(false)
  216.       uiPanel.confirm:SetHidden(true)
  217.    end)
  218.    uiPanel.confirm:SetHidden(true)
  219.    -- handlers
  220.    uiPanel:SetHandler('OnShow', function()
  221.       uiPanel.confirm:SetHidden(true)
  222.       uiPanel.reset:SetHidden(false)
  223.  
  224.       for _, mover in pairs(Azurah.movers) do
  225.          mover:Show()
  226.       end
  227.    end)
  228.    uiPanel:SetHandler('OnHide', function()
  229.       for _, mover in pairs(Azurah.movers) do
  230.          mover:Hide()
  231.       end
  232.    end)
  233.    uiPanel:SetHandler('OnMouseUp', function()
  234.       uiPanel:StopMovingOrResizing()
  235.    end)
  236.  
  237.    Azurah.uiPanel = uiPanel
  238. end
  239.  
  240. function Azurah:LockUI()
  241.    self.uiUnlocked = false
  242.  
  243.    if (uiPanel) then
  244.       uiPanel:SetHidden(true)
  245.    end
  246. end
  247.  
  248. function Azurah:UnlockUI()
  249.    if (not uiPanel) then -- first time using the overlays, register!
  250.       BuildUnlockPanel() -- build ui panel to
  251.  
  252.       local mover
  253.  
  254.       for frame, data in pairs(uiFrames) do
  255.          if (frame == 'ZO_AlertTextNotification') then -- special case, has no dimensions
  256.             ZO_AlertTextNotification:SetDimensions(600, 56)
  257.          end
  258.  
  259.          if (frame == 'ZO_PlayerToPlayerAreaPromptContainer') then -- special case, has no height
  260.             ZO_PlayerToPlayerAreaPromptContainer:SetHeight(100)
  261.          end
  262.  
  263.          if (frame == 'ZO_FocusedQuestTrackerPanel') then
  264.             ZO_FocusedQuestTrackerPanel:SetHeight(200)
  265.          end
  266.  
  267.          mover = self.Mover:New(_G[frame], data[2])
  268.  
  269.          if (data[1] == 2) then -- anchored frame, show but disallow drag
  270.             mover:SetMouseEnabled(false)
  271.             mover.overlay:SetCenterColor(0.6, 0.6, 0.6, 0.32)
  272.             mover.overlay:SetEdgeColor(0.6, 0.6, 0.6, 1)
  273.             mover.label:SetColor(0.6, 0.6, 0.6, 1)
  274.          end
  275.       end
  276.    end
  277.  
  278.    uiPanel:SetHidden(false)
  279.  
  280.    self.uiUnlocked = true
  281. end
  282.  
  283. -- --------------------------------------------
  284. -- COMPASS PINS -------------------------------
  285. -- --------------------------------------------
  286.  
  287. local compassPinScaleRef
  288.  
  289. local function OnPinAreaChanged()
  290.    for k, v in pairs(COMPASS.areaAnimationPool:GetActiveObjects()) do
  291.       v.areaTexture:SetScale(1 / compassPinScaleRef)
  292.    end
  293. end
  294.  
  295. function Azurah:ConfigureCompass()
  296.    ZO_Compass:SetScale(self.db.compassPinScale)
  297.    compassPinScaleRef = self.db.compassPinScale
  298.  
  299.    if (self.db.compassPinScale == 1) then -- default size
  300.       EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_PLAYER_IN_PIN_AREA_CHANGED) -- unregister check event
  301.       EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_QUEST_POSITION_REQUEST_COMPLETE) -- unregister check event
  302.    else -- non-default size
  303.       EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_IN_PIN_AREA_CHANGED,      OnPinAreaChanged)
  304.       EVENT_MANAGER:RegisterForEvent(self.name, EVENT_QUEST_POSITION_REQUEST_COMPLETE, OnPinAreaChanged)
  305.    end
  306.  
  307.    OnPinAreaChanged()
  308.  
  309.    if (self.db.compassHidePinLabel) then
  310.       ZO_CompassCenterOverPinLabel:SetHidden(true)
  311.       ZO_CompassCenterOverPinLabel:SetAlpha(0)
  312.    else
  313.       ZO_CompassCenterOverPinLabel:SetHidden(false)
  314.       ZO_CompassCenterOverPinLabel:SetAlpha(1)
  315.    end
  316. end
  317.  
  318. function Azurah:InitializeUnlock()
  319.    self:RecordDefaultData()
  320.    self:RestoreUserData()
  321.  
  322.    ZO_PreHookHandler(ZO_ActionBar1, 'OnShow', function()
  323.       if (self.db.uiData['ZO_ActionBar1']) then -- user has moved the action bar
  324.          if (ZO_Skills:IsHidden()) then -- restore to user location on skill window close
  325.             local data = self.db.uiData['ZO_ActionBar1']
  326.             ZO_ActionBar1:ClearAnchors()
  327.             ZO_ActionBar1:SetAnchor(data.point, GuiRoot, data.point, data.x, data.y)
  328.             ZO_ActionBar1:SetScale(data.scale)
  329.          else -- skill window is open, restore default scale (window is moved by stock code)
  330.             ZO_ActionBar1:SetScale(1)
  331.          end
  332.       end
  333.    end)
  334.  
  335.    ZO_PreHookHandler(ZO_Skills, 'OnShow', function()
  336.       if (self.db.uiData['ZO_ActionBar1']) then -- user moved the action bar, make sure to move it to its proper place when skill window is open
  337.          ZO_ActionBar1:SetScale(1)
  338.          ZO_ActionBar1:ClearAnchors()
  339.          ZO_ActionBar1:SetAnchor(BOTTOM, ZO_Skills, BOTTOM, -40, 40)
  340.       end
  341.    end)
  342.  
  343.    self:ConfigureCompass()
  344. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement