Buff chest sizes
authorZefram <zefram@fysh.org>
Fri, 20 Jun 2014 17:46:57 +0000 (18:46 +0100)
committerRealBadAngel <maciej.kasatkin@o2.pl>
Fri, 27 Jun 2014 16:48:10 +0000 (18:48 +0200)
Make the inventory sizes of all the technic chests larger, to provide
a more appreciable benefit from upgrading chests, more in keeping with
the resources spent on the upgrades.

Currently the game engine doesn't handle large forms well.  The size
of an inventory slot is fixed relative to the screen height, and a
form that exceeds either screen dimension will extend off the screen,
making parts of it inaccessible.  The tallest a form can get and remain
usable is 13 slots, and even that slightly overspills the screen height.
The maximum usable width depends on the screen aspect ratio.  For the
narrowest common ratio, 5:4, the widest a form can usably get is 15 slots,
again slightly overspilling.  Combined with the layout of the chest forms,
this implies a maximum practical chest inventory size of 15x7 (= 105),
slightly smaller than the largest Minecraft chests.

To provide roughly equal size steps in the five upgrades from wooden
chest (staying at 8x4 = 32) to mithril chest, the steps need to be of
about 15 slots instead of the former 4.  The new sizes are:

    wooden   8x4  32
    iron     9x5  45
    copper  12x5  60
    silver  12x6  72
    gold    15x6  90
    mithril 15x7 105

To make upgrading from the old chest sizes to the new sizes more
convenient, the inventory size is now set not only upon chest construction
but also when accepting form input, at the same time as rewriting
the formspec.  So after upgrading the technic mod, viewing an existing
chest upgrades it to the new size.  The first time a pre-existing chest
is viewed its form will have the old dimensions, looking broken due
to the inventory background image now having the new number of slots.
The second time it is viewed the form will have the new dimensions,
and the full new number of slots will be usable.

12 files changed:
technic_chests/copper_chest.lua
technic_chests/gold_chest.lua
technic_chests/iron_chest.lua
technic_chests/mithril_chest.lua
technic_chests/register.lua
technic_chests/silver_chest.lua
technic_chests/textures/technic_copper_chest_inventory.png
technic_chests/textures/technic_gold_chest_inventory.png
technic_chests/textures/technic_iron_chest_inventory.png
technic_chests/textures/technic_mithril_chest_inventory.png
technic_chests/textures/technic_silver_chest_inventory.png
technic_chests/textures/technic_wooden_chest_inventory.png

