From 83623effbfe686e1b53986ca276c2ea4f3dfbf89 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sun, 2 Apr 2023 00:45:39 +0200 Subject: [PATCH] More HUD improvements --- src/api.lua | 2 +- src/common.lua | 1 + src/hud.lua | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api.lua b/src/api.lua index a6880b2..2122cfa 100644 --- a/src/api.lua +++ b/src/api.lua @@ -341,7 +341,7 @@ function i3.hud_notif(name, msg, img) if notif then notif.show = true notif.max.y = ((nb_notifs - i) + 1) * max_y - notif.hud_timer = 0 + notif.hud_timer = 0.5 * (nb_notifs - i) end end end diff --git a/src/common.lua b/src/common.lua index efd3c41..8fcfb91 100644 --- a/src/common.lua +++ b/src/common.lua @@ -826,6 +826,7 @@ local _ = { -- Math round = round, + abs = math.abs, min = math.min, max = math.max, ceil = math.ceil, diff --git a/src/hud.lua b/src/hud.lua index c1bc04f..5019351 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -1,4 +1,4 @@ -IMPORT("ceil", "remove", "str_to_pos") +IMPORT("abs", "max", "ceil", "remove", "str_to_pos") IMPORT("get_connected_players", "add_hud_waypoint") local function init_hud(player) @@ -29,8 +29,8 @@ local function init_hud(player) } end -local function get_progress(offset, max) - local progress = offset * (1 / (max - 5)) +local function get_progress(offset, max_val) + local progress = offset * (1 / (max_val - 5)) return 1 - (progress ^ 4) end @@ -40,7 +40,7 @@ local function show_hud(player, data, notif, idx, dt) if offset.y < notif.max.y then notif.show = false - notif.hud_timer = notif.hud_timer + dt + notif.hud_timer += dt end player:hud_change(notif.elems.text, "text", notif.hud_msg) @@ -57,7 +57,7 @@ local function show_hud(player, data, notif, idx, dt) player:hud_change(def, "offset", { x = hud_info.offset.x, - y = hud_info.offset.y - speed + y = hud_info.offset.y - (speed * max(1, (#data.hud.notifs - idx + 1) / 1.4)) }) end elseif notif.show == false and notif.hud_timer >= i3.settings.hud_timer_max then @@ -71,7 +71,7 @@ local function show_hud(player, data, notif, idx, dt) y = hud_info.offset.y }) - if offset.x > 0 then + if hud_info.offset.x > abs(notif.max.x) then player:hud_remove(def) remove(data.hud.notifs, idx) end