forked from Sokomine/travelnet
-
Notifications
You must be signed in to change notification settings - Fork 12
/
formspecs-legacy.lua
104 lines (85 loc) · 3.25 KB
/
formspecs-legacy.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local travelnet_form_name = "travelnet:show"
local player_formspec_data = travelnet.player_formspec_data
-- minetest.chat_send_player is sometimes not so well visible
function travelnet.show_message(pos, player_name, title, message)
if not pos or not player_name or not message then
return
end
local formspec = travelnet.formspecs.error_message({
title = title,
message = message
})
travelnet.show_formspec(player_name, formspec)
end
-- show the player the formspec they would see when right-clicking the node;
-- needs to be simulated this way as calling on_rightclick would not do
function travelnet.show_current_formspec(pos, meta, player_name)
player_formspec_data[player_name] = player_formspec_data[player_name] or {}
player_formspec_data[player_name].pos = pos
local node = minetest.get_node(pos)
travelnet.show_formspec(player_name,
travelnet.formspecs.current({
station_network = meta:get_string("station_network"),
station_name = meta:get_string("station_name"),
owner_name = meta:get_string("owner"),
is_elevator = travelnet.is_elevator(node.name)
}, player_name))
end
-- a player clicked on something in the formspec hse was manually shown
-- (back from help page, moved travelnet up or down etc.)
function travelnet.form_input_handler(player, formname, fields)
if formname ~= travelnet_form_name then return end
if not player then return end
local name = player:get_player_name()
player_formspec_data[name] = player_formspec_data[name] or {}
local pos = player_formspec_data[name].pos
return travelnet.on_receive_fields(pos, nil, fields, player)
end
-- most formspecs the travelnet uses are stored in the travelnet node itself,
-- but some may require some "back"-button functionality (i.e. help page,
-- move up/down etc.)
minetest.register_on_player_receive_fields(travelnet.form_input_handler)
function travelnet.reset_formspec()
minetest.log("warning",
"[travelnet] the travelnet.reset_formspec method is deprecated. "..
"Run meta:set_string('station_network', '') to reset the travelnet.")
end
function travelnet.edit_formspec(pos, meta, player_name)
if not pos or not meta or not player_name then
return
end
local node = minetest.get_node_or_nil(pos)
if not node then return end
if travelnet.is_elevator(node.name) then
return travelnet.edit_formspec_elevator(pos, meta, player_name)
end
-- request changed data
local formspec = travelnet.formspecs.edit_travelnet({
owner_name = meta:get_string("owner"),
station_network = meta:get_string("station_network"),
station_name = meta:get_string("station_name")
}, player_name)
-- show the formspec manually
travelnet.show_formspec(player_name, formspec)
end
function travelnet.edit_formspec_elevator(pos, meta, player_name)
if not pos or not meta or not player_name then
return
end
-- request changed data
local formspec = travelnet.formspecs.edit_elevator(
{ station_name = meta:get_string("station_name") },
player_name
)
-- show the formspec manually
travelnet.show_formspec(player_name, formspec)
end
function travelnet.show_formspec(player_name, formspec)
if formspec and formspec ~= "" then
minetest.show_formspec(player_name, travelnet_form_name, formspec)
return true
else
minetest.show_formspec(player_name, "", "")
return false
end
end