Back to Home

ESO Lua File v100031

ingame/skills/gamepad/gamepadassignableactionbar.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
--[[
The (Gamepad)AssignableActionBar shows and lets you manage you what your current pending skill assignments will be inside the Gamepad Skills UI.
It's distinct from the "real" action bar in that only handles skills, it doesn't necessarily care about the state of each ability, and it can change
without changing the real action bar.
]]
--
ZO_AssignableActionBar = ZO_Object:Subclass()
function ZO_AssignableActionBar:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_AssignableActionBar:Initialize(control)
    self.control = control
    self.interpolator = ZO_SimpleControlScaleInterpolator:New(1.0, 1.28)
    self.headerLabel = control:GetNamedChild("Header")
    self.movementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.selectedButtonIndex = nil
    self.buttons =
    {
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button1"), ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 1),
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button2"), ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 2),
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button3"), ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 3),
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button4"), ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 4),
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button5"), ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 5),
        ZO_GamepadAssignableActionBarButton:New(self.control:GetNamedChild("Button6"), ACTION_BAR_ULTIMATE_SLOT_INDEX + 1),
    }
    
    ACTION_BAR_ASSIGNMENT_MANAGER:RegisterCallback("SlotUpdated", function(...) self:OnSlotUpdated(...) end)
    ACTION_BAR_ASSIGNMENT_MANAGER:RegisterCallback("CurrentHotbarUpdated", function(...) self:OnCurrentHotbarUpdated(...) end)
end
function ZO_AssignableActionBar:OnSkillsHidden()
    self:Deactivate()
    ACTION_BAR_ASSIGNMENT_MANAGER:CancelPendingWeaponSwap()
end
function ZO_AssignableActionBar:OnCurrentHotbarUpdated()
    if not self.control:IsControlHidden() then
        self:Refresh()
    end
end
function ZO_AssignableActionBar:OnSlotUpdated(hotbarCategory, actionSlotIndex)
    if not self.control:IsControlHidden() then
        if hotbarCategory == ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbarCategory() then
            local button = self.buttons[ZO_AssignableActionBar.ConvertActionSlotIndexToButtonIndex(actionSlotIndex)]
            if button then
                button:Refresh()
            end
        end
    end
end
function ZO_AssignableActionBar:GetControl()
    return self.control
end
function ZO_AssignableActionBar:Refresh()
end
function ZO_AssignableActionBar:RefreshAllButtons()
    for i, button in ipairs(self.buttons) do
        button:Refresh()
    end
end
function ZO_AssignableActionBar:RefreshHeaderLabel()
    local hotbarName = ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbarName()
    self.headerLabel:SetText(hotbarName)
end
function ZO_AssignableActionBar.ConvertButtonIndexToActionSlotIndex(buttonIndex)
    return buttonIndex + ACTION_BAR_FIRST_NORMAL_SLOT_INDEX
end
function ZO_AssignableActionBar.ConvertActionSlotIndexToButtonIndex(actionSlotIndex)
    return actionSlotIndex - ACTION_BAR_FIRST_NORMAL_SLOT_INDEX
end
function ZO_AssignableActionBar:Activate()
    if not self.active then
        self:RefreshAllButtons()
        DIRECTIONAL_INPUT:Activate(self, self.control)
        self.active = true
    end
end
function ZO_AssignableActionBar:Deactivate()
    if self.active then 
        self:DeselectButtons()
        self:ClearTargetSkill()
        DIRECTIONAL_INPUT:Deactivate(self)
        self.active = false
    end
end
function ZO_AssignableActionBar:SetHighlightAll(highlightAll)
    for i, button in ipairs(self.buttons) do
        button:SetSelected(highlightAll, self.interpolator)
    end
end
end
end
function ZO_AssignableActionBar:IsUltimateSelected()
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        return selectedButton:IsUltimateSlot()
    end
