ESO Lua File v100010

ingame/ram/ram.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local MAX_ESCORTS_SHOWN = 6
local ESCORT_INDICATOR_OFFSET_X = 0
local MIN_MET_TEXTURE = "EsoUI/Art/AvA/AvA_ram_slot_green.dds"
local MIN_NOT_MET_TEXTURE = "EsoUI/Art/AvA/AvA_ram_slot_red.dds"
local SPOT_NOT_FILLED_TEXTURE = "EsoUI/Art/AvA/AvA_ram_slot_empty.dds"
local g_indicators = {}
local g_isInitialized = false
local function UpdateVisibility()
    RAM_FRAGMENT:SetHiddenForReason("NotEscorting", not IsPlayerEscortingRam())
end
local function UpdateNumEscorts(numEscorts)
    local minRequiredEscorts, maxPossibleEscorts = GetMinMaxRamEscorts()
    local spotFilledTexture = (numEscorts >= minRequiredEscorts) and MIN_MET_TEXTURE or MIN_NOT_MET_TEXTURE
    for i = 1, MAX_ESCORTS_SHOWN do
        local control = g_indicators[i]
        if(i <= maxPossibleEscorts) then
            control:SetHidden(false)
            if(i <= numEscorts) then
                control:SetTexture(spotFilledTexture)
            else
                control:SetTexture(SPOT_NOT_FILLED_TEXTURE)
            end
        else
            control:SetHidden(true)
        end
    end
end
local function InitializeRam()
    ZO_RamName:SetText(zo_strformat(SI_SIEGE_BAR_NAME, GetRawUnitName("escortedram")))
    UpdateVisibility()
    g_isInitialized = true
end
local function OnRamEscortCountUpdate(eventCode, numEscorts)
    if not g_isInitialized then
        InitializeRam()
    else
        UpdateNumEscorts(numEscorts)
    end
end
local function OnLeaveRamEscort()
    g_isInitialized = false
    UpdateVisibility()
end
function ZO_Ram_Initialize(parent)
    parent:RegisterForEvent(EVENT_RAM_ESCORT_COUNT_UPDATE, OnRamEscortCountUpdate)
    parent:RegisterForEvent(EVENT_LEAVE_RAM_ESCORT, OnLeaveRamEscort)
    local prevControl
    for i = 1, MAX_ESCORTS_SHOWN do
        local control = CreateControlFromVirtual("ZO_RamIndicators", ZO_RamIndicators, "ZO_RamIndicator", i)
        g_indicators[i] = control
        if(prevControl) then
            control:SetAnchor(TOPLEFT, prevControl, TOPRIGHT, ESCORT_INDICATOR_OFFSET_X, 0)
        else
            control:SetAnchor(TOPLEFT, nil, TOPLEFT, 0, 0)
        end
        prevControl = control
    end
    ZO_StatusBar_SetGradientColor(ZO_RamHealth, ZO_POWER_BAR_GRADIENT_COLORS[POWERTYPE_HEALTH])
    RAM_FRAGMENT = ZO_HUDFadeSceneFragment:New(ZO_Ram)
    if(IsPlayerEscortingRam()) then
        InitializeRam()
    else
        UpdateVisibility()
    end
end