Code clean + support for geolocalisation in the formspec title

master
Zughy 2021-02-27 01:11:43 +01:00
parent 6cae54c5e4
commit c838bdb3d9
6 changed files with 28 additions and 17 deletions

9
SETTINGS.lua Normal file
View File

@ -0,0 +1,9 @@
-- the title is geolocalised, just be sure to edit it in the locale folder too
magic_compass.menu_title = "You can change title and bg in SETTINGS.lua!"
-- add as many rows as you want, the important thing is to follow the format
magic_compass.menu_gui_bg_2rows = "magiccompass_gui_bg_test2.png"
magic_compass.menu_gui_bg_4rows = "magiccompass_gui_bg_test4.png"
magic_compass.menu_gui_bg_6rows = "magiccompass_gui_bg_test6.png"
magic_compass.menu_gui_button_bg = "magiccompass_gui_button_bg.png"

View File

@ -1,6 +1,11 @@
local S = minetest.get_translator("magic_compass")
function magic_compass.get_formspec(p_name)
local SLOTS_PER_ROW = 5
local y_offset = 0.3
local rows = math.floor(table.maxn(magic_compass.items) / SLOTS_PER_ROW - 0.1) + 1
local hidden_rows = 0
local last_pointed_row = 0
@ -15,7 +20,7 @@ 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 - hidden_rows -1)
local y = 0.3 + y_offset + (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]
@ -63,10 +68,10 @@ function magic_compass.get_formspec(p_name)
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) .. "]")
table.insert(formspec, 1, "size[6," .. 2 + (shown_rows-1) .. "]")
table.insert(formspec, 2, "style_type[image_button;border=false;bgimg=" .. magic_compass.menu_gui_button_bg .. "]")
table.insert(formspec, 3, "style_type[item_image_button;border=false;bgimg=" .. magic_compass.menu_gui_button_bg .. "]")
table.insert(formspec, 4, "hypertext[0.25,-0.2;6,1;title;<style font=mono><center>" .. magic_compass.menu_title .. "</center></style>]")
table.insert(formspec, 4, "hypertext[0.25,-0.2;6,1;title;<global font=mono halign=center valign=middle>" .. S(magic_compass.menu_title) .. "</style>]")
if bg and bg ~= "" then
table.insert(formspec, 5, "background[0,0;6," .. 1.5 + (shown_rows -1) .. ";" .. magic_compass["menu_gui_bg_"..shown_rows.."rows"] .. ";true]")

View File

@ -1,11 +1,12 @@
magic_compass = {}
local version = "1.3.0"
local version = "1.4.0-dev"
dofile(minetest.get_modpath("magic_compass") .. "/SETTINGS.lua")
dofile(minetest.get_modpath("magic_compass") .. "/callbacks.lua")
dofile(minetest.get_modpath("magic_compass") .. "/deserializer.lua")
dofile(minetest.get_modpath("magic_compass") .. "/formspec.lua")
dofile(minetest.get_modpath("magic_compass") .. "/items.lua")
dofile(minetest.get_modpath("magic_compass") .. "/load_config.lua")
dofile(minetest.get_modpath("magic_compass") .. "/player_manager.lua")
minetest.log("action", "[MAGIC COMPASS] Mod initialised, running version " .. version)

View File

@ -1,10 +0,0 @@
local config_file = io.open(minetest.get_modpath("magic_compass") .. "/config.txt", "r")
local data = string.split(config_file:read("*all"), "\n")
magic_compass.menu_title = string.match(data[1], "=(.*)")
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()

View File

@ -1,4 +1,4 @@
# version 1.3.0
# version 1.4.0-dev
# author(s): Zughy
# reviewer(s):
# textdomain: magic_compass
@ -9,3 +9,6 @@ Magic Compass=Bussola Magica
# player_manager.lua
[!] This location is not available for you at the moment!=[!] Non ti è consentito l'accesso a questo luogo ora!
[!] You can't reteleport to this location so quickly! (seconds remaining: @1)=[!] Non puoi ritelerasportarti in questo luogo così velocemente! (secondi rimanenti: @1)
# SETTINGS.lua
You can change title and bg in SETTINGS.lua!=Puoi cambiare titolo e sfondo in SETTINGS.lua!

View File

@ -1,4 +1,4 @@
# version 1.3.0
# version 1.4.0-dev
# author(s):
# reviewer(s):
# textdomain: magic_compass
@ -9,3 +9,6 @@ Magic Compass=
# player_manager.lua
[!] This location is not available for you at the moment!=
[!] You can't reteleport to this location so quickly! (seconds remaining: @1)=
# SETTINGS.lua
You can change title and bg in SETTINGS.lua!=