diff --git a/Config/OptionsTables.lua b/Config/OptionsTables.lua index 92db0ed..9403698 100644 --- a/Config/OptionsTables.lua +++ b/Config/OptionsTables.lua @@ -1080,13 +1080,40 @@ local function MakeExtraOptions(opts, categoryName) do local stat = "Damage" - local defaultText = format(DAMAGE_TEMPLATE, sampleDamage * (1-sampleVariance), sampleDamage * (1+sampleVariance)) - local defaultText, formattedText, changed = GetFormattedText(stat, self.COLORS.WHITE, defaultText, self:ModifyWeaponDamage(defaultText, sampleDamage, 1)) + local samples = {} + do + local min, max = self:Round(sampleDamage * (1-sampleVariance)), self:Round(sampleDamage * (1+sampleVariance)) + local default1 = format(DAMAGE_TEMPLATE, min, max) + local default2 = format(PLUS_DAMAGE_TEMPLATE, min, max) + + for _, v in ipairs{ + {default1, self:ModifyWeaponDamage(default1, sampleDamage*2, 1, {min, max}), self:GetOption("hide", stat)}, + {default2, self:ModifyWeaponDamageBonus(default2, {min, max}), self:GetOption("hide", stat) or self:GetOption("hide", "DamageBonus")}, + } do + local defaultText = v[1] + local formattedText = v[2] + local hidden = v[3] + + local originalColor = self.COLORS.WHITE + local color = self:GetOption("color", stat) + if hidden then + formattedText = self.stealthIcon .. self:MakeColorCode(self.COLORS.GRAY, self:StripColorCode(formattedText)) + elseif self:GetOption("allow", "recolor") and self:GetOption("doRecolor", stat) and color ~= originalColor then + formattedText = self:MakeColorCode(color, formattedText) + else + formattedText = self:MakeColorCode(originalColor, formattedText) + end + defaultText = self:MakeColorCode(originalColor, defaultText) + + tinsert(samples, {defaultText, formattedText}) + end + end - local opts = GUI:CreateGroup(opts, stat, formattedText, self.L["Weapon Damage"]) + local opts = GUI:CreateGroup(opts, stat, samples[1][2], self.L["Weapon Damage"]) do - local opts = CreateTitle(opts, defaultText, formattedText, changed, 1) + local opts = CreateSamples(opts, samples) + GUI:CreateNewline(opts) -- Test local option = GUI:CreateRange(opts, {"sampleDamage"}, L["Test"], nil, 0, 1000000, 0.5) @@ -1094,7 +1121,7 @@ local function MakeExtraOptions(opts, categoryName) option.bigStep = 10 option.get = function(info) return sampleDamage end option.set = function(info, val) sampleDamage = val end - local option = GUI:CreateRange(opts, {"sampleVariance"}, L["Test"], nil, 0, 1, 0.1) + local option = GUI:CreateRange(opts, {"sampleVariance"}, L["Test"], nil, 0, 1, 0.05) option.isPercent = true option.get = function(info) return sampleVariance end option.set = function(info, val) sampleVariance = val end @@ -1122,7 +1149,17 @@ local function MakeExtraOptions(opts, categoryName) GUI:CreateReset(opts, {"damage", "variancePrefix"}) end - CreateHide(opts, stat) + do + local opts = GUI:CreateGroupBox(opts, self.L["Hide"]) + + GUI:CreateToggle(opts, {"hide", stat}, self.L["Hide"], nil, disabled) + GUI:CreateReset(opts, {"hide", stat}) + GUI:CreateNewline(opts) + + local disabled = self:GetOption("hide", stat) + GUI:CreateToggle(opts, {"hide", "DamageBonus"}, self.L["Bonus Damage"], L["Merge Bonus Damage into Weapon Damage"], disabled) + GUI:CreateReset(opts, {"hide", "DamageBonus"}) + end end local speedString = strGsub(format("%.2f", sampleSpeed), "%.", DECIMAL_SEPERATOR) diff --git a/Locale/LocaleAutomatic.lua b/Locale/LocaleAutomatic.lua index e958968..775f387 100644 --- a/Locale/LocaleAutomatic.lua +++ b/Locale/LocaleAutomatic.lua @@ -70,6 +70,7 @@ L["End"] = KEY_END L["Short Name"] = COMMUNITIES_SETTINGS_SHORT_NAME_LABEL L["Show Item Level"] = SHOW_ITEM_LEVEL L["Weapon Damage"] = DAMAGE_TOOLTIP +L["Bonus Damage"] = BONUS_DAMAGE L["Speed"] = SPEED L["Damage Per Second"] = ITEM_MOD_DAMAGE_PER_SECOND_SHORT L["Trade"] = TRADE diff --git a/Locale/enUs.lua b/Locale/enUs.lua index 49952b6..245331c 100644 --- a/Locale/enUs.lua +++ b/Locale/enUs.lua @@ -69,11 +69,12 @@ L["Trainable Equipment"] = true L["Equipment that a trainer can teach you to wear."] = true -- weapon damage -L["Show Minimum and Maximum"] = true -L["Show Average"] = true -L["Show Variance"] = true -L["Variance Prefix"] = true -L["Show Percent"] = true +L["Show Minimum and Maximum"] = true +L["Show Average"] = true +L["Show Variance"] = true +L["Variance Prefix"] = true +L["Show Percent"] = true +L["Merge Bonus Damage into Weapon Damage"] = true -- dps L["Remove Brackets"] = true diff --git a/Operations/RecognizeLineTypes.lua b/Operations/RecognizeLineTypes.lua index 047f571..a501ef4 100644 --- a/Operations/RecognizeLineTypes.lua +++ b/Operations/RecognizeLineTypes.lua @@ -84,6 +84,7 @@ local contexts = Addon:MakeLookupTable({ "Type", "RedType", "Damage", + "DamageBonus", "DamagePerSecond", "Armor", "BonusArmor", @@ -324,6 +325,18 @@ contextActions = Addon:Map({ return SetContext(i, tooltipData, line) end end, + DamageBonus = function(i, tooltipData, line) + if MatchesAny(line.textLeftTextStripped, PLUS_SINGLE_DAMAGE_TEMPLATE, PLUS_DAMAGE_TEMPLATE, PLUS_SINGLE_DAMAGE_TEMPLATE_WITH_SCHOOL, PLUS_DAMAGE_TEMPLATE_WITH_SCHOOL) then + local min, max = strMatch(line.textLeftTextStripped, "%+ ?(%d+) ?%- ?(%d+)") + if min then + tooltipData.damageBonus = {tonumber(min), tonumber(max)} + else + local n = tonumber(strMatch(line.textLeftTextStripped, "%+ ?(%d+)")) + tooltipData.damageBonus = {n, n} + end + return SetContext(i, tooltipData, line) + end + end, DamagePerSecond = function(i, tooltipData, line) local _, dps = MatchesAny(line.textLeftTextStripped, DPS_TEMPLATE) if dps then diff --git a/Operations/RecolorLine.lua b/Operations/RecolorLine.lua index 7969edb..9a60e0a 100644 --- a/Operations/RecolorLine.lua +++ b/Operations/RecolorLine.lua @@ -42,6 +42,8 @@ function Addon:RecolorLine(tooltip, line, tooltipData) elseif line.type == "Damage" then Recolor("left", "Damage") Recolor("right", "Speed") + elseif line.type == "DamageBonus" then + Recolor("left", "Damage") elseif line.type == "DamagePerSecond" then Recolor("left", "DamagePerSecond") -- Speed bar colored through rewording diff --git a/Operations/RewordLine.lua b/Operations/RewordLine.lua index 588a686..37fa98f 100644 --- a/Operations/RewordLine.lua +++ b/Operations/RewordLine.lua @@ -72,7 +72,7 @@ function Addon:RewordLine(tooltip, line, tooltipData) text = self:RewordBinding(text, line.bindType) end, Damage = function() - text = self:ModifyWeaponDamage(text, tooltipData.dps, tooltipData.speed) + text = self:ModifyWeaponDamage(text, tooltipData.dps, tooltipData.speed, tooltipData.damageBonus) if not line.hideRight then local rightText = self:ModifyWeaponSpeed(line.textRightText, tooltipData.speed, tooltipData.speedString) if rightText ~= line.textRightText then @@ -80,6 +80,9 @@ function Addon:RewordLine(tooltip, line, tooltipData) end end end, + DamageBonus = function() + text = self:ModifyWeaponDamageBonus(text, tooltipData.damageBonus) + end, DamagePerSecond = function() text = self:ModifyWeaponDamagePerSecond(text) if not line.hideRight and tooltipData.speed then diff --git a/Operations/RewordWeaponStats.lua b/Operations/RewordWeaponStats.lua index a3d095f..2d82c63 100644 --- a/Operations/RewordWeaponStats.lua +++ b/Operations/RewordWeaponStats.lua @@ -9,9 +9,64 @@ local strMatch = string.match local strGsub = string.gsub local strRep = string.rep +local defaultDamageBonus = {0, 0} + +function Addon:ModifyWeaponDamage(text, dps, speed, damageBonus) + damageBonus = damageBonus or defaultDamageBonus + + local showAverage = self:GetOption("allow", "reword") and self:GetOption("damage", "showAverage") + local showVariance = self:GetOption("allow", "reword") and self:GetOption("damage", "showVariance") + local showMinMax = self:GetOption("allow", "reword") and self:GetOption("damage", "showMinMax") + + local minMax, min, gap, max = strMatch(text, "((%d+)( ?%- ?)(%d+))") + if min then + min, max = tonumber(min), tonumber(max) + local mid = dps * speed + if self:GetOption("hide", "DamageBonus") then + min = min + (damageBonus[1]) + max = max + (damageBonus[2]) + minMax = min .. gap .. max + else + mid = mid - (damageBonus[1] + damageBonus[2]) / 2 + end + + local average = showAverage and format("%d", mid) or nil + local usePercent = self:GetOption("damage", "variancePercent") + + local varianceDecimal + if mid == 0 then + varianceDecimal = 0 + else + varianceDecimal = max/mid + end + local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((varianceDecimal-1)*100, 5) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil + local minMax = showMinMax and minMax or nil + + local pattern + if average then + pattern = average + if variance then + pattern = format("%s %s", pattern, variance) + end + if minMax then + pattern = format("%s (%s)", pattern, minMax) + end + else + pattern = minMax + if variance then + pattern = format("%s (%s)", pattern, variance) + end + end + + return strGsub(text, "%d+ ?%- ?%d+", pattern) + end + return text +end -function Addon:ModifyWeaponDamage(text, dps, speed) +function Addon:ModifyWeaponDamageBonus(text, damageBonus) + text = strGsub(text, " +", " ") -- Fix weird spacing (ex. 7730) + local showAverage = self:GetOption("allow", "reword") and self:GetOption("damage", "showAverage") local showVariance = self:GetOption("allow", "reword") and self:GetOption("damage", "showVariance") if not (showAverage or showVariance) then return text end -- no changes to make @@ -20,10 +75,17 @@ function Addon:ModifyWeaponDamage(text, dps, speed) local minMax, min, max = strMatch(text, "((%d+) ?%- ?(%d+))") if min then min, max = tonumber(min), tonumber(max) - local mid = dps * speed + local mid = (damageBonus[1] + damageBonus[2]) / 2 local average = showAverage and format("%d", mid) or nil local usePercent = self:GetOption("damage", "variancePercent") - local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((max/mid-1)*100, 10) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil + + local varianceDecimal + if mid == 0 then + varianceDecimal = 0 + else + varianceDecimal = max/mid + end + local variance = showVariance and format("%s%d%s", self:GetOption("damage", "variancePrefix"), usePercent and self:Round((varianceDecimal-1)*100, 5) or self:Round(max-mid, 1), usePercent and "%%" or "") or nil local minMax = showMinMax and minMax or nil local pattern diff --git a/Stats/Stats.lua b/Stats/Stats.lua index 1cf2624..7d4aaf1 100644 --- a/Stats/Stats.lua +++ b/Stats/Stats.lua @@ -393,6 +393,7 @@ do self.statsInfo["Trainable"] = {color = self.COLORS.ORANGE} self.statsInfo["Damage"] = {color = self.COLORS.WHITE} + self.statsInfo["DamageBonus"] = {color = self.COLORS.WHITE} self.statsInfo["Speed"] = {color = self.COLORS.WHITE} self.statsInfo["DamagePerSecond"] = {color = self.COLORS.WHITE}