Back to Home

ESO Lua File v101036

ingame/companion/keyboard/companionskills_keyboard.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
-----------------------------
-- Companion Skills
-----------------------------
ZO_CompanionSkills_Keyboard = ZO_InitializingObject:Subclass()
function ZO_CompanionSkills_Keyboard:Initialize(control)
    self.control = control
    self.scene = ZO_InteractScene:New("companionSkillsKeyboard", SCENE_MANAGER, ZO_COMPANION_MANAGER:GetInteraction())
    self.scene:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self.skillLinesTreeRefreshGroup:TryClean()
            self.skillListRefreshGroup:TryClean()
            ACTION_BAR_ASSIGNMENT_MANAGER:SetHotbarCycleOverride(HOTBAR_CATEGORY_COMPANION)
            self.assignableActionBar:RefreshAllButtons()
        elseif newState == SCENE_HIDDEN then
            SKILLS_AND_ACTION_BAR_MANAGER:ResetInterface()
            ACTION_BAR_ASSIGNMENT_MANAGER:SetHotbarCycleOverride(nil)
        end
    end)
    COMPANION_SKILLS_KEYBOARD_SCENE = self.scene
    COMPANION_SKILLS_KEYBOARD_FRAGMENT = ZO_FadeSceneFragment:New(self.control)
    self.advisedOverlay = ZO_Skills_SkillLineAdvisedOverlay:New(control:GetNamedChild("SkillLineAdvisedOverlay"))
    self.assignableActionBar = ZO_KeyboardAssignableActionBar:New(control:GetNamedChild("AssignableActionBar"))
    self.skillLineInfo = control:GetNamedChild("SkillLineInfo")
end
function ZO_CompanionSkills_Keyboard:InitializeSkillLinesTree()
    local container = self.control:GetNamedChild("SkillLinesContainer")
    local skillLinesTree = ZO_Tree:New(container:GetNamedChild("ScrollChild"), 74, -10, 300)
    local NEW_COMPANION_SKILLS_FILTER = { ZO_CompanionSkillLineData.IsNew }
    local function TreeHeaderSetup(node, control, skillTypeData, open)
        control.skillTypeData = skillTypeData
        control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
        control.text:SetText(skillTypeData:GetName())
        local up, down, over = skillTypeData:GetKeyboardIcons()
        
        control.icon:SetTexture(open and down or up)
        control.iconHighlight:SetTexture(over)
        control.statusIcon:ClearIcons()
        if not ZO_IsIteratorEmpty(skillTypeData:SkillLineIterator(NEW_COMPANION_SKILLS_FILTER)) then
            control.statusIcon:AddIcon(ZO_KEYBOARD_NEW_ICON)
        end
        control.statusIcon:Show()
        
        ZO_IconHeader_Setup(control, open)
    end
    skillLinesTree:AddTemplate("ZO_SkillIconHeader", TreeHeaderSetup, nil, nil, nil, 0)
    local function TreeEntrySetup(node, control, skillLineData, open)
        control:SetText(skillLineData:GetFormattedName())
        control.statusIcon:ClearIcons()
        if skillLineData:IsNew() then
            control.statusIcon:AddIcon(ZO_KEYBOARD_NEW_ICON)
        end
        control.statusIcon:Show()
    end
    local function TreeEntryOnSelected(control, skillLineData, selected, reselectingDuringRebuild)
        control:SetSelected(selected)
        if selected and not reselectingDuringRebuild then
            self:RefreshSkillLineInfo()
            skillLineData:ClearNew()
            self.skillListRefreshGroup:MarkDirty("List")
            self.skillListRefreshGroup:TryClean()
        end
    end
    skillLinesTree:AddTemplate("ZO_SkillsNavigationEntry", TreeEntrySetup, TreeEntryOnSelected)
    skillLinesTree:SetExclusive(true)
    skillLinesTree:SetOpenAnimation("ZO_TreeOpenAnimation")
    local skillLinesTreeRefreshGroup = ZO_OrderedRefreshGroup:New(ZO_ORDERED_REFRESH_GROUP_AUTO_CLEAN_PER_FRAME)
    skillLinesTreeRefreshGroup:AddDirtyState("List", function()
        self:RefreshSkillLines()
    end)
    skillLinesTreeRefreshGroup:AddDirtyState("Visible", function()
        skillLinesTree:RefreshVisible()
    end)
    skillLinesTreeRefreshGroup:SetActive(function()
        return COMPANION_SKILLS_KEYBOARD_SCENE:IsShowing()
    end)
    skillLinesTreeRefreshGroup:MarkDirty("List")
    self.skillLinesTreeRefreshGroup = skillLinesTreeRefreshGroup
    self.skillLinesTree = skillLinesTree
end
function ZO_CompanionSkills_Keyboard:GetSelectedSkillLineData()
    return self.skillLinesTree:GetSelectedData()
