From 26db573e8005522ef3b972ffce0fbf7e4aa311bc Mon Sep 17 00:00:00 2001 From: unknown <24964441+wsor4035@users.noreply.github.com> Date: Tue, 12 Apr 2022 23:50:59 -0400 Subject: [PATCH] add i3 inv support + i3 styled trash can --- .luacheckrc | 3 ++- common.lua | 26 ++++++++++++++++++++++++++ mod.conf | 2 +- trashcan.lua | 21 +++++++++++++++------ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 85eba0b..494507e 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -19,6 +19,7 @@ read_globals = { -- mods "default", "mesecon", "digiline", - "screwdriver", "unified_inventory" + "screwdriver", "unified_inventory", + "i3", } diff --git a/common.lua b/common.lua index 3d40491..3ceaba9 100644 --- a/common.lua +++ b/common.lua @@ -143,6 +143,32 @@ function fs_helpers.cycling_button(meta, base, meta_name, values) return base..";"..(texture_name and texture_name..";" or "")..field..";"..minetest.formspec_escape(text)..(addopts and ";"..addopts or "").."]" end +function fs_helpers.get_inv(y) + local fs = {} + if minetest.get_modpath("i3") then + local inv_x = i3.settings.legacy_inventory and 0.75 or 0.22 + local inv_y = (y + 0.4) or 6.9 + local size, spacing = 1, 0.1 + local hotbar_len = i3.settings.hotbar_len + + table.insert(fs, "style_type[box;colors=#77777710,#77777710,#777,#777]") + + for i = 0, hotbar_len - 1 do + table.insert(fs, "box["..(i * size + inv_x + (i * spacing))..","..inv_y..";"..size..","..size..";]") + end + + table.insert(fs, "style_type[list;size="..size..";spacing="..spacing.."]") + table.insert(fs, "list[current_player;main;"..inv_x..","..inv_y..";"..hotbar_len..",1;]") + + table.insert(fs, "style_type[list;size="..size..";spacing="..spacing.."]") + table.insert(fs, "list[current_player;main;"..inv_x..","..(inv_y + 1.15)..";"..hotbar_len..","..(i3.settings.inv_size / hotbar_len)..";"..hotbar_len.."]") + else + table.insert(fs, "list[current_player;main;0.22,"..y..";8,4;]") + end + + return table.concat(fs, "") +end + --------- -- Env -- --------- diff --git a/mod.conf b/mod.conf index c95a9c7..20b3214 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. depends = basic_materials -optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api +optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3 min_minetest_version = 5.2.0 diff --git a/trashcan.lua b/trashcan.lua index e106761..d9cd042 100644 --- a/trashcan.lua +++ b/trashcan.lua @@ -20,13 +20,22 @@ minetest.register_node("pipeworks:trashcan", { }, on_construct = function(pos) local meta = minetest.get_meta(pos) + local prepend = "" + if minetest.get_modpath("i3") then + prepend = "no_prepend[]bgcolor[black;neither]background9[0,0;10.2,9;i3_bg_full.png;false;10]" + end meta:set_string("formspec", - "size[8,7]".. - "item_image[0,0;1,1;pipeworks:trashcan]".. - "label[1,0;"..S("Trash Can").."]".. - "list[context;trash;3.5,1;1,1;]".. - "list[current_player;main;0,3;8,4;]" .. - "listring[]") + "formspec_version[2]" .. + "size[10.2,9]".. + prepend .. + "item_image[0.5,0.5;1,1;pipeworks:trashcan]".. + "label[1.5,1;"..S("Trash Can").."]".. + "list[context;trash;4.5,2;1,1;]".. + --"list[current_player;main;0,3;8,4;]" .. + pipeworks.fs_helpers.get_inv(4).. + "listring[context;trash]".. + "listring[current_player;main]" + ) meta:set_string("infotext", S("Trash Can")) meta:get_inventory():set_size("trash", 1) end,