Back to Home

ESO Lua File v100018

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
ZO_AssignableActionBar = ZO_GamepadActionBar:Subclass()
ASSIGNABLE_ACTION_BAR_LOCK_MODE_NONE = 1
ASSIGNABLE_ACTION_BAR_LOCK_MODE_ULTIMATE = 2
ASSIGNABLE_ACTION_BAR_LOCK_MODE_ACTIVE = 3
function ZO_AssignableActionBar:New(...)
    return ZO_GamepadActionBar.New(self, ...)
end
function ZO_AssignableActionBar:Initialize(control)
    ZO_GamepadActionBar.Initialize(self, control)
    self.movementController = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.selectedButtonIndex = nil
    self.lockMode = ASSIGNABLE_ACTION_BAR_LOCK_MODE_NONE
    self.actionButtonSlotAnimation = ANIMATION_MANAGER:CreateTimelineFromVirtual("GamepadActionBarAbilitySlotted")
    self.actionButtonSlotAnimation:SetHandler("OnStop", function()
        self.hasPendingAbilityChangeRequest = nil
        if self.onAbilityFinalizedCallback then
            self.onAbilityFinalizedCallback()
        end
    end)
    local function OnHotBarResult(eventCode, reason)
        if reason == HOT_BAR_RESULT_NO_COMBAT_SWAP then
            self.hasPendingAbilityChangeRequest = nil
        end
    end
    EVENT_MANAGER:RegisterForEvent("GamepadAssignableActionBar", EVENT_HOT_BAR_RESULT, OnHotBarResult)
end
function ZO_AssignableActionBar:UpdateActionButtonSlotAnimation()
    if self.hasPendingAbilityChangeRequest and not self.actionButtonSlotAnimation:IsPlaying() then
        self.actionButtonSlotAnimation:ApplyAllAnimationsToControl(self.hasPendingAbilityChangeRequest:GetControl())
        self.actionButtonSlotAnimation:PlayFromStart()
    end
end
function ZO_AssignableActionBar:OnSkillsChanged()
    ZO_GamepadActionBar.OnSkillsChanged(self)
end
function ZO_AssignableActionBar:RefreshDirtyButtons()
    ZO_GamepadActionBar.RefreshDirtyButtons(self)
end
function ZO_AssignableActionBar:Activate()    
    if not self.active then
        ZO_GamepadActionBar.Activate(self)
        DIRECTIONAL_INPUT:Activate(self, self.control)
        self.active = true
    end
end
function ZO_AssignableActionBar:Deactivate()
    if self.active then 
        ZO_GamepadActionBar.Deactivate(self)
        DIRECTIONAL_INPUT:Deactivate(self)
        self.active = false
    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 moveSuccess = false
    if result == MOVEMENT_CONTROLLER_MOVE_NEXT then
        moveSuccess = self:SetSelectedButton(self.selectedButtonIndex + 1)
    elseif result == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
        moveSuccess = self:SetSelectedButton(self.selectedButtonIndex - 1)
    end
    if moveSuccess then
        PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
    end
end
function ZO_AssignableActionBar:SetSelectedButton(buttonIndex)
    if buttonIndex then
        buttonIndex = zo_clamp(buttonIndex, 1, #self.buttons)
        if self.lockMode == ASSIGNABLE_ACTION_BAR_LOCK_MODE_ULTIMATE then
            if not self.buttons[buttonIndex]:IsUltimateSlot()  then
                return false
            end
        elseif self.lockMode == ASSIGNABLE_ACTION_BAR_LOCK_MODE_ACTIVE then
            if self.buttons[buttonIndex]:IsUltimateSlot() then
                return false
            end
        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:SetSelectedButtonBySlotId(slotId)
    for i, button in ipairs(self.buttons) do
        if button:GetSlotId() == slotId then
            self:SetSelectedButton(i)
            break
        end
    end
end
function ZO_AssignableActionBar:SetLockMode(lockMode)
    if self.lockMode ~= lockMode then
        self.lockMode = lockMode
        if self.lockMode == ASSIGNABLE_ACTION_BAR_LOCK_MODE_ULTIMATE then
            if not self:IsUltimateSelected() then
                self:SetSelectedButtonBySlotId(ACTION_BAR_ULTIMATE_SLOT_INDEX + 1)
            end
        elseif self.lockMode == ASSIGNABLE_ACTION_BAR_LOCK_MODE_ACTIVE then
            if self:IsUltimateSelected() then
                self:SetSelectedButtonBySlotId(ACTION_BAR_FIRST_NORMAL_SLOT_INDEX + 1)
            end
        end
    end
end
function ZO_AssignableActionBar:SetAbility(skillType, skillLineIndex, abilityIndex)
    if not self.hasPendingAbilityChangeRequest then
        local selectedButton = self.buttons[self.selectedButtonIndex]
        if selectedButton then
            selectedButton:SetAbility(skillType, skillLineIndex, abilityIndex)
            self.hasPendingAbilityChangeRequest = selectedButton
        end
    end
end
function ZO_AssignableActionBar:ClearAbility()
    if not self.hasPendingAbilityChangeRequest then
        local selectedButton = self.buttons[self.selectedButtonIndex]
        if selectedButton then
            selectedButton:ClearSlot()
            self.hasPendingAbilityChangeRequest = selectedButton
        end
    end
end
function ZO_AssignableActionBar:GetSelectedSlotId()
    local selectedButton = self.buttons[self.selectedButtonIndex]
    if selectedButton then
        return selectedButton:GetSlotId()
    end
end