if a row only contains hidden items, it's not shown to the player | background customisation according to the rows

master
Marco 2020-07-23 02:19:26 +02:00
parent 7373da8d93
commit 03edd6808a
7 changed files with 60 additions and 22 deletions

View File

@ -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

View File

@ -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;<style font=mono><center>" .. magic_compass.menu_title .. "</center></style>]"
}
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;<style font=mono><center>" .. magic_compass.menu_title .. "</center></style>]")
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,"")

View File

@ -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()

View File

@ -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

1
privs.lua Normal file
View File

@ -0,0 +1 @@
minetest.register_privilege("magiccompass_admin", {})

View File

Before

Width:  |  Height:  |  Size: 313 B

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B