Back to Home

ESO Lua File v100022

libraries/zo_menubar/zo_scenefragmentbar.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
ZO_SceneFragmentBar = ZO_Object:Subclass()
function ZO_SceneFragmentBar:New(...)
    local object = ZO_Object.New(self)
    object:Initialize(...)
    return object
end
function ZO_SceneFragmentBar:Initialize(menuBar)
    self.menuBar = menuBar
    self.label = menuBar:GetNamedChild("Label")
    self.buttonData = {}
end
function ZO_SceneFragmentBar:SelectFragment(name)
    local SKIP_ANIMATIONS = true 
    ZO_MenuBar_SelectDescriptor(self.menuBar, name, SKIP_ANIMATIONS)
end
function ZO_SceneFragmentBar:SetStartingFragment(name)
    self.lastFragmentName = name
end
function ZO_SceneFragmentBar:ShowLastFragment()
    self:SelectFragment(self.lastFragmentName)
end
function ZO_SceneFragmentBar:GetLastFragment()
    return self.lastFragmentName
end
function ZO_SceneFragmentBar:RemoveActiveKeybind()
    local keybindButton = self.currentKeybindButton
    self.currentKeybindButton = nil
    if(keybindButton) then
        if(keybindButton.keybind) then
            KEYBIND_STRIP:RemoveKeybindButton(keybindButton)
        else
            KEYBIND_STRIP:RemoveKeybindButtonGroup(keybindButton)
        end
    end
end
function ZO_SceneFragmentBar:UpdateActiveKeybind()
    if(self.currentKeybindButton) then
        if(self.currentKeybindButton.keybind) then
            KEYBIND_STRIP:UpdateKeybindButton(self.currentKeybindButton)
        else
            KEYBIND_STRIP:UpdateKeybindButtonGroup(self.currentKeybindButton)
        end
    end
end
function ZO_SceneFragmentBar:Clear()
    if(self.currentFragmentGroup) then
        SCENE_MANAGER:RemoveFragmentGroup(self.currentFragmentGroup)
    end
end
function ZO_SceneFragmentBar:RemoveAll()
    self:Clear()
    ZO_MenuBar_ClearButtons(self.menuBar)
    for _, buttonData in ipairs(self.buttonData) do
        buttonData.callback = buttonData.existingCallback
    end
    self.buttonData = {}
end
function ZO_SceneFragmentBar:Add(name, fragmentGroup, buttonData, keybindButton)
    buttonData.descriptor = name
    buttonData.categoryName = name
    buttonData.existingCallback = buttonData.callback
    local existingCallback = buttonData.callback
    buttonData.callback = function()
        self:RemoveActiveKeybind()
        if(self.currentFragmentGroup) then
            SCENE_MANAGER:RemoveFragmentGroup(self.currentFragmentGroup)
        end
        self.currentFragmentGroup = fragmentGroup
        self.currentKeybindButton = keybindButton
        SCENE_MANAGER:AddFragmentGroup(fragmentGroup)
        if(keybindButton) then
            if(keybindButton.keybind) then
                KEYBIND_STRIP:AddKeybindButton(keybindButton)
            else
                KEYBIND_STRIP:AddKeybindButtonGroup(keybindButton)
            end
        end
        if(self.label) then
            self.label:SetText(zo_strformat(SI_SCENE_FRAGMENT_BAR_TITLE, GetString(name)))
        end
        self.lastFragmentName = name
        if(existingCallback) then
            existingCallback()
        end
    end
    ZO_MenuBar_AddButton(self.menuBar, buttonData)
    table.insert(self.buttonData, buttonData)
end