fix in-game chat

This commit is contained in:
MihailRis 2025-01-21 04:31:33 +03:00
parent 266f3059b4
commit 85600eafea
3 changed files with 8 additions and 14 deletions

View File

@ -7,18 +7,11 @@ local initialized = false
local max_lines = 15 local max_lines = 15
local animation_fps = 30 local animation_fps = 30
local function remove_line(line)
document[line[1]]:destruct()
time.post_runnable(function()
if world.is_open() then document.root:reposition() end
end)
end
local function update_line(line, uptime) local function update_line(line, uptime)
local diff = uptime - line[2] local diff = uptime - line[2]
if diff > timeout then if diff > timeout then
remove_line(line) document[line[1]]:destruct()
table.insert(dead_lines, i) table.insert(dead_lines, table.index(lines, line))
elseif diff > timeout-fadeout then elseif diff > timeout-fadeout then
local opacity = (timeout - diff) / fadeout local opacity = (timeout - diff) / fadeout
document[line[1]].color = {0, 0, 0, opacity * 80} document[line[1]].color = {0, 0, 0, opacity * 80}
@ -27,16 +20,16 @@ local function update_line(line, uptime)
end end
events.on("core:chat", function(message) events.on("core:chat", function(message)
while #lines >= max_lines do
document[lines[1][1]]:destruct()
table.remove(lines, 1)
end
local current_time = time.uptime() local current_time = time.uptime()
local id = 'l'..tostring(nextid) local id = 'l'..tostring(nextid)
document.root:add(gui.template("chat_line", {id=id})) document.root:add(gui.template("chat_line", {id=id}))
document.root:reposition() document.root:reposition()
document[id.."L"].text = message document[id.."L"].text = message
nextid = nextid + 1 nextid = nextid + 1
if #lines == max_lines then
remove_line(lines[1])
table.remove(lines, 1)
end
table.insert(lines, {id, current_time}) table.insert(lines, {id, current_time})
end) end)

View File

@ -199,6 +199,7 @@ void Engine::updateFrontend() {
audio::update(delta); audio::update(delta);
gui->act(delta, Viewport(Window::width, Window::height)); gui->act(delta, Viewport(Window::width, Window::height));
screen->update(delta); screen->update(delta);
gui->postAct();
} }
void Engine::nextFrame() { void Engine::nextFrame() {
@ -217,7 +218,6 @@ void Engine::renderFrame() {
Viewport viewport(Window::width, Window::height); Viewport viewport(Window::width, Window::height);
DrawContext ctx(nullptr, viewport, nullptr); DrawContext ctx(nullptr, viewport, nullptr);
gui->draw(ctx, *assets); gui->draw(ctx, *assets);
gui->postAct();
} }
void Engine::saveSettings() { void Engine::saveSettings() {

View File

@ -53,6 +53,7 @@ void Panel::cropToContent() {
void Panel::fullRefresh() { void Panel::fullRefresh() {
refresh(); refresh();
cropToContent(); cropToContent();
reposition();
Container::fullRefresh(); Container::fullRefresh();
} }