ESOUI SVN TaosGroupUltimate

[/] [trunk/] [TaosGroupUltimate/] [ui/] [SimpleList.lua] - Rev 19

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 SimpleList
]]--
SimpleList = {}
SimpleList.__index = SimpleList

--[[
        Class Members
]]--


--[[
        Sets visibility of labels
]]--
function SimpleList.RefreshList()
        if (LOG_ACTIVE) then logTrace("SimpleList.RefreshList") end

        for i=1, GROUP_SIZE_MAX, 1 do
                local row = SimpleListControlContainerScrollChild:GetNamedChild("Row" .. i)
                
        if (row ~= nil) then
                    local groupId = "group" .. i
                        local unitExists = DoesUnitExist(groupId)
                        
                        if (unitExists == false) then
                                row:SetHidden(true)
                        else
                                row:GetNamedChild("SenderNameValueLabel"):SetText(GetUnitName(groupId))
                                row:GetNamedChild("UltimateValueLabel"):SetText("-")
                                row:GetNamedChild("ReadyValueLabel"):SetText("0")
                                row:SetHidden(false)
                        end
        else
            if (LOG_ACTIVE) then logError("SimpleList.RefreshList, row nil " .. i) end
        end
        end
end

--[[
        Updates list row
]]--
function SimpleList.UpdateListRow(player)
        if (LOG_ACTIVE) then 
        logTrace("SimpleList.UpdateListRow")
    end

        if (player) then
                local row = SimpleListControlContainerScrollChild:GetNamedChild("Row" .. player.GroupNumber)

                if (row ~= nil) then
            row:SetHidden(false)

            local localizedUltimateName = zo_strformat(SI_ABILITY_TOOLTIP_NAME, player.UltimateName)
            local nameLength = string.len(localizedUltimateName)

            if (nameLength > 22) then
                localizedUltimateName = string.sub(localizedUltimateName, 0, 22) .. "..."
            end

            row:GetNamedChild("SenderNameValueLabel"):SetText(player.PlayerName)
                        row:GetNamedChild("UltimateValueLabel"):SetText(localizedUltimateName)
                        row:GetNamedChild("ReadyValueLabel"):SetText(player.RelativeUltimate)
                        
                        if (player.IsPlayerDead) then
                row:GetNamedChild("SenderNameValueLabel"):SetColor(1.0, 0.0, 0.0, 1)
                            row:GetNamedChild("UltimateValueLabel"):SetColor(1.0, 0.0, 0.0, 1)
                            row:GetNamedChild("ReadyValueLabel"):SetColor(1.0, 0.0, 0.0, 1)
            elseif (player.RelativeUltimate == 100) then
                                row:GetNamedChild("SenderNameValueLabel"):SetColor(0.0, 1.0, 0.0, 1)
                                row:GetNamedChild("UltimateValueLabel"):SetColor(0.0, 1.0, 0.0, 1)
                                row:GetNamedChild("ReadyValueLabel"):SetColor(0.0, 1.0, 0.0, 1)
                        else
                                row:GetNamedChild("SenderNameValueLabel"):SetColor(1.0, 1.0, 1.0, 1)
                                row:GetNamedChild("UltimateValueLabel"):SetColor(1.0, 1.0, 1.0, 1)
                                row:GetNamedChild("ReadyValueLabel"):SetColor(1.0, 1.0, 1.0, 1)
                        end
                else
                        if (LOG_ACTIVE) then logError("SimpleList.UpdateListRow, row nil " .. tostring(player.GroupNumber)) end
                end
        end
end

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

    SimpleListControl:SetMovable(isMovable)
        SimpleListControl:SetMouseEnabled(isMovable)
end

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

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

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

        local left = SimpleListControl:GetLeft()
        local top = SimpleListControl:GetTop()
        
    SettingsHandler.SavedVariables.PosX = left
    SettingsHandler.SavedVariables.PosY = top

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

--[[
        SetControlHidden sets hidden on control
]]--
function SimpleList.SetControlHidden()
    if (LOG_ACTIVE) then 
        logTrace("SimpleList.SetControlHidden")
    end

    local isHidden = SettingsHandler.IsSimpleListVisible() == false
    if (LOG_ACTIVE) then logDebug("isHidden: " .. tostring(isHidden)) end

    if (isHidden) then
        CALLBACK_MANAGER:UnregisterCallback("TGU-GroupChanged", SimpleList.RefreshList)
        CALLBACK_MANAGER:UnregisterCallback("TGU-MapPingChanged", SimpleList.UpdateListRow)
        CALLBACK_MANAGER:UnregisterCallback("TGU-MovableChanged", SimpleList.SetControlMovable)
    else
        CALLBACK_MANAGER:RegisterCallback("TGU-GroupChanged", SimpleList.RefreshList)
        CALLBACK_MANAGER:RegisterCallback("TGU-MapPingChanged", SimpleList.UpdateListRow)
        CALLBACK_MANAGER:RegisterCallback("TGU-MovableChanged", SimpleList.SetControlMovable)
    end

    SimpleListControl:SetHidden(isHidden)
end

--[[
        CreateSimpleListRows creates simple list rows
]]--
function SimpleList.CreateSimpleListRows()
    if (LOG_ACTIVE) then logTrace("SimpleList.CreateSimpleListRows") end

        for i=1, GROUP_SIZE_MAX, 1 do
                local row = CreateControlFromVirtual("$(parent)Row", SimpleListControlContainerScrollChild, "GroupUltimateSimpleListRow", i)
        if (LOG_ACTIVE) then logDebug("Row created " .. row:GetName()) end

                row:SetHidden(true) -- initial not visible
                
                if i == 1 then
            row:SetAnchor(TOPLEFT, SimpleListControlContainerScrollChild, TOPLEFT, 0, 0)
        else
            row:SetAnchor(TOP, lastRow, BOTTOM, 0, 0)
        end
                
                lastRow = row
        end
end

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

    SimpleList.SetControlMovable(isMovable)
    SimpleList.RestorePosition(posX, posY)
    SimpleList.CreateSimpleListRows()
    SimpleList.SetControlHidden()

    CALLBACK_MANAGER:RegisterCallback("TGU-StyleChanged", SimpleList.SetControlHidden)
end

Go to most recent revision | Compare with Previous | Blame