Skip to content

Commit

Permalink
Add Money Formatting Option and Add Player Money to Currency Trigger (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boneshockx authored Jan 11, 2025
1 parent 083e3e0 commit aa685d5
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
67 changes: 67 additions & 0 deletions WeakAuras/Prototypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11322,6 +11322,73 @@ Private.event_prototypes = {
automaticrequired = true,
progressType = "none"
},
["Money"] = {
type = "unit",
statesParameter = "one",
progressType = "none",
automaticrequired = true,
events = {
["events"] = {"PLAYER_MONEY"}
},
internal_events = {"WA_DELAYED_PLAYER_ENTERING_WORLD"},
force_events = "WA_DELAYED_PLAYER_ENTERING_WORLD",
name = WeakAuras.newFeatureString..L["Player Money"],
init = function()
return [=[
local money = GetMoney()
local gold = floor(money / 1e4)
local silver = floor(money / 100 % 100)
local copper = money % 100
]=]
end,
args = {
{
name = "money",
init = "money",
type = "number",
display = L["Money"],
store = true,
hidden = true,
test = "true",
},
{
name = "gold",
init = "gold",
type = "number",
display = Private.coin_icons.gold .. L["Gold"],
store = true,
conditionType = "number",
},
{
name = "silver",
init = "silver",
type = "number",
display = Private.coin_icons.silver .. L["Silver"],
store = true,
hidden = true,
test = "true",
},
{
name = "copper",
init = "copper",
type = "number",
display = Private.coin_icons.copper .. L["Copper"],
store = true,
hidden = true,
test = "true",
},
{
name = "icon",
init = "C_CurrencyInfo.GetCoinIcon(money)",
store = true,
hidden = true,
test = "true",
},
},
GetNameAndIcon = function()
return MONEY, C_CurrencyInfo.GetCoinIcon(GetMoney())
end,
},
["Currency"] = {
type = "unit",
progressType = "static",
Expand Down
70 changes: 70 additions & 0 deletions WeakAuras/Types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ Private.big_number_types = {
if WeakAuras.IsClassicEra() then
Private.big_number_types.BreakUpLargeNumbers = nil
end
---@type table<string, string>
Private.big_number_types_with_disable = CopyTable(Private.big_number_types)
Private.big_number_types_with_disable["disable"] = L["Disabled"]

---@type table<string, string>
Private.round_types = {
floor = L["Floor"],
Expand Down Expand Up @@ -503,6 +507,58 @@ Private.format_types = {
end
end
},
Money = {
display = L["Money"],
AddOptions = function(symbol, hidden, addOption)
addOption(symbol .. "_money_format", {
type = "select",
name = L["Format Gold"],
width = WeakAuras.normalWidth,
values = Private.big_number_types_with_disable,
hidden = hidden
})
addOption(symbol .. "_money_precision", {
type = "select",
name = L["Coin Precision"],
width = WeakAuras.normalWidth,
values = Private.money_precision_types,
hidden = hidden
})
end,
CreateFormatter = function(symbol, get)
local format = get(symbol .. "_money_format", "AbbreviateNumbers")
local precision = get(symbol .. "_money_precision", 3)

return function(value)
local gold = floor(value / 1e4)
local silver = floor(value / 100 % 100)
local copper = value % 100

if (format == "AbbreviateNumbers") then
gold = simpleFormatters.AbbreviateNumbers(gold)
elseif (format == "BreakUpLargeNumbers") then
gold = simpleFormatters.BreakUpLargeNumbers(gold)
elseif (format == "AbbreviateLargeNumbers") then
gold = simpleFormatters.AbbreviateLargeNumbers(gold)
end

local formatCode
if precision == 1 then
formatCode = "%s%s"
elseif precision == 2 then
formatCode = "%s%s %d%s"
else
formatCode = "%s%s %d%s %d%s"
end

return string.format(formatCode,
tostring(gold), Private.coin_icons.gold,
silver, Private.coin_icons.silver,
copper, Private.coin_icons.copper
)
end
end
},
BigNumber = {
display = L["Big Number"],
AddOptions = function(symbol, hidden, addOption)
Expand Down Expand Up @@ -1530,6 +1586,20 @@ for id, str in pairs(Private.combatlog_spell_school_types) do
Private.combatlog_spell_school_types_for_ui[id] = ("%.3d - %s"):format(id, str)
end

---@type table<string, string>
Private.coin_icons = {
["gold"] = "|Tinterface/moneyframe/ui-goldicon:0|t",
["silver"] = "|Tinterface/moneyframe/ui-silvericon:0|t",
["copper"] = "|Tinterface/moneyframe/ui-coppericon:0|t"
}

---@type table<number, string>
Private.money_precision_types = {
[1] = "123 " .. Private.coin_icons.gold,
[2] = "123 " .. Private.coin_icons.gold .. " 45 " .. Private.coin_icons.silver,
[3] = "123 " .. Private.coin_icons.gold .. " 45 " .. Private.coin_icons.silver .. " 67 " .. Private.coin_icons.copper
}

if WeakAuras.IsRetail() then
Private.GetCurrencyListSize = C_CurrencyInfo.GetCurrencyListSize
Private.GetCurrencyIDFromLink = C_CurrencyInfo.GetCurrencyIDFromLink
Expand Down

0 comments on commit aa685d5

Please sign in to comment.