Skip to content

Commit

Permalink
fix in-game chat
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Jan 21, 2025
1 parent 266f305 commit 85600ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
19 changes: 6 additions & 13 deletions res/layouts/ingame_chat.xml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/graphics/ui/elements/Panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void Panel::cropToContent() {
void Panel::fullRefresh() {
refresh();
cropToContent();
reposition();
Container::fullRefresh();
}

Expand Down

0 comments on commit 85600ea

Please sign in to comment.