Improve Formspec
This commit is contained in:
parent
7264ebd6ad
commit
2bf00221fa
42
init.lua
42
init.lua
|
@ -1,23 +1,24 @@
|
|||
|
||||
local function get_moth_formspec()
|
||||
return "size[10,10]"
|
||||
.. "field[1,1;8,1;target;Recipent: ;]"
|
||||
.. "textarea[1,3;8,5;message;Message: ;]"
|
||||
.. "button_exit[1,8;5,1;send;Fly Away...]"
|
||||
local function get_send_formspec()
|
||||
return "formspec_version[8] size[8,7.75]"
|
||||
.. "field[0.5,0.75;7,1;target;Recipent: ;]"
|
||||
.. "textarea[0.5,2.25;7,4;message;Message: ;]"
|
||||
.. "button_exit[2,6.5;4,1;send;Fly Away...]"
|
||||
end
|
||||
|
||||
local function get_message_formspec(from, msg)
|
||||
return "size[10,10]"
|
||||
return "formspec_version[8] size[8,7.75]"
|
||||
.. "label[0.5,0.5;A moth whispers to you...]"
|
||||
.. "label[0.5,1;(From "..core.formspec_escape(from)..")".."]"
|
||||
.. "textarea[0.5,2.5;7.5,7;;" ..core.formspec_escape(msg) .. ";]"
|
||||
.. "label[0.5,1;(from "..core.formspec_escape(from)..")".."]"
|
||||
.. "textarea[1,1.5;6.5,5.75;;" ..core.formspec_escape(msg) .. ";]"
|
||||
end
|
||||
|
||||
local function get_error_formspec(msg)
|
||||
return "size[5,0.5]"
|
||||
.. "label[0,0;"..core.formspec_escape(msg).."]"
|
||||
return "formspec_version[8] size[8,1]"
|
||||
.. "label[0.5,0.5;"..core.formspec_escape(msg).."]"
|
||||
end
|
||||
|
||||
|
||||
core.register_node("moth:moth", {
|
||||
description = "Moth",
|
||||
inventory_image = "moth_img.png",
|
||||
|
@ -27,20 +28,26 @@ core.register_node("moth:moth", {
|
|||
drawtype = "plantlike",
|
||||
walkable = false,
|
||||
tiles = {{
|
||||
name = "moth.png",
|
||||
animation = { type="vertical_frames", aspect_w=16, aspect_h=16, length=1 }
|
||||
name = "moth.png",
|
||||
animation = { type="vertical_frames", aspect_w=16, aspect_h=16, length=1 }
|
||||
}},
|
||||
groups = { oddly_breakable_by_hand=2 },
|
||||
|
||||
on_use = function(itemstack, player, pointed_thing)
|
||||
core.show_formspec(player:get_player_name(), "moth_send", get_moth_formspec())
|
||||
core.show_formspec(player:get_player_name(), "moth_send", get_send_formspec())
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
local form_handlers = {}
|
||||
|
||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "moth_send" then return end
|
||||
local h = form_handlers[formname]
|
||||
if h then return h(player, formname, fields) end
|
||||
end)
|
||||
|
||||
function form_handlers.moth_send(player, formname, fields)
|
||||
if not fields.send then return end
|
||||
local success = false
|
||||
|
||||
local name = player:get_player_name()
|
||||
local target = core.get_player_by_name(fields.target)
|
||||
|
@ -65,8 +72,9 @@ core.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local player_inv = player:get_inventory()
|
||||
player_inv:remove_item("main", "moth:moth")
|
||||
|
||||
core.show_formspec(target:get_player_name(), "moth_show", get_message_formspec(name, fields.message))
|
||||
end)
|
||||
core.show_formspec(target:get_player_name(), "moth_message", get_message_formspec(name, fields.message))
|
||||
end
|
||||
|
||||
|
||||
if core.get_modpath("flowers") then
|
||||
core.override_item("flowers:dandelion_white", {
|
||||
|
|
Loading…
Reference in New Issue