Back to Home

ESO Lua File v100018

ingame/dyeing/gamepad/dyeing_common_gamepad.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
ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_X = 3
ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_Y = 4
function ZO_Dyeing_Gamepad_Highlight(control, dyeControl)
    local sharedHighlight = control.highlight
    local selected = false
    if dyeControl then
        sharedHighlight:ClearAnchors()
        sharedHighlight:SetParent(dyeControl)
        sharedHighlight:SetAnchor(TOPLEFT, dyeControl, TOPLEFT, -ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_X, -ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_Y)
        sharedHighlight:SetAnchor(BOTTOMRIGHT, dyeControl, BOTTOMRIGHT, ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_X, ZO_DYEING_HIGHLIGHT_OFFSET_GAMEPAD_Y)
        selected = true
    end
    sharedHighlight:SetHidden(not selected)
end
-- A base radial menu with some customized behavior for the gamepad dyeing screen.
ZO_Dyeing_RadialMenu_Gamepad = ZO_RadialMenu:Subclass()
local DEFAULT_ROTATION_ANGLE = (2 * math.pi) * (3 / 5)
local FOCUS_ENTRY_SCALE = 1.3
function ZO_Dyeing_RadialMenu_Gamepad:New(control, template, sharedHighlight)
    local DISABLE_MOUSE = false
    local SELECT_IN_CENTER = true
    return ZO_RadialMenu.New(self, sharedHighlight, control, template, nil, nil, nil, {ZO_DI_LEFT_STICK}, DISABLE_MOUSE, SELECT_IN_CENTER)
end
function ZO_Dyeing_RadialMenu_Gamepad:Initialize(sharedHighlight, ...)
    ZO_RadialMenu.Initialize(self, ...)
    self.swatchInterpolator = ZO_SimpleControlScaleInterpolator:New(1.0, FOCUS_ENTRY_SCALE)
    self.currentlyActive = false
    self.controlsBySlot = {}
    self.isAllFocused = false
    self.previousSelectedControl = nil
    self:SetActivateOnShow(false)
    self.sharedHighlight = sharedHighlight
    -- NOTE: This does not call self:SetOnSelectionChangedCallback as we want to bypass the custom behaviour.
    ZO_RadialMenu.SetOnSelectionChangedCallback(self, function(...) self:OnSelectionChanged(...) end)
end
function ZO_Dyeing_RadialMenu_Gamepad:ResetToDefaultPositon()
    local outerRadius = zo_max(self.control:GetDimensions()) * .5
    self.oldSelectionX = math.sin(DEFAULT_ROTATION_ANGLE) * outerRadius
    self.oldSelectionY = math.cos(DEFAULT_ROTATION_ANGLE) * outerRadius
end
function ZO_Dyeing_RadialMenu_Gamepad:FocusAll()
    if not self.isAllFocused then
        for entrySlot, control in pairs(self.controlsBySlot) do
            if control.shouldHighlight then
                self.swatchInterpolator:ScaleUp(control)
            end
        end
        self.isAllFocused = true
    end
end
function ZO_Dyeing_RadialMenu_Gamepad:DefocusAll()
    if self.isAllFocused then
        for entrySlot, control in pairs(self.controlsBySlot) do
            self.swatchInterpolator:ScaleDown(control)
        end
        self.isAllFocused = false
    end
end
function ZO_Dyeing_RadialMenu_Gamepad:HighlightAll(dyeSlot)
    for entrySlot, control in pairs(self.controlsBySlot) do
        ZO_Dyeing_Gamepad_Highlight(control, control.dyeControls[dyeSlot])
    end
end
function ZO_Dyeing_RadialMenu_Gamepad:OnSelectionChanged(entry)
    if self.previousSelectedControl ~= self.selectedControl then
        if self.previousSelectedControl then
            self.swatchInterpolator:ScaleDown(self.previousSelectedControl)
        end
        self.previousSelectedControl = self.selectedControl
        if self.selectedControl then
            self.swatchInterpolator:ScaleUp(self.selectedControl)
            if self.sharedHighlight then
                self.sharedHighlight:ClearAnchors()
                self.sharedHighlight:SetAnchor(CENTER, self.selectedControl, CENTER, 0, 0)
                self.sharedHighlight:SetHidden(false)
            end
        elseif self.sharedHighlight then
            self.sharedHighlight:SetHidden(true)
        end
    end
    end
end
function ZO_Dyeing_RadialMenu_Gamepad:SetOnSelectionChangedCallback(callback)
end
local SUPPRESS_SOUND = true
function ZO_Dyeing_RadialMenu_Gamepad:Activate(...)
    ZO_RadialMenu.Activate(self, ...)
    if not self.currentlyActive then
        self.virtualMouseX = self.oldSelectionX
        self.virtualMouseY = self.oldSelectionY
        self.selectIfCentered = true
        self:UpdateSelectedEntryFromVirtualMousePosition(SUPPRESS_SOUND)
        self.currentlyActive = true
    end
end
function ZO_Dyeing_RadialMenu_Gamepad:Deactivate(...)
    if self.currentlyActive then
        self.oldSelectionX = self.virtualMouseX
        self.oldSelectionY = self.virtualMouseY
        self.selectIfCentered = false
        self.currentlyActive = false
    end
    ZO_RadialMenu.Deactivate(self, ...)
end
function ZO_Dyeing_RadialMenu_Gamepad:Show(...)
    ZO_RadialMenu.Show(self, ...)
    self:Populate()
end