More areas can now be hidden separately, with a more responsive formspec
parent
003d393d4b
commit
b827c59775
|
@ -1,4 +1,11 @@
|
|||
menu_title =You can change title and bg in config.txt!
|
||||
|
||||
# you can add as many backgrounds/rows as you want, but be sure to edit load_config.lua too if you do so (EMPTY LINES ARE NOT COUNTED)
|
||||
menu_gui_bg_2rows =magiccompass_gui_bg_test2.png
|
||||
menu_gui_bg_4rows =magiccompass_gui_bg_test4.png
|
||||
menu_gui_bg_6rows =magiccompass_gui_bg_test6.png
|
||||
|
||||
menu_gui_button_bg =magiccompass_gui_button_bg.png
|
||||
|
||||
|
||||
|
||||
|
|
39
formspec.lua
39
formspec.lua
|
@ -1,14 +1,9 @@
|
|||
-- 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 last_pointed_row = 0
|
||||
|
||||
local formspec = {}
|
||||
|
||||
|
@ -20,54 +15,60 @@ function magic_compass.get_formspec(p_name)
|
|||
for j = 1, SLOTS_PER_ROW do
|
||||
|
||||
local x = 0.5 + (j-1)
|
||||
local y = 0.33 + (i-1)
|
||||
local y = 0.33 + (i - hidden_rows -1)
|
||||
local idx = SLOTS_PER_ROW * (i - hidden_rows -1) + j
|
||||
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, itemID, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. itemID .. ";" .. itemID .. ";]")
|
||||
table.insert(formspec, idx, "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, itemID, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
|
||||
table.insert(formspec, idx, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
|
||||
hidden_items = hidden_items + 1
|
||||
end
|
||||
else
|
||||
table.insert(formspec, itemID, "item_image_button[" .. x .. "," .. y .. ";1,1;magic_compass:" .. itemID .. ";" .. itemID .. ";]")
|
||||
table.insert(formspec, idx, "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, itemID, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
|
||||
table.insert(formspec, idx, "image_button[" .. x .. "," .. y .. ";1,1;;EMPTY;]")
|
||||
end
|
||||
end
|
||||
|
||||
if not is_row_empty then
|
||||
last_non_empty_row = i
|
||||
last_pointed_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
|
||||
hidden_rows = hidden_rows + (i - last_pointed_row)
|
||||
|
||||
for k = (SLOTS_PER_ROW * (i - hidden_rows)) + 1, SLOTS_PER_ROW * i do
|
||||
formspec[k] = nil
|
||||
end
|
||||
|
||||
hidden_rows = hidden_rows + rows_to_hide
|
||||
last_non_empty_row = i
|
||||
-- fa in modo che se ci sono più aree nascoste da NON mostrare, il conteggio non svuoti linee di troppo incrementando hidden_rows più del dovuto
|
||||
last_pointed_row = i
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
local shown_rows = rows - hidden_rows
|
||||
local bg = magic_compass["menu_gui_bg_"..shown_rows.."rows"]
|
||||
|
||||
-- assegno intestazioni formspec (dimensione, sfondo ecc)
|
||||
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, 1, "style_type[image_button;border=false,alpha=false,bgimg=" .. magic_compass.menu_gui_button_bg .. "]")
|
||||
--table.insert(formspec, 1, "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
|
||||
if bg and bg ~= "" then
|
||||
table.insert(formspec, 3, "background[0,0;6," .. 1.5 + (shown_rows -1) .. ";" .. magic_compass["menu_gui_bg_"..shown_rows.."rows"] .. ";true]")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
local config_file = io.open(minetest.get_modpath("magic_compass") .. "/config.txt", "r")
|
||||
local data = string.split(config_file:read("*all"), "\n")
|
||||
|
||||
minetest.log("action", dump(data))
|
||||
|
||||
magic_compass.menu_title = string.match(data[1], "=(.*)")
|
||||
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], "=(.*)")
|
||||
magic_compass.menu_gui_bg_2rows = string.match(data[3], "=(.*)")
|
||||
magic_compass.menu_gui_bg_4rows = string.match(data[4], "=(.*)")
|
||||
magic_compass.menu_gui_bg_6rows = string.match(data[5], "=(.*)")
|
||||
--magic_compass.menu_gui_button_bg = string.match(data[6], "=(.*)")
|
||||
|
||||
config_file:close()
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
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
|
|
@ -0,0 +1,6 @@
|
|||
And if you can't see ME (you need the password privilege), being the only one in the row, you won't see this row nor all the empty rows before it. THIS IS THE TRUE POWER OF ADMINS, CAN YOU FEEL IT?!
|
||||
magiccompass_example6.png
|
||||
150.5, 100.0, -90.5
|
||||
-1
|
||||
password
|
||||
HIDE
|
|
@ -0,0 +1,6 @@
|
|||
So as you can see we can create empty rows too, not declaring anything in a line and having something LIKE ME after
|
||||
magiccompass_example7.png
|
||||
-180.5, 210.0, -20.5
|
||||
-1
|
||||
settime
|
||||
HIDE
|
|
@ -16,6 +16,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
local item = magic_compass.items[tonumber(ID)]
|
||||
local p_name = player:get_player_name()
|
||||
|
||||
minetest.log("action", "ID = " .. ID)
|
||||
|
||||
-- se non ha i permessi, annullo
|
||||
if item.privs and not minetest.check_player_privs(p_name, minetest.string_to_privs(item.privs, ", ")) then
|
||||
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", S("[!] This location is not available for you at the moment!")))
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 166 B |
Binary file not shown.
Before Width: | Height: | Size: 316 B After Width: | Height: | Size: 315 B |
Binary file not shown.
After Width: | Height: | Size: 334 B |
Loading…
Reference in New Issue