Leistenabstand: Leere, ausgeblendete Slots ("Immer Buttons anzeigen" aus)
werden mit angeordnet. Vorher wurde ihre Lücke zugeschoben, und sobald
sie wieder erschienen, lagen sie fast genau auf dem Nachbarbutton.
Buttons jenseits von "Anzahl Symbole" bleiben außen vor (numShowingButtons,
sonst bis zum letzten sichtbaren Button). Die Haltungsleiste ordnet weiter
nur sichtbare Buttons an.
Goldbeutel: "Diese Sitzung" läuft über /reload weiter (Startwert pro
Charakter gespeichert, Reset nur bei echtem Login). /gold forget findet
auch Namen mit Umlauten und Akzenten unabhängig von Groß-/Kleinschreibung.
ForeverScale: /fscale pixel ist jetzt ein Modus und wird bei jedem
Auflösungswechsel neu berechnet. Kann absichtlich unter 0,30 liegen.
README: Quellcode-Anhang auf den neuen Stand gebracht.
tests/: Mock-Tests für alle drei Addons (luajit tests/<datei>.lua).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
249 lines
7.8 KiB
Lua
249 lines
7.8 KiB
Lua
-- Goldbeutel: zeigt dein Gold in einem kleinen, verschiebbaren Rahmen.
|
||
-- Linksziehen verschieben
|
||
-- Rechtsklick sperren / entsperren
|
||
-- Mauszeiger drauf Gewinn/Verlust dieser Sitzung + alle Charaktere des Realms
|
||
-- /gold ein-/ausblenden
|
||
-- /gold lock sperren / entsperren
|
||
-- /gold reset Position zurücksetzen
|
||
-- /gold forget <Name> Charakter aus der Liste entfernen
|
||
|
||
local ADDON = ...
|
||
|
||
local GOLD = "|TInterface\\MoneyFrame\\UI-GoldIcon: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 db, realm, player, sessionStart
|
||
local frame, text
|
||
|
||
local function say(s)
|
||
print("|cffffd100Goldbeutel:|r " .. s)
|
||
end
|
||
|
||
-- 1234567 -> "1.234.567" (nutzt das Trennzeichen des Clients, falls vorhanden)
|
||
local function thousands(n)
|
||
if BreakUpLargeNumbers then return BreakUpLargeNumbers(n) end
|
||
local s = tostring(n):reverse():gsub("(%d%d%d)", "%1."):reverse()
|
||
return (s:gsub("^%.", ""))
|
||
end
|
||
|
||
local function formatMoney(c)
|
||
c = math.floor(c or 0)
|
||
local g = math.floor(c / 10000)
|
||
local s = math.floor(c / 100) % 100
|
||
local k = c % 100
|
||
if g > 0 then
|
||
return string.format("%s%s %02d%s %02d%s", thousands(g), GOLD, s, SILVER, k, COPPER)
|
||
elseif s > 0 then
|
||
return string.format("%d%s %02d%s", s, SILVER, k, COPPER)
|
||
end
|
||
return string.format("%d%s", k, COPPER)
|
||
end
|
||
|
||
local function classColored(name, class)
|
||
local c = class and RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]
|
||
if c and c.colorStr then
|
||
return "|c" .. c.colorStr .. name .. "|r"
|
||
end
|
||
return name
|
||
end
|
||
|
||
-- string.lower kennt nur A-Z. Fuer Namen wie "Ärger" auch À-Þ (UTF-8 C3 80-9E,
|
||
-- ausser ×) in Kleinbuchstaben umwandeln.
|
||
local function lower(s)
|
||
return (s:lower():gsub("\195([\128-\158])", function(c)
|
||
if c ~= "\151" then return "\195" .. string.char(c:byte() + 32) end
|
||
end))
|
||
end
|
||
|
||
-- Felder aktualisieren statt den Eintrag zu ersetzen, damit der
|
||
-- Sitzungsstart (session) erhalten bleibt
|
||
local function record()
|
||
local chars = db.chars[realm]
|
||
local me = chars[player] or {}
|
||
chars[player] = me
|
||
local _, class = UnitClass("player")
|
||
me.money, me.class = GetMoney(), class
|
||
end
|
||
|
||
local function update()
|
||
record()
|
||
text:SetText(formatMoney(GetMoney()))
|
||
frame:SetSize(math.ceil(text:GetStringWidth()) + 20, math.ceil(text:GetStringHeight()) + 14)
|
||
end
|
||
|
||
local function showTooltip(self)
|
||
-- Tooltip zur Bildschirmmitte hin öffnen, damit er den Rahmen nicht verdeckt
|
||
local _, y = self:GetCenter()
|
||
local anchor = (y and y > UIParent:GetHeight() / 2) and "ANCHOR_BOTTOM" or "ANCHOR_TOP"
|
||
GameTooltip:SetOwner(self, anchor)
|
||
GameTooltip:AddLine("Goldbeutel")
|
||
|
||
local diff = GetMoney() - sessionStart
|
||
local sign, r, g, b = "", 1, 1, 1
|
||
if diff > 0 then
|
||
sign, r, g, b = "+", 0.2, 1, 0.2
|
||
elseif diff < 0 then
|
||
sign, r, g, b = "-", 1, 0.3, 0.3
|
||
end
|
||
GameTooltip:AddDoubleLine("Diese Sitzung:", sign .. formatMoney(math.abs(diff)), 1, 0.82, 0, r, g, b)
|
||
GameTooltip:AddLine(" ")
|
||
|
||
local list, total = {}, 0
|
||
for name, info in pairs(db.chars[realm]) do
|
||
local m = info.money or 0
|
||
list[#list + 1] = { name = name, money = m, class = info.class }
|
||
total = total + m
|
||
end
|
||
table.sort(list, function(a, b) return a.money > b.money end)
|
||
|
||
for _, e in ipairs(list) do
|
||
local label = classColored(e.name, e.class)
|
||
if e.name == player then label = label .. " *" end
|
||
GameTooltip:AddDoubleLine(label, formatMoney(e.money), 1, 1, 1, 1, 1, 1)
|
||
end
|
||
if #list > 1 then
|
||
GameTooltip:AddDoubleLine("Gesamt (" .. realm .. "):", formatMoney(total), 1, 0.82, 0, 1, 1, 1)
|
||
end
|
||
|
||
GameTooltip:AddLine(" ")
|
||
if db.locked then
|
||
GameTooltip:AddLine("Gesperrt. Rechtsklick zum Entsperren.", 0.6, 0.6, 0.6)
|
||
else
|
||
GameTooltip:AddLine("Ziehen: verschieben, Rechtsklick: sperren", 0.6, 0.6, 0.6)
|
||
end
|
||
GameTooltip:Show()
|
||
end
|
||
|
||
local function toggleLock()
|
||
db.locked = not db.locked
|
||
say(db.locked and "Rahmen gesperrt." or "Rahmen entsperrt.")
|
||
if GameTooltip:IsOwned(frame) then showTooltip(frame) end
|
||
end
|
||
|
||
local function savePos()
|
||
local point, _, relPoint, x, y = frame:GetPoint(1)
|
||
db.pos = { point, relPoint, x, y }
|
||
end
|
||
|
||
local function restorePos()
|
||
frame:ClearAllPoints()
|
||
local p = db.pos
|
||
if p then
|
||
frame:SetPoint(p[1], UIParent, p[2], p[3], p[4])
|
||
else
|
||
frame:SetPoint("CENTER", UIParent, "CENTER", 0, -200)
|
||
end
|
||
end
|
||
|
||
local function createFrame()
|
||
frame = CreateFrame("Frame", "GoldbeutelFrame", UIParent, "BackdropTemplate")
|
||
frame:SetFrameStrata("MEDIUM")
|
||
frame:SetClampedToScreen(true)
|
||
frame:SetMovable(true)
|
||
frame:EnableMouse(true)
|
||
frame:RegisterForDrag("LeftButton")
|
||
-- Position speichern wir selbst, nicht im layout-cache des Clients
|
||
if frame.SetDontSavePosition then frame:SetDontSavePosition(true) end
|
||
|
||
frame:SetBackdrop({
|
||
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
|
||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
||
tile = true, tileSize = 16, edgeSize = 12,
|
||
insets = { left = 3, right = 3, top = 3, bottom = 3 },
|
||
})
|
||
frame:SetBackdropColor(0, 0, 0, 0.75)
|
||
frame:SetBackdropBorderColor(0.6, 0.6, 0.6, 1)
|
||
|
||
text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
|
||
text:SetPoint("CENTER")
|
||
|
||
frame:SetScript("OnDragStart", function(self)
|
||
if db.locked then return end
|
||
self.dragging = true
|
||
self:StartMoving()
|
||
end)
|
||
frame:SetScript("OnDragStop", function(self)
|
||
if not self.dragging then return end
|
||
self.dragging = false
|
||
self:StopMovingOrSizing()
|
||
savePos()
|
||
end)
|
||
frame:SetScript("OnMouseUp", function(_, button)
|
||
if button == "RightButton" then toggleLock() end
|
||
end)
|
||
frame:SetScript("OnEnter", showTooltip)
|
||
frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
||
|
||
restorePos()
|
||
frame:SetShown(not db.hidden)
|
||
end
|
||
|
||
local ev = CreateFrame("Frame")
|
||
ev:RegisterEvent("ADDON_LOADED")
|
||
ev:RegisterEvent("PLAYER_LOGIN")
|
||
ev:RegisterEvent("PLAYER_MONEY")
|
||
ev:RegisterEvent("PLAYER_LOGOUT")
|
||
ev:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||
ev:SetScript("OnEvent", function(self, event, arg1, arg2)
|
||
if event == "ADDON_LOADED" then
|
||
if arg1 ~= ADDON then return end
|
||
GoldbeutelDB = GoldbeutelDB or {}
|
||
db = GoldbeutelDB
|
||
db.chars = db.chars or {}
|
||
self:UnregisterEvent("ADDON_LOADED")
|
||
elseif event == "PLAYER_LOGIN" then
|
||
realm, player = GetRealmName(), UnitName("player")
|
||
db.chars[realm] = db.chars[realm] or {}
|
||
sessionStart = GetMoney()
|
||
createFrame()
|
||
update()
|
||
elseif event == "PLAYER_ENTERING_WORLD" then
|
||
-- PLAYER_LOGIN kommt auch bei /reload. Erst hier steht fest, ob es nur ein
|
||
-- Reload war (arg2 = isReloadingUi); dann zaehlt die Sitzung weiter.
|
||
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
|
||
local me = db.chars[realm][player]
|
||
if arg2 and me.session then
|
||
sessionStart = me.session
|
||
else
|
||
me.session = sessionStart
|
||
end
|
||
elseif event == "PLAYER_MONEY" then
|
||
if frame then update() end
|
||
elseif event == "PLAYER_LOGOUT" then
|
||
if realm then record() end
|
||
end
|
||
end)
|
||
|
||
SLASH_GOLDBEUTEL1 = "/gold"
|
||
SLASH_GOLDBEUTEL2 = "/goldbeutel"
|
||
SlashCmdList.GOLDBEUTEL = function(input)
|
||
local cmd, arg = strtrim(input or ""):match("^(%S*)%s*(.-)$")
|
||
cmd = cmd:lower()
|
||
|
||
if cmd == "" then
|
||
db.hidden = frame:IsShown()
|
||
frame:SetShown(not db.hidden)
|
||
if db.hidden then say("ausgeblendet. /gold blendet ihn wieder ein.") end
|
||
elseif cmd == "lock" then
|
||
toggleLock()
|
||
elseif cmd == "reset" then
|
||
db.pos, db.hidden = nil, false
|
||
restorePos()
|
||
frame:Show()
|
||
say("Position zurückgesetzt.")
|
||
elseif cmd == "forget" and arg ~= "" then
|
||
local chars, want = db.chars[realm], lower(arg)
|
||
for name in pairs(chars) do
|
||
if lower(name) == want and name ~= player then
|
||
chars[name] = nil
|
||
say(name .. " entfernt.")
|
||
return
|
||
end
|
||
end
|
||
say("Kein anderer Charakter namens '" .. arg .. "' auf " .. realm .. ".")
|
||
else
|
||
say("/gold (ein/aus), /gold lock, /gold reset, /gold forget <Name>")
|
||
end
|
||
end
|