ESOUI SVN TaosGroupUltimate

[/] [trunk/] [TaosGroupUltimate/] [TaosGroupUltimate.lua] - Rev 2

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

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

--[[
        Global variables
]]--
local MAJOR = "1"
local MINOR = "0"
local PATCH = "0"

local REFRESHRATE = 1000
local ACTION_BAR_ULTIMATE_SLOT_INDEX = ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 -- 8, the constant is 7, but its wrong

--[[
        Class GroupUltimate
]]--
GroupUltimate = {}

--[[
        Class Members
]]--
GroupUltimate.Name = "TaosGroupUltimate"
GroupUltimate.IsInAvA = false
GroupUltimate.LastMapPingTimestamp = GetTimeStamp()
GroupUltimate.Default = {
                        ["PosX"] = 0,
                        ["PosY"] = 0,
                        ["Movable"] = true,
                }

--[[
        UpdateDeath updates SessionDeaths with adding new death
]]--
function GroupUltimate.UpdateDeath(eventID)
        if (GroupUltimate.IsInAvA) then
                -- TODO: And alive?!
        end
end

--[[
        UpdateZone updates the IsInAva member and set visibility of GroupUltimateWindow
]]--
function GroupUltimate.UpdateZone(eventCode)
        GroupUltimate.IsInAvA = IsPlayerInAvAWorld()
    GroupUltimateWindow:SetHidden(not GroupUltimate.IsInAvA)
end

--[[
        Called on map ping; Updates ultimate view if possible ping
]]--
function GroupUltimate.OnMapPing(eventCode, pingEventType, pingType, pingTag, offsetX, offsetY, isLocalPlayerOwner)
    if GroupUltimate.IsPossiblePing(offsetX, offsetY) then
                GroupUltimate.UpdateUltimateView(pingTag, offsetX, offsetY)
    end
end

--[[
        Called on power changing; Call send data if ultimate
]]--
function GroupUltimate.OnPowerUpdate(eventCode, unitTag, powerIndex, powerType, powerValue, powerMax, powerEffectiveMax)
        if (unitTag ~= 'player') then return end -- only care about the player
        if (powerType ~= POWERTYPE_ULTIMATE) then return end -- only care about ultimate
        
        GroupUltimate.SendData(powerValue)
end

--[[
        SendData updates session
]]--
function GroupUltimate.SendData(powerValue)
        if (GroupUltimate.IsInAvA) then return end
        if IsUnitGrouped("player") then return end
        
        local currentTimestamp = GetTimeStamp()
        
        if ((currentTimestamp - roupUltimate.LastMapPingTimestamp) > REFRESHRATE) then
                local abilityID = GetSlotBoundId(ACTION_BAR_ULTIMATE_SLOT_INDEX)
                local abilityCost = math_max(1, GetSlotAbilityCost(ACTION_BAR_ULTIMATE_SLOT_INDEX))
                local relativeUltimate = math.floor((powerValue / abilityCost) * 100)

                if (relativeUltimate > 100) then
                        relativeUltimate = 100
                end

                d("abilityID: " tostring(abilityID)) -- TODO: eventually needed mapping to correct x values for map pings!
                d("relativeUltimate: " tostring(relativeUltimate))
                PingMap(MAP_PIN_TYPE_PING, MAP_TYPE_LOCATION_CENTERED, abilityID, relativeUltimate)
                
                GroupUltimate.LastMapPingTimestamp = GetTimeStamp()
        end
end

--[[
        UpdateUltimates updates ultimate view
]]--
function GroupUltimate.UpdateUltimateView(pingTag, ultimateId, ultimateValue)
        local senderName = GetUnitName(pingTag)
        local ultimateName = GetAbilityName(ultimateId)
        local ultimatePercent = ultimateValue
        -- GetAbilityIcon(number abilityId) -> Icon?!

        ApSessionFurtherWindowValueSenderName:SetText(senderName)
        ApSessionFurtherWindowValueUltimate:SetText(ultimateName)
        ApSessionFurtherWindowValueUltimatePercent:SetText(ultimatePercent)
end

--[[
        Check if map ping is in possible range
]]--
function GroupUltimate.IsPossiblePing(offsetx, offsety)
        return true -- TODO: check in specific range
