ESO Lua File v100010

ingame/group/zo_group_shared.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
-----------------
--Group List
-----------------
do
    local groupUnitTags = setmetatable({}, {__index = function(self, key)
        local groupIndex = tonumber(key:match("^group(%d+)$"))
        if groupIndex and groupIndex >= 1 and groupIndex <= GROUP_SIZE_MAX then
            self[key] = groupIndex
        else
            self[key] = false
        end
        return self[key]
    end, })
    function ZO_Group_IsGroupUnitTag(unitTag)
        return groupUnitTags[unitTag] ~= false
    end
    function ZO_Group_GetGroupIndexFromUnitTag(unitTag)
        return groupUnitTags[unitTag] or nil
    end
    local groupIndices = {}
    function ZO_Group_GetUnitTagForGroupIndex(groupIndex)
        return groupIndices[groupIndex]
    end
    for i = 1, GROUP_SIZE_MAX do
        groupIndices[i] = "group" .. i
    end
end
ZO_GroupListManager_Shared = ZO_SortFilterList:Subclass()
local GROUP_DATA = 1
function ZO_GroupListManager_Shared:Initialize(control)
    control:SetHandler("OnEffectivelyHidden", function() self:OnEffectivelyHidden() end)
    self.masterList = {}
    local function GetGroupInfoTableFromGroupUnitTag(unitTag)
        for i = 1, #self.masterList do
            local data = self.masterList[i]
            if(data.unitTag == unitTag) then
                return data
            end
        end
    end
    local JUST_FILTERS_ARE_DIRTY = true
    local function OnLevelUpdate(evt, unitTag, level)
        local groupInfoTable = GetGroupInfoTableFromGroupUnitTag(unitTag)
        if groupInfoTable then
            groupInfoTable.level = level
            self:HandleDirtyEvent(JUST_FILTERS_ARE_DIRTY)
        end
    end
    local function OnVeteranRankUpdate(evt, unitTag, veteranRank)
        local groupInfoTable = GetGroupInfoTableFromGroupUnitTag(unitTag)
        if groupInfoTable then
            groupInfoTable.veteranRank = veteranRank
            self:HandleDirtyEvent(JUST_FILTERS_ARE_DIRTY)
        end
    end
    local function OnZoneUpdate(evt, unitTag, newZone)
        local groupInfoTable = GetGroupInfoTableFromGroupUnitTag(unitTag)
        if groupInfoTable then
            groupInfoTable.zone = newZone
            self:HandleDirtyEvent(JUST_FILTERS_ARE_DIRTY)
        end
        if(ZO_Group_IsGroupUnitTag(unitTag)) then
            self:TryShowJumpToGroupLeaderPrompt()
        end
    end
    local function OnGroupRolesUpdate(evt, unitTag, isDps, isHeal, isTank)
        local groupInfoTable = GetGroupInfoTableFromGroupUnitTag(unitTag)
        if groupInfoTable then
            groupInfoTable.isDps = isDps
            groupInfoTable.isHeal = isHeal
            groupInfoTable.isTank = isTank
            self:HandleDirtyEvent(JUST_FILTERS_ARE_DIRTY)
        end
    end
    local function OnGroupOnlineUpdate(evt, unitTag, online)
        local groupInfoTable = GetGroupInfoTableFromGroupUnitTag(unitTag)
        if groupInfoTable then
            groupInfoTable.online = online
            self:HandleDirtyEvent(JUST_FILTERS_ARE_DIRTY)
        end
    end
    self.dirtyOnUpdateHandler = function()
        control:SetHandler("OnUpdate", nil)
        if self.justFiltersAreDirty then
            self:RefreshFilters()
        else
            self:RefreshData()
        end
        self.justFiltersAreDirty = nil
    end
    local function RefreshData()
        self:HandleDirtyEvent()
    end
    self.searching = IsCurrentlySearchingForGroup()
    local function OnSearchUpdate(event, searching)
        self.searching = searching
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    end
    local function OnUnitCreated(evt, unitTag)
        if ZO_Group_IsGroupUnitTag(unitTag) then
            self:HandleDirtyEvent()
            self:TryShowJumpToGroupLeaderPrompt()     
        end
    end
    local function OnUnitDestroyed(evt, unitTag)
        if ZO_Group_IsGroupUnitTag(unitTag) then
            self:HandleDirtyEvent()
        end
    end
    local function OnGroupMemberJoined(_, rawCharacterName)
        self:OnGroupMemberJoined(rawCharacterName)
    end
    local function OnGroupMemberLeft(evt, characterName, reason, wasLocalPlayer, amLeader)
        if(wasLocalPlayer) then
            RefreshData()
        end
    end
    control:RegisterForEvent(EVENT_UNIT_CREATED, OnUnitCreated)
    control:RegisterForEvent(EVENT_UNIT_DESTROYED, OnUnitDestroyed)
    control:RegisterForEvent(EVENT_GROUP_MEMBER_JOINED, OnGroupMemberJoined)
    control:RegisterForEvent(EVENT_LEVEL_UPDATE, OnLevelUpdate)
    control:RegisterForEvent(EVENT_VETERAN_RANK_UPDATE, OnVeteranRankUpdate)
    control:RegisterForEvent(EVENT_ZONE_UPDATE, OnZoneUpdate)
    control:RegisterForEvent(EVENT_GROUP_MEMBER_ROLES_CHANGED, OnGroupRolesUpdate)
    control:RegisterForEvent(EVENT_GROUP_MEMBER_CONNECTED_STATUS, OnGroupOnlineUpdate)
    control:RegisterForEvent(EVENT_LEADER_UPDATE, RefreshData)
    control:RegisterForEvent(EVENT_GROUP_UPDATE, RefreshData)
    control:RegisterForEvent(EVENT_GROUP_MEMBER_LEFT, OnGroupMemberLeft)
    control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, RefreshData)
    control:RegisterForEvent(EVENT_GROUPING_TOOLS_STATUS_UPDATE, OnSearchUpdate)
