Back to Home

ESO Lua File v100034

ingame/lfg/readychecktracker.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local KEYBOARD_STYLE =
{
    FONT_COUNT = "ZoFontGameShadow",
    TOP_LEVEL_PRIMARY_ANCHOR_OFFSET_Y = 10,
}
local GAMEPAD_STYLE =
{
    FONT_COUNT = "ZoFontGamepad34",
    TOP_LEVEL_PRIMARY_ANCHOR_OFFSET_Y = 20,
}
local MAX_ICON_COUNT = 4
------------------
--Initialization--
------------------
ZO_ReadyCheckTracker = ZO_Object:Subclass()
function ZO_ReadyCheckTracker:New(...)
    local tracker = ZO_Object.New(self)
    tracker:Initialize(...)
    return tracker
end
function ZO_ReadyCheckTracker:Initialize(control)
    self.control = control
    control.owner = self
    self.container = control:GetNamedChild("Container")
    self.iconsContainer = self.container:GetNamedChild("Icons")
    self.iconControls = {}
    for i = 1, MAX_ICON_COUNT do
        table.insert(self.iconControls, self.iconsContainer:GetNamedChild("Icon" .. i))
    end
    self.countLabel = self.container:GetNamedChild("Count")
    local allConstants = { KEYBOARD_STYLE, GAMEPAD_STYLE }
    for _, constants in ipairs(allConstants) do
        constants.TOP_LEVEL_PRIMARY_ANCHOR = ZO_Anchor:New(TOPRIGHT, ZO_ActivityTracker, BOTTOMRIGHT, 0, constants.TOP_LEVEL_PRIMARY_ANCHOR_OFFSET_Y)
        constants.CONTAINER_PRIMARY_ANCHOR = ZO_Anchor:New(TOPRIGHT)
        constants.COUNT_PRIMARY_ANCHOR = ZO_Anchor:New(TOPRIGHT)
    end
    KEYBOARD_STYLE.TOP_LEVEL_SECONDARY_ANCHOR = ZO_Anchor:New(TOPLEFT, ZO_ActivityTracker, BOTTOMLEFT, 0, KEYBOARD_STYLE.TOP_LEVEL_PRIMARY_ANCHOR_OFFSET_Y)
    KEYBOARD_STYLE.CONTAINER_SECONDARY_ANCHOR = ZO_Anchor:New(TOPLEFT)
    KEYBOARD_STYLE.COUNT_SECONDARY_ANCHOR = ZO_Anchor:New(TOPLEFT)
    KEYBOARD_STYLE.ICONS_PRIMARY_ANCHOR = ZO_Anchor:New(TOPLEFT)
    GAMEPAD_STYLE.ICONS_PRIMARY_ANCHOR = ZO_Anchor:New(TOPRIGHT)
    ZO_PlatformStyle:New(function(style) self:ApplyPlatformStyle(style) end, KEYBOARD_STYLE, GAMEPAD_STYLE)
    READY_CHECK_TRACKER_FRAGMENT = ZO_HUDFadeSceneFragment:New(self.container)
    self:RegisterEvents()
end
function ZO_ReadyCheckTracker:RegisterEvents()
    local function Update()
        self:Update()
    end
    self.control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, Update)
    self.control:RegisterForEvent(EVENT_GROUPING_TOOLS_READY_CHECK_UPDATED, Update)
    self.control:RegisterForEvent(EVENT_GROUPING_TOOLS_READY_CHECK_CANCELLED, Update)
