Skip to content

Commit

Permalink
Add Charges customization
Browse files Browse the repository at this point in the history
Also causes the 'Charges' line to stay with 'Use' lines if they move.
  • Loading branch information
Anonomit committed Feb 17, 2023
1 parent ecae3de commit c4fbc98
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 10 deletions.
53 changes: 53 additions & 0 deletions Config/OptionsTables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,59 @@ function Addon:MakeExtraOptions(categoryName, chatCmd, arg1, ...)

if self:GetOption("doReorder", "EnchantOnUse") then MakeEnchantOnUseOptions() GUI:CreateGroup(opts, GUI:Order(), " ", nil, nil, true) end


-- Charges
do
local stat = "Charges"

local sampleCharges = 10
local someCharges = format(ITEM_SPELL_CHARGES, sampleCharges)
local noCharges = ITEM_SPELL_CHARGES_NONE

local samples = {}
do
local defaultText = someCharges
local defaultText, formattedText = GetFormattedText(stat, self.COLORS.WHITE, defaultText, defaultText)
tinsert(samples, {defaultText, formattedText})
end
do
local defaultText = noCharges
local formattedText = defaultText
local originalColor = self.COLORS.WHITE
local color = Addon:GetOption("color", "NoCharges")

if Addon:GetOption("hide", stat) then
formattedText = Addon.stealthIcon .. Addon:MakeColorCode(Addon.COLORS.GRAY, Addon:StripColorCode(formattedText))
elseif Addon:GetOption("allow", "recolor") and Addon:GetOption("doRecolor", "NoCharges") and color ~= originalColor then
formattedText = Addon:MakeColorCode(color, formattedText)
else
formattedText = Addon:MakeColorCode(originalColor, formattedText)
end
tinsert(samples, {Addon:MakeColorCode(originalColor, defaultText), formattedText})
end

local opts = GUI:CreateGroup(opts, stat, samples[1][2], nil, nil, disabled)

CreateSamples(opts, samples)

do
local opts = GUI:CreateGroupBox(opts, L["Recolor"])

local disabled = disabled or not Addon:GetOption("allow", "recolor")
GUI:CreateToggle(opts, {"doRecolor", "Charges"}, someCharges, nil, disabled).width = 1
GUI:CreateColor(opts, {"color", "Charges"}, self.L["Color"], nil, disabled or not Addon:GetOption("doRecolor", "Charges")).width = 0.5
CreateReset(opts, {"color", "Charges"})
GUI:CreateNewline(opts)

GUI:CreateToggle(opts, {"doRecolor", "NoCharges"}, noCharges, nil, disabled).width = 1
GUI:CreateColor(opts, {"color", "NoCharges"}, self.L["Color"], nil, disabled or not Addon:GetOption("doRecolor", "NoCharges")).width = 0.5
CreateReset(opts, {"color", "NoCharges"})
end

CreateHide(opts, stat)
end
GUI:CreateGroup(opts, GUI:Order(), " ", nil, nil, true)

-- Made By
do
local stat = "MadeBy"
Expand Down
13 changes: 13 additions & 0 deletions Data/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ do
Addon.ITEM_MOD_INTELLECT = ITEM_MOD_INTELLECT
Addon.ITEM_MOD_SPIRIT = ITEM_MOD_SPIRIT

do
local head, single, plural, tail = strMatch(ITEM_SPELL_CHARGES, "(.*)|4([^:]+):([^;]+);(.*)")
if single then
Addon.ITEM_SPELL_CHARGES1 = head .. single .. tail
Addon.ITEM_SPELL_CHARGES2 = head .. plural .. tail
else
Addon.ITEM_SPELL_CHARGES1 = ITEM_SPELL_CHARGES
end
end

local locale = GetLocale()
if locale == "esES" then
Addon.ITEM_MOD_STAMINA = ITEM_MOD_STAMINA :lower()
Expand Down Expand Up @@ -712,6 +722,9 @@ do
self.statsInfo["Enchant"] = {color = self.COLORS.GREEN}
self.statsInfo["WeaponEnchant"] = {color = self.COLORS.GREEN}

