Fix reshowing caption on same player

If only one player is online and they are idling in
darkness, it makes the "Watching: " caption show
up too frequently.  Instead, only show the caption
when we change to a different player.
This commit is contained in:
Aaron Suen 2022-04-22 00:09:27 -04:00
parent 2f3985f1d3
commit fd41bd6a52

View File

@ -122,17 +122,19 @@ local function camcheck(player, dtime)
local data = getdata(player) local data = getdata(player)
local text = "" local text = ""
if data.target and data.tipttl then if data.target then
data.tipttl = data.tipttl - dtime text = "Watching: " .. data.target
if data.tipttl > 0 then
text = "Watching: " .. data.target
end
end end
if data.tip then if data.tip then
if text ~= data.tip.text then if text ~= data.tip.text then data.tip.time = 0 end
player:hud_change(data.tip.id, "text", text) data.tip.text = text
data.tip.text = text local show = text
if data.tip.time >= 2 then show = "" end
if data.tip.show ~= show then
player:hud_change(data.tip.id, "text", show)
data.tip.show = text
end end
data.tip.time = data.tip.time + dtime
elseif text ~= "" then elseif text ~= "" then
data.tip = { data.tip = {
id = player:hud_add({ id = player:hud_add({
@ -143,7 +145,9 @@ local function camcheck(player, dtime)
alignment = {x = 0, y = -1}, alignment = {x = 0, y = -1},
offset = {x = 0, y = -8}, offset = {x = 0, y = -8},
}), }),
text = text text = text,
show = text,
time = 0
} }
end end
@ -160,6 +164,7 @@ local function camcheck(player, dtime)
local target = data.tracktime and data.target local target = data.tracktime and data.target
target = target and minetest.get_player_by_name(target) target = target and minetest.get_player_by_name(target)
if not target then if not target then
data.target = nil
if not (data.queue and #data.queue > 0) then if not (data.queue and #data.queue > 0) then
local q = {} local q = {}
local pname = player:get_player_name() local pname = player:get_player_name()
@ -184,7 +189,6 @@ local function camcheck(player, dtime)
if not target then return camdummy(player, data, dtime) end if not target then return camdummy(player, data, dtime) end
data.dummycam = nil data.dummycam = nil
data.tipttl = 2
end end
local pos = player:get_pos() local pos = player:get_pos()