end
function ZO_AssignableActionBar:UpdateDirectionalInput()
    local result = self.movementController:CheckMovement()
    local newActionSlotIndex
    if result == MOVEMENT_CONTROLLER_MOVE_NEXT then
        newActionSlotIndex = ZO_AssignableActionBar.ConvertButtonIndexToActionSlotIndex(self.selectedButtonIndex + 1)
    elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
        newActionSlotIndex = ZO_AssignableActionBar.ConvertButtonIndexToActionSlotIndex(self.selectedButtonIndex - 1)
    end
    if newActionSlotIndex then
        local clampedSlotIndex = zo_clamp(newActionSlotIndex, ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 1, ACTION_BAR_ULTIMATE_SLOT_INDEX + 1)
        if self:SelectButton(clampedSlotIndex) then
            PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
        end
    end
end
function ZO_AssignableActionBar:SelectButton(actionSlotIndex)
    local buttonIndex = nil
    if actionSlotIndex then
        for index, button in ipairs(self.buttons) do
            if button:GetSlotIndex() == actionSlotIndex then
                buttonIndex = index
                break
            end
        end
        if not buttonIndex then
            internalassert(false, "Button not found")
            return false
        end
        if self.targetSkill and self.targetSkill:IsUltimate() ~= self.buttons[buttonIndex]:IsUltimateSlot() then
            return false
        end
    end
    if buttonIndex ~= self.selectedButtonIndex then
        local oldSelected = self.buttons[self.selectedButtonIndex]
        local oldWasUltimate = nil
        if oldSelected then
            oldSelected:SetSelected(false, self.interpolator)
            oldWasUltimate = oldSelected:IsUltimateSlot()
        end
        self.selectedButtonIndex = buttonIndex
        local newSelected = self.buttons[self.selectedButtonIndex]
        local newIsUltimate = nil
        if newSelected then
            newSelected:SetSelected(true, self.interpolator)
            newIsUltimate = newSelected:IsUltimateSlot()
        end
        if self.onSelectedDataChangedCallback then
            self.onSelectedDataChangedCallback(self, oldWasUltimate ~= newIsUltimate)
        end
        return true
    end
    return false
end
function ZO_AssignableActionBar:SelectFirstNormalButton()
    return self:SelectButton(ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 1)
end
function ZO_AssignableActionBar:SelectFirstUltimateButton()
    return self:SelectButton(ACTION_BAR_ULTIMATE_SLOT_INDEX + 1)
end
function ZO_AssignableActionBar:DeselectButtons()
    return self:SelectButton(nil)
end
function ZO_AssignableActionBar:AssignSkill(skillData)
    internalassert(skillData, "Needs skillData")
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        selectedButton:AssignSkill(skillData)
        if self.onAbilityFinalizedCallback then
            self.onAbilityFinalizedCallback()
        end
    end
end
function ZO_AssignableActionBar:SetTargetSkill(skillData)
    self.targetSkill = skillData
    if not self:GetSelectedSlotIndex() then
        local actionSlotIndex = skillData:GetSlotOnCurrentHotbar() or ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbar():FindEmptySlotForSkill(skillData)
        if actionSlotIndex then
            internalassert(self:SelectButton(actionSlotIndex))
        elseif skillData:IsUltimate() then
            internalassert(self:SelectFirstUltimateButton())
        else
            internalassert(self:SelectFirstNormalButton())
        end
    end
end
function ZO_AssignableActionBar:ClearTargetSkill()
    self.targetSkill = nil
end
function ZO_AssignableActionBar:AssignTargetSkill()
    self:AssignSkill(self.targetSkill)
end
function ZO_AssignableActionBar:ClearAbility()
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        selectedButton:ClearSlot()
        if self.onAbilityFinalizedCallback then
            self.onAbilityFinalizedCallback()
        end
    end
end
function ZO_AssignableActionBar:GetSelectedSlotIndex()
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        return selectedButton:GetSlotIndex()
    end
end
local function SetupTooltipStatusLabel(tooltipType, actionSlotIndex)
    local valueText
    if actionSlotIndex == ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 then
        valueText = zo_strformat(SI_GAMEPAD_SKILLS_TOOLTIP_STATUS_NUMBER, GetString(SI_BINDING_NAME_GAMEPAD_ACTION_BUTTON_8))
    else
        valueText = zo_strformat(SI_GAMEPAD_SKILLS_TOOLTIP_STATUS_NUMBER, ZO_AssignableActionBar.ConvertActionSlotIndexToButtonIndex(actionSlotIndex))
    end
    GAMEPAD_TOOLTIPS:SetStatusLabelText(tooltipType, GetString(SI_GAMEPAD_SKILLS_TOOLTIP_STATUS), valueText)
