0.1.218: Mail: Posteingang in 7er-Paketen mit Ladebalken (Absturz bei viel Post)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016onJCSHLwhs9udhC9ZLzk9
This commit is contained in:
Lacustat
2026-11-01 09:51:50 +01:00
co-authored by Claude Sonnet 5.5
parent 75e564388c
commit fece5d4148
4 changed files with 79 additions and 3 deletions
+44 -2
View File
@@ -230,11 +230,49 @@ end
------------------------------------------------------------------------
-- Liste der Briefe: { i, sender, subject, money, cod, days, hasItem, itemName, itemTex, itemCount, sig, key, take, why }
-- Grosse Postfaecher werden in Haeppchen eingelesen (wie die Seiten des Spiels: 7 je Schritt, mit Pause), sonst haengt der Client.
local CHUNK, LOAD_GAP = 7, 0.45
local function InboxCount()
if not GetInboxNumItems then return 0 end
local ok, n = pcall(GetInboxNumItems)
return (ok and tonumber(n)) or 0
end
Mail.InboxCount = InboxCount
-- Rueckgabe: laedt noch?, geladen, gesamt
function Mail.Loading()
local n = InboxCount()
if n <= CHUNK then return false, n, n end
local L = math.min(n, Mail.loadedN or CHUNK)
return L < n, L, n
end
function Mail:StartLoader()
if not self.loader then
self.loader = CreateFrame("Frame")
local acc = 0
self.loader:SetScript("OnUpdate", function(f, elapsed)
acc = acc + (elapsed or 0)
if acc < LOAD_GAP then return end
acc = 0
if not Mail.open then f:Hide() return end
local loading = Mail.Loading()
if loading then
Mail.loadedN = (Mail.loadedN or CHUNK) + CHUNK
FW:Fire("MAIL_INBOX_CHANGED")
end
if not Mail.Loading() then f:Hide() FW:Fire("MAIL_INBOX_CHANGED") end
end)
end
if Mail.Loading() then self.loader:Show() else self.loader:Hide() end
end
function Mail.ReadInbox()
local list = {}
if not GetInboxNumItems then return list end
local ok, n = pcall(GetInboxNumItems)
n = (ok and tonumber(n)) or 0
local n = InboxCount()
if n > CHUNK then n = math.min(n, Mail.loadedN or CHUNK) end
local seen = {}
for i = 1, n do
local ok1, _, _, sender, subject, money, cod, days, hasItem, wasRead, wasReturned, _, canReply = pcall(GetInboxHeaderInfo, i)
@@ -541,6 +579,7 @@ end
-- onlySelected: nur angehakte Briefe
function Mail:StartOpen(onlySelected)
if self.busy or not self.open then return false end
if Mail.Loading() then Say(FW.L.MAIL_LOADING_WAIT) return false end
local only
if onlySelected then
only = {}
@@ -1005,6 +1044,8 @@ function Mail:OnMailShow()
self.gen = self.gen + 1
self.boardTries, self.boardAutoAt, self.boardSending = 0, nil, nil
self.selected = {}
self.loadedN = CHUNK
self:StartLoader()
self:ApplyReplace()
Trace("Briefkasten geoeffnet")
if self.Replacing() then FW:Fire("MAIL_WINDOW_SHOW") end
@@ -1023,6 +1064,7 @@ end
function Mail:OnInboxUpdate()
if self.run then self.run.updated = true end
if self.open and Mail.Loading() and (not self.loader or not self.loader:IsShown()) then self:StartLoader() end
FW:Fire("MAIL_INBOX_CHANGED")
end