self.statsInfo["Charges"] = {color = self.COLORS.WHITE}
self.statsInfo["NoCharges"] = {color = self.COLORS.RED}

self.statsInfo["Durability"] = {color = self.COLORS.WHITE}

self.statsInfo["MadeBy"] = {color = self.COLORS.GREEN}
Expand Down
8 changes: 4 additions & 4 deletions Operations/CalculatePadding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ local enchantLines = {
}
local padLocations = {
[-1] = {
BaseStat = function(line) return line.type == "BaseStat" or Addon:GetOption"combineStats" and (line.type == "SecondaryStat" or Addon:GetOption("doReorder", "EnchantOnUse") and line.type == "EnchantOnUse") end,
SecondaryStat = function(line) return(line.type == "SecondaryStat" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) and not Addon:GetOption"combineStats" end,
BaseStat = function(line) return line.type == "BaseStat" or Addon:GetOption"combineStats" and (line.type == "SecondaryStat" or line.type == "Charges" or Addon:GetOption("doReorder", "EnchantOnUse") and line.type == "EnchantOnUse") end,
SecondaryStat = function(line) return(line.type == "SecondaryStat" or line.type == "Charges" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) and not Addon:GetOption"combineStats" end,
Enchant = function(line) return enchantLines[line.type] or not Addon:GetOption("doReorder", "EnchantOnUse") and line.type == "EnchantOnUse" end,
WeaponEnchant = function(line) return line.type == "WeaponEnchant" end,
Socket = function(line) return line.type == "Socket" end,
SetName = function(line) return line.type == "SetName" end,
SetBonus = function(line) return line.type == "SetBonus" end,
},
[1] = {
BaseStat = function(line) return line.type == "BaseStat" or Addon:GetOption"combineStats" and (line.type == "SecondaryStat" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) end,
SecondaryStat = function(line) return(line.type == "SecondaryStat" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) and not Addon:GetOption"combineStats" end,
BaseStat = function(line) return line.type == "BaseStat" or Addon:GetOption"combineStats" and (line.type == "SecondaryStat" or line.type == "Charges" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) end,
SecondaryStat = function(line) return(line.type == "SecondaryStat" or line.type == "Charges" or Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse")) and not Addon:GetOption"combineStats" end,
Enchant = function(line) return enchantLines[line.type] or line.type == "RequiredEnchant" or not Addon:GetOption("doReorder", "EnchantOnUse") and (line.type == "EnchantOnUse" or line.type == "RequiredEnchantOnUse") end,
WeaponEnchant = function(line) return line.type == "WeaponEnchant" end,
SocketBonus = function(line) return line.type == "SocketBonus" or line.type == "Socket" or Addon:GetOption("doReorder", "SocketHint") and line.type == "SocketHint" end,
Expand Down
23 changes: 19 additions & 4 deletions Operations/RecognizeLineTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ local strMatch = string.match



-- stripped text recoloring
local ITEM_CREATED_BY = Addon.ITEM_CREATED_BY
local ITEM_WRAPPED_BY = Addon.ITEM_WRAPPED_BY

local ITEM_CREATED_BY = Addon.ITEM_CREATED_BY
local ITEM_WRAPPED_BY = Addon.ITEM_WRAPPED_BY
local ITEM_MOD_STAMINA = Addon.ITEM_MOD_STAMINA
local ITEM_MOD_STRENGTH = Addon.ITEM_MOD_STRENGTH
local ITEM_MOD_AGILITY = Addon.ITEM_MOD_AGILITY
local ITEM_MOD_INTELLECT = Addon.ITEM_MOD_INTELLECT
local ITEM_MOD_SPIRIT = Addon.ITEM_MOD_SPIRIT






local numberPattern = "[%d%"..DECIMAL_SEPERATOR.."]+"
Expand Down Expand Up @@ -93,6 +102,7 @@ local contexts = Addon:MakeLookupTable({
"RequiredRep",
"SecondaryStat",
"LastSecondaryStat",
"Charges",
"EnchantOnUse",
"RequiredEnchantOnUse",
"SetName",
Expand Down Expand Up @@ -320,7 +330,7 @@ contextActions = Addon:Map({
end,
LastBaseStat = function(i, tooltipData, line)
if not line.texture and line.colorLeft == Addon.COLORS.WHITE then
local stat = MatchesAny(line.textLeftTextStripped, Addon.ITEM_MOD_STAMINA, Addon.ITEM_MOD_STRENGTH, Addon.ITEM_MOD_AGILITY, Addon.ITEM_MOD_INTELLECT, Addon.ITEM_MOD_SPIRIT, ITEM_RESIST_SINGLE, ITEM_RESIST_ALL)
local stat = MatchesAny(line.textLeftTextStripped, ITEM_MOD_STAMINA, ITEM_MOD_STRENGTH, ITEM_MOD_AGILITY, ITEM_MOD_INTELLECT, ITEM_MOD_SPIRIT, ITEM_RESIST_SINGLE, ITEM_RESIST_ALL)
if stat then
if stat == ITEM_RESIST_SINGLE then
local n = strMatch(line.textLeftTextStripped, "(%d+)")
Expand Down Expand Up @@ -437,6 +447,11 @@ contextActions = Addon:Map({
end
end
end,
Charges = function(i, tooltipData, line)
if MatchesAny(line.textLeftTextStripped, Addon.ITEM_SPELL_CHARGES1, ITEM_SPELL_CHARGES_NONE) or Addon.ITEM_SPELL_CHARGES2 and MatchesAny(line.textLeftTextStripped, Addon.ITEM_SPELL_CHARGES2) then
return SetContext(i, tooltipData, line)
end
end,
EnchantOnUse = function(i, tooltipData, line)
if tooltipData.hasEnchant and not tooltipData.foundEnchant and line.colorLeft == Addon.COLORS.GREEN and StartsWithAny(line.textLeftTextStripped, ITEM_SPELL_TRIGGER_ONUSE) then
tooltipData.enchant = line.i
Expand Down
11 changes: 9 additions & 2 deletions Operations/RecolorLine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ local ADDON_NAME, Data = ...
local Addon = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME)



local strFind = string.find


local noChargesPattern = Addon:ReversePattern(ITEM_SPELL_CHARGES_NONE)
local sides

local function Recolor(side, stat)
Expand Down Expand Up @@ -45,13 +50,15 @@ function Addon:RecolorLine(tooltip, line, tooltipData)
if stat then
Recolor("left", stat)
end
elseif line.type == "RequiredClasses" then
-- Handled as a reword instead
elseif line.type == "Charges" then
Recolor("left", strFind(line.textLeftTextStripped, noChargesPattern) and "NoCharges" or "Charges")
elseif self.statsInfo[line.type].color then
Recolor("left", line.type)
end
elseif line.type == "DamagePerSecond" and line.rewordRight then
line.recolorRight = self.COLORS.WHITE -- the speedbar default tooltip color is yellow but let's pretend it's white
elseif line.type == "RequiredClasses" then
-- Handled as a reword instead
end

if sides.left ~= line.realColor then
Expand Down
5 changes: 5 additions & 0 deletions Operations/ReorderLines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function SortStats(tooltipData)
local stats = {
BaseStat = {},
SecondaryStat = {},
Charges = {},
EnchantOnUse = {},
RequiredEnchantOnUse = {},
}
Expand All @@ -50,6 +51,10 @@ local function SortStats(tooltipData)
stats.SecondaryStat.location = tooltipData.secondaryStatStart + 1
end

for i = #stats.Charges, 1, -1 do
tinsert(stats.SecondaryStat, tblRemove(stats.Charges, 1))
end

if self:GetOption("doReorder", "EnchantOnUse") then
for i = #stats.EnchantOnUse, 1, -1 do
tinsert(stats.SecondaryStat, tblRemove(stats.EnchantOnUse, 1))
Expand Down

0 comments on commit c4fbc98

Please sign in to comment.