Add some sort of config.

master
None 2015-01-31 03:01:57 +03:00
parent 184ee45ca3
commit 10b5f716d5
3 changed files with 18 additions and 36 deletions

View File

@ -1,7 +1,3 @@
-- TODO
INVENTORY_W = 8
INVENTORY_H = 4
containers = {
["containers:chest"] = { w = 8, h = 4 },
["containers:chest_locked"] = { w = 8, h = 4 },
@ -27,18 +23,17 @@ local function get_container_formspec(pos, name)
local label = minetest.registered_nodes[name].description
-- Calculate formspec width and height
local form_w = math.max(INVENTORY_W, w)
local form_h = INVENTORY_H + h + 1
local form_w = math.max(inventory.width, w)
local form_h = inventory.height + h + 1
-- Calculate offset for container inventory
local x_offset = (INVENTORY_W - w)/2
local x_offset = (inventory.width - w)/2
local y_offset = containers.y_offset
-- Calculate player inventory position,
-- player hotbar position and "Inventory" label position
local inv_y = h + y_offset + containers.inventory_margin
local label_y = inv_y - y_offset - 0.4
local hb_y = inv_y + INVENTORY_H - 1 + containers.hotbar_margin
-- Construct formspec string
local formspec =
@ -52,14 +47,7 @@ local function get_container_formspec(pos, name)
x_offset..","..y_offset..";"..
w..","..h..
";]"..
"list[current_player;main;"..
"0,"..inv_y..";"..
INVENTORY_W..","..(INVENTORY_H-1)..
";]"..
"list[current_player;main;"..
"0,"..hb_y..";"..
INVENTORY_W..",1;24]"..
default.get_hotbar_bg(0,hb_y)
inventory.main(0, inv_y)
return formspec
end

View File

@ -24,17 +24,6 @@ function default.get_hotbar_bg(x,y)
return out
end
default.gui_suvival_form = "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"list[current_player;craft;1.75,0.5;3,3;]"..
"list[current_player;craftpreview;5.75,1.5;1,1;]"..
"image[4.75,1.5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
default.get_hotbar_bg(0,4.25)
-- Load files
dofile(minetest.get_modpath("default").."/functions.lua")
dofile(minetest.get_modpath("default").."/nodes.lua")

View File

@ -1,5 +1,8 @@
inventory = {}
inventory.width = 9
inventory.height = 1
minetest.register_chatcommand("inv_test", {
func = function()
-- Called when command is run.
@ -13,11 +16,11 @@ minetest.register_on_newplayer(function(player)
local invref = player:get_inventory()
-- Main list
invref:set_size("main", 9)
invref:set_size("main", inventory.width * inventory.height)
-- Wear list, for clothes
invref:set_list("wear", {})
invref:set_size("wear", 27)
invref:set_size("wear", inventory.width * 3)
-- Left and right hand (is this needed?)
--invref:set_list("left_hand", {})
@ -57,9 +60,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
print("For debug (from inventory mod) inv. fields:",dump(fields))
end)
inventory.base =
"size[9,5]"..
"size[" ..inventory.width.. "," ..(inventory.height + 4).. "]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
@ -67,25 +69,28 @@ inventory.base =
"button[3.25,4.9;2.5,0.1;wear_inv;Clothes]"..
"button[6.25,4.9;2.5,0.1;notes_inv;Notes]"
inventory.main = function(x,y)
return "list[current_player;main;"..
x.. "," ..y.. ";"..
inventory.width.. "," ..inventory.height.. ";]"
end
inventory.craft =
inventory.base..
-- Craft
"list[current_player;craft;2,0;3,3;]"..
"image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"list[current_player;craftpreview;6,1;1,1;]"..
inventory.main(0,3.5)
-- Left and right hand
--"list[current_player;left_hand;0.25,1;1,1;]"..
--"list[current_player;right_hand;7.75,1;1,1;]"..
-- Main inventory
"list[current_player;main;0,3.5;9,1;]"
inventory.wear =
inventory.base..
"list[current_player;wear;0,0;9,3;]"..
"list[current_player;main;0,3.5;9,1;]"
inventory.main(0,3.5)
inventory.notes =
inventory.base..