end

--[[
        UpdateMovable sets the Movable and MouseEnabled flag in UI elements
]]--
function GroupUltimate.SetMovable()
    GroupUltimateWindow:SetMovable(GroupUltimate.Settings.Movable)
        GroupUltimateWindow:SetMouseEnabled(GroupUltimate.Settings.Movable)
end

--[[
        MakeSettingsWindow creates settings window
]]--
function GroupUltimate.MakeSettingsWindow()
        local panelData = {
                type = "panel",
                name = "Taos Group Ultimate",
                author = "TProg Taonnor",
                version = MAJOR .. "." .. MINOR .. "." .. PATCH,
                slashCommand = "/taosGroupUltimate",
                registerForDefaults = true
        }

        local optionsData = {
                [1] = {
                        type = "header",
                        name = GetString(TAS_OPTIONS_HEADER),
                },
                [2] = {
                        type = "checkbox",
                        name = GetString(TAS_OPTIONS_DRAG_LABEL),
                        tooltip = GetString(TAS_OPTIONS_DRAG_TOOLTIP),
                        getFunc = function() return GroupUltimate.Settings.Movable end,
                        setFunc = function(value) 
                                GroupUltimate.Settings.Movable = value
                GroupUltimate.SetMovable()
                        end,
                        default = GroupUltimate.Default.Movable
                },
        }
        
        local LAM = LibStub("LibAddonMenu-2.0")
        LAM:RegisterAddonPanel("TaosGroupUltimateSettings", panelData)
        LAM:RegisterOptionControls("TaosGroupUltimateSettings", optionsData)
end

--[[
        RestorePosition sets GroupUltimateWindow on settings position
]]--
function GroupUltimate.RestorePosition()
        GroupUltimateWindow:ClearAnchors()
        GroupUltimateWindow:SetAnchor(TOPLEFT, 
                                                                  GuiRoot, 
                                                                  TOPLEFT, 
                                                                  ApSession.Settings.PosX, 
                                                                  ApSession.Settings.PosY)
end

--[[
        OnGroupUltimateWindowMoveStop saves current GroupUltimateWindow position to settings
]]--
function GroupUltimate.OnGroupUltimateWindowMoveStop()
        local left = GroupUltimateWindow:GetLeft()
        local top = GroupUltimateWindow:GetTop()
        
        GroupUltimate.Settings.PosX = left
        GroupUltimate.Settings.PosY = top
end

--[[
        GroupUltimate:initialize initializes addon
]]--
function GroupUltimate:initialize()
        GroupUltimate.Settings = ZO_SavedVars:NewAccountWide(GroupUltimate.Name, 1 , nil, GroupUltimate.Default)

        GroupUltimate.MakeSettingsWindow()
        GroupUltimate.RestorePosition()
        GroupUltimate.UpdateZone()
    GroupUltimate.SetMovable()

        -- Register events
        EVENT_MANAGER:RegisterForEvent(GroupUltimate.name, EVENT_MAP_PING, GroupUltimate.OnMapPing)
        EVENT_MANAGER:RegisterForEvent(GroupUltimate.name, EVENT_POWER_UPDATE, GroupUltimate.OnPowerUpdate)
        EVENT_MANAGER:RegisterForEvent(GroupUltimate.Name, EVENT_PLAYER_DEAD , GroupUltimate.UpdateDeath) -- grey up icon?
        EVENT_MANAGER:RegisterForEvent(GroupUltimate.Name, EVENT_PLAYER_ACTIVATED, GroupUltimate.UpdateZone) -- only cyro?

        -- Start timer
        --EVENT_MANAGER:RegisterForUpdate(GroupUltimate.Name, REFRESHRATE, GroupUltimate.SendData) -- eventually not needed, send data via ultimate points changed
end

--[[
        OnAddOnLoaded if TaosGroupUltimate is loaded, initialize
]]--
local function OnAddOnLoaded(eventCode, addOnName)
        if addOnName == GroupUltimate.Name then
                GroupUltimate:initialize()
        end
end

EVENT_MANAGER:RegisterForEvent(GroupUltimate.Name, EVENT_ADD_ON_LOADED, OnAddOnLoaded);

Go to most recent revision | Compare with Previous | Blame