index 21f056334b3bbe93a94321cb7340320bed61bb9c..2d58379b1f80065a026f8de65b4a3cd73b556efe 100644 (file)
@@ -25,7 +25,8 @@ minetest.register_craft({
 })
 
 technic.chests:register("Copper", {
-       width = 10,
+       width = 12,
+       height = 5,
        sort = true,
        autosort = true,
        infotext = false,
@@ -34,7 +35,8 @@ technic.chests:register("Copper", {
 })
 
 technic.chests:register("Copper", {
-       width = 10,
+       width = 12,
+       height = 5,
        sort = true,
        autosort = true,
        infotext = false,
index 941834de8ab26e8d06ec7351a86a78fd667b28dc..386d1c7486d7f50954b12d481bb039427711428e 100644 (file)
@@ -26,7 +26,8 @@ minetest.register_craft({
 })
 
 technic.chests:register("Gold", {
-       width = 12,
+       width = 15,
+       height = 6,
        sort = true,
        autosort = true,
        infotext = true,
@@ -35,7 +36,8 @@ technic.chests:register("Gold", {
 })
 
 technic.chests:register("Gold", {
-       width = 12,
+       width = 15,
+       height = 6,
        sort = true,
        autosort = true,
        infotext = true,
index a1f5c6358992899315b1f0a5903f36ed9649e5c3..aa025338e8266a6d6bff85dd17dbb11414397318 100644 (file)
@@ -27,6 +27,7 @@ minetest.register_craft({
 
 technic.chests:register("Iron", {
        width = 9,
+       height = 5,
        sort = true,
        autosort = false,
        infotext = false,
@@ -36,6 +37,7 @@ technic.chests:register("Iron", {
 
 technic.chests:register("Iron", {
        width = 9,
+       height = 5,
        sort = true,
        autosort = false,
        infotext = false,
index f5aa986434c3a4a5738fc8d185ffeed5ee5343b8..8fb7baa3f6b371d736bb799d42f3f036614e5d02 100644 (file)
@@ -25,7 +25,8 @@ minetest.register_craft({
 })
 
 technic.chests:register("Mithril", {
-       width = 13,
+       width = 15,
+       height = 7,
        sort = true,
        autosort = true,
        infotext = false,
@@ -34,7 +35,8 @@ technic.chests:register("Mithril", {
 })
 
 technic.chests:register("Mithril", {
-       width = 13,
+       width = 15,
+       height = 7,
        sort = true,
        autosort = true,
        infotext = false,
index cec5e92e5e466401632da66a8b4b45761f7adf99..7f175f19b677c6010724c365073b2c7e844dad14 100644 (file)
@@ -31,13 +31,13 @@ local function colorid_to_postfix(id)
 end
 
 
-local function get_color_buttons()
+local function get_color_buttons(loleft, lotop)
        local buttons_string = ""
        for y = 0, 3 do
                for x = 0, 3 do
                        local file_name = "technic_colorbutton"..(y * 4 + x)..".png"
                        buttons_string = buttons_string.."image_button["
-                               ..(8.1 + x * 0.7)..","..(6.1 + y * 0.7)
+                               ..(loleft + 8.1 + x * 0.7)..","..(lotop + 0.1 + y * 0.7)
                                ..";0.8,0.8;"..file_name..";color_button"
                                ..(y * 4 + x + 1)..";]"
                end
@@ -60,20 +60,25 @@ local function set_formspec(pos, data, page)
        local meta = minetest.get_meta(pos)
        local node = minetest.get_node(pos)
        local formspec = data.formspec
+       local lowidth = data.color and 11 or 8
+       local ovwidth = math.max(lowidth, data.width)
+       local hileft = (ovwidth - data.width) / 2
+       local loleft = (ovwidth - lowidth) / 2
+       local lotop = data.height + 2
        if data.autosort then
                local status = meta:get_int("autosort")
-               formspec = formspec.."button[2,5.1;3,0.8;autosort_to_"..(1-status)..";"..S("Auto-sort is %s"):format(status == 1 and S("On") or S("Off")).."]"
+               formspec = formspec.."button["..(hileft+2)..","..(data.height+1.1)..";3,0.8;autosort_to_"..(1-status)..";"..S("Auto-sort is %s"):format(status == 1 and S("On") or S("Off")).."]"
        end
        if data.infotext then
                local formspec_infotext = minetest.formspec_escape(meta:get_string("infotext"))
                if page == "main" then
-                       formspec = formspec.."image_button[2.1,0.1;0.8,0.8;"
+                       formspec = formspec.."image_button["..(hileft+2.1)..",0.1;0.8,0.8;"
                                        .."technic_pencil_icon.png;edit_infotext;]"
-                                       .."label[3,0;"..formspec_infotext.."]"
+                                       .."label["..(hileft+3)..",0;"..formspec_infotext.."]"
                elseif page == "edit_infotext" then
-                       formspec = formspec.."image_button[2.1,0.1;0.8,0.8;"
+                       formspec = formspec.."image_button["..(hileft+2.1)..",0.1;0.8,0.8;"
                                        .."technic_checkmark_icon.png;save_infotext;]"
-                                       .."field[3.3,0.2;4.8,1;"
+                                       .."field["..(hileft+3.3)..",0.2;4.8,1;"
                                        .."infotext_box;"..S("Edit chest description:")..";"
                                        ..formspec_infotext.."]"
                end
@@ -86,7 +91,7 @@ local function set_formspec(pos, data, page)
                else
                        colorName = S("None")
                end
-               formspec = formspec.."label[8.2,9;"..S("Color Filter: %s"):format(colorName).."]"
+               formspec = formspec.."label["..(loleft+8.2)..","..(lotop+3)..";"..S("Color Filter: %s"):format(colorName).."]"
        end
        meta:set_string("formspec", formspec)
 end
@@ -160,6 +165,7 @@ local function get_receive_fields(name, data)
                        local nn = "technic:"..lname..(data.locked and "_locked" or "").."_chest"
                        check_color_buttons(pos, meta, nn, fields)
                end
+               meta:get_inventory():set_size("main", data.width * data.height)
                set_formspec(pos, data, page)
        end
 end
@@ -169,22 +175,27 @@ function technic.chests:register(name, data)
        local lname = name:lower()
        name = S(name)
 
-       local width = math.max(data.color and 11 or 8, data.width)
+       local lowidth = data.color and 11 or 8
+       local ovwidth = math.max(lowidth, data.width)
+       local hileft = (ovwidth - data.width) / 2
+       local loleft = (ovwidth - lowidth) / 2
+       local lotop = data.height + 2
+       local ovheight = lotop + 4
 
        local locked_after_place = nil
        local front = {"technic_"..lname.."_chest_front.png"}
-       data.formspec = "invsize["..width..",10;]"..
+       data.formspec = "invsize["..ovwidth..","..ovheight..";]"..
                        "label[0,0;"..S("%s Chest"):format(name).."]"..
-                       "list[current_name;main;0,1;"..width..",4;]"..
-                       "list[current_player;main;0,6;8,4;]"..
-                       "background[-0.19,-0.25;"..width..".4,10.75;ui_form_bg.png]"..
-                       "background[0,1;"..width..",4;technic_"..lname.."_chest_inventory.png]"..
-                       "background[0,6;8,4;ui_main_inventory.png]"
+                       "list[current_name;main;"..hileft..",1;"..data.width..","..data.height..";]"..
+                       "list[current_player;main;"..loleft..","..lotop..";8,4;]"..
+                       "background[-0.19,-0.25;"..(ovwidth+0.4)..","..(ovheight+0.75)..";ui_form_bg.png]"..
+                       "background["..hileft..",1;"..data.width..","..data.height..";technic_"..lname.."_chest_inventory.png]"..
+                       "background["..loleft..","..lotop..";8,4;ui_main_inventory.png]"
        if data.sort then
-               data.formspec = data.formspec.."button[0,5.1;1,0.8;sort;"..S("Sort").."]"
+               data.formspec = data.formspec.."button["..hileft..","..(data.height+1.1)..";1,0.8;sort;"..S("Sort").."]"
        end
        if data.color then
-               data.formspec = data.formspec..get_color_buttons()
+               data.formspec = data.formspec..get_color_buttons(loleft, lotop)
        end
 
        if data.locked then
@@ -221,7 +232,7 @@ function technic.chests:register(name, data)
                        meta:set_string("infotext", S("%s Chest"):format(name))
                        set_formspec(pos, data, "main")
                        local inv = meta:get_inventory()
-                       inv:set_size("main", data.width * 4)
+                       inv:set_size("main", data.width * data.height)
                end,
                can_dig = self.can_dig,
                on_receive_fields = get_receive_fields(name, data),
index 75b33f829bf1138c5f3f196c033b0140d8100861..0370488961d1f16c47371f95049093dd530df36e 100644 (file)
@@ -25,7 +25,8 @@ minetest.register_craft({
 })
 
 technic.chests:register("Silver", {
-       width = 11,
+       width = 12,
+       height = 6,
        sort = true,
        autosort = true,
        infotext = true,
@@ -34,7 +35,8 @@ technic.chests:register("Silver", {
 })
 
 technic.chests:register("Silver", {
-       width = 11,
+       width = 12,
+       height = 6,
        sort = true,
        autosort = true,
        infotext = true,
index 273a867967a659b3b8c08b0ebb105eb386778c7a..70da5108123a58299d67229d1259c1cb0a0908cf 100644 (file)
Binary files a/technic_chests/textures/technic_copper_chest_inventory.png and b/technic_chests/textures/technic_copper_chest_inventory.png differ
index b19524b3f6d0fdc9af23a70e621942af96be01a7..d4aa8b30bd8f9b791453c8982265909787c37c35 100644 (file)
Binary files a/technic_chests/textures/technic_gold_chest_inventory.png and b/technic_chests/textures/technic_gold_chest_inventory.png differ
index 1785f888b045ae3b0fbcb627f6f5f7ae0ae3d9b0..a33967bdfa78fb899b6eb36c84a09326218e60a5 100644 (file)
Binary files a/technic_chests/textures/technic_iron_chest_inventory.png and b/technic_chests/textures/technic_iron_chest_inventory.png differ
index 905477562e7f3ba88be5d8efe54faec48c123892..9bec6fe8dae7f4fd220cddbb66aa10a5c2e34fd2 100644 (file)
Binary files a/technic_chests/textures/technic_mithril_chest_inventory.png and b/technic_chests/textures/technic_mithril_chest_inventory.png differ
index a61c4b9690e1b5eabd23a683f3d899d7a6cae5d2..b2fe835b19bba5b50b9aa8eb045f22da75fbfdca 100644 (file)
Binary files a/technic_chests/textures/technic_silver_chest_inventory.png and b/technic_chests/textures/technic_silver_chest_inventory.png differ
index 145d9d2230834dc48b93bdfd708fad790ac5e82c..5ffbc1208ab7744c126caa68bf8492bcd99fbcc1 100644 (file)
Binary files a/technic_chests/textures/technic_wooden_chest_inventory.png and b/technic_chests/textures/technic_wooden_chest_inventory.png differ