mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
adapt real_time_universal to new style
addresses https://gitlab.com/4w/mtimer/-/issues/16
This commit is contained in:
parent
06b370280f
commit
c6f9afc831
@ -1,15 +1,35 @@
|
|||||||
-- # vim: nowrap
|
|
||||||
--
|
|
||||||
-- Set Vim to no-wrapping mode because of some lines not fitting within the 80
|
|
||||||
-- characters width limit due to overall readability of the code.
|
|
||||||
|
|
||||||
|
|
||||||
-- Localise needed functions
|
|
||||||
local m = mtimer
|
local m = mtimer
|
||||||
local S = m.translator
|
local S = m.translator
|
||||||
local esc = minetest.formspec_escape
|
local esc = minetest.formspec_escape
|
||||||
|
|
||||||
|
|
||||||
|
-- Return a table line
|
||||||
|
--
|
||||||
|
-- The index determines the position from top within the current container and
|
||||||
|
-- is calculated to display the string in the correct position.
|
||||||
|
--
|
||||||
|
-- If `name` is a literal `'-'` then a line is printed at the position.
|
||||||
|
--
|
||||||
|
-- @param index The numerical index for the line
|
||||||
|
-- @param name Human-readable name for the variable
|
||||||
|
-- @param variable The variable like it’s used in the definition
|
||||||
|
-- @param value The value to show for that variable
|
||||||
|
-- @return string The created formspec string
|
||||||
|
local line = function (index, name, variable, value)
|
||||||
|
local position = ((index-1) * 0.4)
|
||||||
|
|
||||||
|
if name == '-' then
|
||||||
|
return 'box[0,'..position..';+contentWidth,0.02;#ffffff]'
|
||||||
|
end
|
||||||
|
|
||||||
|
return table.concat({
|
||||||
|
'label[0,'..position..';'..name..']',
|
||||||
|
'label[4,'..position..';'..variable..']',
|
||||||
|
'label[7,'..position..';'..value..']'
|
||||||
|
}, ' ')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Real Time Universal Formspec
|
-- Real Time Universal Formspec
|
||||||
--
|
--
|
||||||
-- This formspec can be used to show formatting options for all real-world time
|
-- This formspec can be used to show formatting options for all real-world time
|
||||||
@ -23,38 +43,36 @@ local esc = minetest.formspec_escape
|
|||||||
-- @see mtimer.get_times
|
-- @see mtimer.get_times
|
||||||
mtimer.dialog.real_time_universal = function (player_name, config)
|
mtimer.dialog.real_time_universal = function (player_name, config)
|
||||||
local time_data = mtimer.get_times(player_name)[config.time_type]
|
local time_data = mtimer.get_times(player_name)[config.time_type]
|
||||||
|
local vars = time_data.variables
|
||||||
|
|
||||||
mtimer.show_formspec(config.formspec_name, {
|
mtimer.show_formspec(config.formspec_name, {
|
||||||
title = config.title,
|
title = config.title,
|
||||||
show_to = player_name,
|
show_to = player_name,
|
||||||
height = 7.5,
|
height = 8.75,
|
||||||
formspec = {
|
formspec = {
|
||||||
'field_close_on_enter[format;false]',
|
'field_close_on_enter[format;false]',
|
||||||
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
|
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
|
||||||
'container[0,0.9]',
|
'container[0,1.5]',
|
||||||
'label[2.8,0;'..S('Variable')..']',
|
line(0, '', S('Variable'), S('Current Value')),
|
||||||
'label[4.6,0;'..S('Current Value')..']',
|
line(1, '-'),
|
||||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
line(2, S('Hours (24h)'), '{24h}', vars.hours_24),
|
||||||
'label[0,0.5;'..S('Hours (24h)')..'] label[2.8,0.5;{24h}] label[4.6,0.5;'..time_data.variables.hours_24..']',
|
line(3, S('Hours (12h)'), '{12h}', vars.hours_12),
|
||||||
'label[0,0.9;'..S('Hours (12h)')..'] label[2.8,0.9;{12h}] label[4.6,0.9;'..time_data.variables.hours_12..']',
|
line(4, S('Minutes'), '{min}', vars.minutes),
|
||||||
'label[0,1.3;'..S('Minutes')..'] label[2.8,1.3;{min}] label[4.6,1.3;'..time_data.variables.minutes..']',
|
line(5, S('Seconds'), '{sec}', vars.seconds),
|
||||||
'label[0,1.7;'..S('Seconds')..'] label[2.8,1.7;{sec}] label[4.6,1.7;'..time_data.variables.seconds..']',
|
line(6, '-'),
|
||||||
'box[0,1.98;+contentWidth,0.02;#ffffff]',
|
line(7, S('Day Name'), '{dname}', vars.dayname),
|
||||||
'label[0,2.2;'..S('Day Name')..'] label[2.8,2.2;{dname}] label[4.6,2.2;'..time_data.variables.dayname..']',
|
line(8, S('Month Name'), '{mname}', vars.monthname),
|
||||||
'label[0,2.6;'..S('Month Name')..'] label[2.8,2.6;{mname}] label[4.6,2.6;'..time_data.variables.monthname..']',
|
line(9, '-'),
|
||||||
'box[0,2.85;+contentWidth,0.02;#ffffff]',
|
line(10, S('Year'), '{year}', vars.year),
|
||||||
'label[0,3.1;'..S('Year')..'] label[2.8,3.1;{year}] label[4.6,3.1;'..time_data.variables.year..']',
|
line(11, S('Month'), '{month}', vars.month),
|
||||||
'label[0,3.5;'..S('Month')..'] label[2.8,3.5;{month}] label[4.6,3.5;'..time_data.variables.month..']',
|
line(12, S('Day'), '{day}', vars.day),
|
||||||
'label[0,3.9;'..S('Day')..'] label[2.8,3.9;{day}] label[4.6,3.9;'..time_data.variables.day..']',
|
line(13, '-'),
|
||||||
'box[0,4.2;+contentWidth,0.02;#ffffff]',
|
line(14, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date),
|
||||||
'label[0,4.45;'..S('ISO 8601 Date')..'] label[2.8,4.45;{isodate}] label[4.6,4.45;'..time_data.variables.iso8601_date..']',
|
line(15, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time),
|
||||||
'label[0,4.85;'..S('ISO 8601 Time')..'] label[2.8,4.85;{isotime}] label[4.6,4.85;'..time_data.variables.iso8601_time..']',
|
line(16, S('Timestamp'), '{timestamp}', vars.timestamp),
|
||||||
'label[0,5.25;'..S('Timestamp')..'] label[2.8,5.25;{timestamp}] label[4.6,5.25;'..time_data.variables.timestamp..']',
|
line(17, '-'),
|
||||||
'box[0,5.55;+contentWidth,0.02;#ffffff]',
|
line(18, S('Current Result'), esc(time_data.formatted), ''),
|
||||||
'label[0,5.8;'..S('Current Result')..']',
|
|
||||||
'label[2.8,5.8;'..esc(time_data.formatted)..']',
|
|
||||||
'container_end[]'
|
'container_end[]'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user