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 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 diff = uptime - line[2]
if diff > timeout then
remove_line(line)
table.insert(dead_lines, i)
document[line[1]]:destruct()
table.insert(dead_lines, table.index(lines, line))
elseif diff > timeout-fadeout then
local opacity = (timeout - diff) / fadeout
document[line[1]].color = {0, 0, 0, opacity * 80}
@ -27,16 +20,16 @@ local function update_line(line, uptime)
end
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 id = 'l'..tostring(nextid)
document.root:add(gui.template("chat_line", {id=id}))
document.root:reposition()
document[id.."L"].text = message
nextid = nextid + 1
if #lines == max_lines then
remove_line(lines[1])
table.remove(lines, 1)
end
table.insert(lines, {id, current_time})
end)

View File

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

View File

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