ESOUI SVN TaosGroupUltimate

[/] [trunk/] [TaosGroupUltimate/] [ui/] [SwimlaneList.lua] - Rev 13

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 = true
local SWIMLANES = 6
local ROWS = 6

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

--[[
        Class Members
]]--
SwimlaneList.Swimlanes = {}


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

--      for i=1, GROUP_SIZE_MAX, 1 do
--              local row = SwimlaneListControlContainerScrollChild:GetNamedChild("Row" .. i)

--        if (row ~= nil) then
--                  if (DoesUnitExist("group" .. i) == false) then
--                          row:SetHidden(true)
--                          row:GetNamedChild("SenderNameValueLabel"):SetText("-")
--                          row:GetNamedChild("UltimateValueLabel"):SetText("-")
--                          row:GetNamedChild("ReadyValueLabel"):SetText("0")
--                  end
--        else
--            if (LOG_ACTIVE) then logError("SwimlaneList.RefreshList, row nil " .. i) end
--        end
--      end
end

--[[
        Updates list row
]]--
function SwimlaneList.UpdateListRow(player)
        if (LOG_ACTIVE) then 
        logTrace("SwimlaneList.UpdateListRow")
--        logDebug("player.PingTag: " .. tostring(player.PingTag),
--                 "player.GroupNumber: " .. tostring(player.GroupNumber), 
--                 "player.PlayerName: " .. tostring(player.PlayerName), 
--                 "player.IsPlayerDead: " .. tostring(player.IsPlayerDead), 
--                 "player.AbilityID: " .. tostring(player.AbilityID), 
--                 "player.UltimateName: " .. tostring(player.UltimateName), 
--                 "player.UltimateIcon: " .. tostring(player.UltimateIcon), 
--                 "player.RelativeUltimate: " .. tostring(player.RelativeUltimate))
    end

        if (player) then
        local ultimateGroupId = UltimateGroupHandler.GetUltimateGroupByAbilityId(player.AbilityID)
        local swimLane = SwimlaneList.GetSwimLane(ultimateGroupId)
        local row = nil

        if (swimLane) then
            local playerRowId = SwimlaneList.GetSwimLaneRow(swimLane, player.PlayerName)

            if (playerRowId ~= -1) then
                row = swimLane.SwimlaneControl:GetNamedChild("Row" .. playerRowId)
            else
                local nextFreeRow = 1

                for i,row in ipairs(swimLane.Players) do
                            nextFreeRow = nextFreeRow + 1
                    end

                if (LOG_ACTIVE) then 
                    logDebug("SwimlaneList.UpdateListRow, add player " .. tostring(playerName) .. " to row " .. tostring(nextFreeRow)) 
                end

                swimLane.Players[nextFreeRow] = player
                row = swimLane.SwimlaneControl:GetNamedChild("Row" .. nextFreeRow)
            end
        end

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

            row:GetNamedChild("SenderNameValueLabel"):SetText(player.PlayerName)
            row:GetNamedChild("RelativeUltimateStatusBar"):SetValue(player.RelativeUltimate)

                        if (player.IsPlayerDead) then
                -- Dead Color
                row:GetNamedChild("SenderNameValueLabel"):SetColor(0.5, 0.5, 0.5, 0.8)
                row:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.8, 0.03, 0.03, 0.7)
            elseif (player.RelativeUltimate == 100) then
                                -- Ready Color
                row:GetNamedChild("SenderNameValueLabel"):SetColor(1, 1, 1, 1)
                row:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.03, 0.7, 0.03, 0.7)
                        else
                                -- Inprogress Color
                row:GetNamedChild("SenderNameValueLabel"):SetColor(1, 1, 1, 0.8)
                row:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.03, 0.03, 0.7, 0.7)
                        end
                else
                        if (LOG_ACTIVE) then logError("SwimlaneList.UpdateListRow, row nil " .. tostring(player.GroupNumber)) end
                end
        end
end

