mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-24 08:13:48 +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 S = m.translator
|
||||
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
|
||||
--
|
||||
-- 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
|
||||
mtimer.dialog.real_time_universal = function (player_name, config)
|
||||
local time_data = mtimer.get_times(player_name)[config.time_type]
|
||||
local vars = time_data.variables
|
||||
|
||||
mtimer.show_formspec(config.formspec_name, {
|
||||
title = config.title,
|
||||
show_to = player_name,
|
||||
height = 7.5,
|
||||
height = 8.75,
|
||||
formspec = {
|
||||
'field_close_on_enter[format;false]',
|
||||
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
|
||||
'container[0,0.9]',
|
||||
'label[2.8,0;'..S('Variable')..']',
|
||||
'label[4.6,0;'..S('Current Value')..']',
|
||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,0.5;'..S('Hours (24h)')..'] label[2.8,0.5;{24h}] label[4.6,0.5;'..time_data.variables.hours_24..']',
|
||||
'label[0,0.9;'..S('Hours (12h)')..'] label[2.8,0.9;{12h}] label[4.6,0.9;'..time_data.variables.hours_12..']',
|
||||
'label[0,1.3;'..S('Minutes')..'] label[2.8,1.3;{min}] label[4.6,1.3;'..time_data.variables.minutes..']',
|
||||
'label[0,1.7;'..S('Seconds')..'] label[2.8,1.7;{sec}] label[4.6,1.7;'..time_data.variables.seconds..']',
|
||||
'box[0,1.98;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,2.2;'..S('Day Name')..'] label[2.8,2.2;{dname}] label[4.6,2.2;'..time_data.variables.dayname..']',
|
||||
'label[0,2.6;'..S('Month Name')..'] label[2.8,2.6;{mname}] label[4.6,2.6;'..time_data.variables.monthname..']',
|
||||
'box[0,2.85;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,3.1;'..S('Year')..'] label[2.8,3.1;{year}] label[4.6,3.1;'..time_data.variables.year..']',
|
||||
'label[0,3.5;'..S('Month')..'] label[2.8,3.5;{month}] label[4.6,3.5;'..time_data.variables.month..']',
|
||||
'label[0,3.9;'..S('Day')..'] label[2.8,3.9;{day}] label[4.6,3.9;'..time_data.variables.day..']',
|
||||
'box[0,4.2;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,4.45;'..S('ISO 8601 Date')..'] label[2.8,4.45;{isodate}] label[4.6,4.45;'..time_data.variables.iso8601_date..']',
|
||||
'label[0,4.85;'..S('ISO 8601 Time')..'] label[2.8,4.85;{isotime}] label[4.6,4.85;'..time_data.variables.iso8601_time..']',
|
||||
'label[0,5.25;'..S('Timestamp')..'] label[2.8,5.25;{timestamp}] label[4.6,5.25;'..time_data.variables.timestamp..']',
|
||||
'box[0,5.55;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,5.8;'..S('Current Result')..']',
|
||||
'label[2.8,5.8;'..esc(time_data.formatted)..']',
|
||||
'container[0,1.5]',
|
||||
line(0, '', S('Variable'), S('Current Value')),
|
||||
line(1, '-'),
|
||||
line(2, S('Hours (24h)'), '{24h}', vars.hours_24),
|
||||
line(3, S('Hours (12h)'), '{12h}', vars.hours_12),
|
||||
line(4, S('Minutes'), '{min}', vars.minutes),
|
||||
line(5, S('Seconds'), '{sec}', vars.seconds),
|
||||
line(6, '-'),
|
||||
line(7, S('Day Name'), '{dname}', vars.dayname),
|
||||
line(8, S('Month Name'), '{mname}', vars.monthname),
|
||||
line(9, '-'),
|
||||
line(10, S('Year'), '{year}', vars.year),
|
||||
line(11, S('Month'), '{month}', vars.month),
|
||||
line(12, S('Day'), '{day}', vars.day),
|
||||
line(13, '-'),
|
||||
line(14, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date),
|
||||
line(15, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time),
|
||||
line(16, S('Timestamp'), '{timestamp}', vars.timestamp),
|
||||
line(17, '-'),
|
||||
line(18, S('Current Result'), esc(time_data.formatted), ''),
|
||||
'container_end[]'
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user