end
function ZO_AssignableActionBar:LayoutOrClearSlotTooltip(tooltipType)
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        local slotData = selectedButton:GetSlotData()
        SetupTooltipStatusLabel(tooltipType, selectedButton:GetSlotIndex())
        slotData:LayoutGamepadTooltip(tooltipType)
    else
        GAMEPAD_TOOLTIPS:ClearTooltip(tooltipType)
    end
end
function ZO_AssignableActionBar:LayoutAssignableSkillLineAbilityTooltip(tooltipType, skillData)
    local skillProgressionData = skillData:GetPointAllocatorProgressionData()
    local abilityId = skillProgressionData:GetAbilityId()
    -- Mark the ability as already slotted if it is
    for i = ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 1, ACTION_BAR_ULTIMATE_SLOT_INDEX + 1 do
        if abilityId == GetSlotBoundId(i) then
            SetupTooltipStatusLabel(tooltipType, i)
            break
        end
    end 
    GAMEPAD_TOOLTIPS:LayoutSkillProgression(tooltipType, skillProgressionData)
end
function ZO_AssignableActionBar:IsActive()
    return self.active
end
ZO_GamepadAssignableActionBarButton = ZO_Object:Subclass()
function ZO_GamepadAssignableActionBarButton:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_GamepadAssignableActionBarButton:Initialize(control, actionSlotIndex)
    self.control = control
    self.icon = control:GetNamedChild("Icon")
    self.highlight = control:GetNamedChild("Highlight")
    self.keybindLabel = control:GetNamedChild("KeybindLabel")
    self.frame = control:GetNamedChild("Frame")
    if self.keybindLabel then
        local HIDE_UNBOUND = false
        ZO_Keybindings_RegisterLabelForBindingUpdate(self.keybindLabel, "GAMEPAD_ACTION_BUTTON_" .. actionSlotIndex, HIDE_UNBOUND)
    end
    self.actionSlotIndex = actionSlotIndex
end
function ZO_GamepadAssignableActionBarButton:GetSlotIndex()
    return self.actionSlotIndex
end
function ZO_GamepadAssignableActionBarButton:GetSlotData()
    return ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbar():GetSlotData(self.actionSlotIndex)
end
function ZO_GamepadAssignableActionBarButton:IsUltimateSlot()
    return ACTION_BAR_ASSIGNMENT_MANAGER:IsUltimateSlot(self.actionSlotIndex)
end
function ZO_GamepadAssignableActionBarButton:GetControl()
    return self.control
end
function ZO_GamepadAssignableActionBarButton:GetIconControl()
    return self.icon
end
function ZO_GamepadAssignableActionBarButton:SetSelected(selected, interpolator)
    if selected then
        interpolator:ScaleUp(self:GetIconControl())
    else
        interpolator:ScaleDown(self:GetIconControl())
    end
    if self.highlight then
        self.highlight:SetHidden(not selected)
    end
    if self.frame then
        local color = selected and ZO_SELECTED_TEXT or ZO_NORMAL_TEXT
        self.frame:SetEdgeColor(color:UnpackRGBA())
    end
end
function ZO_GamepadAssignableActionBarButton:Refresh()
    local slotData = self:GetSlotData()
    local slotIcon = slotData:GetIcon()
    if slotIcon then
        self.icon:SetHidden(false)
        self.icon:SetTexture(slotIcon)
    else
        self.icon:SetHidden(true)
    end
end
function ZO_GamepadAssignableActionBarButton:ClearSlot()
    if ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbar():ClearSlot(self.actionSlotIndex) then
        PlaySound(SOUNDS.ABILITY_SLOT_CLEARED)
    end
end
function ZO_GamepadAssignableActionBarButton:AssignSkill(skillData)
    if ACTION_BAR_ASSIGNMENT_MANAGER:GetCurrentHotbar():AssignSkillToSlot(self.actionSlotIndex, skillData) then
        PlaySound(SOUNDS.ABILITY_SLOTTED)
    end
end