--[[
        Get swimlane from current SwimLanes
]]--
function SwimlaneList.GetSwimLane(ultimateGroupId)
    if (LOG_ACTIVE) then 
        logTrace("SwimlaneList.GetSwimLane")
        logDebug("ultimateGroupId: " .. tostring(ultimateGroupId))
    end

    if (ultimateGroupId ~= 0) then
        for i,swimLane in ipairs(SwimlaneList.Swimlanes) do
                    if (swimLane.UltimateGroupId == ultimateGroupId) then
                return swimLane
            end
            end

        if (LOG_ACTIVE) then logDebug("SwimlaneList.GetSwimLane, swimLane not found " .. tostring(ultimateGroupId)) end
        return nil
    else
        if (LOG_ACTIVE) then logError("SwimlaneList.GetSwimLane, ultimateGroupId is 0") end
        return nil
    end
end

--[[
        Get Player Row from current players in swimlane
]]--
function SwimlaneList.GetSwimLaneRow(swimLane, playerName)
    if (LOG_ACTIVE) then 
        logTrace("SwimlaneList.GetSwimLaneRow")
        logDebug("swimLane ID: " .. tostring(swimLane.Id))
    end

    if (swimLane) then
        for i,player in ipairs(swimLane.Players) do
            logDebug(player.PlayerName .. " == " .. playerName)
                    if (player.PlayerName == playerName) then
                return i
            end
            end

        if (LOG_ACTIVE) then logDebug("SwimlaneList.GetSwimLane, player not found " .. tostring(playerName)) end
        return -1
    else
        if (LOG_ACTIVE) then logError("SwimlaneList.GetSwimLane, swimLane is nil") end
        return -1
    end
end

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

    SwimlaneListControl:SetMovable(isMovable)
        SwimlaneListControl:SetMouseEnabled(isMovable)
end

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

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

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

        local left = SwimlaneListControl:GetLeft()
        local top = SwimlaneListControl: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 SwimlaneList.SetControlHidden(isHidden)
    if (LOG_ACTIVE) then 
        logTrace("SwimlaneList.SetControlHidden")
        logDebug("isHidden: " .. tostring(isHidden))
    end

    SwimlaneListControl:SetHidden(isHidden)
end

--[[
        CreateSwimLaneListHeaders creates swimlane list headers
]]--
function SwimlaneList.CreateSwimLaneListHeaders()
    if (LOG_ACTIVE) then logTrace("SwimlaneList.CreateSwimLaneListHeaders") end

        for i=1, SWIMLANES, 1 do
        local ultimateGroupId = SettingsHandler.SavedVariables.SwimlaneUltimateGroupIds[i]
        local swimlaneControlName = "Swimlane" .. tostring(i)
        local swimlaneControl = SwimlaneListControl:GetNamedChild(swimlaneControlName)
        local icon = swimlaneControl:GetNamedChild("Header"):GetNamedChild("Border"):GetNamedChild("Icon")

        if (icon ~= nil and swimlaneControl ~= nil) then
            if (ultimateGroupId ~= 0) then
                if (LOG_ACTIVE) then 
                    logDebug("Create Swimlane: " .. tostring(i),
                             "ultimateGroupId: " .. tostring(ultimateGroupId),
                             "swimlaneControlName: " .. tostring(swimlaneControlName))
                end

                -- TODO: Namen des Headers auf die GruppenID setzen! (Eigene Übersetzung)
                icon:SetTexture(GetAbilityIcon(ultimateGroupId))

                local swimLane = {}
                swimLane.Id = i
                swimLane.UltimateGroupId = ultimateGroupId
                swimLane.SwimlaneControl = swimlaneControl
                swimLane.Players = {}

                SwimlaneList.CreateSwimlaneListRows(swimlaneControl)

                    SwimlaneList.Swimlanes[i] = swimLane
            else
                swimlaneControl:SetHidden(true)
            end
        else
            if (LOG_ACTIVE) then 
                logError("SwimlaneList.CreateSwimLaneListHeaders, controls nil " .. tostring(swimlaneControl) .. ";" .. tostring(icon) .. ";" .. tostring(swimlaneControl))
            end
        end
        end

