establish formspec system

This commit is contained in:
Dirk Sohler 2019-02-16 16:45:32 +01:00
parent ecfac04415
commit 028cdbf99e
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
8 changed files with 142 additions and 1 deletions

@ -0,0 +1,18 @@
local modpath = minetest.get_modpath('mtimer')..DIR_DELIM
local syspath = modpath..'system'..DIR_DELIM
mtimer = {
translator = minetest.get_translator('mtimer'),
show_formspec = {},
meta = {
visible = { key = 'mtimer:visible', default = 'true' },
}
}
dofile(syspath..'chat_command.lua')
dofile(syspath..'formspec_creation.lua')
dofile(syspath..'timer_update.lua')
dofile(syspath..'on_receive_fields.lua')
dofile(syspath..'on_joinplayer.lua')

43
locale/mtimer.de.tr Normal file

@ -0,0 +1,43 @@
# textdomain: mtimer
# Configuration Selection Menu
Toggle Visibility=Sichtbarkeit umschalten
Set Position=Position setzen
Set Color=Farbe einstellen
Timezone Offset=Zeitzonenunterschied
Ingame Time Representation=Spielzeit-Repräsentation
Real World Time Representation=Realzeit-Repräsentation
Set Timer Text=Timertext einstellen
# Visibility
mTimer Visibility=mTimer-Sichtbarkeit
Visible=Sichtbar
Invisible=Unsichtbar
# Generic Formspec Strings
Default=Standard
Exit=Verlassen
Back=Zurück
# Timer Weekdays
Monday=Montag
Tuesday=Dienstag
Wednesday=Mittwoch
Thursday=Donnerstag
Friday=Freitag
Saturday=Samstag
Sunday=Sonntag
# Timer Months
January=Januar
February=Februar
March=März
April=April
May=Mai
June=Juni
July=Juli
August=Auggust
September=September
Oktober=Oktober
November=November
December=Dezember

@ -1,3 +1,3 @@
name = mtimer
depends = default
depends = default, sfinv
description = Ingame timer for showing current playtime, current day time, ingame time, etc.

10
system/chat_command.lua Normal file

@ -0,0 +1,10 @@
local m = mtimer
local S = m.translator
minetest.register_chatcommand('mtimer', {
description = S('Configure timer display'),
func = function(name, parameters)
local action = parameters:match('%a+')
if not action then m.show_formspec.menu(name) end
end
})

@ -0,0 +1,30 @@
local m = mtimer
local S = m.translator
mtimer.show_formspec.menu = function (player_name)
minetest.show_formspec(player_name, 'mtimer:main_menu', [[
size[4,7.75]
button[0,0;4,1;set_visibility;]]..S('Set Visibility')..[[]
button[0,1;4,1;set_position;]]..S('Set Position')..[[]
button[0,2;4,1;set_color;]]..S('Set Color')..[[]
button[0,3;4,1;timezone_offset;]]..S('Timezone Offset')..[[]
button[0,4;4,1;ingame_time;]]..S('Ingame Time Representation')..[[]
button[0,5;4,1;real_time;]]..S('Real World Time Representation')..[[]
button[0,6;4,1;timer_text;]]..S('Set Timer Text')..[[]
button_exit[0,7;4,1;exit;]]..S('Exit')..[[]
]])
end
mtimer.show_formspec.set_visibility = function (player_name)
minetest.show_formspec(player_name, 'mtimer:set_visibility', [[
size[6,2.25]
label[0,-0.125;]]..S('mTimer Visibility')..[[]
button[0,0.5;2,1;visible;]]..S('Visible')..[[]
button[2,0.5;2,1;invisible;]]..S('Invisible')..[[]
button[4,0.5;2,1;default;]]..S('Default')..[[]
button_exit[0,1.5;3,1;exit;]]..S('Exit')..[[]
button[3,1.5;3,1;back;]]..S('Back')..[[]
]])
end

9
system/on_joinplayer.lua Normal file

@ -0,0 +1,9 @@
local m = mtimer
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()
for _,def in pairs(m.meta) do
local current = meta:get_string(def.key)
if current == '' then meta:set_string(def.key, def.default) end
end
end)

@ -0,0 +1,30 @@
local m = mtimer
local f = mtimer.show_formspec
minetest.register_on_player_receive_fields(function(player, formname, fields)
local meta = player:get_meta()
local name = player:get_player_name()
-- Select what formspec to show basing on main menu button
if formname == 'mtimer:main_menu' then
if fields.set_visibility then f.set_visibility(name) end
end
-- Set timer visibility
if formname == 'mtimer:set_visibility' then
local attr = m.meta.visible
if fields.visible then meta:set_string(attr.key, 'true') end
if fields.invisible then meta:set_string(attr.key, 'false') end
if fields.default then meta:set_string(attr.key, attr.default) end
end
-- Back to menu from all formspecs
if fields.back then f.menu(name) end
-- DEBUG: Print all player meta data
print(dump(meta:to_table()))
end)

1
system/timer_update.lua Normal file

@ -0,0 +1 @@
local m = mtimer