Back to Home

ESO Lua File v101042

internalingame/tribute/tributepatronselection_manager.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
-----------------------------
-- Tribute Patron Selection Manager
-----------------------------
ZO_TributePatronSelection_Manager = ZO_InitializingCallbackObject:Subclass()
function ZO_TributePatronSelection_Manager:Initialize()
    EVENT_MANAGER:RegisterForEvent("TributePatronSelection_Manager", EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, function() 
        if self.isSelectionInProgress then
            self:FireCallbacks("EndSelection")
            self:FireCallbacks("BeginSelection")
        end
    end)
    EVENT_MANAGER:RegisterForEvent("TributePatronSelection_Manager", EVENT_TRIBUTE_PATRON_DRAFTED, function(_, patronDraftId, patronDefId)
        local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(patronDefId)
        --Filter out neutral patrons
        if patronData:IsNeutral() then
            return
        end
        
        local family = patronData:GetFamily()
        if family ~= 0 then
            self.draftedFamilies[family] = true
        end
        
        self.draftedPatrons[patronDefId] = patronDraftId
        self.isAnimating = true
        PlaySound(SOUNDS.TRIBUTE_PATRON_DRAFTED)
        --No need to do this if the screen isn't up
        if self.isSelectionInProgress then
            self.selectedPatron = nil
            self:FireCallbacks("PatronDrafted")
        end
    end)
    EVENT_MANAGER:RegisterForEvent("TributePatronSelection_Manager", EVENT_TRIBUTE_PATRON_START_NEXT_DRAFT, function()
        self.isAnimating = false
        --No need to do this if the screen isn't up
        if self.isSelectionInProgress then
            self:FireCallbacks("BeginNextDraftingPhase")
        end
    end)
    self.patronFilterFunction = function(currentData)
        if currentData:GetPatronCollectibleId() == 0 then
            return false
        end
        if currentData:IsNeutral() then
            return false
        end
        return true
    end
    self.patronDataList = {}
    self.draftedPatrons = {}
    self.draftedFamilies = {}
    self.showGamepadTooltips = true
end
do
    local function ComparePatrons(left, right)
        local isLeftLocked = left:IsPatronLocked()
        local isRightLocked = right:IsPatronLocked()
        if isLeftLocked == isRightLocked then
            return left:GetId() < right:GetId()
        else
            return isRightLocked
        end
    end
    function ZO_TributePatronSelection_Manager:RefreshPatronData()
        ZO_ClearNumericallyIndexedTable(self.patronDataList)
        for _, patronData in TRIBUTE_DATA_MANAGER:TributePatronIterator({self.patronFilterFunction}) do
            table.insert(self.patronDataList, patronData)
        end
        table.sort(self.patronDataList, ComparePatrons)
    end
end
function ZO_TributePatronSelection_Manager:GetPatronData()
    if self.isSelectionInProgress then
        return self.patronDataList
    end
end
function ZO_TributePatronSelection_Manager:IsSelectionInProgress()
    return self.isSelectionInProgress
end
function ZO_TributePatronSelection_Manager:IsDraftAnimating()
    return self.isAnimating
end
function ZO_TributePatronSelection_Manager:BeginPatronSelection()
    if not self.isSelectionInProgress then
        self.isSelectionInProgress = true
        self.showGamepadTooltips = true
        self:RefreshPatronData()
        self:FireCallbacks("BeginSelection")
    end
end
function ZO_TributePatronSelection_Manager:EndPatronSelection(forceEndSelection)
    if self.isSelectionInProgress or forceEndSelection then
        ZO_ClearTable(self.draftedPatrons)
        ZO_ClearTable(self.draftedFamilies)
        self.isSelectionInProgress = false
        self.isAnimating = false
        self.selectedPatron = nil
        self:FireCallbacks("EndSelection")
    end
end
function ZO_TributePatronSelection_Manager:SelectPatron(patronId)
    self.selectedPatron = patronId
    self:FireCallbacks("PatronSelected")
end
function ZO_TributePatronSelection_Manager:ConfirmSelection()
    if self.selectedPatron then
        DraftPatron(self.selectedPatron)
    end
end
function ZO_TributePatronSelection_Manager:GetSelectedPatron()
    return self.selectedPatron
end
function ZO_TributePatronSelection_Manager:IsPatronDrafted(patronId)
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(patronId)
    return self.draftedPatrons[patronId] ~= nil or self.draftedFamilies[patronData:GetFamily()] == true
end
function ZO_TributePatronSelection_Manager:GetNumDraftedPatrons()
    return NonContiguousCount(self.draftedPatrons)
end
function ZO_TributePatronSelection_Manager:ToggleShowGamepadTooltips()
    self.showGamepadTooltips = not self.showGamepadTooltips
end
function ZO_TributePatronSelection_Manager:ShouldShowGamepadTooltips()
    return self.showGamepadTooltips
end
function ZO_TributePatronSelection_Manager:HasTurnTimer()
    return GetTributeRemainingTimeForTurn() ~= nil
end
ZO_TRIBUTE_PATRON_SELECTION_MANAGER = ZO_TributePatronSelection_Manager:New()