ESOUI SVN TaosGroupUltimate

[/] [trunk/] [TaosGroupUltimate/] [ui/] [GroupUltimateSelector.lua] - Rev 27

Go to most recent revision | Compare with Previous | Blame | View Log

--[[
        Addon: Taos Group Ultimate
        Author: TProg Taonnor
        Created by @Taonnor
]]--

--[[
        Global variables
]]--
local LOG_ACTIVE = false

--[[
        Class GroupUltimateSelector
]]--
GroupUltimateSelector = {}
GroupUltimateSelector.__index = GroupUltimateSelector

--[[
        Class Members
]]--


--[[
        SetUltimateIcon sets the button icon in base of staticUltimateID
]]--
function GroupUltimateSelector.SetUltimateIcon(staticUltimateID)
    if (LOG_ACTIVE) then 
        logTrace("GroupUltimateSelector.SetUltimateIcon")
        logDebug("staticUltimateID: " .. tostring(staticUltimateID))
    end

    local icon = "/esoui/art/icons/icon_missing.dds"

    if (staticUltimateID ~= 0) then
        icon = GetAbilityIcon(staticUltimateID)
    end

    local iconControl = UltimateSelectorControl:GetNamedChild("SelectorButtonControl"):GetNamedChild("Icon")

    if (icon ~= nil and iconControl ~= nil) then
        iconControl:SetTexture(icon)
    else
        logError("GroupUltimateSelector.SetUltimateIcon, icon is " .. tostring(icon) .. "; iconControl is " .. tostring(iconControl))
    end
end

--[[
        SetControlMovable sets the Movable and MouseEnabled flag in UI elements
]]--
function GroupUltimateSelector.SetControlMovable(isMovable)
    if (LOG_ACTIVE) then 
        logTrace("GroupUltimateSelector.SetControlMovable")
        logDebug("isMovable: " .. tostring(isMovable))
    end

    UltimateSelectorControl:GetNamedChild("MovableControl"):SetHidden(isMovable == false)

    UltimateSelectorControl:SetMovable(isMovable)
        UltimateSelectorControl:SetMouseEnabled(isMovable)
end

--[[
        RestorePosition sets GroupUltimateSelector on settings position
]]--
function GroupUltimateSelector.RestorePosition(posX, posY)
    if (LOG_ACTIVE) then 
        logTrace("GroupUltimateSelector.RestorePosition")
        logDebug("posX: " .. tostring(posX), 
                 "posY: " .. tostring(posY))
    end

        UltimateSelectorControl:ClearAnchors()
        UltimateSelectorControl:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, posX, posY)
end

--[[
        OnGroupUltimateSelectorMoveStop saves current GroupUltimateSelector position to settings
]]--
function GroupUltimateSelector.OnGroupUltimateSelectorMoveStop()
    if (LOG_ACTIVE) then logTrace("GroupUltimateSelector.OnGroupUltimateSelectorMoveStop") end

        local left = UltimateSelectorControl:GetLeft()
        local top = UltimateSelectorControl:GetTop()
        
    SettingsHandler.SavedVariables.SelectorPosX = left
    SettingsHandler.SavedVariables.SelectorPosY = top

    if (LOG_ACTIVE) then 
        logDebug("PosX set: " .. tostring(SettingsHandler.SavedVariables.SelectorPosX), 
                 "PosY set: " .. tostring(SettingsHandler.SavedVariables.SelectorPosY))
    end
end

--[[
        OnGroupUltimateSelectorClicked shows ultimate group menu
]]--
function GroupUltimateSelector.OnGroupUltimateSelectorClicked()
    if (LOG_ACTIVE) then logTrace("GroupUltimateSelector.OnGroupUltimateSelectorClicked") end

    local button = UltimateSelectorControl:GetNamedChild("SelectorButtonControl"):GetNamedChild("Button")

    if (button ~= nil) then
        CALLBACK_MANAGER:RegisterCallback("TGU-SetUltimateGroup", GroupUltimateSelector.OnSetUltimateGroup)
        CALLBACK_MANAGER:FireCallbacks("TGU-ShowUltimateGroupMenu", button)
    else
        logError("GroupUltimateSelector.OnGroupUltimateSelectorClicked, button nil")
    end
end

--[[
        OnSetUltimateGroup sets ultimate group for button
]]--
function GroupUltimateSelector.OnSetUltimateGroup(group)
    if (LOG_ACTIVE) then 
        logTrace("UltimateGroupMenu.ShowUltimateGroupMenu")
        logDebug("group.GroupName: " .. group.GroupName)
    end

    CALLBACK_MANAGER:UnregisterCallback("TGU-SetUltimateGroup", GroupUltimateSelector.OnSetUltimateGroup)

    if (group ~= nil) then
        SettingsHandler.SetStaticUltimateIDSettings(group.GroupAbilityId)
    else
        logError("UltimateGroupMenu.ShowUltimateGroupMenu, group nil")
    end
end

--[[
        SetControlHidden sets hidden on control
]]--
function GroupUltimateSelector.SetControlHidden(isHidden)
    if (LOG_ACTIVE) then 
        logTrace("GroupUltimateSelector.SetControlHidden")
        logDebug("isHidden: " .. tostring(isHidden))
    end

    UltimateSelectorControl:SetHidden(isHidden)
end

--[[
        Initialize initializes GroupUltimateSelector
]]--
function GroupUltimateSelector.Initialize(isMovable, posX, posY, staticUltimateID)
    if (LOG_ACTIVE) then 
        logTrace("GroupUltimateSelector.Initialize")
        logDebug("isMovable: " .. tostring(isMovable), 
                 "posX: " .. tostring(posX), 
                 "posY: " .. tostring(posY), 
                 "staticUltimateID: " .. tostring(staticUltimateID))
    end

    GroupUltimateSelector.SetControlMovable(isMovable)
    GroupUltimateSelector.RestorePosition(posX, posY)
    GroupUltimateSelector.SetUltimateIcon(staticUltimateID)

    CALLBACK_MANAGER:RegisterCallback("TGU-MovableChanged", GroupUltimateSelector.SetControlMovable)
    CALLBACK_MANAGER:RegisterCallback("TGU-StaticUltimateIDChanged", GroupUltimateSelector.SetUltimateIcon)
end

Go to most recent revision | Compare with Previous | Blame