diff options
author | Pierre-Yves Rollo <dev@pyrollo.com> | 2018-11-23 11:35:42 +0100 |
---|---|---|
committer | Pierre-Yves Rollo <dev@pyrollo.com> | 2018-11-23 11:35:42 +0100 |
commit | 0f8db34368378efeedc5689446fbea9017d096df (patch) | |
tree | e7363f128eec9283f88712867bcdca66918bd385 /signs_api | |
parent | db66553fbfd5f251b4a26e8b4867cebd021a5647 (diff) | |
parent | 367e5026ddef3e6a0220f37a2f4aba64ec88f16b (diff) | |
download | display_modpack-0f8db34368378efeedc5689446fbea9017d096df.tar.gz display_modpack-0f8db34368378efeedc5689446fbea9017d096df.tar.bz2 display_modpack-0f8db34368378efeedc5689446fbea9017d096df.zip |
Font chooser form added
Diffstat (limited to 'signs_api')
-rw-r--r-- | signs_api/init.lua | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/signs_api/init.lua b/signs_api/init.lua index ec3b0e9..9fcaa10 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -35,49 +35,53 @@ function signs_api.set_display_text(pos, text, font) else meta:set_string("infotext", "") end - meta:set_string("font", font) + if font then + meta:set_string("font", font) + end display_api.update_entities(pos) end function signs_api.set_formspec(pos) local meta = minetest.get_meta(pos) local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - if ndef and ndef.display_entities + if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then local maxlines = ndef.display_entities["signs:display_text"].maxlines - local formspec, formheight + local fs, y if maxlines == 1 then - formspec = - "field[0.5,0.7;5.5,1;display_text;"..F("Text").. - ";${display_text}]" - formheight = 2 + fs = "field[0.5,0.7;5.5,1;display_text;"..F("Text").. + ";${display_text}]" + y = 1.2 else local extralabel = "" if maxlines then extralabel = F(" (first %s lines only)"):format(maxlines) end - formspec = - "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. + fs = "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. extralabel..";${display_text}]" - formheight = 3 + y = 2.4 end - formspec = formspec.."button_exit[2,"..formheight..";2,1;ok;".. - F("Write").."]" - formheight = formheight + 1 - formspec = "size[6,"..formheight.."]"..default.gui_bg.. - default.gui_bg_img..default.gui_slots..formspec + fs = fs.."button[1,"..y..";2,1;font;"..F("Font").."]" + fs = fs.."button_exit[3,"..y..";2,1;ok;"..F("Write").."]" + y = y + 0.8 + fs = "size[6,"..y.."]"..default.gui_bg.. + default.gui_bg_img..default.gui_slots..fs - meta:set_string("formspec", formspec) + meta:set_string("formspec", fs) end end function signs_api.on_receive_fields(pos, formname, fields, player) if not minetest.is_protected(pos, player:get_player_name()) then if fields and (fields.ok or fields.key_enter) then - signs_api.set_display_text(pos, fields.display_text, fields.font) + signs_api.set_display_text(pos, fields.display_text) + end + if fields and (fields.font) then + signs_api.set_display_text(pos, fields.display_text) + font_api.show_font_list(player, pos) end end end @@ -183,7 +187,8 @@ function signs_api.register_sign(mod, name, model) on_destruct = display_api.on_destruct, on_rotate = signs_api.on_rotate, on_receive_fields = signs_api.on_receive_fields, - on_punch = function(pos, node, player, pointed_thing) + on_punch = function(pos, node, player, pointed_thing) + signs_api.set_formspec(pos) display_api.update_entities(pos) end, } @@ -211,7 +216,3 @@ end -- Text entity for all signs display_api.register_display_entity("signs:display_text") - - - - |