ESO Lua File v100015

ingame/stats/zo_stats_common.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
-------------------
-- General Stats --
-------------------
STAT_TYPES =
{
    [ATTRIBUTE_HEALTH] = STAT_HEALTH_MAX,
    [ATTRIBUTE_MAGICKA] = STAT_MAGICKA_MAX,
    [ATTRIBUTE_STAMINA] = STAT_STAMINA_MAX,
}
ZO_STATS_REFRESH_TIME_SECONDS = 2
------------------
-- Stats Common --
------------------
ZO_Stats_Common = ZO_Object:Subclass()
function ZO_Stats_Common:New(...)
    local statsCommon = ZO_Object.New(self)
    statsCommon:Initialize(...)
    return statsCommon
end
function ZO_Stats_Common:Initialize()
    self.availablePoints = 0
    self.statBonuses = {}
end
function ZO_Stats_Common:GetAvailablePoints()
    return self.availablePoints
end
function ZO_Stats_Common:SetAvailablePoints(points)
    self.availablePoints = points
end
function ZO_Stats_Common:OnSetAvailablePoints()
    -- To be overridden.
end
function ZO_Stats_Common:SpendAvailablePoints(points)
end
function ZO_Stats_Common:GetTotalSpendablePoints()
    return GetAttributeUnspentPoints()
end
function ZO_Stats_Common:SetPendingStatBonuses(statType, pendingBonus)
    self.statBonuses[statType] = pendingBonus
end
function ZO_Stats_Common:UpdatePendingStatBonuses(statType, pendingBonus)
    self:SetPendingStatBonuses(statType, pendingBonus)
end
function ZO_Stats_Common:GetPendingStatBonuses(statType)
    return self.statBonuses[statType]
end
function ZO_Stats_Common:UpdateTitleDropdownSelection(dropdown)
    local currentTitleIndex = GetCurrentTitleIndex()
    if currentTitleIndex then
        dropdown:SetSelectedItem(zo_strformat(GetTitle(currentTitleIndex), GetRawUnitName("player")))
    else
        dropdown:SetSelectedItem(GetString(SI_STATS_NO_TITLE))
    end
end
function ZO_Stats_Common:UpdateTitleDropdownTitles(dropdown)
    dropdown:ClearItems()
    dropdown:AddItem(ZO_ComboBox:CreateItemEntry(GetString(SI_STATS_NO_TITLE), function() SelectTitle(nil) end), ZO_COMBOBOX_SUPRESS_UPDATE)
    for i=1, GetNumTitles() do
        dropdown:AddItem(ZO_ComboBox:CreateItemEntry(zo_strformat(GetTitle(i), GetRawUnitName("player")) , function() SelectTitle(i) end), ZO_COMBOBOX_SUPRESS_UPDATE)
    end
end
function ZO_Stats_Common:IsPlayerBattleLeveled()
    return IsUnitChampionBattleLeveled("player") or IsUnitBattleLeveled("player")
end
function ZO_StatsRidingSkillIcon_Initialize(control, trainingType)
    control.trainingType = trainingType
    control:GetNamedChild("Icon"):SetTexture(STABLE_TRAINING_TEXTURES[trainingType])
end
-----------------------
-- Attribute Spinner --
-----------------------
ZO_AttributeSpinner_Shared = ZO_Object:Subclass()
function ZO_AttributeSpinner_Shared:New(attributeControl, attributeType, attributeManager, valueChangedCallback)
    local attributeSpinner = ZO_Object.New(self)
    attributeSpinner.attributeControl = attributeControl
    
    attributeSpinner.points = 0
    attributeSpinner.addedPoints = 0
    attributeSpinner.attributeManager = attributeManager
    
    attributeSpinner:SetAttributeType(attributeType)
    return attributeSpinner
end
function ZO_AttributeSpinner_Shared:SetSpinner(spinner)
    self.pointsSpinner = spinner
    self.pointsSpinner:RegisterCallback("OnValueChanged", function(points) self:OnValueChanged(points) end)
end
function ZO_AttributeSpinner_Shared:Reinitialize(attributeType, addedPoints, valueChangedCallback)
    self:SetAttributeType(attributeType)
    self.points = GetAttributeSpentPoints(self.attributeType)
    self:SetAddedPoints(addedPoints, true)
    self.pointsSpinner:SetValue(self.points + addedPoints)
end
function ZO_AttributeSpinner_Shared:SetValueChangedCallback(fn)
end
function ZO_AttributeSpinner_Shared:SetAttributeType(attributeType)
    self.attributeType = attributeType
    self.perPoint = GetAttributeDerivedStatPerPointValue(attributeType, STAT_TYPES[attributeType])
end
function ZO_AttributeSpinner_Shared:OnValueChanged(points)
    
    if(self.valueChangedCallback ~= nil) then
        self.valueChangedCallback(self.points, self.addedPoints)
    end
end
function ZO_AttributeSpinner_Shared:RefreshSpinnerMax()
    self.pointsSpinner:SetMinMax(self.points, self.points + self.addedPoints + self.attributeManager:GetAvailablePoints())
end
function ZO_AttributeSpinner_Shared:RefreshPoints()
    self.points = GetAttributeSpentPoints(self.attributeType)
     self:RefreshSpinnerMax()
    self.pointsSpinner:SetValue(self.points)
end
function ZO_AttributeSpinner_Shared:ResetAddedPoints()
    self.addedPoints = 0    
    self:RefreshPoints()
end
function ZO_AttributeSpinner_Shared:GetPoints()
    return self.points
end
function ZO_AttributeSpinner_Shared:GetAllocatedPoints()
    return self.addedPoints
end
function ZO_AttributeSpinner_Shared:SetAddedPointsByTotalPoints(totalPoints)
    self:SetAddedPoints(totalPoints - self.points)
end
function ZO_AttributeSpinner_Shared:SetAddedPoints(points, force)
    points = zo_max(points, 0)
    
    local diff = points - self.addedPoints
    local availablePoints = self.attributeManager:GetAvailablePoints()
    if(force) then
        diff = 0
    elseif diff > availablePoints then
        diff = availablePoints
        points = diff + self.addedPoints
    end
    self.addedPoints = points
    if(diff ~= 0) then
        self.attributeManager:SpendAvailablePoints(diff)
    end
    self.attributeManager:UpdatePendingStatBonuses(STAT_TYPES[self.attributeType], self.perPoint * self.addedPoints)
end
function ZO_AttributeSpinner_Shared:SetButtonsHidden(hidden)
    self.pointsSpinner:SetButtonsHidden(hidden)
end