Fehler aus dem Code-Review behoben, Tests hinzugefügt
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>
This commit is contained in:
1 parent
da38820c2e
commit
f1eca2d1c5
7 files changed
+425
-50
No files matched your search
@@ -138,14 +138,28 @@ ForeverScale.lua
|
||||
-- ForeverScale: re-applies a fixed UIParent scale on every login/reload,
|
||||
-- so values below Blizzard's 0.64 slider floor stick.
|
||||
-- /fscale 0.5333 set a scale (0.30 - 1.50), saved account-wide
|
||||
-- /fscale pixel pixel-perfect: 768 / your vertical resolution
|
||||
-- /fscale pixel pixel-perfect: 768 / your vertical resolution, worked out
|
||||
-- again whenever the resolution changes. Not limited to
|
||||
-- 0.30 - 1.50, so on 5K/6K screens it goes below 0.30.
|
||||
-- /fscale reset stop overriding (then /reload)
|
||||
|
||||
local ADDON = ...
|
||||
local f = CreateFrame("Frame")
|
||||
|
||||
-- the scale to enforce, or nil if there is no override
|
||||
local function target()
|
||||
local db = ForeverScaleDB
|
||||
if not db then return end
|
||||
if db.pixel then
|
||||
local _, h = GetPhysicalScreenSize()
|
||||
if h and h > 0 then return 768 / h end
|
||||
return
|
||||
end
|
||||
return db.scale
|
||||
end
|
||||
|
||||
local function apply()
|
||||
local s = ForeverScaleDB and ForeverScaleDB.scale
|
||||
local s = target()
|
||||
if not s then return end
|
||||
if InCombatLockdown() then
|
||||
-- UIParent has protected children; wait until combat ends
|
||||
@@ -183,12 +197,11 @@ SlashCmdList.FOREVERSCALE = function(msg)
|
||||
msg = strtrim(msg or ""):lower()
|
||||
|
||||
if msg == "reset" then
|
||||
ForeverScaleDB.scale = nil
|
||||
ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, nil
|
||||
print("ForeverScale: override cleared. /reload to return to Blizzard's scale.")
|
||||
return
|
||||
elseif msg == "pixel" then
|
||||
local _, h = GetPhysicalScreenSize()
|
||||
ForeverScaleDB.scale = 768 / h
|
||||
ForeverScaleDB.scale, ForeverScaleDB.pixel = nil, true
|
||||
else
|
||||
local v = tonumber(msg)
|
||||
if not v or v < 0.3 or v > 1.5 then
|
||||
@@ -197,11 +210,12 @@ SlashCmdList.FOREVERSCALE = function(msg)
|
||||
UIParent:GetScale()))
|
||||
return
|
||||
end
|
||||
ForeverScaleDB.scale = v
|
||||
ForeverScaleDB.scale, ForeverScaleDB.pixel = v, nil
|
||||
end
|
||||
|
||||
apply()
|
||||
print(string.format("ForeverScale: scale set to %.4f%s", ForeverScaleDB.scale,
|
||||
print(string.format("ForeverScale: scale set to %.4f%s%s", target() or UIParent:GetScale(),
|
||||
ForeverScaleDB.pixel and " (pixel, follows your resolution)" or "",
|
||||
InCombatLockdown() and " (applies after combat)" or ""))
|
||||
end
|
||||
```
|
||||
@@ -271,9 +285,22 @@ local function classColored(name, class)
|
||||
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")
|
||||
db.chars[realm][player] = { money = GetMoney(), class = class }
|
||||
me.money, me.class = GetMoney(), class
|
||||
end
|
||||
|
||||
local function update()
|
||||
@@ -394,7 +421,8 @@ ev:RegisterEvent("ADDON_LOADED")
|
||||
ev:RegisterEvent("PLAYER_LOGIN")
|
||||
ev:RegisterEvent("PLAYER_MONEY")
|
||||
ev:RegisterEvent("PLAYER_LOGOUT")
|
||||
ev:SetScript("OnEvent", function(self, event, arg1)
|
||||
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 {}
|
||||
@@ -407,6 +435,16 @@ ev:SetScript("OnEvent", function(self, event, arg1)
|
||||
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
|
||||
@@ -432,9 +470,9 @@ SlashCmdList.GOLDBEUTEL = function(input)
|
||||
frame:Show()
|
||||
say("Position zurückgesetzt.")
|
||||
elseif cmd == "forget" and arg ~= "" then
|
||||
local chars = db.chars[realm]
|
||||
local chars, want = db.chars[realm], lower(arg)
|
||||
for name in pairs(chars) do
|
||||
if name:lower() == arg:lower() and name ~= player then
|
||||
if lower(name) == want and name ~= player then
|
||||
chars[name] = nil
|
||||
say(name .. " entfernt.")
|
||||
return
|
||||
@@ -486,7 +524,8 @@ local BARS = {
|
||||
{ key = "6", name = "Aktionsleiste 6", frames = { "MultiBar5" }, prefix = "MultiBar5Button", n = 12 },
|
||||
{ key = "7", name = "Aktionsleiste 7", frames = { "MultiBar6" }, prefix = "MultiBar6Button", n = 12 },
|
||||
{ key = "8", name = "Aktionsleiste 8", frames = { "MultiBar7" }, prefix = "MultiBar7Button", n = 12 },
|
||||
{ key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10 },
|
||||
-- Haltungsbuttons sind nie "leer": ausgeblendet heisst, die Haltung gibt es nicht
|
||||
{ key = "haltung", name = "Haltungsleiste", frames = { "StanceBar" }, prefix = "StanceButton", n = 10, onlyShown = true },
|
||||
{ key = "pet", name = "Begleiterleiste", frames = { "PetActionBar" }, prefix = "PetActionButton", n = 10 },
|
||||
}
|
||||
local BY_KEY = {}
|
||||
@@ -522,6 +561,33 @@ local function getButtons(def)
|
||||
return list
|
||||
end
|
||||
|
||||
-- Die Buttons, die Blizzard ins Raster legt. Dazu gehoeren auch leere Slots, die
|
||||
-- bei ausgeschaltetem "Immer Buttons anzeigen" ausgeblendet sind: Blizzard laesst
|
||||
-- ihre Luecke stehen, und wenn sie wieder erscheinen (Zauber hineingezogen, Raster
|
||||
-- beim Ziehen, Leistenwechsel), muessen sie schon am richtigen Platz sein. Buttons
|
||||
-- jenseits von "Anzahl Symbole" gehoeren nicht dazu.
|
||||
local function gridButtons(def)
|
||||
local all = getButtons(def)
|
||||
local n
|
||||
if not def.onlyShown then
|
||||
n = def.bar.numShowingButtons
|
||||
if type(n) ~= "number" then
|
||||
-- Feld fehlt: bis zum letzten sichtbaren Button, Luecken dazwischen zaehlen mit
|
||||
n = 0
|
||||
for i, b in ipairs(all) do
|
||||
if b:IsShown() then n = i end
|
||||
end
|
||||
end
|
||||
end
|
||||
local list = {}
|
||||
for i, b in ipairs(all) do
|
||||
local inGrid
|
||||
if n then inGrid = i <= n else inGrid = b:IsShown() end
|
||||
if inGrid and b:GetCenter() then list[#list + 1] = b end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
-- sortiert die Werte und fasst nahe beieinanderliegende zu einer Spalte/Reihe zusammen
|
||||
local function clusters(values, tol)
|
||||
table.sort(values)
|
||||
@@ -551,9 +617,9 @@ end
|
||||
-- auf der Seite des ersten Buttons gemessen (den verschiebt das Addon nie) und
|
||||
-- auf der anderen Seite gespiegelt. So bleibt das Ergebnis stabil, egal ob der
|
||||
-- Rahmen vorher Blizzards Groesse hatte oder schon verkleinert war.
|
||||
local function fitBar(bar, anchor, shown)
|
||||
local function fitBar(bar, anchor, grid)
|
||||
local l, r, t, b
|
||||
for _, btn in ipairs(shown) do
|
||||
for _, btn in ipairs(grid) do
|
||||
local L, R, T, B = rectIn(btn, bar)
|
||||
if L then
|
||||
l = l and math.min(l, L) or L
|
||||
@@ -573,19 +639,16 @@ end
|
||||
|
||||
local function compress(def, pad)
|
||||
local bar = def.bar
|
||||
local shown = {}
|
||||
for _, b in ipairs(getButtons(def)) do
|
||||
if b:IsShown() and b:GetCenter() then shown[#shown + 1] = b end
|
||||
end
|
||||
if #shown < 2 then return end
|
||||
local grid = gridButtons(def)
|
||||
if #grid < 2 then return end
|
||||
|
||||
-- Der erste Button bleibt, wo Blizzard ihn hingesetzt hat; alle anderen
|
||||
-- werden relativ zu ihm angeordnet. Falls er selbst an einem anderen
|
||||
-- Button haengt, lieber nichts anfassen (sonst Ankerschleife).
|
||||
local anchor = shown[1]
|
||||
local anchor = grid[1]
|
||||
for i = 1, anchor:GetNumPoints() do
|
||||
local _, rel = anchor:GetPoint(i)
|
||||
for _, b in ipairs(shown) do
|
||||
for _, b in ipairs(grid) do
|
||||
if rel == b then return end
|
||||
end
|
||||
end
|
||||
@@ -595,7 +658,7 @@ local function compress(def, pad)
|
||||
local s = anchor:GetEffectiveScale()
|
||||
local tolX, tolY = w * s / 2, h * s / 2
|
||||
local px, py, xs, ys = {}, {}, {}, {}
|
||||
for i, b in ipairs(shown) do
|
||||
for i, b in ipairs(grid) do
|
||||
local x, y = b:GetCenter()
|
||||
local es = b:GetEffectiveScale()
|
||||
px[i], py[i] = x * es, -y * es -- y negiert: Reihe 1 = oben
|
||||
@@ -604,15 +667,15 @@ local function compress(def, pad)
|
||||
local cols, rows = clusters(xs, tolX), clusters(ys, tolY)
|
||||
local c0, r0 = rank(cols, px[1], tolX), rank(rows, py[1], tolY)
|
||||
|
||||
for i = 2, #shown do
|
||||
local b = shown[i]
|
||||
for i = 2, #grid do
|
||||
local b = grid[i]
|
||||
local dc = rank(cols, px[i], tolX) - c0
|
||||
local dr = rank(rows, py[i], tolY) - r0
|
||||
b:ClearAllPoints()
|
||||
b:SetPoint("CENTER", anchor, "CENTER", dc * (w + pad), -dr * (h + pad))
|
||||
end
|
||||
|
||||
if db.resize then fitBar(bar, anchor, shown) end
|
||||
if db.resize then fitBar(bar, anchor, grid) end
|
||||
end
|
||||
|
||||
local function apply(def)
|
||||
|
||||
Reference in new issue
Block a user