Skip to content

Commit b259906

Browse files
bell07sfan5
authored andcommittedNov 13, 2017
Add support for smart_inventory
1 parent 12270dc commit b259906

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
 

‎worldedit_gui/depends.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ unified_inventory?
44
inventory_plus?
55
sfinv?
66
creative?
7+
smart_inventory?

‎worldedit_gui/init.lua

+49
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,55 @@ elseif rawget(_G, "inventory_plus") then --inventory++ installed
134134
inventory_plus.set_inventory_formspec(player, get_formspec(name, page))
135135
end
136136
end
137+
elseif rawget(_G, "smart_inventory") then -- smart_inventory installed
138+
-- redefinition: Update the code element on inventory page to show the we-page
139+
function worldedit.show_page(name, page)
140+
local state = smart_inventory.get_page_state("worldedit_gui", name)
141+
if state then
142+
state:get("code"):set_we_formspec(page)
143+
state.location.rootState:show() -- update inventory page
144+
end
145+
end
146+
147+
-- smart_inventory page callback. Contains just a "custom code" element
148+
local function smart_worldedit_gui_callback(state)
149+
local codebox = state:element("code", { name = "code", code = "" })
150+
function codebox:set_we_formspec(we_page)
151+
local new_formspec = get_formspec(state.location.rootState.location.player, we_page)
152+
new_formspec = new_formspec:gsub('button_exit','button') --no inventory closing
153+
self.data.code = "container[1,1]".. new_formspec .. "container_end[]"
154+
end
155+
codebox:set_we_formspec("worldedit_gui")
156+
157+
-- process input (the back button)
158+
state:onInput(function(state, fields, player)
159+
if fields.worldedit_gui then --main page
160+
state:get("code"):set_we_formspec("worldedit_gui")
161+
elseif fields.worldedit_gui_exit then --return to original page
162+
state:get("code"):set_we_formspec("worldedit_gui")
163+
state.location.parentState:get("crafting_button"):submit() -- switch to the crafting tab
164+
end
165+
end)
166+
end
167+
168+
-- all handler should return false to force inventory UI update
169+
local orig_register_gui_handler = worldedit.register_gui_handler
170+
worldedit.register_gui_handler = function(identifier, handler)
171+
local wrapper = function(...)
172+
handler(...)
173+
return false
174+
end
175+
orig_register_gui_handler(identifier, wrapper)
176+
end
177+
178+
-- register the inventory button
179+
smart_inventory.register_page({
180+
name = "worldedit_gui",
181+
tooltip = "Edit your World!",
182+
icon = "inventory_plus_worldedit_gui.png",
183+
smartfs_callback = smart_worldedit_gui_callback,
184+
sequence = 99
185+
})
137186
elseif rawget(_G, "sfinv") then --sfinv installed (part of minetest_game since 0.4.15)
138187
assert(sfinv.enabled)
139188
local orig_get = sfinv.pages["sfinv:crafting"].get

0 commit comments

Comments
 (0)
Please sign in to comment.