ESO Lua File v100010

common/zo_keybindstrip/keybindstrip.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
KEYBIND_STRIP = nil
    return KEYBIND_STRIP:TryHandlingKeybindDown(keybind)
end
    return KEYBIND_STRIP:TryHandlingKeybindUp(keybind)
end
KEYBIND_STRIP_STANDARD_STYLE = {
    nameFont = "ZoFontKeybindStripDescription",
    nameFontColor = ZO_NORMAL_TEXT,
    keyFont = "ZoFontKeybindStripKey",
    modifyTextType = MODIFY_TEXT_TYPE_NONE,
    alwaysPreferGamepadMode = false,
    resizeToFitPadding = 40,
    leftAnchorOffset = 10,
    centerAnchorOffset = 0,
    rightAnchorOffset = -10,
}
KEYBIND_STRIP_GAMEPAD_STYLE = {
    nameFont = "ZoFontGamepad34",
    nameFontColor = ZO_SELECTED_TEXT,
    keyFont = "ZoFontGamepad22",
    modifyTextType = MODIFY_TEXT_TYPE_UPPERCASE,
    alwaysPreferGamepadMode = true,
    resizeToFitPadding = 15,
    leftAnchorOffset = 96,
    centerAnchorOffset = 0,
    rightAnchorOffset = -96,
    yAnchorOffset = -53,
}
    KEYBIND_STRIP = ZO_KeybindStrip:New(control, "ZO_KeybindStripButtonTemplate", KEYBIND_STRIP_STANDARD_STYLE)
    local defaultExit = {
        name = GetString(SI_EXIT_BUTTON),
        keybind = "UI_SHORTCUT_EXIT",
        order = -10000,
        callback = function()
            SCENE_MANAGER:ShowBaseScene()
        end,
    }
    local defaultGamepadExit = {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        keybind = "UI_SHORTCUT_EXIT",
        order = -10000,
        ethereal = true,
        callback = function()
            SCENE_MANAGER:ShowBaseScene()
        end,
    }
    function KEYBIND_STRIP:HasDefaultExit()
        return self.allowDefaultExit
    end
    function KEYBIND_STRIP:RemoveDefaultExit()
        self.allowDefaultExit = false
        self:RefreshDefaultExits()
    end
    function KEYBIND_STRIP:RestoreDefaultExit()
        self.allowDefaultExit = true
        self:RefreshDefaultExits()
    end
    function KEYBIND_STRIP:RefreshDefaultExits()
        if self.allowDefaultExit then
            local styleInfo = self:GetStyle()
            if styleInfo.alwaysPreferGamepadMode then
                self:RemoveKeybindButton(defaultExit)
                self:AddKeybindButton(defaultGamepadExit)
            else
                self:RemoveKeybindButton(defaultGamepadExit)
                self:AddKeybindButton(defaultExit)
            end
        else
            self:RemoveKeybindButton(defaultExit)
            self:RemoveKeybindButton(defaultGamepadExit)
        end
    end
    function KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(callback, keybind)
        keybind = keybind or "UI_SHORTCUT_NEGATIVE"
        return {
            alignment = KEYBIND_STRIP_ALIGN_LEFT,
            name = GetString(SI_GAMEPAD_BACK_OPTION),
            keybind = keybind,
            order = -1000,
            callback = callback,
        }
    end
    function KEYBIND_STRIP:GenerateGamepadRightScrollButtonDescriptor(text, visibleFunc)
        local rightScrollIcon = "EsoUI/Art/Buttons/Gamepad/Xbox/Nav_XBone_RS_Scroll.dds";
        if (GetUIPlatform() == UI_PLATFORM_PS4) then
            rightScrollIconPS4 = "EsoUI/Art/Buttons/Gamepad/PS4/Nav_Ps4_RS_Scroll.dds";
        end
        if self.rightScrollKeybind == nil then
            local keybind = CreateControlFromVirtual("$(parent)RightStickScroll", control, "ZO_KeybindStripRightScrollKeybind")
            keybind:SetCustomKeyIcon(rightScrollIcon)
            keybind:SetKeybindEnabledInEdit(true)
            keybind:SetMouseOverEnabled(false)
        
            local styleInfo = ZO_ShallowTableCopy(KEYBIND_STRIP_GAMEPAD_STYLE)
            styleInfo.resizeToFitPadding = 0
            keybind:SetupStyle(styleInfo)
            keybind:AdjustBindingAnchors(false)
            keybind.nameLabel:SetAnchor(RIGHT, keybind, RIGHT, 0)
            keybind:SetParent(nil)
            keybind:SetHidden(true)
            self.rightScrollKeybind = keybind
        end
        local keybind = {
            customKeybindControl = self.rightScrollKeybind,
            keybind = "",
            name = text,
            gamepadOrder = 1,
        }
        if visibleFunc then
            keybind.visible = visibleFunc
        end
        return keybind
    end
    local defaultGamepadBack = KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function() SCENE_MANAGER:HideCurrentScene() end)
    function KEYBIND_STRIP:GetDefaultGamepadBackButtonDescriptor()
        return defaultGamepadBack
    end
    KEYBIND_STRIP:SetOnStyleChangedCallback(function()
        KEYBIND_STRIP:RefreshDefaultExits()
    end)
    KEYBIND_STRIP:RestoreDefaultExit()
end