add I3 support + update to formspecs v2 (#22)

* add fs helper inv function

* add fs helper prepends function

* add trash can, vacuum tube, teleport tube. wielders, autocrafter, mesetube, injectors

* fixed missed texture to make game agnostic

* fix luacheck
This commit is contained in:
wsor4035 2022-04-16 14:51:59 -04:00 committed by GitHub
parent 3092ce771f
commit 37eef73695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 195 additions and 64 deletions

View File

@ -19,6 +19,7 @@ read_globals = {
-- mods
"default", "mesecon", "digiline",
"screwdriver", "unified_inventory"
"screwdriver", "unified_inventory",
"i3",
}

View File

@ -172,14 +172,38 @@ end
local function update_meta(meta, enabled)
local state = enabled and "on" or "off"
meta:set_int("enabled", enabled and 1 or 0)
local fs = "size[8,12]"..
"list[context;recipe;0,0;3,3;]"..
"image[3,1;1,1;gui_hb_bg.png^[colorize:#141318:255]"..
"list[context;output;3,1;1,1;]"..
"image_button[3,2;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
"list[context;src;0,4.5;8,3;]"..
"list[context;dst;4,0;4,3;]"..
"list[current_player;main;0,8;8,4;]" ..
local list_backgrounds = ""
if minetest.get_modpath("i3") then
list_backgrounds = "style_type[box;colors=#666]"
for i=0, 2 do
for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
end
end
for i=0, 3 do
for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[".. 5.28+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
end
end
for i=0, 7 do
for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 4.5+(j*1.25) ..";1,1;]"
end
end
end
local size = "10.2,14"
local fs =
"formspec_version[2]"..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size)..
list_backgrounds..
"list[context;recipe;0.22,0.22;3,3;]"..
"image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]"..
"list[context;output;4,1.45;1,1;]"..
"image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
"list[context;dst;5.28,0.22;4,3;]"..
"list[context;src;0.22,4.5;8,3;]"..
pipeworks.fs_helpers.get_inv(9)..
"listring[current_player;main]"..
"listring[context;src]" ..
"listring[current_player;main]"..

View File

@ -143,6 +143,55 @@ 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[box;colors=#666]")
for i=0, 2 do
for j=0, (i3.settings.legacy_inventory and 7 or 8) do
table.insert(fs, "box["..0.2+(j*0.1)+(j*size)..","..(inv_y+size+spacing+0.05)+(i*0.1)+(i*size)..";"..size..","..size..";]")
end
end
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
function fs_helpers.get_prepends(size)
local prepend = {}
if minetest.get_modpath("i3") then
prepend = {
"no_prepend[]",
"bgcolor[black;neither]",
"background9[0,0;"..size..";i3_bg_full.png;false;10]",
"style_type[button;border=false;bgimg=[combine:16x16^[noalpha^[colorize:#6b6b6b]",
"listcolors[#0000;#ffffff20]"
}
end
return table.concat(prepend, "")
end
---------
-- Env --
---------

View File

@ -32,22 +32,35 @@ local function set_filter_formspec(data, meta)
local exmatch_button = ""
if data.stackwise then
exmatch_button =
fs_helpers.cycling_button(meta, "button[4,3.5;4,1", "exmatch_mode",
fs_helpers.cycling_button(meta, "button["..(10.2-(0.22)-4)..",4.5;4,1", "exmatch_mode",
{S("Exact match - off"),
S("Exact match - on")})
end
formspec = "size[8,8.5]"..
"item_image[0,0;1,1;pipeworks:"..data.name.."]"..
"label[1,0;"..minetest.formspec_escape(itemname).."]"..
"label[0,1;"..S("Prefer item types:").."]"..
"list[context;main;0,1.5;8,2;]"..
fs_helpers.cycling_button(meta, "button[0,3.5;4,1", "slotseq_mode",
local size = "10.2,11"
local list_backgrounds = ""
if minetest.get_modpath("i3") then
list_backgrounds = "style_type[box;colors=#666]"
for i=0, 7 do
for j=0, 1 do
list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 1.75+(j*1.25) ..";1,1;]"
end
end
end
formspec =
"formspec_version[2]"..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size)..
"item_image[0.22,0.22;1,1;pipeworks:"..data.name.."]"..
"label[1.22,0.72;"..minetest.formspec_escape(itemname).."]"..
"label[0.22,1.5;"..S("Prefer item types:").."]"..
list_backgrounds..
"list[context;main;0.22,1.75;8,2;]"..
fs_helpers.cycling_button(meta, "button[0.22,4.5;4,1", "slotseq_mode",
{S("Sequence slots by Priority"),
S("Sequence slots Randomly"),
S("Sequence slots by Rotation")})..
exmatch_button..
"list[current_player;main;0,4.5;8,4;]" ..
pipeworks.fs_helpers.get_inv(6)..
"listring[]"
end
meta:set_string("formspec", formspec)
@ -65,8 +78,8 @@ local function punch_filter(data, filtpos, filtnode, msg)
local fromnode = minetest.get_node(frompos)
if not fromnode then return end
local fromdef = minetest.registered_nodes[fromnode.name]
if not fromdef then return end
local fromtube = fromdef.tube
if not fromdef or not fromdef.tube then return end
local fromtube = table.copy(fromdef.tube)
local input_special_cases = {
["technic:mv_electric_furnace"] = "dst",
["technic:mv_electric_furnace_active"] = "dst",

View File

@ -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

View File

@ -16,29 +16,43 @@ if pipeworks.enable_mese_tube then
local buttons_formspec = ""
for i = 0, 5 do
buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta,
"image_button[7,"..(i+0.2)..";1,0.6", "l"..(i+1).."s",
"image_button[9,"..(i+(i*0.25)+0.5)..";1,0.6", "l"..(i+1).."s",
{
pipeworks.button_off,
pipeworks.button_on
}
)
end
local list_backgrounds = ""
if minetest.get_modpath("i3") then
list_backgrounds = "style_type[box;colors=#666]"
for i=0, 5 do
for j=0, 5 do
list_backgrounds = list_backgrounds .. "box[".. 1.5+(i*1.25) ..",".. 0.25+(j*1.25) ..";1,1;]"
end
end
end
local size = "10.2,13"
meta:set_string("formspec",
"size[8,11]"..
"list[context;line1;1,0;6,1;]"..
"list[context;line2;1,1;6,1;]"..
"list[context;line3;1,2;6,1;]"..
"list[context;line4;1,3;6,1;]"..
"list[context;line5;1,4;6,1;]"..
"list[context;line6;1,5;6,1;]"..
"image[0,0;1,1;pipeworks_white.png]"..
"image[0,1;1,1;pipeworks_black.png]"..
"image[0,2;1,1;pipeworks_green.png]"..
"image[0,3;1,1;pipeworks_yellow.png]"..
"image[0,4;1,1;pipeworks_blue.png]"..
"image[0,5;1,1;pipeworks_red.png]"..
"formspec_version[2]"..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size)..
"list[context;line1;1.5,0.25;6,1;]"..
"list[context;line2;1.5,1.50;6,1;]"..
"list[context;line3;1.5,2.75;6,1;]"..
"list[context;line4;1.5,4.00;6,1;]"..
"list[context;line5;1.5,5.25;6,1;]"..
"list[context;line6;1.5,6.50;6,1;]"..
list_backgrounds..
"image[0.22,0.25;1,1;pipeworks_white.png]"..
"image[0.22,1.50;1,1;pipeworks_black.png]"..
"image[0.22,2.75;1,1;pipeworks_green.png]"..
"image[0.22,4.00;1,1;pipeworks_yellow.png]"..
"image[0.22,5.25;1,1;pipeworks_blue.png]"..
"image[0.22,6.50;1,1;pipeworks_red.png]"..
buttons_formspec..
"list[current_player;main;0,7;8,4;]" ..
--"list[current_player;main;0,8;8,4;]" ..
pipeworks.fs_helpers.get_inv(8)..
"listring[current_player;main]" ..
"listring[current_player;main]" ..
"listring[context;line1]" ..

View File

@ -143,17 +143,19 @@ local function update_meta(meta, can_receive)
local itext = S("Channels are public by default").."\n"..
S("Use <player>:<channel> for fully private channels").."\n"..
S("Use <player>\\;<channel> for private receivers")
local size = "8.5,4"
meta:set_string("formspec",
"size[8.5,3.5]"..
"image[0.2,o;1,1;pipeworks_teleport_tube_inv.png]"..
"label[1.2,0.2;"..S("Teleporting Tube").."]"..
"field[0.5,1.6;4.6,1;channel;"..S("Channel")..";${channel}]"..
"button[4.8,1.3;1.5,1;set_channel;"..S("Set").."]"..
"label[7.0,0;"..S("Receive").."]"..
"image_button[7.0,0.5;1,0.6;pipeworks_button_" .. cr_state .. ".png;cr" .. (can_receive and 0 or 1) .. ";;;false;pipeworks_button_interm.png]"..
"button_exit[6.3,1.3;2,1;close;"..S("Close").."]"..
"label[0.2,2.3;"..itext.."]")
"formspec_version[2]"..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size) ..
"image[0.5,o;1,1;pipeworks_teleport_tube_inv.png]"..
"label[1.5,0.5;"..S("Teleporting Tube").."]"..
"field[0.5,1.6;4.3,0.75;channel;"..S("Channel")..";${channel}]"..
"button[4.8,1.6;1.5,0.75;set_channel;"..S("Set").."]"..
"label[7.0,0.5;"..S("Receive").."]"..
"image_button[7.0,0.75;1,0.6;pipeworks_button_" .. cr_state .. ".png;cr" .. (can_receive and 0 or 1) .. ";;;false;pipeworks_button_interm.png]"..
"button_exit[6.3,1.6;2,0.75;close;"..S("Close").."]"..
"label[0.5,2.7;"..itext.."]")
end
pipeworks.register_tube("pipeworks:teleport_tube", {

View File

@ -20,13 +20,24 @@ minetest.register_node("pipeworks:trashcan", {
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local size = "10.2,9"
local list_background = ""
if minetest.get_modpath("i3") then
list_background = "style_type[box;colors=#666]box[4.5,2;1,1;]"
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["..size.."]"..
pipeworks.fs_helpers.get_prepends(size) ..
"item_image[0.5,0.5;1,1;pipeworks:trashcan]"..
"label[1.5,1;"..S("Trash Can").."]"..
list_background..
"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,

View File

@ -39,9 +39,11 @@ if pipeworks.enable_mese_sand_tube then
groups = {vacuum_tube = 1},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local size = "6.0,2.4"
meta:set_int("dist", 0)
meta:set_string("formspec",
"size[6.0,2.2]"..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size) ..
"image[0.2,0;1,1;pipeworks_mese_sand_tube_inv.png]"..
"label[1.2,0.2;"..S("Adjustable Vacuuming Tube").."]"..
"field[0.5,1.6;2.1,1;dist;"..S("Radius")..";${dist}]"..

View File

@ -6,13 +6,28 @@ local function delay(x)
end
local function set_wielder_formspec(data, meta)
local size = "10.2,"..(7+data.wield_inv_height)
local list_background = ""
if minetest.get_modpath("i3") then
list_background = "style_type[box;colors=#666]"
for i=0, data.wield_inv_height-1 do
for j=0, data.wield_inv_width-1 do
list_background = list_background .. "box[".. ((10-data.wield_inv_width)*0.5)+(i*1.25) ..",".. 1+(j*1.25) ..";1,1;]"
end
end
end
meta:set_string("formspec",
"size[8,"..(6+data.wield_inv_height)..";]"..
"item_image[0,0;1,1;"..data.name_base.."_off]"..
"label[1,0;"..minetest.formspec_escape(data.description).."]"..
"list[current_name;"..minetest.formspec_escape(data.wield_inv_name)..";"..((8-data.wield_inv_width)*0.5)..",1;"..data.wield_inv_width..","..data.wield_inv_height..";]"..
"list[current_player;main;0,"..(2+data.wield_inv_height)..";8,4;]" ..
"listring[]")
"formspec_version[2]" ..
"size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size)..
"item_image[0.5,0.5;1,1;"..data.name_base.."_off]"..
"label[1.5,1;"..minetest.formspec_escape(data.description).."]"..
list_background ..
"list[current_name;"..minetest.formspec_escape(data.wield_inv_name)..";"..((10-data.wield_inv_width)*0.5)..",1;"..data.wield_inv_width..","..data.wield_inv_height..";]"..
pipeworks.fs_helpers.get_inv((2+data.wield_inv_height))
--"list[current_player;main;0,"..(2+data.wield_inv_height)..";8,4;]" ..
--"listring[]"
)
meta:set_string("infotext", data.description)
end