From 7e72af629252db26347a5248c9fdd370739dd16d Mon Sep 17 00:00:00 2001 From: webdesigner97 Date: Tue, 15 Oct 2013 14:28:42 +0200 Subject: Finished code --- roadsigns/workshop.lua | 76 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/roadsigns/workshop.lua b/roadsigns/workshop.lua index 283d2b4..5ee1af5 100644 --- a/roadsigns/workshop.lua +++ b/roadsigns/workshop.lua @@ -1,28 +1,48 @@ --[[ StreetsMod: Create signs in the signworkshop ]] +local forms = { + inactive = { + "size[12,10]", + "label[3.5,0;Sign workshop - Create signs for your roads!]", + "label[0,0.5;Available signs:]", + "list[context;streets:signworkshop_list;0,1;5,4]", + "label[9,0.5;Needed stuff:]", + "list[context;streets:signworkshop_recipe;8,1;4,1]", + "label[9,2;Put it here:]", + "list[context;streets:signworkshop_input;8,3;4,1]", + "button[8,4;2,1;streets:signworkshop_send;Start!]", + "label[5.8,0.5;Selected:]", + "list[context;streets:signworkshop_select;6,1;1,1]", + "label[5.8,2.5;Output:]", + "list[context;streets:signworkshop_output;6,3;1,1]", + "list[current_player;main;2,6;8,4]", + }, + active = { + "size[12,10]", + "label[3.5,0;Sign workshop - Create signs for your roads!]", + "label[0,0.5;Available signs:]", + "list[context;streets:signworkshop_list;0,1;5,4]", + "label[9,0.5;Needed stuff:]", + "list[context;streets:signworkshop_recipe;8,1;4,1]", + "label[9,2;Put it here:]", + "list[context;streets:signworkshop_input;8,3;4,1]", + "label[5.8,0.5;Selected:]", + "list[context;streets:signworkshop_select;6,1;1,1]", + "label[5.8,2.5;Output:]", + "list[context;streets:signworkshop_output;6,3;1,1]", + "list[current_player;main;2,6;8,4]", + "label[8,4;Please wait...]", + } +} minetest.register_node(":streets:signworkshop",{ description = "Sign workshop", tiles = {}, groups = {cracky = 1, level = 2}, after_place_node = function(pos) - minetest.get_meta(pos):set_string("formspec",table.concat({ - "size[12,10]", - "label[3.5,0;Sign workshop - Create signs for your roads!]", - "label[0,0.5;Available signs:]", - "list[context;streets:signworkshop_list;0,1;5,4]", - "label[9,0.5;Needed stuff:]", - "list[context;streets:signworkshop_recipe;8,1;4,1]", - "label[9,2;Put it here:]", - "list[context;streets:signworkshop_input;8,3;4,1]", - "button[8,4;2,1;streets:signworkshop_send;Start!]", - "label[5.8,0.5;Selected:]", - "list[context;streets:signworkshop_select;6,1;1,1]", - "label[5.8,2.5;Output:]", - "list[context;streets:signworkshop_output;6,3;1,1]", - "list[current_player;main;2,6;8,4]", - })) - local inv = minetest.get_inventory({type = "node", pos = pos}) + minetest.get_meta(pos):set_string("formspec",table.concat(forms.inactive)) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() inv:set_size("streets:signworkshop_list",5*4) inv:set_size("streets:signworkshop_recipe",3*2) inv:set_size("streets:signworkshop_input",4*1) @@ -33,6 +53,9 @@ minetest.register_node(":streets:signworkshop",{ inv:add_item("streets:signworkshop_list","streets:sign_lava") inv:add_item("streets:signworkshop_list","streets:sign_water") inv:add_item("streets:signworkshop_list","streets:sign_construction") + -- Meta + meta:set_string("infotext","Sign workshop idle") + meta:set_string("idle","y") end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) if listname ~= "streets:signworkshop_input" then @@ -70,9 +93,10 @@ minetest.register_node(":streets:signworkshop",{ end end, on_receive_fields = function(pos, formname, fields, sender) - local inv = minetest.get_inventory({type = "node", pos = pos}) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() -- - if inv:is_empty("streets:signworkshop_input") ~= true and inv:is_empty("streets:signworkshop_select") ~= true then + if inv:is_empty("streets:signworkshop_input") ~= true and inv:is_empty("streets:signworkshop_select") ~= true and meta:get_string("idle") == "y" then local selection = inv:get_stack("streets:signworkshop_select",1):get_name() local def = minetest.registered_nodes[selection].streets.signworkshop local need = inv:get_list("streets:signworkshop_recipe") @@ -94,7 +118,19 @@ minetest.register_node(":streets:signworkshop",{ if has[3] == nil then has[3] = { name = "" } end if has[4] == nil then has[4] = { name = "" } end if need[1].name == has[1].name and need[2].name == has[2].name and need[3].name == has[3].name and need[4].name == has[4].name then - minetest.chat_send_all("yay") + meta:set_string("infotext","Sign workshop working") + meta:set_string("idle","n") + meta:set_string("formspec",table.concat(forms.active)) + -- Clear input + inv:set_list("streets:signworkshop_input",{"","","",""}) + minetest.after(def.time,function() + -- Reset infotext and meta + meta:set_string("infotext","Sign workshop idle") + meta:set_string("idle","y") + meta:set_string("formspec",table.concat(forms.inactive)) + -- Fill output + inv:add_item("streets:signworkshop_output",selection) + end) end end end -- cgit v1.2.3