123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- --[[
- boards mod for Minetest. Black boards with text on it.
- (c) Pierre-Yves Rollo
- This file is part of boards.
- boards is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- boards is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with boards. If not, see <http://www.gnu.org/licenses/>.
- --]]
- boards = {}
- boards.name = minetest.get_current_modname()
- boards.path = minetest.get_modpath(boards.name)
- -- Load support for intllib.
- local S, NS = dofile(boards.path.."/intllib.lua")
- boards.intllib = S
- local F = function(...) return minetest.formspec_escape(S(...)) end
- -- Load font
- dofile(boards.path.."/font_tinycurs.lua")
- local function set_formspec(pos)
- local meta = minetest.get_meta(pos)
- meta:set_string("formspec",
- "size[6,4]"..default.gui_bg..default.gui_bg_img..default.gui_slots..
- "textarea[0.5,0.7;5.5,3;display_text;"..F("Text")..";${display_text}]"..
- "button_exit[3,3.5;2,1;ok;"..F("Write").."]"..
- "button_exit[1,3.5;2,1;wipe;"..F("Wipe").."]")
- end
- -- On boards, everyone is allowed to write and wipe
- local function on_receive_fields(pos, formname, fields, player)
- if fields then
- if fields.ok or fields.key_enter then
- signs_api.set_display_text(pos, fields.display_text, fields.font)
- end
- if fields.wipe then
- signs_api.set_display_text(pos, "", fields.font)
- end
- end
- end
- models = {
- black_board = {
- depth = 1/16, width = 1, height = 1,
- entity_fields = {
- top = -1/32,
- size = { x = 1, y = 15/16 },
- maxlines = 5,
- color = "#fff",
- font_name = "tinycurs",
- valign = "top",
- },
- node_fields = {
- description = S("Black board"),
- tiles = { "default_wood.png", "default_wood.png",
- "default_wood.png", "default_wood.png",
- "default_wood.png", "board_black_front.png" },
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5},
- {-0.5, -7/16, 6/16, 0.5, -0.5, 7/16}
- },
- },
- on_construct = function(pos)
- set_formspec(pos)
- display_api.on_construct(pos)
- end,
- on_receive_fields = on_receive_fields,
- },
- },
- green_board = {
- depth = 1/16, width = 1, height = 1,
- entity_fields = {
- top = -1/32,
- size = { x = 1, y = 15/16 },
- maxlines = 5,
- color = "#fff",
- font_name = "tinycurs",
- valign = "top",
- },
- node_fields = {
- description = S("Green board"),
- tiles = { "default_wood.png", "default_wood.png",
- "default_wood.png", "default_wood.png",
- "default_wood.png", "board_green_front.png" },
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {
- {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5},
- {-0.5, -7/16, 6/16, 0.5, -0.5, 7/16}
- },
- },
- on_construct = function(pos)
- set_formspec(pos)
- display_api.on_construct(pos)
- end,
- on_receive_fields = on_receive_fields,
- },
- },
- }
- -- Node registration
- for name, model in pairs(models)
- do
- signs_api.register_sign("boards", name, model)
- end
- -- Recipes
- minetest.register_craft(
- {
- output = "boards:black_board",
- recipe = {
- {"group:wood", "group:stone", "dye:black"},
- }
- })
- minetest.register_craft(
- {
- output = "boards:green_board",
- recipe = {
- {"group:wood", "group:stone", "dye:dark_green"},
- }
- })
|