Back to Home

ESO Lua File v100031

pregame/charactercreate/zo_charactercreateslider_base.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
--[[ Character Create Slider ]]--
ZO_CharacterCreateSlider_Base = ZO_Object:Subclass()
function ZO_CharacterCreateSlider_Base:New(...)
    local slider = ZO_Object.New(self)
    slider:Initialize(...)
    return slider
end
function ZO_CharacterCreateSlider_Base:Initialize(control)
    control.sliderObject = self
    self.control = control
    self.slider = GetControl(control, "Slider")
    self.name = GetControl(control, "Name")
    self.padlock = GetControl(control, "Padlock")
    self.lockState = TOGGLE_BUTTON_OPEN
end
function ZO_CharacterCreateSlider_Base:SetName(displayName, enumNameFallback, enumValue)
    if displayName and displayName ~= "" then
        self.name:SetText(displayName)
    else
        self.name:SetText(GetString(enumNameFallback, enumValue))
    end
end
function ZO_CharacterCreateSlider_Base:SetData(sliderIndex, name, category, steps, value, defaultValue)
    self.sliderIndex = sliderIndex
    self.category = category
    self.initializing = true
    self.numSteps = steps
    self.defaultValue = defaultValue
    self.slider:SetValueStep(1 / steps)
    self:SetName(nil, "SI_CHARACTERSLIDERNAME", name)
    self:Update(value)
end
function ZO_CharacterCreateSlider_Base:SetValue(value)
    if not self.initializing then
        SetSliderValue(self.sliderIndex, value)
        self:UpdateChangeButtons(value)
    end
end
function ZO_CharacterCreateSlider_Base:ChangeValue(changeAmount)
    local currentValue = self.slider:GetValue()
    local valueStep = self.slider:GetValueStep()
    local newSteppedValue = currentValue + (changeAmount * valueStep)
    local min, max = self.slider:GetMinMax()
    if newSteppedValue < min or newSteppedValue > max then
        newSteppedValue = zo_clamp(newSteppedValue, min, max)
    end
    if currentValue ~= newSteppedValue then
        self:SetValue(newSteppedValue)
        self:Update()
    end
end
function ZO_CharacterCreateSlider_Base:GetValue()
    return self.slider:GetValue()
end
function ZO_CharacterCreateSlider_Base:Randomize(randomizeType)
    if self.lockState == TOGGLE_BUTTON_OPEN then
        local randomValue = 0
        if (randomizeType == "initial") and (self.defaultValue >= 0) then
            -- If this is the initial randomization and we have a valid default value
            -- then don't actually randomize anything, just use the default value.
            randomValue = self.defaultValue
        else
            -- Otherwise, pick a random value from the valid values
            local numSteps = self.numSteps
            
            if numSteps > 0 then
                randomValue = zo_random(0, numSteps) / numSteps
            end
        end
        self:SetValue(randomValue)
        self:Update()
    end
end
function ZO_CharacterCreateSlider_Base:ToggleLocked()
    self.lockState = not self.lockState
    ZO_ToggleButton_SetState(self.padlock, self.lockState)
end
function ZO_CharacterCreateSlider_Base:SetLocked(isLocked)
    if self:IsLocked() ~= isLocked then
        self:ToggleLocked()
    end
end
function ZO_CharacterCreateSlider_Base:CanLock()
    return true
end
function ZO_CharacterCreateSlider_Base:IsLocked()
    return self.lockState ~= TOGGLE_BUTTON_OPEN
end
function ZO_CharacterCreateSlider_Base:UpdateLockState()
    local enabled = self.lockState == TOGGLE_BUTTON_OPEN
    if enabled then
        self:UpdateChangeButtons()
    else
        self:UpdateChangeButton(self.decrementButton, false)
        self:UpdateChangeButton(self.incrementButton, false)
    end
end
function ZO_CharacterCreateSlider_Base:UpdateChangeButton(button, isEnabled)
    if button then     --- This means that the gamepad version (which has no buttons) works fine.
        if isEnabled then
            button:SetState(BSTATE_NORMAL, false)
        else
            button:SetState(BSTATE_DISABLED, true)
        end
    end
end
function ZO_CharacterCreateSlider_Base:UpdateChangeButtons(value)
    if value == nil then
        value = select(4, GetSliderInfo(self.sliderIndex))
    end
    local steppedValue = zo_floor(value * self.numSteps)
    self:UpdateChangeButton(self.decrementButton, steppedValue > 0)
    self:UpdateChangeButton(self.incrementButton, steppedValue < self.numSteps)
end
function ZO_CharacterCreateSlider_Base:Update(value)
    self.initializing = true
    if not value then
        value = select(4, GetSliderInfo(self.sliderIndex))
    end
    self.initializing = nil
end
--[[ Character Create Appearance Slider ]]--
-- Implemented as a mixin
ZO_CharacterCreateAppearanceSlider = {}
function ZO_CharacterCreateAppearanceSlider:SetData(appearanceName, numValues, displayName)
    self.category = appearanceName
    self:SetName(displayName, "SI_CHARACTERAPPEARANCENAME", appearanceName)
    
    self.legalInitialSettings = {}
    for appearanceIndex =  1, numValues do
        local legalInitialSetting = select(4, GetAppearanceValueInfo(appearanceName, appearanceIndex))
        if legalInitialSetting then
            table.insert(self.legalInitialSettings, appearanceIndex)
        end
    end
    self.initializing = true
    self.slider:SetMinMax(1, numValues)
    self.numSteps = numValues
    self:Update()
end
function ZO_CharacterCreateAppearanceSlider:GetAppearanceValue()
    return GetAppearanceValue(self.category)
end
function ZO_CharacterCreateAppearanceSlider:SetAppearanceValue(value)
    SetAppearanceValue(self.category, value)
end
function ZO_CharacterCreateAppearanceSlider:SetValue(value)
    if not self.initializing then
        self:SetAppearanceValue(value)
        self:UpdateChangeButtons(value)
    end
end
function ZO_CharacterCreateAppearanceSlider:Randomize(randomizeType)
    if self.lockState == TOGGLE_BUTTON_OPEN then
        local randomValue = 1
        if (randomizeType == "initial") and (#self.legalInitialSettings > 0) then
            -- If this is the initial randomization and we have some legal initial values
            -- then only randomize over those values
            randomValue = self.legalInitialSettings[zo_random(1, #self.legalInitialSettings)]
        else
            -- Otherwise, pick a random value from the valid values
            local maxValue = self.numSteps
            if maxValue > 0 then
                randomValue = zo_random(1, maxValue)
            end
        end
        self:SetValue(randomValue)
        self:Update()
    end
end
function ZO_CharacterCreateAppearanceSlider:UpdateChangeButtons(value)
    if value == nil then
        value = self:GetAppearanceValue()
    end
    self:UpdateChangeButton(self.decrementButton, value > 1)
    self:UpdateChangeButton(self.incrementButton, value < self.numSteps)
end
function ZO_CharacterCreateAppearanceSlider:Update()
    self.initializing = true
    local currentValue = self:GetAppearanceValue()
    self.slider:SetValue(currentValue)
    self.initializing = nil
    self:UpdateChangeButtons(currentValue)
end
-- Global XML functions
    slider:GetParent().sliderObject:SetValue(value)
end