From 03edd6808a32d321cbc2a73935940c355a43fb99 Mon Sep 17 00:00:00 2001
From: Marco <4279489-marco_a@users.noreply.gitlab.com>
Date: Thu, 23 Jul 2020 02:19:26 +0200
Subject: [PATCH] if a row only contains hidden items, it's not shown to the
player | background customisation according to the rows
---
config.txt | 3 +-
formspec.lua | 67 +++++++++++++-----
load_config.lua | 5 +-
.../18_(and this can hide an entire row!) | 6 ++
privs.lua | 1 +
...test.png => magiccompass_gui_bg_test2.png} | Bin
textures/magiccompass_gui_bg_test4.png | Bin 0 -> 316 bytes
7 files changed, 60 insertions(+), 22 deletions(-)
create mode 100644 locations/18_(and this can hide an entire row!)
create mode 100644 privs.lua
rename textures/{magiccompass_gui_bg_test.png => magiccompass_gui_bg_test2.png} (100%)
create mode 100644 textures/magiccompass_gui_bg_test4.png
diff --git a/config.txt b/config.txt
index 1c8ab4a..536d18a 100644
--- a/config.txt
+++ b/config.txt
@@ -1,3 +1,4 @@
menu_title =You can change title and bg in config.txt!
-menu_gui_bg =magiccompass_gui_bg_test.png
+menu_gui_bg_2rows =magiccompass_gui_bg_test2.png
+menu_gui_bg_4rows =magiccompass_gui_bg_test4.png
menu_gui_button_bg =magiccompass_gui_button_bg.png
diff --git a/formspec.lua b/formspec.lua
index ba4ac16..17b1431 100644
--- a/formspec.lua
+++ b/formspec.lua
@@ -1,45 +1,74 @@
+-- REMINDER: oltre a `itemID` c'era anche un `idx` per far sì che si potevano avere altre righe visibili dopo alcune nascoste (idx = SLOTS_PER_ROW * (i- hidden_rows) + j).
+-- Tuttavia, l'errore sembra dovuto a Minetest che non ne vuole sapere di renderizzare le linee seguenti a quelle nascoste, che gli ID del formspec siano continui o meno;
+-- questo spiega anche il `last_non_empty_row = i` nella riga invisibile al giocatore, che doveva permetter tale cosa ma che è attualmente inutile
+
+
function magic_compass.get_formspec(p_name)
local SLOTS_PER_ROW = 5
local rows = math.floor(table.maxn(magic_compass.items) / SLOTS_PER_ROW - 0.1) + 1
+ local hidden_rows = 0
+ local last_non_empty_row = 0
-
- local formspec = {
- "size[6," .. 1.5 + (rows-1) .. "]",
- --"style_type[image_button;border=false,alpha=false,bgimg=" .. magic_compass.menu_gui_button_bg .. "]",
- --"style_type[item_image_button;border=false,alpha=false,bgimg=" .. magic_compass.menu_gui_button_bg .. "]",
- "hypertext[0.25,-0.2;6,1;title;]"
- }
-
- if magic_compass.menu_gui_bg then
- table.insert(formspec, "background[0,0;6," .. 1.5 + (rows-1) .. ";" .. magic_compass.menu_gui_bg .. ";true]")
- end
+ local formspec = {}
-- aggiungo i vari slot (matrice i*j)
for i = 1, rows do
- --local idx = i +3 -- il +3 serve per evitare che vengano PRIMA di style_type (size, style1, style2 = 3)
- local idx = i +1
+ local hidden_items = 0
+ local is_row_empty = true
+
for j = 1, SLOTS_PER_ROW do
local x = 0.5 + (j-1)
local y = 0.33 + (i-1)
- local ID = SLOTS_PER_ROW * (i-1) + j
- local item = magic_compass.items[ID]
+ local itemID = SLOTS_PER_ROW * (i-1) + j
+ local item = magic_compass.items[itemID]
if item then
if item.privs then
if not item.hide or (item.hide and minetest.check_player_privs(p_name, minetest.string_to_privs(item.privs, ", "))) then
- table.insert(formspec, idx, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. ID .. ";" .. ID .. ";]")
+ table.insert(formspec, itemID, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. itemID .. ";" .. itemID .. ";]")
+ if is_row_empty then is_row_empty = false end
else
- table.insert(formspec, idx, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
+ table.insert(formspec, itemID, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
+ hidden_items = hidden_items + 1
end
else
- table.insert(formspec, idx, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. ID .. ";" .. ID .. ";]")
+ table.insert(formspec, itemID, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. itemID .. ";" .. itemID .. ";]")
+ if is_row_empty then is_row_empty = false end
end
else
- table.insert(formspec, idx, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
+ table.insert(formspec, itemID, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
end
end
+
+ if not is_row_empty then
+ last_non_empty_row = i
+ end
+
+ -- se una riga contiene solo oggetti non visibili al giocatore, non la mostro
+ if hidden_items > 0 and is_row_empty then
+ local rows_to_hide = i - last_non_empty_row
+
+ for k = (SLOTS_PER_ROW * (i - rows_to_hide)) + 1, SLOTS_PER_ROW * i do
+ formspec[k] = nil
+ end
+
+ hidden_rows = hidden_rows + rows_to_hide
+ last_non_empty_row = i
+ end
+
+ end
+
+ local shown_rows = rows - hidden_rows
+
+ table.insert(formspec, 1, "size[6," .. 1.5 + (shown_rows-1) .. "]")
+ --"style_type[image_button;border=false,alpha=false,bgimg=" .. magic_compass.menu_gui_button_bg .. "]",
+ --"style_type[item_image_button;border=false,alpha=false,bgimg=" .. magic_compass.menu_gui_button_bg .. "]",
+ table.insert(formspec, 2, "hypertext[0.25,-0.2;6,1;title;]")
+
+ if magic_compass["menu_gui_bg_"..shown_rows.."rows"] then
+ table.insert(formspec, 3, "background[0,0;6," .. 1.5 + (shown_rows -1) .. ";" .. magic_compass["menu_gui_bg_"..shown_rows.."rows"] .. ";true]")
end
return table.concat(formspec,"")
diff --git a/load_config.lua b/load_config.lua
index 2a946ee..add0479 100644
--- a/load_config.lua
+++ b/load_config.lua
@@ -2,7 +2,8 @@ local config_file = io.open(minetest.get_modpath("magic_compass") .. "/config.tx
local data = string.split(config_file:read("*all"), "\n")
magic_compass.menu_title = string.match(data[1], "=(.*)")
-magic_compass.menu_gui_bg = string.match(data[2], "=(.*)")
---magic_compass.menu_gui_button_bg = string.match(data[3], "=(.*)")
+magic_compass.menu_gui_bg_2rows = string.match(data[2], "=(.*)")
+magic_compass.menu_gui_bg_4rows = string.match(data[3], "=(.*)")
+--magic_compass.menu_gui_button_bg = string.match(data[4], "=(.*)")
config_file:close()
diff --git a/locations/18_(and this can hide an entire row!) b/locations/18_(and this can hide an entire row!)
new file mode 100644
index 0000000..a2f31e4
--- /dev/null
+++ b/locations/18_(and this can hide an entire row!)
@@ -0,0 +1,6 @@
+And if you can't see ME (you need the teleport privilege), being the only one in the row, you won't see the entire row. THIS IS THE TRUE POWER OF ADMINS, CAN YOU FEEL IT?!
+magiccompass_example6.png
+150.5, 100.0, -90.5
+-1
+teleport
+HIDE
diff --git a/privs.lua b/privs.lua
new file mode 100644
index 0000000..a4ce302
--- /dev/null
+++ b/privs.lua
@@ -0,0 +1 @@
+minetest.register_privilege("magiccompass_admin", {})
diff --git a/textures/magiccompass_gui_bg_test.png b/textures/magiccompass_gui_bg_test2.png
similarity index 100%
rename from textures/magiccompass_gui_bg_test.png
rename to textures/magiccompass_gui_bg_test2.png
diff --git a/textures/magiccompass_gui_bg_test4.png b/textures/magiccompass_gui_bg_test4.png
new file mode 100644
index 0000000000000000000000000000000000000000..112d5472b36c989182ebc8e9686d07cda7df6e6c
GIT binary patch
literal 316
zcmeAS@N?(olHy`uVBq!ia0vp^2|(<@!VDyTd%g_-QW60^A+DD06_yn%G|t?=|Ltqn
z>yHa2_eBK<*A^6R=iT)hsOG+>i(^Q|t+$sP`I;33SOeBw&^DQOKy%l&bG&B?7?o`u
zf_K&(%$#7Bk(hXywZ7Ble*;%w5C{mJ)HJrw(0E|akYsj1PdvfwMG>PM|GMW-3|{c%
zTSzo`&*fv-)WR@7#X&c<#KK{UVJL?JuLpOVO5jfY4}7oI|JG$l=2^n<<-q*J@?}~K
z!fQll+wy&3;Mp>*rjI+%ukDZUM-Q