Goldbeutel: freie Taschenplätze, Rüstungszustand und Gegenstandsstufe

Der Rahmen zeigt jetzt in einer Zeile Gold, freie Taschenplätze, den
Zustand des am stärksten beschädigten Teils und die durchschnittliche
Gegenstandsstufe der angelegten Ausrüstung. Spezialtaschen zählen nicht
mit. Wenig Platz oder niedriger Zustand werden gelb bzw. rot.

Der Tooltip zeigt zusätzlich Spezialtaschen, den Gesamtzustand der
Rüstung samt schwächstem Teil und die Gegenstandsstufe mit bester
Ausrüstung aus den Taschen. Mehrere Ereignisse kurz hintereinander lösen
nur eine Aktualisierung aus.

Tests für die neue Anzeige ergänzt, ZIP neu gebaut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mikeandClaude Opus 5.5 committed 2026-11-24 12:18:46 +01:00
1 parent 4959c470c1
commit 3065c3e70e
4 files changed
+212 -11

No files matched your search

+152 -8
View File
@@ -1,7 +1,9 @@
-- Goldbeutel: zeigt dein Gold in einem kleinen, verschiebbaren Rahmen. -- Goldbeutel: zeigt Gold, freie Taschenplaetze, Ruestungszustand und
-- Gegenstandsstufe in einem kleinen, verschiebbaren Rahmen.
-- Linksziehen verschieben -- Linksziehen verschieben
-- Rechtsklick sperren / entsperren -- Rechtsklick sperren / entsperren
-- Mauszeiger drauf Gewinn/Verlust dieser Sitzung + alle Charaktere des Realms -- Mauszeiger drauf Details zu Taschen, Ruestung und Gegenstandsstufe,
-- Gewinn/Verlust dieser Sitzung + alle Charaktere des Realms
-- /gold ein-/ausblenden -- /gold ein-/ausblenden
-- /gold lock sperren / entsperren -- /gold lock sperren / entsperren
-- /gold reset Position zurücksetzen -- /gold reset Position zurücksetzen
@@ -13,6 +15,20 @@ local GOLD = "|TInterface\\MoneyFrame\\UI-GoldIcon:0:0:2:0|t"
local SILVER = "|TInterface\\MoneyFrame\\UI-SilverIcon:0:0:2:0|t" local SILVER = "|TInterface\\MoneyFrame\\UI-SilverIcon:0:0:2:0|t"
local COPPER = "|TInterface\\MoneyFrame\\UI-CopperIcon:0:0:2:0|t" local COPPER = "|TInterface\\MoneyFrame\\UI-CopperIcon:0:0:2:0|t"
local SEP = " |cff666666||r " -- "||" ist ein woertliches |
local LABEL = "|cffaaaaaa" -- Beschriftungen im Rahmen
local YELLOW = "|cffffd100"
local RED = "|cffff3333"
-- Rucksack (0) und die vier Taschenplaetze, dahinter ggf. die Reagenzientasche
local NORMAL_BAGS = NUM_BAG_SLOTS or 4
local LAST_BAG = math.max(NUM_TOTAL_EQUIPPED_BAG_SLOTS or 0, NORMAL_BAGS)
local FIRST_SLOT = INVSLOT_FIRST_EQUIPPED or 1
local LAST_SLOT = INVSLOT_LAST_EQUIPPED or 19
local GetNumSlots = C_Container and C_Container.GetContainerNumSlots or GetContainerNumSlots
local GetFreeSlots = C_Container and C_Container.GetContainerNumFreeSlots or GetContainerNumFreeSlots
local db, realm, player, sessionStart local db, realm, player, sessionStart
local frame, text local frame, text
@@ -40,6 +56,24 @@ local function formatMoney(c)
return string.format("%d%s", k, COPPER) return string.format("%d%s", k, COPPER)
end end
-- 245.34 -> "245,3"
local function decimal(x)
return (string.format("%.1f", x):gsub("%.", ","))
end
local function paint(s, color)
if color then return color .. s .. "|r" end
return s
end
local function pctColor(p)
if p < 20 then return RED elseif p < 50 then return YELLOW end
end
local function freeColor(n)
if n == 0 then return RED elseif n <= 5 then return YELLOW end
end
local function classColored(name, class) local function classColored(name, class)
local c = class and RAID_CLASS_COLORS and RAID_CLASS_COLORS[class] local c = class and RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]
if c and c.colorStr then if c and c.colorStr then
@@ -56,6 +90,65 @@ local function lower(s)
end)) end))
end end
-- Freie und gesamte Plaetze. Spezialtaschen (Koecher, Kraeuter-, Reagenzientasche
-- usw.) zaehlen getrennt, weil dort nicht alles hineinpasst.
local function bagSpace()
local free, total, sFree, sTotal = 0, 0, 0, 0
for bag = 0, LAST_BAG do
local n = GetNumSlots(bag) or 0
if n > 0 then
local f, family = GetFreeSlots(bag)
f = f or 0
if bag <= NORMAL_BAGS and (family or 0) == 0 then
free, total = free + f, total + n
else
sFree, sTotal = sFree + f, sTotal + n
end
end
end
return free, total, sFree, sTotal
end
-- Zustand des am staerksten beschaedigten Teils (Prozent und Slot) und der
-- Gesamtzustand in Prozent. nil, wenn nichts mit Haltbarkeit angelegt ist.
local function durability()
local low, lowSlot, cur, max
cur, max = 0, 0
for slot = FIRST_SLOT, LAST_SLOT do
local c, m = GetInventoryItemDurability(slot)
if c and m and m > 0 then
local p = c / m * 100
if not low or p < low then low, lowSlot = p, slot end
cur, max = cur + c, max + m
end
end
if low then return low, lowSlot, cur / max * 100 end
end
-- Durchschnittliche Gegenstandsstufe wie im Charakterfenster: angelegt und mit
-- der besten Ausruestung aus den Taschen. nil, solange der Client sie nicht kennt.
local function itemLevel()
if not GetAverageItemLevel then return end
local best, equipped = GetAverageItemLevel()
if equipped and equipped > 0 then return equipped, best end
end
-- Eine Zeile: Gold | Taschen 23 | 87% | iLvl 245
local function frameText()
local parts = { formatMoney(GetMoney()) }
local free = bagSpace()
parts[#parts + 1] = LABEL .. "Taschen|r " .. paint(free, freeColor(free))
local low = durability()
if low then
parts[#parts + 1] = paint(math.floor(low) .. "%", pctColor(low))
end
local ilvl = itemLevel()
if ilvl then
parts[#parts + 1] = LABEL .. "iLvl|r " .. math.floor(ilvl)
end
return table.concat(parts, SEP)
end
-- Felder aktualisieren statt den Eintrag zu ersetzen, damit der -- Felder aktualisieren statt den Eintrag zu ersetzen, damit der
-- Sitzungsstart (session) erhalten bleibt -- Sitzungsstart (session) erhalten bleibt
local function record() local function record()
@@ -66,10 +159,32 @@ local function record()
me.money, me.class = GetMoney(), class me.money, me.class = GetMoney(), class
end end
local function update() local function addStatusLines()
record() local free, total, sFree, sTotal = bagSpace()
text:SetText(formatMoney(GetMoney())) GameTooltip:AddDoubleLine("Taschen frei:", paint(free, freeColor(free)) .. " / " .. total,
frame:SetSize(math.ceil(text:GetStringWidth()) + 20, math.ceil(text:GetStringHeight()) + 14) 1, 0.82, 0, 1, 1, 1)
if sTotal > 0 then
GameTooltip:AddDoubleLine("Spezialtaschen frei:", sFree .. " / " .. sTotal, 1, 0.82, 0, 1, 1, 1)
end
local low, lowSlot, overall = durability()
if low then
GameTooltip:AddDoubleLine("Rüstung gesamt:", paint(math.floor(overall) .. "%", pctColor(overall)),
1, 0.82, 0, 1, 1, 1)
if low < 100 then
local link = GetInventoryItemLink("player", lowSlot) or "?"
GameTooltip:AddDoubleLine(" " .. link, paint(math.floor(low) .. "%", pctColor(low)),
1, 1, 1, 1, 1, 1)
end
end
local ilvl, best = itemLevel()
if ilvl then
GameTooltip:AddDoubleLine("Gegenstandsstufe:", decimal(ilvl), 1, 0.82, 0, 1, 1, 1)
if best and best - ilvl >= 0.05 then
GameTooltip:AddDoubleLine("Beste Ausrüstung:", decimal(best), 1, 0.82, 0, 0.6, 0.6, 0.6)
end
end
end end
local function showTooltip(self) local function showTooltip(self)
@@ -78,6 +193,8 @@ local function showTooltip(self)
local anchor = (y and y > UIParent:GetHeight() / 2) and "ANCHOR_BOTTOM" or "ANCHOR_TOP" local anchor = (y and y > UIParent:GetHeight() / 2) and "ANCHOR_BOTTOM" or "ANCHOR_TOP"
GameTooltip:SetOwner(self, anchor) GameTooltip:SetOwner(self, anchor)
GameTooltip:AddLine("Goldbeutel") GameTooltip:AddLine("Goldbeutel")
addStatusLines()
GameTooltip:AddLine(" ")
local diff = GetMoney() - sessionStart local diff = GetMoney() - sessionStart
local sign, r, g, b = "", 1, 1, 1 local sign, r, g, b = "", 1, 1, 1
@@ -115,6 +232,25 @@ local function showTooltip(self)
GameTooltip:Show() GameTooltip:Show()
end end
local function update()
record()
text:SetText(frameText())
frame:SetSize(math.ceil(text:GetStringWidth()) + 20, math.ceil(text:GetStringHeight()) + 14)
if GameTooltip:IsOwned(frame) then showTooltip(frame) end
end
-- Mehrere Ereignisse kurz hintereinander (Ausruestung wechseln, Taschen sortieren)
-- loesen nur eine Aktualisierung im naechsten Frame aus
local queued = false
local function queueUpdate()
if queued or not frame then return end
queued = true
C_Timer.After(0, function()
queued = false
update()
end)
end
local function toggleLock() local function toggleLock()
db.locked = not db.locked db.locked = not db.locked
say(db.locked and "Rahmen gesperrt." or "Rahmen entsperrt.") say(db.locked and "Rahmen gesperrt." or "Rahmen entsperrt.")
@@ -185,6 +321,11 @@ ev:RegisterEvent("PLAYER_LOGIN")
ev:RegisterEvent("PLAYER_MONEY") ev:RegisterEvent("PLAYER_MONEY")
ev:RegisterEvent("PLAYER_LOGOUT") ev:RegisterEvent("PLAYER_LOGOUT")
ev:RegisterEvent("PLAYER_ENTERING_WORLD") ev:RegisterEvent("PLAYER_ENTERING_WORLD")
-- Taschen, Ruestung, Gegenstandsstufe. pcall, falls ein Client eines davon nicht kennt.
for _, e in ipairs({ "BAG_UPDATE_DELAYED", "UPDATE_INVENTORY_DURABILITY",
"PLAYER_EQUIPMENT_CHANGED", "PLAYER_AVG_ITEM_LEVEL_UPDATE" }) do
pcall(ev.RegisterEvent, ev, e)
end
ev:SetScript("OnEvent", function(self, event, arg1, arg2) ev:SetScript("OnEvent", function(self, event, arg1, arg2)
if event == "ADDON_LOADED" then if event == "ADDON_LOADED" then
if arg1 ~= ADDON then return end if arg1 ~= ADDON then return end
@@ -208,10 +349,13 @@ ev:SetScript("OnEvent", function(self, event, arg1, arg2)
else else
me.session = sessionStart me.session = sessionStart
end end
elseif event == "PLAYER_MONEY" then -- Taschen und Ausruestung sind jetzt sicher vollstaendig geladen
if frame then update() end queueUpdate()
elseif event == "PLAYER_LOGOUT" then elseif event == "PLAYER_LOGOUT" then
if realm then record() end if realm then record() end
else
-- PLAYER_MONEY und die Ereignisse fuer Taschen, Ruestung und Gegenstandsstufe
queueUpdate()
end end
end) end)
+1 -1
View File
@@ -1,5 +1,5 @@
## Interface: 16001 ## Interface: 16001
## Title: Goldbeutel ## Title: Goldbeutel
## Notes: Zeigt dein Gold in einem kleinen, verschiebbaren Rahmen. /gold ## Notes: Zeigt Gold, freie Taschenplätze, Rüstungszustand und Gegenstandsstufe in einem kleinen, verschiebbaren Rahmen. /gold
## SavedVariables: GoldbeutelDB ## SavedVariables: GoldbeutelDB
Goldbeutel.lua Goldbeutel.lua
Binary file not shown.
+59 -2
View File
@@ -8,7 +8,16 @@ local noop = function() end
local function obj(t) return setmetatable(t or {}, {__index = function() return noop end}) end local function obj(t) return setmetatable(t or {}, {__index = function() return noop end}) end
---------------------------------------------------------------- Goldbeutel ---------------------------------------------------------------- Goldbeutel
local money, ev, lines local money, ev, lines, shownText, gtimers
-- Ausgangszustand fuer Taschen, Ruestung und Gegenstandsstufe (in Tests veraenderbar)
-- bags[i] = { Plaetze, frei, Taschentyp }; Index 0 = Rucksack, 5 = Reagenzientasche
local bags, dura, ilvl
local function defaultGear()
bags = { [0] = {16, 5, 0}, {20, 10, 0}, {16, 16, 1}, {0, 0, 0}, {20, 8, 0}, {36, 30, 0} }
dura = { [1] = {45, 100}, [5] = {100, 100}, [7] = {80, 80} } -- Kopf, Brust, Beine
ilvl = {247.14, 245.34} -- beste, angelegt
end
defaultGear()
local function startGold(name, db) local function startGold(name, db)
GoldbeutelDB = db GoldbeutelDB = db
print = noop print = noop
@@ -18,6 +27,16 @@ local function startGold(name, db)
UnitName = function() return name end UnitName = function() return name end
UnitClass = function() return "Magier", "MAGE" end UnitClass = function() return "Magier", "MAGE" end
GetMoney = function() return money end GetMoney = function() return money end
NUM_BAG_SLOTS, NUM_TOTAL_EQUIPPED_BAG_SLOTS, INVSLOT_FIRST_EQUIPPED, INVSLOT_LAST_EQUIPPED = 4, 5, 1, 19
C_Container = {
GetContainerNumSlots = function(b) return bags[b] and bags[b][1] or 0 end,
GetContainerNumFreeSlots = function(b) if bags[b] then return bags[b][2], bags[b][3] end return 0, 0 end,
}
GetInventoryItemDurability = function(s) if dura[s] then return dura[s][1], dura[s][2] end end
GetInventoryItemLink = function(_, s) return "[Item" .. s .. "]" end
GetAverageItemLevel = function() return ilvl[1], ilvl[2] end
gtimers = {}
C_Timer = { After = function(_, fn) gtimers[#gtimers + 1] = fn end }
UIParent = obj{ GetHeight = function() return 800 end } UIParent = obj{ GetHeight = function() return 800 end }
lines = {} lines = {}
GameTooltip = obj{ AddDoubleLine = function(_, l, r) lines[l] = r end, IsOwned = function() return false end } GameTooltip = obj{ AddDoubleLine = function(_, l, r) lines[l] = r end, IsOwned = function() return false end }
@@ -28,7 +47,8 @@ local function startGold(name, db)
GetCenter = function() return 500, 300 end, GetCenter = function() return 500, 300 end,
SetShown = function(self, v) self.shown = v end, SetShown = function(self, v) self.shown = v end,
IsShown = function(self) return self.shown end, IsShown = function(self) return self.shown end,
CreateFontString = function() return obj{ GetStringWidth = function() return 80 end, GetStringHeight = function() return 12 end } end } CreateFontString = function() return obj{ SetText = function(_, t) shownText = t end,
GetStringWidth = function() return 80 end, GetStringHeight = function() return 12 end } end }
frames[#frames + 1] = f frames[#frames + 1] = f
return f return f
end end
@@ -68,6 +88,43 @@ SlashCmdList.GOLDBEUTEL("forget ÉLODIE"); check("ÉLODIE -> Élodie entfernt",
SlashCmdList.GOLDBEUTEL("forget öx×y"); check("öx×y -> Öx×y entfernt (× unveraendert)", chars["Öx×y"] == nil) SlashCmdList.GOLDBEUTEL("forget öx×y"); check("öx×y -> Öx×y entfernt (× unveraendert)", chars["Öx×y"] == nil)
SlashCmdList.GOLDBEUTEL("forget testmagier"); check("Eigener Charakter bleibt", chars.Testmagier ~= nil) SlashCmdList.GOLDBEUTEL("forget testmagier"); check("Eigener Charakter bleibt", chars.Testmagier ~= nil)
out("Goldbeutel: Taschen, Ruestung, Gegenstandsstufe")
local function flush() while #gtimers > 0 do table.remove(gtimers, 1)() end end
local function plain(s) return (s:gsub("|T.-|t", ""):gsub("|c%x%x%x%x%x%x%x%x", ""):gsub("|r", ""):gsub("||", "|")) end
defaultGear(); money = 1234567
fr = startGold("Testmagier", nil); ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD", true, false); flush()
check("Rahmen: eine Zeile mit allen vier Werten",
plain(shownText) == "123 45 67 | Taschen 23 | 45% | iLvl 245")
check("Spezialtaschen (Koecher, Reagenzientasche) nicht im Rahmen mitgezaehlt", plain(shownText):find("Taschen 23", 1, true))
check("45% gelb (unter 50)", shownText:find("|cffffd10045%|r", 1, true) ~= nil)
check("23 freie Plaetze ohne Warnfarbe", shownText:find("|r 23", 1, true) ~= nil)
lines = {}; fr.scripts.OnEnter(fr)
check("Tooltip: Taschen frei 23 / 56", lines["Taschen frei:"] == "23 / 56")
check("Tooltip: Spezialtaschen frei 46 / 52", lines["Spezialtaschen frei:"] == "46 / 52")
check("Tooltip: Ruestung gesamt 80% (225/280)", lines["Rüstung gesamt:"] == "80%")
check("Tooltip: am staerksten beschaedigtes Teil (Kopf) mit 45%", plain(lines[" [Item1]"] or "") == "45%")
check("Tooltip: Gegenstandsstufe 245,3", lines["Gegenstandsstufe:"] == "245,3")
check("Tooltip: beste Ausruestung 247,1", lines["Beste Ausrüstung:"] == "247,1")
bags[0][2], bags[1][2], bags[4][2] = 0, 3, 0; dura[1][1] = 10
for _ = 1, 3 do ev.scripts.OnEvent(ev, "BAG_UPDATE_DELAYED") end
ev.scripts.OnEvent(ev, "UPDATE_INVENTORY_DURABILITY")
check("Mehrere Ereignisse -> nur eine Aktualisierung", #gtimers == 1)
flush()
check("3 freie Plaetze gelb", shownText:find("|cffffd1003|r", 1, true) ~= nil)
check("10% rot", shownText:find("|cffff333310%|r", 1, true) ~= nil)
bags[1][2] = 0; ev.scripts.OnEvent(ev, "BAG_UPDATE_DELAYED"); flush()
check("0 freie Plaetze rot", shownText:find("|cffff33330|r", 1, true) ~= nil)
dura = {}; ilvl = {0, 0}; ev.scripts.OnEvent(ev, "PLAYER_EQUIPMENT_CHANGED"); flush()
check("Ohne Haltbarkeit und ohne iLvl nur Gold und Taschen", plain(shownText) == "123 45 67 | Taschen 0")
lines = {}; fr.scripts.OnEnter(fr)
check("Tooltip ohne Ruestungs- und iLvl-Zeilen", lines["Rüstung gesamt:"] == nil and lines["Gegenstandsstufe:"] == nil)
dura = { [1] = {50, 50} }; ilvl = {245.34, 245.34}; ev.scripts.OnEvent(ev, "PLAYER_AVG_ITEM_LEVEL_UPDATE"); flush()
lines = {}; fr.scripts.OnEnter(fr)
check("Alles heil: keine Zeile fuer beschaedigtes Teil", lines[" [Item1]"] == nil and lines["Rüstung gesamt:"] == "100%")
check("Beste = angelegt: keine Zeile 'Beste Ausruestung'", lines["Beste Ausrüstung:"] == nil)
---------------------------------------------------------------- ForeverScale ---------------------------------------------------------------- ForeverScale
local scale, h, combat, timers, f local scale, h, combat, timers, f
local function startScale(db) local function startScale(db)