end
local SKILL_ABILITY_DATA = 1
local SKILL_HEADER_DATA = 2
function ZO_CompanionSkills_Keyboard:InitializeSkillList()
    local skillList = self.control:GetNamedChild("SkillList")
    local SKILL_ABILITY_HEIGHT = 70
    ZO_ScrollList_AddDataType(skillList, SKILL_ABILITY_DATA, "ZO_Skills_Ability", SKILL_ABILITY_HEIGHT, function(abilityControl, data)
        ZO_Skills_CompanionSkillEntry_Setup(abilityControl, data.skillData)
    end)
    local SKILL_HEADER_HEIGHT = 32
    ZO_ScrollList_AddDataType(skillList, SKILL_HEADER_DATA, "ZO_Skills_AbilityTypeHeader", SKILL_HEADER_HEIGHT, function(headerControl, data)
        headerControl:GetNamedChild("Label"):SetText(data.headerText)
    end)
    local skillListRefreshGroup = ZO_OrderedRefreshGroup:New(ZO_ORDERED_REFRESH_GROUP_AUTO_CLEAN_PER_FRAME)
    skillListRefreshGroup:AddDirtyState("List", function()
        self:RefreshSkills()
    end)
    skillListRefreshGroup:AddDirtyState("Visible", function()
        local skillLineData = self:GetSelectedSkillLineData()
        if skillLineData then
            ZO_ScrollList_RefreshVisible(skillList)
        end
    end)
    skillListRefreshGroup:SetActive(function()
        return COMPANION_SKILLS_KEYBOARD_SCENE:IsShowing()
    end)
    self.skillListRefreshGroup = skillListRefreshGroup
    self.skillList = skillList
end
function ZO_CompanionSkills_Keyboard:RegisterForEvents()
    local control = self.control
    local function OnFullSystemUpdated()
        self.skillLinesTreeRefreshGroup:MarkDirty("List")
    end
    local function OnSkillLineUpdated(skillLineData)
        if skillLineData == self:GetSelectedSkillLineData() then
            self:RefreshSkillLineInfo()
            self.skillListRefreshGroup:MarkDirty("Visible")
        end
    end
    local function OnSkillProgressionUpdated(skillData)
        if skillData:GetSkillLineData() == self:GetSelectedSkillLineData() then
            self.skillListRefreshGroup:MarkDirty("Visible")
        end
    end
    local function OnSkillLineNewStatusChanged()
        self.skillLinesTreeRefreshGroup:MarkDirty("Visible")
    end
    COMPANION_SKILLS_DATA_MANAGER:RegisterCallback("FullSystemUpdated", OnFullSystemUpdated)
    COMPANION_SKILLS_DATA_MANAGER:RegisterCallback("SkillLineUpdated", OnSkillLineUpdated)
    COMPANION_SKILLS_DATA_MANAGER:RegisterCallback("SkillProgressionUpdated", OnSkillProgressionUpdated)
    COMPANION_SKILLS_DATA_MANAGER:RegisterCallback("SkillLineNewStatusChanged", OnSkillLineNewStatusChanged)
    control:RegisterForEvent(EVENT_PLAYER_ACTIVATED, OnFullSystemUpdated)
    local function OnPurchaseLockStateChanged()
        self.skillListRefreshGroup:MarkDirty("Visible")
    end
    control:RegisterForEvent(EVENT_ACTION_BAR_LOCKED_REASON_CHANGED, OnPurchaseLockStateChanged)
end
do
    local AVAILABLE_COMPANION_SKILLS_FILTER = { ZO_CompanionSkillLineData.IsAvailableOrAdvised }
    function ZO_CompanionSkills_Keyboard:RefreshSkillLines()
        self.skillLinesTree:Reset()
        for _, skillTypeData in COMPANION_SKILLS_DATA_MANAGER:SkillTypeIterator() do
            local parent
            for _, skillLineData in skillTypeData:SkillLineIterator(AVAILABLE_COMPANION_SKILLS_FILTER) do
                if not parent then
                    parent = self.skillLinesTree:AddNode("ZO_SkillIconHeader", skillTypeData)
                end
                self.skillLinesTree:AddNode("ZO_SkillsNavigationEntry", skillLineData, parent)
            end
        end
        self.skillLinesTree:Commit()
        self.skillListRefreshGroup:MarkDirty("List")
        self.skillListRefreshGroup:TryClean()
        local FORCE_INIT = true
        self:RefreshSkillLineInfo(FORCE_INIT)
    end
end
function ZO_CompanionSkills_Keyboard:RefreshSkills()
    local scrollData = ZO_ScrollList_GetDataList(self.skillList)
    ZO_ScrollList_Clear(self.skillList)
    local skillLineData = self:GetSelectedSkillLineData()
    if skillLineData then
        local lastHeaderText = nil
        for _, skillData in skillLineData:SkillIterator() do
            local headerText = skillData:GetHeaderText()
            if lastHeaderText ~= headerText then
                table.insert(scrollData, ZO_ScrollList_CreateDataEntry(SKILL_HEADER_DATA, { headerText = headerText }))
                lastHeaderText = headerText
            end
            table.insert(scrollData, ZO_ScrollList_CreateDataEntry(SKILL_ABILITY_DATA, { skillData = skillData }))
        end
    end
    ZO_ScrollList_Commit(self.skillList)
    self:RefreshSkillLineAdvisedOverlay(skillLineData)
end
function ZO_CompanionSkills_Keyboard:RefreshSkillLineInfo(forceInit)
    local skillLineData = self:GetSelectedSkillLineData()
    if skillLineData then
        self.skillLineInfo:SetHidden(false)
        ZO_SkillLineInfo_Keyboard_Refresh(self.skillLineInfo, skillLineData, forceInit)
    else
        self.skillLineInfo:SetHidden(true)
    end
end
function ZO_CompanionSkills_Keyboard:RefreshSkillLineAdvisedOverlay(skillLineData)
    if skillLineData and not skillLineData:IsAvailable() and skillLineData:IsAdvised() then
        self.advisedOverlay:Show(skillLineData)
        self.skillList:SetAlpha(0.1)
    else
        self.advisedOverlay:Hide()
        self.skillList:SetAlpha(1)
    end 
end
-----------------------------
-- Global XML Functions
-----------------------------
    COMPANION_SKILLS_KEYBOARD = ZO_CompanionSkills_Keyboard:New(control)
end