mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-02-17 17:03:46 +01:00
build custom timer formspec with options parsing
No functionality yet and the fields are just dumped. Translation to German is done and the meta data is loaded properly. Addresses https://gitlab.com/4w/mtimer/-/issues/10
This commit is contained in:
@ -70,6 +70,13 @@ Session Duration=Sitzungsdauer
|
||||
Session Start Time=Sitzungsstart-Zeit
|
||||
Host Time=Hostzeit
|
||||
|
||||
# Custom Timer Things
|
||||
Timer Mode=Timermodus
|
||||
Countdown=Herunterzählen
|
||||
Timer Mode=Heraufzählen
|
||||
Continuous Run=Dauerlauf
|
||||
The timer has finished=Der Timer hat sein Ziel erreicht
|
||||
|
||||
# Default Timer Format
|
||||
Current Date: @1=Aktuelles Datum: @1
|
||||
Ingame Time: @1=Spielzeit: @1
|
||||
|
@ -328,15 +328,70 @@ end
|
||||
|
||||
|
||||
mtimer.dialog.custom_timer = function (player_name)
|
||||
local timer_data = mtimer.get_timer_data(player_name)
|
||||
local player_meta = minetest.get_player_by_name(player_name):get_meta()
|
||||
local ctv = minetest.deserialize(player_meta:get_string(m.meta.custom_timer_settings.key))
|
||||
local format = player_meta:get_string(m.meta.custom_timer_format.key)
|
||||
|
||||
local days = ctv.input_values.days or 0
|
||||
local hours = ctv.input_values.hours or 0
|
||||
local minutes = ctv.input_values.minutes or 0
|
||||
local seconds = ctv.input_values.seconds or 0
|
||||
|
||||
local a_countdown = ctv.timer_mode == 'countdown' and 'x' or ''
|
||||
local a_timer = ctv.timer_mode == 'timer' and 'x' or ''
|
||||
local a_continuous = ctv.timer_mode == 'continuous' and 'x' or ''
|
||||
|
||||
mtimer.show_formspec('mtimer:custom_timer', {
|
||||
title = S('Custom Timer'),
|
||||
show_to = player_name,
|
||||
height = 5.75,
|
||||
width = 8.5,
|
||||
height = 4.25,
|
||||
width = 9,
|
||||
formspec = {
|
||||
'label[0,0;'..S('Custom Timer')..']',
|
||||
'field_close_on_enter[days_value;false]',
|
||||
'field_close_on_enter[hours_value;false]',
|
||||
'field_close_on_enter[minutes_value;false]',
|
||||
'field_close_on_enter[seconds_value;false]',
|
||||
'container[0,0]',
|
||||
' field[0,0;+linewidth,0.5;format;;'..fe(format)..']',
|
||||
' field[0,0.6;+linewidth,0.5;target_message;;'..fe(ctv.target_message)..']',
|
||||
'container_end[]',
|
||||
'container[3.75,1.5]',
|
||||
' label[0,0;'..S('Information')..']',
|
||||
' label[1.75,0;'..S('Variable')..']',
|
||||
' label[3.25,0;'..S('Value')..']',
|
||||
' box[0,0.25;5,0.02;#ffffff]',
|
||||
' label[0,0.5;'..S('Days')..'] label[1.75,0.5;{days}] label[3.25,0.5;'..days..']',
|
||||
' label[0,0.9;'..S('Hours')..'] label[1.75,0.9;{hours}] label[3.25,0.9;'..hours..']',
|
||||
' label[0,1.3;'..S('Minutes')..'] label[1.75,1.3;{minutes}] label[3.25,1.3;'..minutes..']',
|
||||
' label[0,1.7;'..S('Seconds')..'] label[1.75,1.7;{seconds}] label[3.25,1.7;'..seconds..']',
|
||||
'container_end[]',
|
||||
'container[0,1.35]',
|
||||
' container[0,0]',
|
||||
' button[0,0;0.75,0.25;days_add_1;'..S('+')..']',
|
||||
' field[0,0.25;0.755,0.5;days_value;;'..days..']',
|
||||
' button[0,0.75;0.75,0.25;days_substract_1;'..S('-')..']',
|
||||
' container_end[]',
|
||||
' container[0.9,0]',
|
||||
' button[0,0;0.75,0.25;hours_add_1;'..S('+')..']',
|
||||
' field[0,0.25;0.755,0.5;hours_value;;'..hours..']',
|
||||
' button[0,0.75;0.75,0.25;hours_substract_1;'..S('-')..']',
|
||||
' container_end[]',
|
||||
' container[1.8,0]',
|
||||
' button[0,0;0.75,0.25;minutes_add_1;'..S('+')..']',
|
||||
' field[0,0.25;0.755,0.5;minutes_value;;'..minutes..']',
|
||||
' button[0,0.75;0.75,0.25;minutes_substract_1;'..S('-')..']',
|
||||
' container_end[]',
|
||||
' container[2.7,0]',
|
||||
' button[0,0;0.75,0.25;seconds_add_1;'..S('+')..']',
|
||||
' field[0,0.25;0.755,0.5;seconds_value;;'..seconds..']',
|
||||
' button[0,0.75;0.75,0.25;seconds_substract_1;'..S('-')..']',
|
||||
' container_end[]',
|
||||
'container_end[]',
|
||||
'container[0,2.625]',
|
||||
' button[0,0;0.25,0.25;type_countdown;'..a_countdown..'] label[0.35,0.125;'..S('Countdown')..']',
|
||||
' button[0,0.4;0.25,0.25;type_timer;'..a_timer..'] label[0.35,0.525;'..S('Timer Mode')..']',
|
||||
' button[0,0.8;0.25,0.25;type_continuous;'..a_continuous..'] label[0.35,0.925;'..S('Continuous Run')..']',
|
||||
'container_end[]',
|
||||
}
|
||||
})
|
||||
end
|
||||
|
@ -1,5 +1,6 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
local ds = minetest.deserialize
|
||||
|
||||
|
||||
-- Get translated date names
|
||||
@ -248,6 +249,7 @@ local get_custom_timer = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local player_meta = player:get_meta()
|
||||
local format = player_meta:get_string(m.meta.custom_timer_format.key)
|
||||
local ctv = ds(player_meta:get_string(m.meta.custom_timer_settings.key))
|
||||
|
||||
local values = {}
|
||||
|
||||
|
@ -56,6 +56,7 @@ set('position', 'bl')
|
||||
set('timezone_offset', 0)
|
||||
set('visible', true)
|
||||
|
||||
|
||||
-- Formatting settings
|
||||
set('host_time_format', '{24h}:{min} ({isodate})')
|
||||
set('ingame_time_format', '{24h}:{min}')
|
||||
@ -64,6 +65,31 @@ set('session_duration_format', '{hours}:{minutes}')
|
||||
set('session_start_time_format', '{isodate}T{isotime}')
|
||||
set('custom_timer_format', 'd: {days}, h: {hours}, m: {minutes}, s: {seconds}')
|
||||
|
||||
|
||||
-- Custom timer settings
|
||||
--
|
||||
-- `timer_mode` can be one of the following:
|
||||
--
|
||||
-- 'countdown': Counting backwards from the calculated starting point to the
|
||||
-- `start_timestamp` value. The starting point is calculated
|
||||
-- using the input values and `start_timestamp`.
|
||||
--
|
||||
-- 'timer': Counting up from the `start_timestamp` value to the calculated
|
||||
-- target. The target is calculated by the `start_timestamp` and the
|
||||
-- given `input_values`.
|
||||
--
|
||||
-- 'continuous': The timer shows the difference between the current timestamp
|
||||
-- and the stored `start_timestamp`. Here the `target_message`
|
||||
-- is ignored and will never be shown.
|
||||
set('custom_timer_settings', minetest.serialize({
|
||||
input_values = { days = 0, hours = 0, minutes = 0, seconds = 0 },
|
||||
start_timestamp = 0,
|
||||
target_message = S('The timer has finished'),
|
||||
timer_mode = 'countdown',
|
||||
running = false
|
||||
}), false)
|
||||
|
||||
|
||||
-- Timer display format (the HUD element’s content)
|
||||
set('timer_format', table.concat({
|
||||
S('Current Date: @1', '{rd}'),
|
||||
|
Reference in New Issue
Block a user