Back to Home

ESO Lua File v100023

libraries/zo_buttontabbar/gamepad/zo_gamepadbuttontabbar.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
ZO_GamepadButtonTabBar = ZO_Object:Subclass()
function ZO_GamepadButtonTabBar:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
    self.control = control
    self.movementControllerHorizontal = ZO_MovementController:New(MOVEMENT_CONTROLLER_DIRECTION_HORIZONTAL)
    self.isActivated = false
    self.buttons = {}
    self.selectedIndex = nil
    self.deactivatedIndex = nil
end
function ZO_GamepadButtonTabBar:AddButton(control, data)
    self.buttons[#self.buttons + 1] = control
    control.data = data
end
function ZO_GamepadButtonTabBar:Activate()
    if self.isActivated then
        return --already activated
    end
    self.isActivated = true
    DIRECTIONAL_INPUT:Activate(self, self.control)
    self:SetSelectedButton(self.deactivatedIndex or 1)
end
function ZO_GamepadButtonTabBar:Deactivate()
    if not self.isActivated then
        return --already deactivated
    end
    DIRECTIONAL_INPUT:Deactivate(self)
    self.deactivatedIndex = self.selectedIndex
    self:SetSelectedButton(nil)
    self.isActivated = false
end
function ZO_GamepadButtonTabBar:UpdateDirectionalInput()
    local horizontalResult = self.movementControllerHorizontal:CheckMovement()
    if horizontalResult == MOVEMENT_CONTROLLER_MOVE_NEXT then
        local oldIndex = self.selectedIndex
        local index = zo_clamp(self.selectedIndex + 1, 1, #self.buttons)
        self:SetSelectedButton(index)
        if oldIndex ~= index then
            PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
        end
    elseif horizontalResult == MOVEMENT_CONTROLLER_MOVE_PREVIOUS then
        local oldIndex = self.selectedIndex
        local index = zo_clamp(self.selectedIndex - 1, 1, #self.buttons)
        self:SetSelectedButton(index)
        if oldIndex ~= index then
            PlaySound(SOUNDS.HOR_LIST_ITEM_SELECTED)
        end
    end
end
function ZO_GamepadButtonTabBar:SetSelectedButton(index)
    if index ~= self.selectedIndex then
        local oldIndex = self.selectedIndex
        if oldIndex and self.onUnselectedCallback then
            self.onUnselectedCallback(self.buttons[oldIndex])
        end
        self.selectedIndex = index
        if index then
            self.onSelectedCallback(self.buttons[index])
        end
    end
end
function ZO_GamepadButtonTabBar:IsActivated()
    return self.isActivated
end