end
function ZO_GroupListManager_Shared:New(control)
    local manager = ZO_SortFilterList.New(self, control)
    manager:Initialize(control)
    return manager
end
function ZO_GroupListManager_Shared:HandleDirtyEvent(justFilters)
    if not self.control:GetHandler("OnUpdate") then
        self.control:SetHandler("OnUpdate", self.dirtyOnUpdateHandler)
    end
    if justFilters then
        if self.justFiltersAreDirty == nil then
            self.justFiltersAreDirty = justFilters
        end
    else
        self.justFiltersAreDirty = false
        if(GROUP_MEMBERS) then
            GROUP_MEMBERS:Update(GetGroupSize())
        end
        if GROUP_MEMBERS_GAMEPAD then
            GROUP_MEMBERS_GAMEPAD:Update(GetGroupSize())
        end
    end
end
function ZO_GroupListManager_Shared:TryShowJumpToGroupLeaderPrompt()
end
function ZO_GroupListManager_Shared:OnGroupMemberJoined(rawCharacterName)
    PlaySound(SOUNDS.GROUP_JOIN)
    if(GetRawUnitName("player") == rawCharacterName) then
        local groupLeaderUnitTag = GetGroupLeaderUnitTag()
        if(not AreUnitsEqual(groupLeaderUnitTag, "player")) then
            self.pendingJumpToGroupLeaderPrompt = true
            self:TryShowJumpToGroupLeaderPrompt()
        end
    end