end
do
    local TANKS_ACCEPTED_PATH = "EsoUI/Art/LFG/LFG_tank_down_no_glow_64.dds"
    local TANKS_PENDING_PATH = "EsoUI/Art/LFG/LFG_tank_disabled_64.dds"
    local HEALERS_ACCEPTED_PATH = "EsoUI/Art/LFG/LFG_healer_down_no_glow_64.dds"
    local HEALERS_PENDING_PATH = "EsoUI/Art/LFG/LFG_healer_disabled_64.dds"
    local DPS_ACCEPTED_PATH = "EsoUI/Art/LFG/LFG_dps_down_no_glow_64.dds"
    local DPS_PENDING_PATH = "EsoUI/Art/LFG/LFG_dps_disabled_64.dds"
    local function SetIcons(iconControls, path, startingIndex, numToSet)
        for i = 1, numToSet do
            local control = iconControls[startingIndex]
            control:SetTexture(path)
            control:SetHidden(false)
            startingIndex = startingIndex + 1
        end
        return startingIndex
    end
    function ZO_ReadyCheckTracker:Update()
        local inReadyCheckState = GetActivityFinderStatus() == ACTIVITY_FINDER_STATUS_READY_CHECK
        if inReadyCheckState and ZO_Dialogs_IsShowing("LFG_LEAVE_QUEUE_CONFIRMATION") then
            ZO_Dialogs_ReleaseDialog("LFG_LEAVE_QUEUE_CONFIRMATION")
        end
        if inReadyCheckState and HasAcceptedLFGReadyCheck() then
            local tanksAccepted, tanksPending, healersAccepted, healersPending, dpsAccepted, dpsPending = GetLFGReadyCheckCounts()
            local pendingTotal = tanksPending + healersPending + dpsPending
            local total = pendingTotal + tanksAccepted + healersAccepted + dpsAccepted 
            local activityType = GetLFGReadyCheckActivityType()
            if ZO_IsActivityTypeDungeon(activityType) and pendingTotal <= MAX_ICON_COUNT then
                self.countLabel:SetHidden(true)
                self.iconsContainer:SetHidden(false)
                local currentIndex = 1
                local iconControls = self.iconControls
                currentIndex = SetIcons(iconControls, TANKS_ACCEPTED_PATH, currentIndex, tanksAccepted)
                currentIndex = SetIcons(iconControls, TANKS_PENDING_PATH, currentIndex, tanksPending)
                currentIndex = SetIcons(iconControls, HEALERS_ACCEPTED_PATH, currentIndex, healersAccepted)
                currentIndex = SetIcons(iconControls, HEALERS_PENDING_PATH, currentIndex, healersPending)
                currentIndex = SetIcons(iconControls, DPS_ACCEPTED_PATH, currentIndex, dpsAccepted)
                currentIndex = SetIcons(iconControls, DPS_PENDING_PATH, currentIndex, dpsPending)
            
                for unusedIndex = currentIndex, MAX_ICON_COUNT do
                    iconControls[unusedIndex]:SetHidden(true)
                end
            else
                self.countLabel:SetText(zo_strformat(SI_READY_CHECK_TRACKER_COUNT_FORMAT, pendingTotal))
                self.countLabel:SetHidden(false)
                self.iconsContainer:SetHidden(true)
            end
        else
            self.iconsContainer:SetHidden(true)
            self.countLabel:SetHidden(true)
        end
    end
end
function ZO_ReadyCheckTracker:ApplyPlatformStyle(style)
    self.countLabel:SetFont(style.FONT_COUNT)
    self.control:ClearAnchors()
    style.TOP_LEVEL_PRIMARY_ANCHOR:AddToControl(self.control)
    if style.TOP_LEVEL_SECONDARY_ANCHOR then
        style.TOP_LEVEL_SECONDARY_ANCHOR:AddToControl(self.control)
    end
    self.container:ClearAnchors()
    style.CONTAINER_PRIMARY_ANCHOR:AddToControl(self.container)
    if style.CONTAINER_SECONDARY_ANCHOR then
        style.CONTAINER_SECONDARY_ANCHOR:AddToControl(self.container)
    end
    self.iconsContainer:ClearAnchors()
    style.ICONS_PRIMARY_ANCHOR:AddToControl(self.iconsContainer)
    self.countLabel:ClearAnchors()
    style.COUNT_PRIMARY_ANCHOR:AddToControl(self.countLabel)
    if style.COUNT_SECONDARY_ANCHOR then
        style.COUNT_SECONDARY_ANCHOR:AddToControl(self.countLabel)
    end
end
    READY_CHECK_TRACKER = ZO_ReadyCheckTracker:New(control)
end