--    logDebug("Create TestRow")
--    local row = CreateControlFromVirtual("$(parent)Row", SwimlaneListControlSwimlane1, "GroupUltimateSwimlaneRow", 1)
--    row:SetAnchor(TOPLEFT, SwimlaneListControlSwimlane1, TOPLEFT, 0, 25)
--    row:GetNamedChild("SenderNameValueLabel"):SetText("Taonnor Annare")
--    row:GetNamedChild("RelativeUltimateStatusBar"):SetValue(50)
--    -- Inprogress Color
--    row:GetNamedChild("SenderNameValueLabel"):SetColor(1, 1, 1, 0.8)
--    row:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.03, 0.03, 0.7, 0.7)

--    logDebug("Create TestRow2")
--    local row2 = CreateControlFromVirtual("$(parent)Row", SwimlaneListControlSwimlane1, "GroupUltimateSwimlaneRow", 2)
--    row2:SetAnchor(TOP, row, BOTTOM, 0, -1)
--    row2:GetNamedChild("SenderNameValueLabel"):SetText("Taonnor ...")
--    row2:GetNamedChild("RelativeUltimateStatusBar"):SetValue(100)
--    -- Ready Color
--    row2:GetNamedChild("SenderNameValueLabel"):SetColor(1, 1, 1, 1)
--    row2:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.03, 0.7, 0.03, 0.7)

--    logDebug("Create TestRow3")
--    local row3 = CreateControlFromVirtual("$(parent)Row", SwimlaneListControlSwimlane1, "GroupUltimateSwimlaneRow", 3)
--    row3:SetAnchor(TOP, row2, BOTTOM, 0, -1)
--    row3:GetNamedChild("SenderNameValueLabel"):SetText("Taonnor")
--    row3:GetNamedChild("RelativeUltimateStatusBar"):SetValue(25)
--    -- Dead Color
--    row3:GetNamedChild("SenderNameValueLabel"):SetColor(0.5, 0.5, 0.5, 0.8)
--    row3:GetNamedChild("RelativeUltimateStatusBar"):SetColor(0.8, 0.03, 0.03, 0.7)
end

--[[
        CreateSwimlaneListRows creates swimlane lsit rows
]]--
function SwimlaneList.CreateSwimlaneListRows(swimlaneControl)
    if (LOG_ACTIVE) then logTrace("SwimlaneList.CreateSwimlaneListRows") end

    if (swimlaneControl ~= nil) then
            for i=1, ROWS, 1 do
                    local row = CreateControlFromVirtual("$(parent)Row", swimlaneControl, "GroupUltimateSwimlaneRow", i)
            if (LOG_ACTIVE) then logDebug("Row created " .. row:GetName()) end

                    row:SetHidden(true) -- initial not visible

                    if i == 1 then
                row:SetAnchor(TOPLEFT, swimlaneControl, TOPLEFT, 0, 25)
            else
                row:SetAnchor(TOP, lastRow, BOTTOM, 0, -1)
            end

                    lastRow = row
            end
    else
        if (LOG_ACTIVE) then 
            logError("SwimlaneList.CreateSwimlaneListRows, swimlaneControl nil.")
        end
    end
end

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

    SwimlaneList.SetControlHidden(isHidden)
    SwimlaneList.SetControlMovable(isMovable)
    SwimlaneList.RestorePosition(posX, posY)
    SwimlaneList.CreateSwimLaneListHeaders()

    CALLBACK_MANAGER:RegisterCallback("TGU-GroupChanged", SwimlaneList.RefreshList)
    CALLBACK_MANAGER:RegisterCallback("TGU-MapPingChanged", SwimlaneList.UpdateListRow)
end

Go to most recent revision | Compare with Previous | Blame