Remote UI refinements.

This commit is contained in:
Mike Stump 2024-01-06 17:10:52 -08:00
parent e0f8c0949a
commit 50aa1f2470

@ -207,6 +207,7 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
local page = toolmeta.page local page = toolmeta.page
local did_update = false local did_update = false
local update_search = false
for field, value in pairs(fields) do for field, value in pairs(fields) do
me.log("REMOTE: form "..field.." value "..value, "error") me.log("REMOTE: form "..field.." value "..value, "error")
if field == "next" then if field == "next" then
@ -223,8 +224,45 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
end end
elseif field == "crafts" then elseif field == "crafts" then
toolmeta.crafts = value toolmeta.crafts = value
page = 1
toolmeta.page = page
update_search = true
elseif (field == "key_enter_field" and value == "filter")
or field == "filter" or field == "search" then
if field == "filter" then
toolmeta.query = value
end
if (field == "key_enter_field" and value == "filter") or field == "search" then
page = 1
toolmeta.page = page
update_search = true
end
elseif field == "clear" then
own_inv:set_size("me_search", 0)
own_inv:set_size("me_crafts", 0)
page = 1
toolmeta.page = page
toolmeta.inv_name = "main"
toolmeta.query = ""
toolmeta.crafts = "false"
toolmeta.page_max = math.floor(inv:get_size(inv_name) / 32) + 1
update_search = true
elseif field == "tochest" then
elseif field == "autocraft" then
if tonumber(value) ~= nil then
toolmeta.autocraft = value
end
elseif field == "key_enter_field" and value == "autocraft" then
local count = tonumber(toolmeta.autocraft)
if not own_inv:get_stack("output", 1):is_empty() and count < math.pow(2,16) then
me.autocraft(me.autocrafterCache, pos, net, own_inv, ctrl_inv, count)
end
end
end
if update_search then
inv_name = "main" inv_name = "main"
if value == "true" then if toolmeta.crafts == "true" then
inv_name = "me_crafts" inv_name = "me_crafts"
local tab = {} local tab = {}
if net then if net then
@ -266,7 +304,7 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
tab[#tab + 1] = inv:get_stack(inv_name, i) tab[#tab + 1] = inv:get_stack(inv_name, i)
end end
end end
inv_name = "search" inv_name = "me_search"
own_inv:set_size(inv_name, #tab) own_inv:set_size(inv_name, #tab)
own_inv:set_list(inv_name, tab) own_inv:set_list(inv_name, tab)
toolmeta.inv_name = inv_name toolmeta.inv_name = inv_name
@ -274,30 +312,8 @@ minetest.register_on_player_receive_fields(function(user, formname, fields)
toolmeta.page_max = page_max toolmeta.page_max = page_max
did_update = true did_update = true
end end
elseif field == "filter" then
toolmeta.query = value
elseif field == "search" then
elseif field == "clear" then
own_inv:set_size("me_search", 0)
own_inv:set_size("me_crafts", 0)
toolmeta.page = 1
toolmeta.inv_name = "main"
toolmeta.query = ""
toolmeta.crafts = "false"
toolmeta.page_max = math.floor(inv:get_size(inv_name) / 32) + 1
did_update = true
elseif field == "tochest" then
elseif field == "autocraft" then
if tonumber(value) ~= nil then
toolmeta.autocraft = value
end
elseif field == "key_enter_field" and value == "autocraft" then
local count = tonumber(toolmeta.autocraft)
if not own_inv:get_stack("output", 1):is_empty() and count < math.pow(2,16) then
me.autocraft(me.autocrafterCache, pos, net, own_inv, ctrl_inv, count)
end
end
end end
if did_update then if did_update then
minetest.show_formspec(user:get_player_name(), "microexpansion:remote_control", minetest.show_formspec(user:get_player_name(), "microexpansion:remote_control",
chest_formspec(toolmeta, pos, page, inv_name)) chest_formspec(toolmeta, pos, page, inv_name))