Skip to content

Commit

Permalink
Add Soulbound Tradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonomit committed Sep 25, 2022
1 parent 39b4f9c commit eaafa86
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 36 deletions.
65 changes: 56 additions & 9 deletions Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ function Addon:MakeDefaultOptions()
},
color = (function() local colors = {["*"] = "00ff00"} for stat, StatInfo in pairs(self.statsInfo) do colors[stat] = StatInfo.color end return colors end)(),

doReorder = {
["*"] = true,
},

damage = {
["*"] = true,
showVariance = false,
Expand Down Expand Up @@ -234,16 +238,16 @@ function Addon:MakeDefaultOptions()
debugOutput = {
suppressAll = false,

tooltipHook = true,
lineRecognitions = true,
constructorCached = true,
constructorWiped = true,
constructorValidationFailed = true,
tooltipHook = false,
lineRecognitions = false,
constructorCached = false,
constructorWiped = false,
constructorValidationFailed = false,

GameTooltip = true,
ItemRefTooltip = true,
ShoppingTooltip1 = true,
ShoppingTooltip2 = true,
GameTooltip = false,
ItemRefTooltip = false,
ShoppingTooltip1 = false,
ShoppingTooltip2 = false,
},

constructor = {
Expand Down Expand Up @@ -796,6 +800,47 @@ function Addon:MakeExtraOptions()
local GUI = self.GUI:ResetOrder()
local opts = GUI:CreateGroupTop(title)

-- Soulbound Tradeable
local function MakeSoulboundOption()
local stat = "SoulboundTradeable"

do
local defaultText = format(BIND_TRADE_TIME_REMAINING, format(INT_SPELL_DURATION_HOURS, 2))
local formattedText = Addon:RewordTradeable(defaultText)
local defaultText, formattedText, changed = GetFormattedText(stat, self.COLORS.SKY_BLUE, defaultText, formattedText)

local opts = GUI:CreateGroup(opts, stat, formattedText)

CreateTitle(opts, defaultText, formattedText, changed)

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

local disabled = not Addon:GetOption("allow", "reorder")

GUI:CreateToggle(opts, {"doReorder", stat}, self.L["Enable"], nil, disabled).width = 0.6
CreateReset(opts, {"doReorder", stat}, function() self:ResetOption("doReorder", stat) end)
end

CreateColor(opts, stat)

-- Reword
do
local opts = GUI:CreateGroupBox(opts, self.L["Rename"])

local disabled = not Addon:GetOption("allow", "reword")
GUI:CreateToggle(opts, {"doReword", stat}, self.L["Enable"], nil, disabled).width = 0.6
CreateReset(opts, {"doReword", stat}, function() self:ResetOption("doReword", stat) end)
end

CreateHide(opts, stat)
end

GUI:CreateGroup(opts, "afterSoulboundTradeable" , " ").disabled = true
end
if self:GetOption("doReorder", "SoulboundTradeable") then MakeSoulboundOption() end

-- Trainable
do
local stat = "Trainable"
Expand Down Expand Up @@ -1254,6 +1299,8 @@ function Addon:MakeExtraOptions()

GUI:CreateGroup(opts, "afterPrefixes" , " ", nil, true)

if not self:GetOption("doReorder", "SoulboundTradeable") then MakeSoulboundOption() end

-- Socket Hint
do
local stat = "SocketHint"
Expand Down
31 changes: 17 additions & 14 deletions Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ L["Enchant"] = ENSCRIBE
L["Weapon Enchantment"] = WEAPON_ENCHANTMENT
L["End"] = KEY_END

L["Trade"] = TRADE
L["Settings"] = SETTINGS
L["Other Options"] = UNIT_FRAME_DROPDOWN_SUBSECTION_TITLE_OTHER
L["Weapon"] = WEAPON
Expand Down Expand Up @@ -566,12 +567,13 @@ end

-- https://colornamer.robertcooper.me/
Addon.COLORS = {
WHITE = rgb(255, 255, 255),
GRAY = rgb(127, 127, 127),
RED = rgb(255, 32, 32),
ORANGE = rgb(255, 127, 32),
GREEN = rgb( 0, 255, 0),
BLUE = rgb( 0, 0, 255),
WHITE = rgb(255, 255, 255),
GRAY = rgb(127, 127, 127),
RED = rgb(255, 32, 32),
ORANGE = rgb(255, 127, 32),
GREEN = rgb( 0, 255, 0),
BLUE = rgb( 0, 0, 255),
SKY_BLUE = rgb( 0, 204, 255), -- used by BIND_TRADE_TIME_REMAINING

ARCANE = rgb(255, 127, 255),
FIRE = rgb(255, 128, 0),
Expand Down Expand Up @@ -811,14 +813,15 @@ do
end
end

Addon.statsInfo["Trainable"] = {color = Addon.COLORS.ORANGE}
Addon.statsInfo["Damage"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["DamagePerSecond"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["Enchant"] = {color = Addon.COLORS.GREEN}
Addon.statsInfo["WeaponEnchant"] = {color = Addon.COLORS.GREEN}
Addon.statsInfo["Speed"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["Speedbar"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["SocketHint"] = {color = Addon.COLORS.GREEN}
Addon.statsInfo["SoulboundTradeable"] = {color = Addon.COLORS.SKY_BLUE}
Addon.statsInfo["Trainable"] = {color = Addon.COLORS.ORANGE}
Addon.statsInfo["Damage"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["DamagePerSecond"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["Enchant"] = {color = Addon.COLORS.GREEN}
Addon.statsInfo["WeaponEnchant"] = {color = Addon.COLORS.GREEN}
Addon.statsInfo["Speed"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["Speedbar"] = {color = Addon.COLORS.WHITE}
Addon.statsInfo["SocketHint"] = {color = Addon.COLORS.GREEN}
end


Expand Down
2 changes: 1 addition & 1 deletion Operations/ModifyTooltipData.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Addon:ModifyTooltipData(tooltip, tooltipData)
self:DebugfIf({"debugOutput", "lineRecognitions"}, "line: %d, textLeft: '%s', type: '%s', stat: '%s', prefix: '%s'", i, line.textLeftText, tostring(line.type), tostring(line.stat), tostring(line.prefix))
end

self:SortStats(tooltipData)
self:ReorderLines(tooltipData)

self:CalculatePadding(tooltipData)
end
25 changes: 19 additions & 6 deletions Operations/RecognizeLineTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,38 @@ local contexts = Addon:MakeLookupTable({
"SetBonus",
"LastSetBonus",
"SocketHint",
"SoulboundTradeable",
"Delta",
"RecipeMats",
"RecipeTitle",
}, nil, true)

local contextAscensions = Addon:Map({
Binding = function(context, tooltipData, line, currentContext)
-- mark where the binding would be if it existed on this item
if not tooltipData.binding then
tooltipData.binding = line.i
end
end,
-- Damage = function(context, tooltipData, line)
-- local lastLine = tooltipData[line.i-1]
-- if not lastLine.type then
-- lastLine.type = "Type"
-- end
-- end,
BaseStat = function(context, tooltipData, line, currentContext)
-- mark where the base stats would be if they existed on this item
if not tooltipData.statStart then
tooltipData.statStart = line.i - 1
end
end,
Enchant = function(context, tooltipData, line, currentContext)
-- mark red enchantment lines if I found an "enchantment disabled" line
if currentContext == contexts.RequiredEnchant then
local lastLine = tooltipData[line.i-2]
lastLine.type = "Enchant"
end
end,
BaseStat = function(context, tooltipData, line, currentContext)
-- mark where the base stats would be if they existed on this item
if not tooltipData.statStart then
tooltipData.statStart = line.i - 1
end
end,
RecipeTitle = function(context, tooltipData, line, currentContext)
-- reset the base stat location
tooltipData.statStart = nil
Expand Down Expand Up @@ -147,6 +154,7 @@ local contextActions = Addon:Map({
end,
Binding = function(i, tooltipData, line)
if MatchesAny(line.textLeftTextStripped, ITEM_SOULBOUND, ITEM_BIND_ON_EQUIP, ITEM_BIND_ON_USE, ITEM_BIND_ON_PICKUP, ITEM_BIND_TO_ACCOUNT, ITEM_BIND_TO_BNETACCOUNT) then
tooltipData.binding = line.i
return SetContext(i, tooltipData, line)
end
end,
Expand Down Expand Up @@ -298,6 +306,11 @@ local contextActions = Addon:Map({
return SetContext(i, tooltipData, line)
end
end,
SoulboundTradeable = function(i, tooltipData, line)
if line.colorLeft == Addon.COLORS.SKY_BLUE and MatchesAny(line.textLeftTextStripped, BIND_TRADE_TIME_REMAINING) then
return SetContext(i, tooltipData, line)
end
end,
Delta = function(i, tooltipData, line)
if MatchesAny(line.textLeftTextStripped, ITEM_DELTA_DESCRIPTION, ITEM_DELTA_MULTIPLE_COMPARISON_DESCRIPTION) then
-- crop the tooltip here
Expand Down
27 changes: 24 additions & 3 deletions Operations/SortStats.lua → Operations/ReorderLines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ local function StatSorter(a, b)
return GetStatSortValue(a) < GetStatSortValue(b)
end

function Addon:SortStats(tooltipData)
if not self:GetOption("allow", "reorder") then return end
local function SortStats(tooltipData)
if not Addon:GetOption("allow", "reorder") then return end
local stats = {
BaseStat = {},
SecondaryStat = {},
Expand All @@ -43,7 +43,7 @@ function Addon:SortStats(tooltipData)
-- end
-- end

if self:GetOption"combineStats" then
if Addon:GetOption"combineStats" then
while #stats.SecondaryStat > 0 do
tinsert(stats.BaseStat, tblRemove(stats.SecondaryStat, 1))
end
Expand All @@ -57,3 +57,24 @@ function Addon:SortStats(tooltipData)
end
end
end

function Addon:ReorderLines(tooltipData)

SortStats(tooltipData)

local i = 1
while i <= #tooltipData do
local line = tooltipData[i]

if not line.hide then
if line.type == "SoulboundTradeable" then
if self:GetOption("doReorder", line.type) then
tinsert(tooltipData, (tooltipData.binding or 1) + 1, tblRemove(tooltipData, i))
end
end
end

i = i + 1
end

end
4 changes: 4 additions & 0 deletions Operations/RewordLine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function Addon:RewordLine(tooltip, line, tooltipData)
if self:GetOption("doRecolor", line.type) then
text = self:ChainGsub(text, unpack(self.classColorReplacements))
end
elseif line.type == "SoulboundTradeable" then
if self:GetOption("doReword", line.type) then
text = self:RewordTradeable(text)
end
elseif line.type == "SocketHint" then
text = self:RewordSocketHint(text)
end
Expand Down
26 changes: 26 additions & 0 deletions Operations/RewordTradeable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

local ADDON_NAME, Data = ...


local Addon = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME)


local strMatch = string.match



local stat = "SoulboundTradeable"
function Addon:RewordTradeable(text)
local self = Addon

if not self:GetOption("allow", "reword") then return text end

if self:GetOption("doReword", stat) then
local time = strMatch(text, self:ReversePattern(BIND_TRADE_TIME_REMAINING))
if time then
text = format("%s: %s", self.L["Trade"], time)
end
end

return text
end
3 changes: 2 additions & 1 deletion Operations/operations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
<Script file="RewordLine.lua"/>
<Script file="RewordPrefix.lua"/>
<Script file="RewordSocketHint.lua"/>
<Script file="RewordTradeable.lua"/>
<Script file="RewordWeaponStats.lua"/>
<Script file="ScanTooltip.lua"/>
<Script file="SortStats.lua"/>
<Script file="ReorderLines.lua"/>
<Script file="ThrottleAuction.lua"/>
<Script file="ThrottleInspect.lua"/>
<Script file="ThrottleMail.lua"/>
Expand Down
4 changes: 2 additions & 2 deletions ZeraTooltip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ enchantment should be found only if the link has an enchantment
measure performance and memory usage with and without caches. maybe only cache particularly expensive operations? like localeExtras
show races, classes, level at top
reorder races, classes, level
show heroic tag
show ilvl
show bind time
REFUND_TIME_REMAINING
--]]
Expand Down

0 comments on commit eaafa86

Please sign in to comment.