diff --git a/init.lua b/init.lua index 22ea613..337d5f8 100644 --- a/init.lua +++ b/init.lua @@ -37,7 +37,6 @@ i3 = { damage_enabled = core.settings:get_bool"enable_damage", progressive_mode = core.settings:get_bool"i3_progressive_mode", - legacy_inventory = core.settings:get_bool"i3_legacy_inventory", item_compression = core.settings:get_bool("i3_item_compression", true), }, @@ -57,6 +56,7 @@ i3 = { waypoints = true, inv_items = true, known_recipes = true, + legacy_inventory = true, }, files = { @@ -94,9 +94,6 @@ i3 = { sorting_methods = {}, } -i3.settings.hotbar_len = i3.settings.legacy_inventory and 8 or 9 -i3.settings.inv_size = 4 * i3.settings.hotbar_len - i3.files.common() i3.files.api(http) i3.files.compress() diff --git a/mod.conf b/mod.conf index cf9ea1f..04452f7 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = i3 description = Next-generation inventory optional_depends = 3d_armor, skinsdb, awards -min_minetest_version = 5.4 +min_minetest_version = 5.6 diff --git a/settingtypes.txt b/settingtypes.txt index fa5e80d..1a45de6 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -3,6 +3,3 @@ i3_progressive_mode (Learn crafting recipes progressively) bool false # Regroup the items of the same type in the item list. i3_item_compression (Regroup items of the same type) bool true - -# Set the inventory size to common chests size (8*4). -i3_legacy_inventory (Legacy inventory size) bool false \ No newline at end of file diff --git a/src/callbacks.lua b/src/callbacks.lua index e57aea3..166d6f6 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -6,7 +6,7 @@ local init_hud = i3.files.hud() local set_fs = i3.set_fs IMPORT("slz", "min", "insert", "copy", "ItemStack") -IMPORT("spawn_item", "reset_data", "get_detached_inv", "play_sound") +IMPORT("spawn_item", "reset_data", "get_detached_inv", "play_sound", "update_inv_size") core.register_on_player_hpchange(function(player, hpchange) local name = player:get_player_name() @@ -226,8 +226,7 @@ local function init_data(player, info) data.lang_code = get_lang_code(info) data.fs_version = info.formspec_version - local inv = player:get_inventory() - inv:set_size("main", i3.settings.inv_size) + update_inv_size(player, data) core.after(0, set_fs, player) end diff --git a/src/common.lua b/src/common.lua index 64f71ff..628b9b6 100644 --- a/src/common.lua +++ b/src/common.lua @@ -557,7 +557,7 @@ local function sort_inventory(player, data) local inv = player:get_inventory() local list = inv:get_list"main" local size = inv:get_size"main" - local start_i = data.ignore_hotbar and (i3.settings.hotbar_len + 1) or 1 + local start_i = data.ignore_hotbar and (data.hotbar_len + 1) or 1 if data.inv_compress then list = compress_items(list, start_i) @@ -623,6 +623,24 @@ local function get_detached_inv(name, player_name) } end +local function update_inv_size(player, data) + data.hotbar_len = data.legacy_inventory and 8 or 9 + data.inv_size = 4 * data.hotbar_len + + local inv = player:get_inventory() + inv:set_size("main", data.inv_size) + + player:hud_set_hotbar_itemcount(data.hotbar_len) + + core.after(0, function() + if data.legacy_inventory then + player:hud_set_hotbar_image"gui_hotbar.png" + else + player:hud_set_hotbar_image"i3_hotbar.png" + end + end) +end + -- Much faster implementation of `unpack` local function createunpack(n) local ret = {"local t = ... return "} @@ -704,6 +722,7 @@ local _ = { -- Inventory get_stack = get_stack, craft_stack = craft_stack, + update_inv_size = update_inv_size, get_detached_inv = get_detached_inv, get_bag_description = get_bag_description, create_inventory = core.create_detached_inventory, diff --git a/src/fields.lua b/src/fields.lua index 5db3cbb..fb04691 100644 --- a/src/fields.lua +++ b/src/fields.lua @@ -5,8 +5,8 @@ IMPORT("min", "max", "vec_eq", "vec_round") IMPORT("S", "random", "translate", "ItemStack") IMPORT("sort", "copy", "insert", "remove", "indexof") IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper") -IMPORT("search", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv") IMPORT("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "reset_data") +IMPORT("search", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv", "update_inv_size") IMPORT("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport") local function inv_fields(player, data, fields) @@ -32,6 +32,10 @@ local function inv_fields(player, data, fields) data[str] = true end + if str == "legacy_inventory" then + update_inv_size(player, data) + end + elseif sub(field, 1, 8) == "setting_" then data.show_setting = match(field, "_(%w+)$") diff --git a/src/gui.lua b/src/gui.lua index 7ede458..f493f14 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1,5 +1,4 @@ local damage_enabled = i3.settings.damage_enabled -local hotbar_len = i3.settings.hotbar_len local debug_mode = i3.settings.debug_mode local model_aliases = i3.files.model_alias() @@ -128,10 +127,13 @@ local function get_stack_max(inv, data, is_recipe, rcp) return max_stacks end -local function get_inv_slots(fs) - local inv_x = i3.settings.legacy_inventory and 0.75 or 0.22 - local inv_y = 6.9 - local size, spacing = 1, 0.1 +local function get_inv_slots(data, fs) + local legacy_inventory = data.legacy_inventory + local hotbar_len = data.hotbar_len + local inv_x = legacy_inventory and 0.23 or 0.22 + local inv_y = legacy_inventory and 6.5 or 6.9 + local spacing = legacy_inventory and 0.25 or 0.1 + local size = 1 fs"style_type[box;colors=#77777710,#77777710,#777,#777]" @@ -142,11 +144,12 @@ local function get_inv_slots(fs) fs(fmt("style_type[list;size=%f;spacing=%f]", size, spacing), fmt("list[current_player;main;%f,%f;%u,1;]", inv_x, inv_y, hotbar_len)) - fs(fmt("style_type[list;size=%f;spacing=%f]", size, spacing), - fmt("list[current_player;main;%f,%f;%u,%u;%u]", inv_x, inv_y + 1.15, - hotbar_len, i3.settings.inv_size / hotbar_len, hotbar_len), - "style_type[list;size=1;spacing=0.15]") + fs(fmt("style_type[list;size=%f;spacing=%f]", size, spacing)) + fs(fmt("list[current_player;main;%f,%f;%u,%u;%u]", inv_x, inv_y + (legacy_inventory and 1.25 or 1.15), + hotbar_len, data.inv_size / hotbar_len, hotbar_len)) + + fs"style_type[list;size=1;spacing=0.15]" fs"listring[current_player;craft]listring[current_player;main]" end @@ -625,13 +628,14 @@ local function show_settings(fs, data) elseif show_style then checkbox(2.6, 9.95, "cb_hide_tabs", "Hide tabs", tostring(data.hide_tabs)) + checkbox(2.6, 10.4, "cb_legacy_inventory", "Legacy inventory", tostring(data.legacy_inventory)) local sign = (data.font_size > 0 and "+") or (data.font_size > 0 and "-") or "" - label(2.6, 10.45, ES"Font size" .. fmt(": %s", sign .. data.font_size)) + label(5.3, 9.95, ES"Font size" .. fmt(": %s", sign .. data.font_size)) local range = 5 fs(fmt("scrollbaroptions[min=-%u;max=%u;smallstep=1;largestep=1;thumbsize=2]", range, range)) - fs(fmt("scrollbar[2.6,10.65;2.5,0.3;horizontal;sb_font_size;%d]", data.font_size)) + fs(fmt("scrollbar[5.3,10.25;2.45,0.3;horizontal;sb_font_size;%d]", data.font_size)) elseif show_sorting then checkbox(2.6, 9.95, "cb_inv_compress", "Compression", tostring(data.inv_compress)) @@ -670,10 +674,12 @@ end local function get_inventory_fs(player, data, fs) fs"listcolors[#bababa50;#bababa99]" - get_inv_slots(fs) + get_inv_slots(data, fs) local props = player:get_properties() - local ctn_len, ctn_hgt, yoffset = 5.7, 6.3, 0 + local ctn_len = 5.7 + local ctn_hgt = data.legacy_inventory and 6.1 or 6.3 + local yoffset = 0 if props.mesh ~= "" then local anim = player:get_local_animation() @@ -697,6 +703,7 @@ local function get_inventory_fs(player, data, fs) local awards_unlocked, award_list, award_list_nb = 0 local max_val = damage_enabled and 12 or 7 + max_val += (data.legacy_inventory and 2 or 0) local bag_size = get_group(ItemStack(data.bag):get_name(), "bag") if data.subcat == 1 and bag_size > 0 then diff --git a/src/hud.lua b/src/hud.lua index 5eee7ac..135b237 100644 --- a/src/hud.lua +++ b/src/hud.lua @@ -33,13 +33,6 @@ local function init_hud(player) style = 1, }, } - - if not i3.settings.legacy_inventory then - core.after(0, function() - player:hud_set_hotbar_itemcount(i3.settings.hotbar_len) - player:hud_set_hotbar_image"i3_hotbar.png" - end) - end end local function show_hud(player, data)