techage/basis/guide.lua

135 lines
3.4 KiB
Lua
Raw Normal View History

--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
Construction Guide
]]--
-- Load support for intllib.
local MP = minetest.get_modpath("techage")
local S, NS = dofile(MP.."/intllib.lua")
local Recipes = {}
local RecipeList = {}
local PlanImages = {}
local NamesAsStr = ""
-- formspec images
local function plan(images)
local tbl = {}
if images == "none" then return "label[1,3;No plan available" end
for y=1,#images do
for x=1,#images[1] do
local img = images[y][x] or false
if img ~= false then
local x_offs, y_offs = (x-1) * 1, (y-1) * 1 + 0.8
tbl[#tbl+1] = "image["..x_offs..","..y_offs..";1,1;"..img..".png]"
end
end
end
return table.concat(tbl)
end
local function formspec_help(idx)
return "size[9,9]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"tabheader[0,0;tab;"..S("Help,Plan")..";1;;true]"..
"table[0.1,0;8.6,3;page;"..NamesAsStr..";"..idx.."]"..
"textarea[0.3,3.7;9,6.2;help;Help:;"..Recipes[idx].."]"
end
local function formspec_plan(idx)
return "size[9,9]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"tabheader[0,0;tab;"..S("Help,Plan")..";2;;true]"..
"label[0,0;"..RecipeList[idx]..":]"..
plan(PlanImages[idx])
end
local board_box = {
type = "wallmounted",
--wall_top = {-8/16, 15/32, -6/16, 8/16, 8/16, 6/16},
--wall_bottom = {-8/16, 15/32, -6/16, 8/16, 8/16, 6/16},
wall_side = {-16/32, -11/32, -16/32, -15/32, 6/16, 8/16},
}
minetest.register_node("techage:constr_board", {
description = S("TA Construction Board"),
inventory_image = 'techage_constr_plan_inv.png',
tiles = {"techage_constr_plan.png"},
drawtype = "nodebox",
node_box = board_box,
selection_box = board_box,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", formspec_help(1))
end,
on_receive_fields = function(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
return
end
local meta = minetest.get_meta(pos)
local idx = meta:get_int("help_idx")
idx = techage.range(idx, 1, #Recipes)
if fields.tab == "1" then
meta:set_string("formspec", formspec_help(idx))
elseif fields.tab == "2" then
meta:set_string("formspec", formspec_plan(idx))
elseif fields.page then
local evt = minetest.explode_table_event(fields.page)
if evt.type == "CHG" then
local idx = tonumber(evt.row)
idx = techage.range(idx, 1, #Recipes)
meta:set_int("help_idx", idx)
meta:set_string("formspec", formspec_help(idx))
end
end
end,
paramtype2 = "wallmounted",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:constr_board",
recipe = {
{"default:sticks", "default:sticks", "default:sticks"},
{"default:paper", "default:paper", "default:paper"},
{"", "", ""},
},
})
function techage.register_help_page(name, text, images)
RecipeList[#RecipeList+1] = name
NamesAsStr = table.concat(RecipeList, ", ") or ""
Recipes[#Recipes+1] = text
PlanImages[#PlanImages+1] = images or "none"
end
function techage.register_chap_page(name, text)
RecipeList[#RecipeList+1] = name
NamesAsStr = table.concat(RecipeList, ",") or ""
Recipes[#Recipes+1] = text
PlanImages[#PlanImages+1] = "none"
end