end
function ZO_GroupListManager_Shared:InitializeKeybindDescriptors()
end
function ZO_GroupListManager_Shared:OnEffectivelyHidden()
end
function ZO_GroupListManager_Shared:SetupGroupEntry(control, data)
    ZO_SortFilterList.SetupRow(self, control, data)
    local bg = GetControl(control, "BG")
    local hidden = (data.index % 2) == 0
    bg:SetHidden(hidden)
    data.control = control
    control.statusIcon = GetControl(control, "Status")
    control.nameLabel = GetControl(control, "Name")
    control.zoneLabel = GetControl(control, "Zone")
    control.classIcon = GetControl(control, "Class")
    control.levelLabel = GetControl(control, "Level")
    control.roleDPS = GetControl(control, "RoleDPS")
    control.roleHeal = GetControl(control, "RoleHeal")
    control.roleTank = GetControl(control, "RoleTank")
    control.statusIcon:SetHidden(not data.leader)
    control.nameLabel:SetText(zo_strformat(SI_GROUP_LIST_PANEL_CHARACTER_NAME, data.index, data.rawCharacterName))
    control.zoneLabel:SetText(zo_strformat(SI_SOCIAL_LIST_LOCATION_FORMAT, data.zone))
    local classTexture = GetClassIcon(data.class)
    if(classTexture) then
        control.classIcon:SetHidden(false)
        control.classIcon:SetTexture(classTexture)
    else
        control.classIcon:SetHidden(true)
    end
    control.levelLabel:SetText(GetLevelOrVeteranRankString(data.level, data.veteranRank, 32))
    if(data.isDps) then
        control.roleDPS:SetTexture("EsoUI/Art/LFG/LFG_dps_down.dds")
    else
        control.roleDPS:SetTexture("EsoUI/Art/LFG/LFG_dps_up.dds")
    end
    if(data.isHeal) then
        control.roleHeal:SetTexture("EsoUI/Art/LFG/LFG_healer_down.dds")
    else
        control.roleHeal:SetTexture("EsoUI/Art/LFG/LFG_healer_up.dds")
    end
    if(data.isTank) then
        control.roleTank:SetTexture("EsoUI/Art/LFG/LFG_tank_down.dds")
    else
        control.roleTank:SetTexture("EsoUI/Art/LFG/LFG_tank_up.dds")
    end
end
function ZO_GroupListManager_Shared:SortScrollList()
    -- No sorting...just leave in group order
end
function ZO_GroupListManager_Shared:FilterScrollList()
    -- No real filtering...just show everything in the master list
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    ZO_ClearNumericallyIndexedTable(scrollData)
    for i = 1, #self.masterList do
        local data = self.masterList[i]
        table.insert(scrollData, ZO_ScrollList_CreateDataEntry(GROUP_DATA, data))
    end
end
local activeColor = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_NORMAL))
local inactiveColor = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_DISABLED))
function ZO_GroupListManager_Shared:UpdateHeaders(active)
    local color = active and activeColor or inactiveColor
    for i = 1, #self.headers do
        local header = self.headers[i]
        header:SetColor(color:UnpackRGBA())
    end
end
function ZO_GroupListManager_Shared:BuildMasterList()
    self.playerIsLeader = IsUnitGroupLeader("player")
    self.groupSize = GetGroupSize()
    self.noGroupRow:SetHidden(self.groupSize > 0)
    self:UpdateHeaders(self.groupSize > 0)
    for i = 1, self.groupSize do
        local unitTag = GetGroupUnitTagByIndex(i)
        if unitTag then
            local isDps, isHeal, isTank = GetGroupMemberRoles(unitTag)
            local rawCharacterName = GetRawUnitName(unitTag)
               local zoneName = zo_strformat(SI_ZONE_NAME, GetUnitZone(unitTag))
            self.masterList[i] = {
                                    index = i,
                                    unitTag = unitTag,
                                    characterName = GetUnitName(unitTag),
                                    rawCharacterName = rawCharacterName,
                                    gender = GetGenderFromNameDescriptor(rawCharacterName),
                                    zone = zoneName,
                                    class = GetUnitClassId(unitTag),
                                    level = GetUnitLevel(unitTag),
                                    veteranRank = GetUnitVeteranRank(unitTag),
                                    leader = IsUnitGroupLeader(unitTag),
                                    online = IsUnitOnline(unitTag),
                                    isPlayer = AreUnitsEqual(unitTag, "player"),
                                    isDps = isDps,
                                    isHeal = isHeal,
                                    isTank = isTank,
                                 }
        end
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
end
function ZO_GroupListManager_Shared:GetRowColors(data, mouseIsOver)
    return ZO_SocialList.GetRowColors(self, data, mouseIsOver)
end