diff --git a/inventory_framework.lua b/inventory_framework.lua index 32d2b8f..2619017 100644 --- a/inventory_framework.lua +++ b/inventory_framework.lua @@ -36,8 +36,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state) state:size(20,12) state:label(1,0.2,"header","Smart Inventory") state:image(0,0,1,1,"header_logo", "logo.png") --- state:image_button(19,0,1,1,"exit", "Exit","???.png", true) - state:button(19,0,1,1,"exit", "Exit", true) + state:image_button(19,0,1,1,"exit", "","smart_inventory_exit_button.png", true):setTooltip("Close the inventory") local button_x = 0.1 table.sort(smart_inventory.registered_pages, function(a,b) if not a.sequence then diff --git a/pages/crafting.lua b/pages/crafting.lua index feb3559..3e242d2 100644 --- a/pages/crafting.lua +++ b/pages/crafting.lua @@ -332,11 +332,17 @@ local function crafting_callback(state) state:image(8,9,1,1,"trash_icon","creative_trash_icon.png") state:inventory(8, 9, 1, 1, "trash"):useDetached(player.."_trash_inv") - state:button(1, 4.2, 2, 0.5, "compress", "Compress"):onClick(function(self, state, player) + local btn_compress = state:image_button(1, 3.8, 1, 1, "compress", "","smart_inventory_compress_button.png") + btn_compress:setTooltip("Merge stacks with same items to get free place") + btn_compress:onClick(function(self, state, player) + ui_tools.image_button_feedback(player, "crafting", "compress") state.param.invobj:compress() end) - state:button(3, 4.2, 2, 0.5, "clear", "Sweep"):onClick(function(self, state, player) + local btn_sweep = state:image_button(2, 3.8, 1, 1, "clear", "", "smart_inventory_sweep_button.png") + btn_sweep:setTooltip("Move all items from crafting grid back to inventory") + btn_sweep:onClick(function(self, state, player) + ui_tools.image_button_feedback(player, "crafting", "clear") state.param.invobj:sweep_crafting_inventory() end) @@ -416,12 +422,15 @@ local function crafting_callback(state) -- Lookup create_lookup_inv(state, player) - state:image(10, 4, 1, 1,"lookup_icon", "default_bookshelf_slot.png") - state:inventory(10, 4.0, 1, 1,"lookup"):useDetached(player.."_crafting_inv") + state:image(10, 4, 1, 1,"lookup_icon", "smart_inventory_lookup_field.png") + local inv_lookup = state:inventory(10, 4.0, 1, 1,"lookup"):useDetached(player.."_crafting_inv") + -- Get craftable by items in inventory - local craftable_button = state:button(11, 4.2, 2, 0.5, "craftable", "Craftable") - craftable_button:onClick(function(self, state, player) + local btn_craftable = state:image_button(11, 4, 1, 1, "craftable", "", "smart_inventory_craftable_button.png") + btn_craftable:setTooltip("Show items crafteable by items in inventory") + btn_craftable:onClick(function(self, state, player) + ui_tools.image_button_feedback(player, "crafting", "craftable") -- reset group selection and search field on proposal mode change if state.param.survival_proposal_mode ~= "craftable" then state.param.survival_proposal_mode = "craftable" @@ -482,7 +491,7 @@ local function crafting_callback(state) end) -- initial values - craftable_button:submit("not used fieldname", state.location.rootState.location.player) + btn_craftable:submit("not used fieldname", state.location.rootState.location.player) end ----------------------------------------------------- diff --git a/textures/smart_inventory_compress_button.png b/textures/smart_inventory_compress_button.png new file mode 100644 index 0000000..e4efc18 Binary files /dev/null and b/textures/smart_inventory_compress_button.png differ diff --git a/textures/smart_inventory_craftable_button.png b/textures/smart_inventory_craftable_button.png new file mode 100644 index 0000000..0d5f7b2 Binary files /dev/null and b/textures/smart_inventory_craftable_button.png differ diff --git a/textures/smart_inventory_exit_button.png b/textures/smart_inventory_exit_button.png new file mode 100644 index 0000000..956cdde Binary files /dev/null and b/textures/smart_inventory_exit_button.png differ diff --git a/textures/smart_inventory_lookup_field.png b/textures/smart_inventory_lookup_field.png new file mode 100644 index 0000000..873febf Binary files /dev/null and b/textures/smart_inventory_lookup_field.png differ diff --git a/textures/smart_inventory_sweep_button.png b/textures/smart_inventory_sweep_button.png new file mode 100644 index 0000000..98a2935 Binary files /dev/null and b/textures/smart_inventory_sweep_button.png differ diff --git a/ui_tools.lua b/ui_tools.lua index 955ab2d..a2c341c 100644 --- a/ui_tools.lua +++ b/ui_tools.lua @@ -426,5 +426,24 @@ local function prepare_root_lists() end cache.register_on_cache_filled(prepare_root_lists) +----------------------------------------------------- +-- Take a visual feedback on pressing button since the minetest client does nothing visible on pressing button +----------------------------------------------------- +function ui_tools.image_button_feedback(playername, page, element) + local function reset_background(playername, page, element) + local state = smart_inventory.get_page_state(page, playername) + if state then + state:get(element):setBackground(nil) + state.location.rootState:show() + end + end + + local state = smart_inventory.get_page_state(page, playername) + if state then + state:get(element):setBackground("halo.png") + minetest.after(0.3, reset_background, playername, page, element) + end + +end -------------------------------- return ui_tools