inital commit
commit
e73208a4d3
|
@ -0,0 +1,7 @@
|
|||
Copyright 2019 Pascal Abresch
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,2 @@
|
|||
Api:
|
||||
notify.hud.sendtext(mt_player player, string text, optional int timeout)
|
|
@ -0,0 +1,38 @@
|
|||
notify = notify or {}
|
||||
notify.hud = notify.hud or {}
|
||||
|
||||
-- the only API gurantee is that notify.hud.sendtext(mt_player player, string text, optional int timeout) is available
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
--register the hud elements to use later
|
||||
--this is a simple implementation, so just one
|
||||
|
||||
local hud_fg = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x=0.5,y=0.8 },
|
||||
text = "",
|
||||
direction = 0,
|
||||
number = "0xFFFFFF"
|
||||
})
|
||||
player:get_meta():set_int("notify_fg", hud_fg)
|
||||
end)
|
||||
|
||||
notify.hud.sendtext = function(player, text, timeout)
|
||||
if not player then return end
|
||||
if not text then return end
|
||||
if timeout <= 0 or not timeout then timeout = 1 end
|
||||
minetest.after(1, notify.hud.timeout, player)
|
||||
player:get_meta():set_int("time_left", timeout)
|
||||
player:hud_change(player:get_meta():get_int("notify_fg"), "text", text)
|
||||
end
|
||||
|
||||
notify.hud.timeout = function(player) -- checks whether player timed out yet
|
||||
if not player then return end
|
||||
local timeout = player:get_meta():get_int("time_left")
|
||||
timeout = timeout -1
|
||||
if timeout <= 0 then
|
||||
player:hud_change(player:get_meta():get_int("notify_fg"), "text", "")
|
||||
else
|
||||
player:get_meta():set_int("time_left", timeout)
|
||||
minetest.after(1, notify.hud.timeout, player)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue