Compare commits
10 Commits
9f24dbfd46
...
f790cc8bb3
Author | SHA1 | Date | |
---|---|---|---|
|
f790cc8bb3 | ||
|
8b807e4cf8 | ||
|
943fe836a1 | ||
|
a66b9a7299 | ||
|
cbd843311a | ||
|
8ff56a3322 | ||
|
b02d730978 | ||
|
ab3035402c | ||
|
4080daaa35 | ||
|
de81ce9dd8 |
2
API.md
2
API.md
@ -13,6 +13,7 @@ smart_inventory.register_page({
|
|||||||
smartfs_callback = function,
|
smartfs_callback = function,
|
||||||
sequence = number,
|
sequence = number,
|
||||||
on_button_click = function,
|
on_button_click = function,
|
||||||
|
is_visible_func = function,
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
- name - unique short name, used for identification
|
- name - unique short name, used for identification
|
||||||
@ -22,6 +23,7 @@ smart_inventory.register_page({
|
|||||||
- smartfs_callback(state) - smartfs callback function See [smartfs documentation](https://github.com/minetest-mods/smartfs/blob/master/docs) and existing pages implementations for reference.
|
- smartfs_callback(state) - smartfs callback function See [smartfs documentation](https://github.com/minetest-mods/smartfs/blob/master/docs) and existing pages implementations for reference.
|
||||||
- sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20)
|
- sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20)
|
||||||
- on_button_click(state) - function called each page button click
|
- on_button_click(state) - function called each page button click
|
||||||
|
- is_visible_func(state) - function for dynamic page enabelling. Should return bool value.
|
||||||
|
|
||||||
### Get the definition for registered smart_inventory page
|
### Get the definition for registered smart_inventory page
|
||||||
```smart_inventory.get_registered_page(pagename)```
|
```smart_inventory.get_registered_page(pagename)```
|
||||||
|
@ -74,3 +74,4 @@ License: [LGPL-3](https://github.com/bell07/minetest-smart_inventory/blob/master
|
|||||||
Textures:
|
Textures:
|
||||||
- Workbench: WTFPL (credits: to xdecor project)
|
- Workbench: WTFPL (credits: to xdecor project)
|
||||||
- Buttons: WTFPL (credits to Stix (Minetest-forum))
|
- Buttons: WTFPL (credits to Stix (Minetest-forum))
|
||||||
|
- Arrow buttons: WTFPL (credits to daretmavi)
|
||||||
|
7
init.lua
7
init.lua
@ -22,3 +22,10 @@ dofile(modpath.."/pages/creative.lua")
|
|||||||
dofile(modpath.."/pages/player.lua")
|
dofile(modpath.."/pages/player.lua")
|
||||||
dofile(modpath.."/pages/doc.lua")
|
dofile(modpath.."/pages/doc.lua")
|
||||||
dofile(modpath.."/pages/awards.lua")
|
dofile(modpath.."/pages/awards.lua")
|
||||||
|
|
||||||
|
-- Cleanup inventories
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
local player_name = player:get_player_name()
|
||||||
|
minetest.remove_detached_inventory(player_name.."_crafting_inv")
|
||||||
|
minetest.remove_detached_inventory(player_name.."_trash_inv")
|
||||||
|
end)
|
||||||
|
@ -7,6 +7,13 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
|||||||
|
|
||||||
-- enhanced object to the main inventory functions
|
-- enhanced object to the main inventory functions
|
||||||
state.param.invobj = maininv.get(state.location.player)
|
state.param.invobj = maininv.get(state.location.player)
|
||||||
|
|
||||||
|
-- Set language code
|
||||||
|
local player_info = minetest.get_player_information(state.location.player)
|
||||||
|
if player_info and player_info.lang_code ~= "" then
|
||||||
|
state.lang_code = player_info.lang_code
|
||||||
|
end
|
||||||
|
|
||||||
-- tabbed view controller
|
-- tabbed view controller
|
||||||
local tab_controller = {
|
local tab_controller = {
|
||||||
_tabs = {},
|
_tabs = {},
|
||||||
@ -52,6 +59,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
|||||||
for _, def in ipairs(smart_inventory.registered_pages) do
|
for _, def in ipairs(smart_inventory.registered_pages) do
|
||||||
assert(def.smartfs_callback, "Callback function needed")
|
assert(def.smartfs_callback, "Callback function needed")
|
||||||
assert(def.name, "Name is needed")
|
assert(def.name, "Name is needed")
|
||||||
|
if not def.is_visible_func or def.is_visible_func(state) then
|
||||||
local tabdef = {}
|
local tabdef = {}
|
||||||
local label
|
local label
|
||||||
if not def.label then
|
if not def.label then
|
||||||
@ -76,6 +84,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
|||||||
tab_controller:tab_add(def.name, tabdef)
|
tab_controller:tab_add(def.name, tabdef)
|
||||||
button_x = button_x + 1
|
button_x = button_x + 1
|
||||||
end
|
end
|
||||||
|
end
|
||||||
tab_controller:set_active(smart_inventory.registered_pages[1].name)
|
tab_controller:set_active(smart_inventory.registered_pages[1].name)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -8,26 +8,7 @@ cache.citems = {}
|
|||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
-- Add an Item to the cache
|
-- Add an Item to the cache
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
function cache.add_item(def)
|
function cache.add_item(item_def)
|
||||||
|
|
||||||
-- special handling for doors. In inventory the item should be displayed instead of the node_a/node_b
|
|
||||||
local item_def
|
|
||||||
|
|
||||||
if def.groups and def.groups.door then
|
|
||||||
if def.door then
|
|
||||||
item_def = minetest.registered_items[def.door.name]
|
|
||||||
elseif def.drop and type(def.drop) == "string" then
|
|
||||||
item_def = minetest.registered_items[def.drop]
|
|
||||||
else
|
|
||||||
item_def = def
|
|
||||||
end
|
|
||||||
if not item_def then
|
|
||||||
minetest.log("[smart_inventory] Buggy door found: "..def.name)
|
|
||||||
item_def = def
|
|
||||||
end
|
|
||||||
else
|
|
||||||
item_def = def
|
|
||||||
end
|
|
||||||
|
|
||||||
-- already in cache. Skip duplicate processing
|
-- already in cache. Skip duplicate processing
|
||||||
if cache.citems[item_def.name] then
|
if cache.citems[item_def.name] then
|
||||||
@ -49,7 +30,7 @@ function cache.add_item(def)
|
|||||||
cache.citems[item_def.name] = entry
|
cache.citems[item_def.name] = entry
|
||||||
-- classify the item
|
-- classify the item
|
||||||
for _, flt in pairs(filter.registered_filter) do
|
for _, flt in pairs(filter.registered_filter) do
|
||||||
local filter_result = flt:check_item_by_def(def)
|
local filter_result = flt:check_item_by_def(item_def)
|
||||||
if filter_result then
|
if filter_result then
|
||||||
if filter_result == true then
|
if filter_result == true then
|
||||||
cache.assign_to_group(flt.name, item_def, flt)
|
cache.assign_to_group(flt.name, item_def, flt)
|
||||||
|
@ -216,8 +216,17 @@ end
|
|||||||
filter.register_filter({
|
filter.register_filter({
|
||||||
name = "shape",
|
name = "shape",
|
||||||
check_item_by_def = function(self, def)
|
check_item_by_def = function(self, def)
|
||||||
|
local door_groups
|
||||||
|
if shaped_groups["door"] then
|
||||||
|
local door_filter = filter.get("door")
|
||||||
|
door_groups = door_filter:check_item_by_def(def)
|
||||||
|
if door_groups and door_groups.door then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for k, v in pairs(def.groups) do
|
for k, v in pairs(def.groups) do
|
||||||
if shaped_groups[k] then
|
if k ~= "door" and shaped_groups[k] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -356,6 +365,45 @@ filter.register_filter({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
local door_groups
|
||||||
|
local function fill_door_groups()
|
||||||
|
door_groups = {}
|
||||||
|
for _, extend_def in pairs(minetest.registered_items) do
|
||||||
|
local base_def
|
||||||
|
if extend_def.groups and extend_def.groups.door then
|
||||||
|
if extend_def.door then
|
||||||
|
base_def = minetest.registered_items[extend_def.door.name]
|
||||||
|
elseif extend_def.drop and type(extend_def.drop) == "string" then
|
||||||
|
base_def = minetest.registered_items[extend_def.drop]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if base_def then
|
||||||
|
door_groups[base_def.name] = extend_def
|
||||||
|
door_groups[extend_def.name] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
filter.register_filter({
|
||||||
|
name = "door",
|
||||||
|
check_item_by_def = function(self, def)
|
||||||
|
if not door_groups then
|
||||||
|
fill_door_groups()
|
||||||
|
end
|
||||||
|
if not door_groups[def.name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local group_filter = filter.get("group")
|
||||||
|
local ret = group_filter:check_item_by_def(door_groups[def.name])
|
||||||
|
if ret then
|
||||||
|
ret["not_in_creative_inventory"] = nil
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
----------------
|
----------------
|
||||||
return filter
|
return filter
|
||||||
|
|
||||||
|
@ -152,4 +152,9 @@ function maininv.get(playername)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check if player has creative privilege.
|
||||||
|
function maininvClass:get_has_creative()
|
||||||
|
return minetest.is_creative_enabled(self.playername)
|
||||||
|
end
|
||||||
|
|
||||||
return maininv
|
return maininv
|
||||||
|
@ -228,14 +228,14 @@ function buttons_grid:update()
|
|||||||
if btnid == 1 and self.data.list_start > 1 then
|
if btnid == 1 and self.data.list_start > 1 then
|
||||||
-- setup back button
|
-- setup back button
|
||||||
button:setVisible(true)
|
button:setVisible(true)
|
||||||
button:setImage("left_arrow.png")
|
button:setImage("smart_inventory_left_arrow.png")
|
||||||
button:setText(tostring(self.data.list_start-1))
|
button:setText(tostring(self.data.list_start-1))
|
||||||
button:setSize(self.data.cell_size.w, self.data.cell_size.h)
|
button:setSize(self.data.cell_size.w, self.data.cell_size.h)
|
||||||
self.data.pagesize = self.data.pagesize - 1
|
self.data.pagesize = self.data.pagesize - 1
|
||||||
elseif btnid == self.data.grid_size.w * self.data.grid_size.h and self.data.list[itemindex+1] then
|
elseif btnid == self.data.grid_size.w * self.data.grid_size.h and self.data.list[itemindex+1] then
|
||||||
-- setup next button
|
-- setup next button
|
||||||
button:setVisible(true)
|
button:setVisible(true)
|
||||||
button:setImage("right_arrow.png")
|
button:setImage("smart_inventory_right_arrow.png")
|
||||||
self.data.pagesize = self.data.pagesize - 1
|
self.data.pagesize = self.data.pagesize - 1
|
||||||
button:setText(tostring(#self.data.list-self.data.list_start-self.data.pagesize+1))
|
button:setText(tostring(#self.data.list-self.data.list_start-self.data.pagesize+1))
|
||||||
button:setSize(self.data.cell_size.w, self.data.cell_size.h)
|
button:setSize(self.data.cell_size.w, self.data.cell_size.h)
|
||||||
|
@ -370,9 +370,10 @@ local function crafting_callback(state)
|
|||||||
if smart_inventory.doc_items_mod then
|
if smart_inventory.doc_items_mod then
|
||||||
self.state:get("reveal_tipp"):setPosition(11.5, 4.5)
|
self.state:get("reveal_tipp"):setPosition(11.5, 4.5)
|
||||||
end
|
end
|
||||||
self.state:get("search"):setPosition(12.3, 4.5)
|
self.state:get("search"):setPosition(12.2, 4.5)
|
||||||
self.state:get("search_bg"):setPosition(12, 4)
|
self.state:get("search_bg"):setPosition(12, 4)
|
||||||
self.state:get("info_tog"):setPosition(16, 4.2)
|
self.state:get("search_btn"):setPosition(15.2, 4.2)
|
||||||
|
self.state:get("info_tog"):setPosition(16.2, 4.2)
|
||||||
|
|
||||||
self.state:get("buttons_grid_Bg"):setPosition(10, 5)
|
self.state:get("buttons_grid_Bg"):setPosition(10, 5)
|
||||||
self.state:get("buttons_grid_Bg"):setSize(8, 4)
|
self.state:get("buttons_grid_Bg"):setSize(8, 4)
|
||||||
@ -389,9 +390,10 @@ local function crafting_callback(state)
|
|||||||
if smart_inventory.doc_items_mod then
|
if smart_inventory.doc_items_mod then
|
||||||
self.state:get("reveal_tipp"):setPosition(11.5, 0.5)
|
self.state:get("reveal_tipp"):setPosition(11.5, 0.5)
|
||||||
end
|
end
|
||||||
self.state:get("search"):setPosition(12.3, 0.5)
|
self.state:get("search"):setPosition(12.2, 0.5)
|
||||||
self.state:get("search_bg"):setPosition(12, 0)
|
self.state:get("search_bg"):setPosition(12, 0)
|
||||||
self.state:get("info_tog"):setPosition(16, 0.2)
|
self.state:get("search_btn"):setPosition(15.2, 0.2)
|
||||||
|
self.state:get("info_tog"):setPosition(16.2, 0.2)
|
||||||
|
|
||||||
self.state:get("groups_sel"):setVisible(false)
|
self.state:get("groups_sel"):setVisible(false)
|
||||||
self.state:get("inf_area"):setVisible(false)
|
self.state:get("inf_area"):setVisible(false)
|
||||||
@ -675,7 +677,7 @@ local function crafting_callback(state)
|
|||||||
|
|
||||||
-- search
|
-- search
|
||||||
state:background(12, 4, 4, 0.9, "search_bg", nil) --field background not usable
|
state:background(12, 4, 4, 0.9, "search_bg", nil) --field background not usable
|
||||||
local searchfield = state:field(12.3, 4.5, 4, 0.5, "search")
|
local searchfield = state:field(12.2, 4.5, 3.4, 0.5, "search")
|
||||||
searchfield:setCloseOnEnter(false)
|
searchfield:setCloseOnEnter(false)
|
||||||
searchfield:onKeyEnter(function(self, state, player)
|
searchfield:onKeyEnter(function(self, state, player)
|
||||||
local search_string = self:getText()
|
local search_string = self:getText()
|
||||||
@ -683,15 +685,21 @@ local function crafting_callback(state)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list_all, search_string)
|
local filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list_all, search_string, state.location.rootState.lang_code)
|
||||||
filtered_list = ui_tools.filter_by_revealed(filtered_list, player)
|
filtered_list = ui_tools.filter_by_revealed(filtered_list, player)
|
||||||
state.param.crafting_grouped_items = ui_tools.get_list_grouped(filtered_list)
|
state.param.crafting_grouped_items = ui_tools.get_list_grouped(filtered_list)
|
||||||
update_group_selection(state, true)
|
update_group_selection(state, true)
|
||||||
ui_controller:update_list_variant("search", search_string)
|
ui_controller:update_list_variant("search", search_string)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local search_button = state:button(15.2, 4.2, 0.8, 0.5, "search_btn", "Go")
|
||||||
|
search_button:setTooltip("Perform search action")
|
||||||
|
search_button:onClick(function(self, state, player)
|
||||||
|
state:get("search"):submit_key_enter("", player)
|
||||||
|
end)
|
||||||
|
|
||||||
-- groups toggle
|
-- groups toggle
|
||||||
local info_tog = state:toggle(16,4.2,2,0.5, "info_tog", {"Info", "Groups", "Hide"})
|
local info_tog = state:toggle(16.2,4.2,1.8,0.5, "info_tog", {"Info", "Groups", "Hide"})
|
||||||
info_tog:onToggle(function(self, state, player)
|
info_tog:onToggle(function(self, state, player)
|
||||||
local id = self:getId()
|
local id = self:getId()
|
||||||
if id == 1 then
|
if id == 1 then
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local cache = smart_inventory.cache
|
local cache = smart_inventory.cache
|
||||||
local ui_tools = smart_inventory.ui_tools
|
local ui_tools = smart_inventory.ui_tools
|
||||||
|
|
||||||
@ -78,6 +74,7 @@ end
|
|||||||
-- Page layout definition
|
-- Page layout definition
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
local function creative_callback(state)
|
local function creative_callback(state)
|
||||||
|
|
||||||
local player = state.location.rootState.location.player
|
local player = state.location.rootState.location.player
|
||||||
|
|
||||||
-- build up UI controller
|
-- build up UI controller
|
||||||
@ -95,6 +92,7 @@ local function creative_callback(state)
|
|||||||
-- toggle show/hide elements
|
-- toggle show/hide elements
|
||||||
if new_ui == 'list_small' then
|
if new_ui == 'list_small' then
|
||||||
self.ui_toggle = new_ui
|
self.ui_toggle = new_ui
|
||||||
|
self.state:get("groups_sel1"):setSize(5.6, 3)
|
||||||
self.state:get("groups_sel2"):setVisible(true)
|
self.state:get("groups_sel2"):setVisible(true)
|
||||||
self.state:get("groups_sel3"):setVisible(true)
|
self.state:get("groups_sel3"):setVisible(true)
|
||||||
self.state:get("buttons_grid"):reset(9.55, 3.75, 9.0 , 6.5)
|
self.state:get("buttons_grid"):reset(9.55, 3.75, 9.0 , 6.5)
|
||||||
@ -103,6 +101,7 @@ local function creative_callback(state)
|
|||||||
self.state:get("btn_tog"):setId(1)
|
self.state:get("btn_tog"):setId(1)
|
||||||
elseif new_ui == 'list_big' then
|
elseif new_ui == 'list_big' then
|
||||||
self.ui_toggle = new_ui
|
self.ui_toggle = new_ui
|
||||||
|
self.state:get("groups_sel1"):setSize(7.8, 3)
|
||||||
self.state:get("groups_sel2"):setVisible(false)
|
self.state:get("groups_sel2"):setVisible(false)
|
||||||
self.state:get("groups_sel3"):setVisible(false)
|
self.state:get("groups_sel3"):setVisible(false)
|
||||||
self.state:get("buttons_grid"):reset(9.55, 0.25, 9.0 , 10)
|
self.state:get("buttons_grid"):reset(9.55, 0.25, 9.0 , 10)
|
||||||
@ -155,17 +154,25 @@ local function creative_callback(state)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
-- functions
|
-- functions
|
||||||
local searchfield = state:field(1.3, 4.1, 4.8, 0.5, "search")
|
local searchfield = state:field(1.3, 4.1, 4.2, 0.5, "search")
|
||||||
searchfield:setCloseOnEnter(false)
|
searchfield:setCloseOnEnter(false)
|
||||||
searchfield:onKeyEnter(function(self, state, player)
|
searchfield:onKeyEnter(function(self, state, player)
|
||||||
local search_string = self:getText()
|
local search_string = self:getText()
|
||||||
local filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list, search_string)
|
local lang_code = state.location.rootState.lang_code
|
||||||
|
local filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list, search_string, lang_code)
|
||||||
state.param.creative_grouped_items = ui_tools.get_list_grouped(filtered_list)
|
state.param.creative_grouped_items = ui_tools.get_list_grouped(filtered_list)
|
||||||
filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list_shape, search_string)
|
filtered_list = ui_tools.filter_by_searchstring(ui_tools.root_list_shape, search_string, lang_code)
|
||||||
state.param.creative_grouped_shape_items = filtered_list
|
state.param.creative_grouped_shape_items = filtered_list
|
||||||
update_group_selection(state, 0)
|
update_group_selection(state, 0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local search_button = state:button(5.0, 3.8, 1, 0.5, "search_btn", "Go")
|
||||||
|
search_button:setTooltip("Perform search action")
|
||||||
|
search_button:onClick(function(self, state, player)
|
||||||
|
state:get("search"):submit_key_enter("", player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
-- action mode toggle
|
-- action mode toggle
|
||||||
state:toggle(6, 3.8,1.5,0.5, "btn_tog_mode", {"Give 1", "Give stack"})
|
state:toggle(6, 3.8,1.5,0.5, "btn_tog_mode", {"Give 1", "Give stack"})
|
||||||
|
|
||||||
@ -268,6 +275,10 @@ local function creative_callback(state)
|
|||||||
ui_controller:restore()
|
ui_controller:restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function player_has_creative(state)
|
||||||
|
return state.param.invobj:get_has_creative()
|
||||||
|
end
|
||||||
|
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
-- Register page in smart_inventory
|
-- Register page in smart_inventory
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
@ -276,5 +287,24 @@ smart_inventory.register_page({
|
|||||||
tooltip = "The creative way to get items",
|
tooltip = "The creative way to get items",
|
||||||
icon = "smart_inventory_creative_button.png",
|
icon = "smart_inventory_creative_button.png",
|
||||||
smartfs_callback = creative_callback,
|
smartfs_callback = creative_callback,
|
||||||
|
is_visible_func = player_has_creative,
|
||||||
sequence = 15
|
sequence = 15
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Redefinition for sfinv method maybe called from other mods
|
||||||
|
if minetest.global_exists("sfinv") then
|
||||||
|
function sfinv.set_player_inventory_formspec(player, context)
|
||||||
|
local playername = player:get_player_name()
|
||||||
|
|
||||||
|
local page_state = smart_inventory.get_page_state("creative", playername)
|
||||||
|
if page_state then
|
||||||
|
local state = page_state.location.parentState
|
||||||
|
local has_creative = player_has_creative(state)
|
||||||
|
state:get("creative_button"):setVisible(has_creative)
|
||||||
|
if not has_creative then
|
||||||
|
state:get("crafting_button"):submit(nil, playername)
|
||||||
|
end
|
||||||
|
state:show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -12,9 +12,9 @@ local filter = smart_inventory.filter
|
|||||||
local cache = smart_inventory.cache
|
local cache = smart_inventory.cache
|
||||||
local ui_tools = smart_inventory.ui_tools
|
local ui_tools = smart_inventory.ui_tools
|
||||||
local txt = smart_inventory.txt
|
local txt = smart_inventory.txt
|
||||||
local creative = minetest.setting_getbool("creative_mode")
|
|
||||||
|
|
||||||
local function update_grid(state, listname)
|
local function update_grid(state, listname)
|
||||||
|
local player_has_creative = state.param.invobj:get_has_creative()
|
||||||
-- Update the users inventory grid
|
-- Update the users inventory grid
|
||||||
local list = {}
|
local list = {}
|
||||||
state.param["player_"..listname.."_list"] = list
|
state.param["player_"..listname.."_list"] = list
|
||||||
@ -69,7 +69,7 @@ local function update_grid(state, listname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- add all usable in creative available armor to the main list
|
-- add all usable in creative available armor to the main list
|
||||||
if listname == "main" and creative == true then
|
if listname == "main" and player_has_creative == true then
|
||||||
if smart_inventory.armor_mod then
|
if smart_inventory.armor_mod then
|
||||||
for _, itemdef in pairs(cache.cgroups["armor"].items) do
|
for _, itemdef in pairs(cache.cgroups["armor"].items) do
|
||||||
if not list_dedup[itemdef.name] and not itemdef.groups.not_in_creative_inventory then
|
if not list_dedup[itemdef.name] and not itemdef.groups.not_in_creative_inventory then
|
||||||
@ -225,6 +225,7 @@ local function update_page(state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function move_item_to_armor(state, item)
|
local function move_item_to_armor(state, item)
|
||||||
|
local player_has_creative = state.param.invobj:get_has_creative()
|
||||||
local name = state.location.rootState.location.player
|
local name = state.location.rootState.location.player
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local inventory = player:get_inventory()
|
local inventory = player:get_inventory()
|
||||||
@ -232,7 +233,7 @@ local function move_item_to_armor(state, item)
|
|||||||
|
|
||||||
-- get item to be moved to armor inventory
|
-- get item to be moved to armor inventory
|
||||||
local itemstack, itemname, itemdef
|
local itemstack, itemname, itemdef
|
||||||
if creative == true then
|
if player_has_creative == true then
|
||||||
itemstack = ItemStack(item.item)
|
itemstack = ItemStack(item.item)
|
||||||
itemname = item.item
|
itemname = item.item
|
||||||
else
|
else
|
||||||
@ -273,7 +274,7 @@ local function move_item_to_armor(state, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- handle put backs in non-creative to not lost items
|
-- handle put backs in non-creative to not lost items
|
||||||
if creative == false then
|
if player_has_creative == false then
|
||||||
inventory:set_stack("main", item.stack_index, itemstack)
|
inventory:set_stack("main", item.stack_index, itemstack)
|
||||||
for _, stack in ipairs(removed_items) do
|
for _, stack in ipairs(removed_items) do
|
||||||
stack = inventory:add_item("main", stack)
|
stack = inventory:add_item("main", stack)
|
||||||
@ -304,7 +305,7 @@ local function move_item_to_clothing(state, item)
|
|||||||
clothing:set_player_clothing(player)
|
clothing:set_player_clothing(player)
|
||||||
state.param.player_clothing_data = clothes_ordered
|
state.param.player_clothing_data = clothes_ordered
|
||||||
-- handle put backs in non-creative to not lost items
|
-- handle put backs in non-creative to not lost items
|
||||||
if creative == false then
|
if player_has_creative == false then
|
||||||
local itemstack = inventory:get_stack("main", item.stack_index)
|
local itemstack = inventory:get_stack("main", item.stack_index)
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
inventory:set_stack("main", item.stack_index, itemstack)
|
inventory:set_stack("main", item.stack_index, itemstack)
|
||||||
@ -313,6 +314,7 @@ local function move_item_to_clothing(state, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function move_item_to_inv(state, item)
|
local function move_item_to_inv(state, item)
|
||||||
|
local player_has_creative = state.param.invobj:get_has_creative()
|
||||||
local name = state.location.rootState.location.player
|
local name = state.location.rootState.location.player
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
local inventory = player:get_inventory()
|
local inventory = player:get_inventory()
|
||||||
@ -320,7 +322,7 @@ local function move_item_to_inv(state, item)
|
|||||||
if cache.cgroups["armor"] and cache.cgroups["armor"].items[item.item] then
|
if cache.cgroups["armor"] and cache.cgroups["armor"].items[item.item] then
|
||||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||||
local itemstack = armor_inv:get_stack("armor", item.stack_index)
|
local itemstack = armor_inv:get_stack("armor", item.stack_index)
|
||||||
if creative == true then
|
if player_has_creative == true then
|
||||||
-- trash armor item in creative
|
-- trash armor item in creative
|
||||||
itemstack = ItemStack("")
|
itemstack = ItemStack("")
|
||||||
else
|
else
|
||||||
@ -332,7 +334,7 @@ local function move_item_to_inv(state, item)
|
|||||||
elseif cache.cgroups["clothing"] and cache.cgroups["clothing"].items[item.item] then
|
elseif cache.cgroups["clothing"] and cache.cgroups["clothing"].items[item.item] then
|
||||||
local clothes = state.param.player_clothing_data
|
local clothes = state.param.player_clothing_data
|
||||||
|
|
||||||
if creative ~= true and clothes[item.stack_index] then
|
if player_has_creative ~= true and clothes[item.stack_index] then
|
||||||
local itemstack = inventory:add_item("main", ItemStack(clothes[item.stack_index]))
|
local itemstack = inventory:add_item("main", ItemStack(clothes[item.stack_index]))
|
||||||
if itemstack:is_empty() then
|
if itemstack:is_empty() then
|
||||||
clothes[item.stack_index] = nil
|
clothes[item.stack_index] = nil
|
||||||
|
BIN
textures/smart_inventory_left_arrow.png
Normal file
BIN
textures/smart_inventory_left_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 444 B |
BIN
textures/smart_inventory_right_arrow.png
Normal file
BIN
textures/smart_inventory_right_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 460 B |
19
ui_tools.lua
19
ui_tools.lua
@ -104,21 +104,34 @@ end
|
|||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
-- Filter a list by search string
|
-- Filter a list by search string
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
function ui_tools.filter_by_searchstring(list, search_string)
|
function ui_tools.filter_by_searchstring(list, search_string, lang_code)
|
||||||
local filtered_list = {}
|
local filtered_list = {}
|
||||||
search_string = search_string:lower()
|
search_string = search_string:lower()
|
||||||
for _, entry in ipairs(list) do
|
for _, entry in ipairs(list) do
|
||||||
local def = minetest.registered_items[entry.item]
|
local def = minetest.registered_items[entry.item]
|
||||||
if string.find(def.description:lower(), search_string) or
|
local description = def.description
|
||||||
|
if lang_code then
|
||||||
|
description = minetest.get_translated_string(lang_code, description)
|
||||||
|
end
|
||||||
|
if string.find(description:lower(), search_string) or
|
||||||
string.find(def.name:lower(), search_string) then
|
string.find(def.name:lower(), search_string) then
|
||||||
table.insert(filtered_list, entry)
|
table.insert(filtered_list, entry)
|
||||||
else
|
else
|
||||||
for _, cgroup in pairs(entry.citem.cgroups) do
|
for _, cgroup in pairs(entry.citem.cgroups) do
|
||||||
if cgroup.keyword and string.find(cgroup.keyword:lower():gsub("_", ":"), search_string:gsub("_", ":")) then
|
if cgroup.keyword then
|
||||||
|
if string.find(cgroup.keyword:lower():gsub("_", ":"), search_string:gsub("_", ":"))then
|
||||||
table.insert(filtered_list, entry)
|
table.insert(filtered_list, entry)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if cgroup.group_desc then
|
||||||
|
local group_desc =txt[cgroup.group_desc] or cgroup.group_desc
|
||||||
|
if string.find(group_desc:lower(), search_string)then
|
||||||
|
table.insert(filtered_list, entry)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return filtered_list
|
return filtered_list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user