implement timer format setting

This commit is contained in:
Dirk Sohler 2019-02-22 14:08:44 +01:00
parent ef34c5d392
commit 3aeae84356
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
6 changed files with 100 additions and 8 deletions

@ -10,8 +10,14 @@ mtimer = {
position = { key = 'mtimer:position', default = 'bl' },
color = { key = 'mtimer:color', default = '#ffffffFF' },
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
ingame_time = {key='mtimer:ingame_time_format',default='{24h}:{min}'},
real_time = { key='mtimer:real_time_format', default='{24h}:{min}' },
ingame_time = {
key = 'mtimer:ingame_time_format',
default = '{24h}:{min}'
},
real_time = {
key = 'mtimer:real_time_format',
default = '{24h}:{min} ({isodate})'
},
session_start_time = {
key = 'mtimer:session_start_time_format',
default = '{isodate}T{isotime}'
@ -19,7 +25,14 @@ mtimer = {
session_duration = {
key = 'mtimer:session_duration_format',
default = '{hours}:{minutes}'
}
},
timer_format = {
key = 'mtimer:timer_format',
default = 'Current Date: {rd}\n'..
'Ingame Time: {it}\n'..
'Session Start: {st}\n'..
'Session Duration: {sd}'
},
}
}
@ -35,4 +48,5 @@ dofile(syspath..'timer_update.lua')
dofile(syspath..'on_receive_fields.lua')
dofile(syspath..'on_joinplayer.lua')
dofile(syspath..'get_times.lua')
dofile(syspath..'get_timer_data.lua')

@ -10,7 +10,7 @@ Ingame Time Format=Spielzeit-Format
Real-World Time Format=Realzeit-Format
Session Start Time Format=Session-Startzeit-Format
Session Duration Format=Session-Dauer-Format
Set Timer Text=Timertext einstellen
Timer Format=Timerformat
Open Main Menu=Hauptmenü öffnen
# Visibility

@ -10,7 +10,7 @@ end
minetest.register_chatcommand('mtimer', {
description = S('Configure timer display'),
params = '<vi/po/co/tz/in/re/st/sd/te/help>',
params = '<vi/po/co/tz/in/re/st/sd/tt/help>',
func = function(name, parameters)
local action = parameters:match('%a+')
@ -25,7 +25,7 @@ minetest.register_chatcommand('mtimer', {
if action == 're' then fs.real_world_time_format(name) end
if action == 'st' then fs.session_start_time_format(name) end
if action == 'sd' then fs.session_duration_format(name) end
if action == 'te' then fs.timer_text(name) end
if action == 'tf' then fs.timer_format(name) end
if action == 'help' then
local message = {
@ -37,7 +37,7 @@ minetest.register_chatcommand('mtimer', {
command('re')..S('Real-World Time Format'),
command('st')..S('Session Start Time Format'),
command('sd')..S('Session Duration Format'),
command('te')..S('Set Timer Text'),
command('tf')..S('Timer Format'),
command(' ')..S('Open Main Menu')
}
cs(name, table.concat(message, '\n'))

@ -17,7 +17,7 @@ mtimer.show_formspec.main_menu = function (player_name)
button[0,5.5;4,1;real_world_time_format;]]..S('Real-World Time Format')..[[]
button[0,6.5;4,1;session_start_time_format;]]..S('Session Start Time Format')..[[]
button[0,7.5;4,1;session_duration_format;]]..S('Session Duration Format')..[[]
button[0,8.5;4,1;timer_text;]]..S('Set Timer Text')..[[]
button[0,8.5;4,1;timer_format;]]..S('Timer Format')..[[]
button_exit[0,9.5;4,1;exit;]]..S('Exit')..[[]
]])
end
@ -196,3 +196,42 @@ mtimer.show_formspec.session_duration_format = function (player_name)
container_end[]
]])
end
mtimer.show_formspec.timer_format = function (player_name)
local timer_data = mtimer.get_timer_data(player_name)
minetest.show_formspec(player_name, 'mtimer:timer_format',
build_frame(9, 5.8, S('Timer Format'))..[[
textarea[0.25,0.5;6,2.5;format;;]]..fe(timer_data.format)..[[]
container[0,2.785]
label[2.5,0;]]..S('Variable')..[[]
label[4,0;]]..S('Current value')..[[]
box[0,0.45;8.75,0.02;#ffffff]
label[0,0.5;]]..S('Real-World Date')..[[]
label[2.5,0.5;{rd}]
label[4,0.5;]]..fe(timer_data.real_world_date)..[[]
label[0,0.9;]]..S('In-Game Time')..[[]
label[2.5,0.9;{it}]
label[4,0.9;]]..fe(timer_data.ingame_time)..[[]
label[0,1.3;]]..S('Session Start Time')..[[]
label[2.5,1.3;{st}]
label[4,1.3;]]..fe(timer_data.session_start_time)..[[]
label[0,1.7;]]..S('Session Duration')..[[]
label[2.5,1.7;{sd}]
label[4,1.7;]]..fe(timer_data.session_duration)..[[]
container_end[]
container[6,0.45]
button[0,0;3,1;apply;]]..S('Apply')..[[]
container_end[]
]])
end

28
system/get_timer_data.lua Normal file

@ -0,0 +1,28 @@
local m = mtimer
local S = m.translator
mtimer.get_timer_data = function (player_name)
local player_meta = minetest.get_player_by_name(player_name):get_meta()
local time_data = mtimer.get_times(player_name)
local ingame_time = time_data.ingame_time.formatted
local session_start_time = time_data.session_start_time.formatted
local session_duration = time_data.session_duration.formatted
local values = {
format = player_meta:get_string(m.meta.timer_format.key),
real_world_date = time_data.real_time.formatted,
ingame_time = time_data.ingame_time.formatted,
session_start_time = time_data.session_start_time.formatted,
session_duration = time_data.session_duration.formatted
}
values['formatted'] = values.format:gsub('{[0-9a-z]+}', {
['{rd}'] = values.real_world_date,
['{it}'] = values.ingame_time,
['{st}'] = values.session_start_time,
['{sd}'] = values.session_duration,
})
return values
end

@ -20,6 +20,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.session_duration_format then
f.session_duration_format(name)
end
if fields.timer_format then f.timer_format(name) end
end
@ -119,6 +120,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
-- Set timer text
if formname == 'mtimer:timer_format' then
local attr = m.meta.timer_format
local value = fields.format or attr.default
meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.timer_format(name) end
end
-- Back to menu from all formspecs
if fields.main_menu then f.main_menu(name) end