forked from dejoblue/DejaCharacterStats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCSDecimals.lua
401 lines (357 loc) · 16.7 KB
/
DCSDecimals.lua
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
local ADDON_NAME, namespace = ... --localization
local L = namespace.L --localization
local _, gdbprivate = ...
local doll_tooltip_format = namespace.doll_tooltip_format --PAPERDOLLFRAME_TOOLTIP_FORMAT
local highlight_code = namespace.highlight_code --HIGHLIGHT_FONT_COLOR_CODE
local font_color_close = namespace.font_color_close --FONT_COLOR_CODE_CLOSE
-- Decimal Check
local notinteger
local my_floor = math.floor
--local _, dcs_format = ... --seems like shared upvaluing of tables isn't so easy
local dcs_format = format
local function round(x)
return my_floor(x+0.5)
end
local statformat
local multiplier
local notexactlyzero
--hideatzero gets used in DCSLayouts, so there's small use to make faster access to it here.
local function DCS_Decimals()
--version with localisation of PAPERDOLLFRAME_TOOLTIP_FORMAT, HIGHLIGHT_FONT_COLOR_CODE and FONT_COLOR_CODE_CLOSE (doll_tooltip_format, highlight_code and font_color_close)
-- Crit Chance
--setting of statformat and multiplier values is done by calling function for checkbox (in OnEvent and OnClick)
--[[
if notinteger then
statformat = "%.2f%%"
multiplier = 100
else
statformat = "%.0f%%"
multiplier = 1
end
local notexactlyzero = gdbprivate.gdb.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked
--]]
function PaperDollFrame_SetCritChance(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
local rating;
local spellCrit, rangedCrit, meleeCrit;
local critChance;
-- Start at 2 to skip physical damage
local holySchool = 2;
local minCrit = GetSpellCritChance(holySchool);
statFrame.spellCrit = {};
statFrame.spellCrit[holySchool] = minCrit;
--local spellCrit;
for i=(holySchool+1), MAX_SPELL_SCHOOLS do
spellCrit = GetSpellCritChance(i);
minCrit = min(minCrit, spellCrit);
statFrame.spellCrit[i] = spellCrit;
end
spellCrit = minCrit
rangedCrit = GetRangedCritChance();
meleeCrit = GetCritChance();
if (spellCrit >= rangedCrit and spellCrit >= meleeCrit) then
critChance = spellCrit;
rating = CR_CRIT_SPELL;
elseif (rangedCrit >= meleeCrit) then
critChance = rangedCrit;
rating = CR_CRIT_RANGED;
else
critChance = meleeCrit;
rating = CR_CRIT_MELEE;
end
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_CRITICAL_STRIKE, dcs_format(statformat, critChance), false, round(multiplier*critChance)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_CRITICAL_STRIKE, dcs_format(statformat, critChance), false, critChance);
end
--PaperDollFrame_SetLabelAndText(statFrame, STAT_CRITICAL_STRIKE, format(statformat1, critChance), true, format(statformat1, critChance)); --can't do it because PaperDollFrame_SetLabelAndText converts to integer
statFrame.tooltip = highlight_code..dcs_format(doll_tooltip_format, STAT_CRITICAL_STRIKE).." "..dcs_format("%.2f%%", critChance)..font_color_close;
local extraCritChance = GetCombatRatingBonus(rating);
local extraCritRating = GetCombatRating(rating);
if (GetCritChanceProvidesParryEffect()) then
statFrame.tooltip2 = dcs_format(CR_CRIT_PARRY_RATING_TOOLTIP, BreakUpLargeNumbers(extraCritRating), extraCritChance, GetCombatRatingBonusForCombatRatingValue(CR_PARRY, extraCritRating));
else
statFrame.tooltip2 = dcs_format(CR_CRIT_TOOLTIP, BreakUpLargeNumbers(extraCritRating), extraCritChance);
end
statFrame:Show();
end
-- Haste Chance
function PaperDollFrame_SetHaste(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
local haste = GetHaste();
local rating = CR_HASTE_MELEE;
local hasteFormatString;
if (haste < 0) then
hasteFormatString = RED_FONT_COLOR_CODE.."%s"..font_color_close;
else
hasteFormatString = "+%s";
end
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_HASTE, dcs_format(hasteFormatString, dcs_format(statformat, haste)), false, round(multiplier*haste)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_HASTE, dcs_format(hasteFormatString, dcs_format(statformat, haste)), false, haste);
end
statFrame.tooltip = highlight_code .. dcs_format(doll_tooltip_format, STAT_HASTE) .. " " .. dcs_format(hasteFormatString, dcs_format("%.2f%%", haste)) .. font_color_close;
local _, class = UnitClass(unit);
statFrame.tooltip2 = _G["STAT_HASTE_"..class.."_TOOLTIP"];
if (not statFrame.tooltip2) then
statFrame.tooltip2 = STAT_HASTE_TOOLTIP;
end
statFrame.tooltip2 = statFrame.tooltip2 .. dcs_format(STAT_HASTE_BASE_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(rating)), GetCombatRatingBonus(rating));
statFrame:Show();
end
-- Versatility
function PaperDollFrame_SetVersatility(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
local versatility = GetCombatRating(CR_VERSATILITY_DAMAGE_DONE);
local versatilityDamageBonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
local versatilityDamageTakenReduction = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_TAKEN) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_TAKEN);
-- PaperDollFrame_SetLabelAndText Format Change
--local result
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_VERSATILITY, dcs_format(statformat, versatilityDamageBonus) .. " / " .. dcs_format(statformat, versatilityDamageTakenReduction), false, round(multiplier*versatilityDamageBonus)/multiplier);
--result = round(multiplier*versatilityDamageBonus)/multiplier
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_VERSATILITY, dcs_format(statformat, versatilityDamageBonus) .. " / " .. dcs_format(statformat, versatilityDamageTakenReduction), false, versatilityDamageBonus);
--result = versatilityDamageBonus
end
--print("vesratility",result)
statFrame.tooltip = highlight_code .. dcs_format(VERSATILITY_TOOLTIP_FORMAT, STAT_VERSATILITY, versatilityDamageBonus, versatilityDamageTakenReduction) .. font_color_close;
statFrame.tooltip2 = dcs_format(CR_VERSATILITY_TOOLTIP, versatilityDamageBonus, versatilityDamageTakenReduction, BreakUpLargeNumbers(versatility), versatilityDamageBonus, versatilityDamageTakenReduction);
statFrame:Show();
end
-- Mastery
function PaperDollFrame_SetMastery(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
--if (UnitLevel("player") < SHOW_MASTERY_LEVEL) then
-- statFrame:Hide();
-- return;
--end
local color_mastery
if namespace.locale == "zhTW" then
color_mastery = STAT_MASTERY .. ":" --Chinese colon
else
color_mastery = STAT_MASTERY ..":"
end
local color_format = statformat
if (UnitLevel("player") < SHOW_MASTERY_LEVEL) then
color_mastery = "|cff7f7f7f" .. color_mastery .. "|r"
color_format = "|cff7f7f7f" .. color_format .. "|r"
end
local mastery = GetMasteryEffect();
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, "", dcs_format(color_format, mastery), false, round(multiplier*mastery)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, "", dcs_format(color_format, mastery), false, mastery);
end
statFrame.Label:SetText(color_mastery)
statFrame.onEnterFunc = Mastery_OnEnter;
statFrame:Show();
end
-- Leech (Lifesteal)
function PaperDollFrame_SetLifesteal(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
local lifesteal = GetLifesteal();
-- PaperDollFrame_SetLabelAndText Format Change
--local result
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_LIFESTEAL, dcs_format(statformat, lifesteal), false, round(multiplier*lifesteal)/multiplier);
--result = round(multiplier*lifesteal)/multiplier
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_LIFESTEAL, dcs_format(statformat, lifesteal), false, lifesteal);
--result = lifesteal
end
--print("leech",result)
statFrame.tooltip = highlight_code .. dcs_format(doll_tooltip_format, STAT_LIFESTEAL) .. " " .. dcs_format("%.2f%%", lifesteal) .. font_color_close;
statFrame.tooltip2 = dcs_format(CR_LIFESTEAL_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(CR_LIFESTEAL)), GetCombatRatingBonus(CR_LIFESTEAL));
statFrame:Show();
end
-- Avoidance
function PaperDollFrame_SetAvoidance(statFrame, unit)
if ( unit ~= "player" ) then
statFrame:Hide();
return;
end
local avoidance = GetAvoidance();
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_AVOIDANCE, dcs_format(statformat, avoidance), false, round(multiplier*avoidance)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_AVOIDANCE, dcs_format(statformat, avoidance), false, avoidance);
end
statFrame.tooltip = highlight_code .. dcs_format(doll_tooltip_format, STAT_AVOIDANCE) .. " " .. dcs_format("%.2f%%", avoidance) .. font_color_close;
statFrame.tooltip2 = dcs_format(CR_AVOIDANCE_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(CR_AVOIDANCE)), GetCombatRatingBonus(CR_AVOIDANCE));
statFrame:Show();
end
-- Dodge Chance
function PaperDollFrame_SetDodge(statFrame, unit)
if (unit ~= "player") then
statFrame:Hide();
return;
end
local chance = GetDodgeChance();
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_DODGE, dcs_format(statformat, chance), false, round(multiplier*chance)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_DODGE, dcs_format(statformat, chance), false, chance);
end
statFrame.tooltip = highlight_code..dcs_format(doll_tooltip_format, DODGE_CHANCE).." "..string.format("%.2f", chance).."%"..font_color_close;
statFrame.tooltip2 = dcs_format(CR_DODGE_TOOLTIP, GetCombatRating(CR_DODGE), GetCombatRatingBonus(CR_DODGE));
statFrame:Show();
end
-- Parry Chance
function PaperDollFrame_SetParry(statFrame, unit)
if (unit ~= "player") then
statFrame:Hide();
return;
end
local chance = GetParryChance();
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_PARRY, dcs_format(statformat, chance), false, round(multiplier*chance)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_PARRY, dcs_format(statformat, chance), false, chance);
end
statFrame.tooltip = highlight_code..dcs_format(doll_tooltip_format, PARRY_CHANCE).." "..dcs_format("%.2f", chance).."%"..font_color_close;
statFrame.tooltip2 = dcs_format(CR_PARRY_TOOLTIP, GetCombatRating(CR_PARRY), GetCombatRatingBonus(CR_PARRY));
statFrame:Show();
end
-- Block Chance
function PaperDollFrame_SetBlock(statFrame, unit)
if (unit ~= "player") then
statFrame:Hide();
return;
end
local chance = GetBlockChance();
-- PaperDollFrame_SetLabelAndText Format Change
if notexactlyzero then
PaperDollFrame_SetLabelAndText(statFrame, STAT_BLOCK, dcs_format(statformat, chance), false, round(multiplier*chance)/multiplier);
else
PaperDollFrame_SetLabelAndText(statFrame, STAT_BLOCK, dcs_format(statformat, chance), false, chance);
end
statFrame.tooltip = highlight_code..dcs_format(doll_tooltip_format, BLOCK_CHANCE).." "..dcs_format("%.2f", chance).."%"..font_color_close;
statFrame.tooltip2 = dcs_format(CR_BLOCK_TOOLTIP, GetShieldBlock());
statFrame:Show();
end
--PaperDollFrame_UpdateStats() -- needs to get called for checkbox Decimals; will get called for clicks in checkboxes but not during login
end
gdbprivate.gdbdefaults.gdbdefaults.dejacharacterstatsShowDecimalsChecked = {
SetChecked = true,
}
local function set_statformat_multiplier_value()
if notinteger then
statformat = "%.2f%%"
multiplier = 100
else
statformat = "%.0f%%"
multiplier = 1
end
end
local DCS_DecimalCheck = CreateFrame("CheckButton", "DCS_DecimalCheck", DejaCharacterStatsPanel, "InterfaceOptionsCheckButtonTemplate")
DCS_DecimalCheck:RegisterEvent("PLAYER_LOGIN")
DCS_DecimalCheck:ClearAllPoints()
--DCS_DecimalCheck:SetPoint("TOPLEFT", 30, -205)
DCS_DecimalCheck:SetPoint("TOPLEFT", "dcsStatsPanelcategoryFS", 7, -55)
DCS_DecimalCheck:SetScale(1)
DCS_DecimalCheck.tooltipText = L['Displays "Enhancements" category stats to two decimal places.'] --Creates a tooltip on mouseover.
_G[DCS_DecimalCheck:GetName() .. "Text"]:SetText(L["Decimals"])
DCS_DecimalCheck:SetScript("OnEvent", function(self, event, arg1)
if event == "PLAYER_LOGIN" then
notinteger= gdbprivate.gdb.gdbdefaults.dejacharacterstatsShowDecimalsChecked.SetChecked
self:SetChecked(notinteger)
set_statformat_multiplier_value()
--local status = self:GetChecked(true) --???
--DCS_Decimals(status)
DCS_Decimals() --PaperDollFrame_UpdateStats() here isn't needed
--gdbprivate.gdb.gdbdefaults.dejacharacterstatsShowDecimalsChecked.SetChecked = status --???
end
end)
DCS_DecimalCheck:SetScript("OnClick", function(self,event,arg1)
--local checked = gdbprivate.gdb.gdbdefaults.dejacharacterstatsShowDecimalsChecked
notinteger = self:GetChecked(true)
set_statformat_multiplier_value()
gdbprivate.gdb.gdbdefaults.dejacharacterstatsShowDecimalsChecked.SetChecked = notinteger
DCS_Decimals()
PaperDollFrame_UpdateStats() --for Enhancements to have updated accuracy and visibility
end)
gdbprivate.gdbdefaults.gdbdefaults.dejacharacterstatsHideAtZeroChecked = {
SetChecked = true,
}
gdbprivate.gdbdefaults.gdbdefaults.dejacharacterstatsDCSZeroChecked = {
SetChecked = false,
}
local DCS_BlizHideAtZero = CreateFrame("CheckButton", "DCS_BlizHideAtZero", DejaCharacterStatsPanel, "InterfaceOptionsCheckButtonTemplate")
local DCS_DCSHideAtZero = CreateFrame("CheckButton", "DCS_DCSHideAtZero", DejaCharacterStatsPanel, "InterfaceOptionsCheckButtonTemplate")
DCS_DCSHideAtZero:RegisterEvent("PLAYER_LOGIN")
DCS_DCSHideAtZero:ClearAllPoints()
--DCS_DCSHideAtZero:SetPoint("TOPLEFT", 25, -150)
--DCS_DCSHideAtZero:SetPoint("TOPLEFT", 30, -165)
DCS_DCSHideAtZero:SetPoint("TOPLEFT", "dcsStatsPanelcategoryFS", 7, -15)
DCS_DCSHideAtZero:SetScale(1)
DCS_DCSHideAtZero.tooltipText = L['Hides "Enhancements" stats if their displayed value would be zero. Checking "Decimals" changes the displayed value.'] --Creates a tooltip on mouseover.
_G[DCS_DCSHideAtZero:GetName() .. "Text"]:SetText(L["DCS's Hide At Zero"])
DCS_DCSHideAtZero:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
--local status = gdbprivate.gdb.gdbdefaults.dejacharacterstatsHideAtZeroChecked.SetChecked
--local DCSstatus = gdbprivate.gdbdefaults.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked
notexactlyzero = gdbprivate.gdbdefaults.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked
local hideatzero = gdbprivate.gdb.gdbdefaults.dejacharacterstatsHideAtZeroChecked.SetChecked
if hideatzero then
self:SetChecked(notexactlyzero)
DCS_BlizHideAtZero:SetChecked(not notexactlyzero)
else
self:SetChecked(false)
DCS_BlizHideAtZero:SetChecked(false)
end
end
end)
DCS_DCSHideAtZero:SetScript("OnClick", function(self)
--local status = self:GetChecked()
--gdbprivate.gdb.gdbdefaults.dejacharacterstatsHideAtZeroChecked.SetChecked = status
--gdbprivate.gdb.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked = status
notexactlyzero = not notexactlyzero
gdbprivate.gdb.gdbdefaults.dejacharacterstatsHideAtZeroChecked.SetChecked = notexactlyzero
gdbprivate.gdb.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked = notexactlyzero
if notexactlyzero then
DCS_BlizHideAtZero:SetChecked(false)
end
DCS_Decimals()
PaperDollFrame_UpdateStats() --for Enhancements to have updated accuracy and visibility
end)
_G[DCS_BlizHideAtZero:GetName() .. "Text"]:SetText(L["Blizzard's Hide At Zero"] )
DCS_BlizHideAtZero:ClearAllPoints()
--DCS_BlizHideAtZero:SetPoint("TOPLEFT", 50, -220)
--DCS_BlizHideAtZero:SetPoint("TOPLEFT", 30, -185)
DCS_BlizHideAtZero:SetPoint("TOPLEFT", "dcsStatsPanelcategoryFS", 7, -35)
DCS_BlizHideAtZero:SetScale(1)
DCS_BlizHideAtZero.tooltipText = L['Hides "Enhancements" stats only if their numerical value is exactly zero. For example, if stat value is 0.001%, then it would be displayed as 0%.'] --Creates a tooltip on mouseover.
DCS_BlizHideAtZero:SetScript("OnClick", function(self)
local status = self:GetChecked()
gdbprivate.gdb.gdbdefaults.dejacharacterstatsHideAtZeroChecked.SetChecked = status
if status then
DCS_DCSHideAtZero:SetChecked(false)
notexactlyzero = false
gdbprivate.gdb.gdbdefaults.dejacharacterstatsDCSZeroChecked.SetChecked = false
end
DCS_Decimals()
PaperDollFrame_UpdateStats() --for Enhancements to have updated accuracy and visibility
end)