mirror of
https://github.com/tacigar/maidroid.git
synced 2025-01-10 08:10:17 +01:00
[ADD] Nametag
This commit is contained in:
parent
8198cd9620
commit
6d8e4b662d
@ -145,6 +145,8 @@ end) ()
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
||||
local formspec_opened_selves = {}
|
||||
|
||||
-- maidroid.register_core registers a definition of a new core.
|
||||
function maidroid.register_core(core_name, def)
|
||||
maidroid.registered_cores[core_name] = def
|
||||
@ -181,7 +183,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
|
||||
-- create_inventory creates a new inventory, and returns it.
|
||||
local function create_inventory(self)
|
||||
self.inventory_name = self.product_name .. tostring(self.manufacturing_number)
|
||||
self.inventory_name = self.product_name .. "_" .. tostring(self.manufacturing_number)
|
||||
local inventory = minetest.create_detached_inventory(self.inventory_name, {
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
if listname == "core" then
|
||||
@ -222,12 +224,18 @@ function maidroid.register_maidroid(product_name, def)
|
||||
|
||||
-- create_formspec_string returns a string that represents a formspec definition.
|
||||
local function create_formspec_string(self)
|
||||
local nametag = self.object:get_nametag_attributes().text
|
||||
return "size[8,9]"
|
||||
.. default.gui_bg
|
||||
.. default.gui_bg_img
|
||||
.. default.gui_slots
|
||||
.. "list[detached:"..self.inventory_name..";main;0,0;4,4;]"
|
||||
.. "label[5,0;core]"
|
||||
.. "list[detached:"..self.inventory_name..";core;6,0;1,1;]"
|
||||
.. "label[5.5,1;core]"
|
||||
.. "list[detached:"..self.inventory_name..";core;5.5,1.5;1,1;]"
|
||||
.. "list[current_player;main;0,5;8,1;]"
|
||||
.. "list[current_player;main;0,6.2;8,3;8]"
|
||||
.. "button[7,0.25;1,0.875;apply_name;Apply]"
|
||||
.. "field[4.5,0.5;2.75,1;name;name;" .. nametag .. "]"
|
||||
end
|
||||
|
||||
-- on_activate is a callback function that is called when the object is created or recreated.
|
||||
@ -236,6 +244,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
if staticdata == "" then
|
||||
self.product_name = product_name
|
||||
self.manufacturing_number = maidroid.manufacturing_data[product_name]
|
||||
self.nametag = self.inventory_name
|
||||
maidroid.manufacturing_data[product_name] = maidroid.manufacturing_data[product_name] + 1
|
||||
create_inventory(self)
|
||||
else
|
||||
@ -244,6 +253,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
|
||||
self.product_name = data["product_name"]
|
||||
self.manufacturing_number = data["manufacturing_number"]
|
||||
self.nametag = data["nametag"]
|
||||
|
||||
local inventory = create_inventory(self)
|
||||
local core_name = data["inventory"]["core"]
|
||||
@ -263,9 +273,12 @@ function maidroid.register_maidroid(product_name, def)
|
||||
end
|
||||
end
|
||||
|
||||
self.formspec_string = create_formspec_string(self)
|
||||
update_infotext(self)
|
||||
|
||||
self.object:set_nametag_attributes{
|
||||
text = self.nametag
|
||||
}
|
||||
|
||||
local core = self:get_core()
|
||||
if core ~= nil then
|
||||
core.on_start(self)
|
||||
@ -281,6 +294,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
local data = {
|
||||
["product_name"] = self.product_name,
|
||||
["manufacturing_number"] = self.manufacturing_number,
|
||||
["nametag"] = self.nametag,
|
||||
["inventory"] = {
|
||||
["main"] = {},
|
||||
["core"] = self.core_name,
|
||||
@ -308,10 +322,12 @@ function maidroid.register_maidroid(product_name, def)
|
||||
|
||||
-- on_rightclick is a callback function that is called when a player right-click them.
|
||||
local function on_rightclick(self, clicker)
|
||||
formspec_opened_selves[clicker] = self
|
||||
|
||||
minetest.show_formspec(
|
||||
clicker:get_player_name(),
|
||||
self.inventory_name,
|
||||
self.formspec_string
|
||||
"maidroid:gui",
|
||||
create_formspec_string(self)
|
||||
)
|
||||
end
|
||||
|
||||
@ -348,6 +364,7 @@ function maidroid.register_maidroid(product_name, def)
|
||||
makes_footstep_sound = true,
|
||||
automatic_face_movement_dir = 90.0,
|
||||
infotext = "",
|
||||
nametag = "",
|
||||
|
||||
-- extra initial properties
|
||||
pause = false,
|
||||
@ -387,3 +404,23 @@ function maidroid.register_maidroid(product_name, def)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "maidroid:gui" then return end
|
||||
|
||||
local self = formspec_opened_selves[player]
|
||||
|
||||
if not self then return end
|
||||
|
||||
if fields.name then
|
||||
if fields.name == "" then
|
||||
self.nametag = self.inventory_name
|
||||
else
|
||||
self.nametag = fields.name
|
||||
end
|
||||
|
||||
self.object:set_nametag_attributes{
|
||||
text = self.nametag
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
1
maidroid/depends.txt
Normal file
1
maidroid/depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default
|
Loading…
Reference in New Issue
Block a user