Horrible Workaround for messages sometimes failing to be moved with hud_changed
This commit is contained in:
parent
2acee63353
commit
8b773dbd36
86
init.lua
86
init.lua
@ -5,40 +5,60 @@ cmsg.active_messages = {}
|
|||||||
cmsg.default_color = 0xFFFFFF
|
cmsg.default_color = 0xFFFFFF
|
||||||
|
|
||||||
cmsg.push_message_player = function(player, text, color)
|
cmsg.push_message_player = function(player, text, color)
|
||||||
local pname = player:get_player_name()
|
local function push(tbl)
|
||||||
if color == nil then color = cmsg.default_color end
|
-- Horrible Workaround code starts here
|
||||||
if cmsg.hudids[pname] == nil then
|
if not (cmsg.last_push < cmsg.steps) then
|
||||||
cmsg.hudids[pname] = {}
|
minetest.after(0, push, tbl)
|
||||||
cmsg.active_messages[pname] = 0
|
return
|
||||||
else
|
end
|
||||||
-- move older HUD IDs up
|
|
||||||
for hudid,tbl in pairs(cmsg.hudids[pname]) do
|
local player = tbl.player
|
||||||
minetest.after(0, function()
|
local text = tbl.text
|
||||||
|
local color = tbl.color
|
||||||
|
-- Horrible Workaround code ends here
|
||||||
|
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
if color == nil then color = cmsg.default_color end
|
||||||
|
if cmsg.hudids[pname] == nil then
|
||||||
|
cmsg.hudids[pname] = {}
|
||||||
|
cmsg.active_messages[pname] = 0
|
||||||
|
else
|
||||||
|
-- move older HUD IDs up
|
||||||
|
for hudid,tbl in pairs(cmsg.hudids[pname]) do
|
||||||
tbl.stackpos = tbl.stackpos + 1
|
tbl.stackpos = tbl.stackpos + 1
|
||||||
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
|
player:hud_change(hudid, "offset", {x=0,y=-128-(18*tbl.stackpos)})
|
||||||
end)
|
end
|
||||||
end
|
end
|
||||||
|
local hudid = player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
text = text,
|
||||||
|
number = color,
|
||||||
|
position = {x=0.5, y=0.5},
|
||||||
|
offset = {x=0,y=-128},
|
||||||
|
direction = 0,
|
||||||
|
alignment = {x=0,y=0},
|
||||||
|
scale = {x=300,y=18},
|
||||||
|
})
|
||||||
|
|
||||||
|
cmsg.hudids[pname][hudid] = {stackpos=0}
|
||||||
|
cmsg.active_messages[pname] = cmsg.active_messages[pname] + 1
|
||||||
|
|
||||||
|
minetest.after(5, function(param)
|
||||||
|
local pname = param.player:get_player_name()
|
||||||
|
param.player:hud_remove(param.hudid)
|
||||||
|
cmsg.hudids[pname][param.hudid] = nil
|
||||||
|
cmsg.active_messages[pname] = cmsg.active_messages[pname] - 1
|
||||||
|
end, {player=player, hudid = hudid})
|
||||||
|
|
||||||
|
-- Update timer for Horrible Workaround
|
||||||
|
cmsg.last_push = cmsg.steps
|
||||||
end
|
end
|
||||||
local hudid = player:hud_add({
|
|
||||||
hud_elem_type = "text",
|
|
||||||
text = text,
|
|
||||||
number = color,
|
|
||||||
position = {x=0.5, y=0.5},
|
|
||||||
offset = {x=0,y=-128},
|
|
||||||
direction = 0,
|
|
||||||
alignment = {x=0,y=0},
|
|
||||||
scale = {x=300,y=18},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmsg.hudids[pname][hudid] = {stackpos=0}
|
if cmsg.last_push < cmsg.steps then
|
||||||
cmsg.active_messages[pname] = cmsg.active_messages[pname] + 1
|
push({player=player, text=text, color=color})
|
||||||
|
else
|
||||||
minetest.after(5, function(param)
|
minetest.after(0, push, {player=player, text=text, color=color})
|
||||||
local pname = param.player:get_player_name()
|
end
|
||||||
param.player:hud_remove(param.hudid)
|
|
||||||
cmsg.hudids[pname][param.hudid] = nil
|
|
||||||
cmsg.active_messages[pname] = cmsg.active_messages[pname] - 1
|
|
||||||
end, {player=player, hudid = hudid})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
cmsg.push_message_all = function(text, color)
|
cmsg.push_message_all = function(text, color)
|
||||||
@ -51,3 +71,11 @@ end
|
|||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
cmsg.hudids[player:get_player_name()] = nil
|
cmsg.hudids[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Horrible Workaround code starts here
|
||||||
|
cmsg.steps = 0
|
||||||
|
cmsg.last_push = -1
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
cmsg.steps = cmsg.steps + 1
|
||||||
|
end)
|
||||||
|
-- Horrible Workaround code ends here
|
||||||
|
Loading…
Reference in New Issue
Block a user