mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2024-11-19 22:03:55 +01:00
Update the timer in the formspec in real-time (#55)
This commit is contained in:
parent
c692fa2ed1
commit
cf6a550378
@ -69,7 +69,12 @@ minetest.register_chatcommand("tpn", {
|
||||
minetest.register_chatcommand("tpf", {
|
||||
description = S("Show all teleport requests, made by you or to you, that are still active"),
|
||||
privs = {interact = true, tp = true},
|
||||
func = tp.list_requests
|
||||
func = function(player)
|
||||
local playername = minetest.get_player_by_name(player)
|
||||
|
||||
tp.tpf_update_time[playername] = true
|
||||
tp.list_requests(playername)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tpr_mute", {
|
||||
|
@ -200,7 +200,9 @@ function tp.deny_request(id, own)
|
||||
end
|
||||
end
|
||||
|
||||
function tp.list_requests(playername)
|
||||
function tp.list_requests(player)
|
||||
local playername = player:get_player_name()
|
||||
|
||||
local sent_requests = tp.get_requests(playername, "sender")
|
||||
local received_requests = tp.get_requests(playername, "receiver")
|
||||
local area_requests = tp.get_requests(playername, "area")
|
||||
@ -277,7 +279,23 @@ function tp.list_requests(playername)
|
||||
formspec = ("size[8,%f]label[1,0.3;%s:]"):format(math.min(y,10),S("Teleport Requests"))
|
||||
..request_list_formspec
|
||||
end
|
||||
|
||||
minetest.show_formspec(playername, "teleport_request_list", formspec)
|
||||
|
||||
local function update_time()
|
||||
if formspec == "" or string.find(formspec, S("You have no requests.")) then
|
||||
tp.tpf_update_time[player] = false
|
||||
return
|
||||
end
|
||||
|
||||
if tp.tpf_update_time[player] then
|
||||
-- TODO: find a way to edit the text only and update
|
||||
-- the formspec without re-calling the function.
|
||||
tp.list_requests(player)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.after(1, update_time)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
@ -307,8 +325,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
changes = true
|
||||
end
|
||||
end
|
||||
|
||||
if changes and not fields.quit then
|
||||
tp.list_requests(playername)
|
||||
tp.tpf_update_time[player] = true
|
||||
tp.list_requests(player)
|
||||
elseif fields.quit then
|
||||
tp.tpf_update_time[player] = false
|
||||
end
|
||||
end)
|
||||
|
||||
|
9
init.lua
9
init.lua
@ -31,10 +31,11 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
tp = {
|
||||
S = S,
|
||||
tpr_list = {},
|
||||
tphr_list = {},
|
||||
tpc_list = {},
|
||||
tpn_list = {}
|
||||
tpr_list = { },
|
||||
tphr_list = { },
|
||||
tpc_list = { },
|
||||
tpn_list = { },
|
||||
tpf_update_time = { }
|
||||
}
|
||||
|
||||
-- Clear requests when the player leaves
|
||||
|
Loading…
Reference in New Issue
Block a user