From 37c6cbba997571069185fa15b2fe7223f0e65a9d Mon Sep 17 00:00:00 2001
From: Alexander Weber <web.alexander@web.de>
Date: Thu, 27 Aug 2020 15:34:46 +0200
Subject: [PATCH] smart_sfinv_tweaks: Move sfinv_buttons for compress and
 rotate There was issue placing the buttons on creative page

---
 smart_sfinv_tweaks/depends.txt |  1 +
 smart_sfinv_tweaks/init.lua    | 36 ++++++++++++++++++++++------------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/smart_sfinv_tweaks/depends.txt b/smart_sfinv_tweaks/depends.txt
index 8619dff..711d60c 100644
--- a/smart_sfinv_tweaks/depends.txt
+++ b/smart_sfinv_tweaks/depends.txt
@@ -1 +1,2 @@
 smart_sfinv_api
+sfinv_buttons
diff --git a/smart_sfinv_tweaks/init.lua b/smart_sfinv_tweaks/init.lua
index fab66d1..de52353 100644
--- a/smart_sfinv_tweaks/init.lua
+++ b/smart_sfinv_tweaks/init.lua
@@ -1,11 +1,29 @@
 local maininv = dofile(minetest.get_modpath(minetest.get_current_modname()).."/maininv.lua")
 
-smart_sfinv_api.defaults.theme_inv = smart_sfinv_api.defaults.theme_inv ..
-		'image_button[0.1,3.97;0.8,0.8;smart_sfinv_tweaks_compress_button.png;sfinv_tweaks_compress;]' ..
-		'tooltip[sfinv_tweaks_compress;Compress stacks]'..
-		'image_button[1.1,3.97;0.8,0.8;smart_sfinv_tweaks_rotate.png;sfinv_tweaks_rotate;]' ..
-		'tooltip[sfinv_tweaks_rotate;Rotate rows]'
 
+sfinv_buttons.register_button('compress', {
+	image = "smart_sfinv_tweaks_compress_button.png",
+	tooltip = "Compress stacks",
+	position = 7,
+	action = function(player)
+		maininv.get(player):compress()
+	end,
+	show = function(player, context, content, show_inv)
+		return show_inv
+	end
+})
+
+sfinv_buttons.register_button('rotate', {
+	image = "smart_sfinv_tweaks_rotate.png",
+	tooltip = "Rotate inventory rows",
+	position = 7,
+	action = function(player)
+		maininv.get(player):rotate_rows()
+	end,
+	show = function(player, context, content, show_inv)
+		return show_inv
+	end
+})
 
 local crafting_enhance = 'image_button[0.5,1.6;0.8,0.8;smart_sfinv_tweaks_sweep_button.png;sfinv_tweaks_sweep;]' ..
 		'tooltip[sfinv_tweaks_sweep;Sweep crafting area]'
@@ -17,14 +35,6 @@ smart_sfinv_api.register_enhancement({
 		end
 	end,
 	receive_fields = function(handler, player, context, fields)
-		if fields.sfinv_tweaks_compress then
-			context.tweaks_inv = context.tweaks_inv or maininv.get(player)
-			context.tweaks_inv:compress()
-		end
-		if fields.sfinv_tweaks_rotate then
-			context.tweaks_inv = context.tweaks_inv or maininv.get(player)
-			context.tweaks_inv:rotate_rows()
-		end
 		if fields.sfinv_tweaks_sweep then
 			context.tweaks_inv = context.tweaks_inv or maininv.get(player)
 			context.tweaks_inv:sweep_crafting_inventory()