adapt timezone offset to new style

This commit is contained in:
Dirk Sohler 2021-10-06 01:43:53 +02:00
parent a11cda6475
commit 77ff151591
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
5 changed files with 102 additions and 38 deletions

@ -11,7 +11,6 @@ HUD Element Offset=Anzeigeversatz
Session Duration Format=Sitzungsdauer-Format
Session Start Time Format=Sitzungsstartzeit-Format
Timer Format=Timerformat
Timezone Offset=Zeitzonenunterschied
Custom Timer=Individueller Timer
mTimer Configuration=mTimer-Konfiguration
@ -40,9 +39,14 @@ Current color: @1=Aktuelle Farbe: @1
Use `@1` format only!=Ausschließlich `@1`-Format benutzen!
Set a predefined color=Eine vordefinierte Farbe einstellen
# Information & Warnings
30 minutes @= 0.5, 60 minutes @= 1=30 Minuten @= 0.5, 60 Minuten @= 1
“Arbitrary” values are possible.=Es sind „beliebige“ Werte möglich.
# Dialog: Timezone Offset
Timezone Offset=Zeitzonenunterschied
set a value between -12 and +12 hours=einen Wert zwischen -12 und +12 Stunden setzen
Set timezone offset to @1=Zeitzonenunterschied auf @1 setzen
Current server time: @1=Aktuelle Serverseitige Zeit: @1
Calculated local time: @1=Errechnete lokale Zeit: @1
Please note that daylight saving time (DST) is ignored entirely due to minimizing implementation complexity. You need to manually adjust the time zone in order to adapt to any DST changes. This messes up the visual representation a bit (but its not very accurate anyways …).=Die Sommerzeit wird aus Gründen der Komplexität der Implementierung vollständig ignoriert. Um der Sommerzeit Rechnung zu tragen muss die Zeitzone angepasst werden. Dies bringt zwar die grafische Darstellung durcheinander, aber die ist eh nicht ganz genau.
# Named Times
ISO 8601 Date=Datum nach ISO 8601

@ -49,38 +49,6 @@ mtimer.dialog.set_visibility = function (player_name)
end
mtimer.dialog.timezone_offset = function (player_name)
local time_data = mtimer.get_times(player_name).real_time
local format = {
conversion = S('30 minutes @= 0.5, 60 minutes @= 1'),
arbitrarity = S('“Arbitrary” values are possible.')
}
local time_information = {
s = S('Server Time: @1', time_data.times.server_time),
l = S('Local Time: @1', time_data.times.local_time)
}
mtimer.show_formspec('mtimer:timezone_offset', {
title = S('Timezone Offset'),
show_to = player_name,
formspec = {
'field_close_on_enter[offset;false]',
'field[0,0;3,0.5;offset;;'..time_data.times.offset..']',
'container[3.25,0.1]',
'label[0,0;'..format.conversion..']',
'label[0,0.3;'..format.arbitrarity..']',
'container_end[]',
'container[0,0.9]',
'label[0,0;'..time_information.s..']',
'label[0,0.3;'..time_information.l..']',
'container_end[]'
}
})
end
mtimer.dialog.ingame_time_format = function (player_name)
local time_data = mtimer.get_times(player_name).ingame_time

@ -0,0 +1,79 @@
-- # 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
-- Render the world map
--
-- This function renders the world map with the marker of the current time
-- zone offset and the buttons for selecting the new time zone.
--
-- @param offset The current offset as number
-- @return string The formspec code for the rendered world map
local render_world_map = function (offset)
local zones_multiplicator = 10/25
local marker_pos = (5 + (offset * zones_multiplicator)) - 0.2
local buttons = ''
for zone = -12,12,1 do
local position = (5 + (zone * zones_multiplicator)) - 0.2
local template = 'image_button[+position,0;0.4,5;+texture;+id;;;false]'
local infotext = S('Set timezone offset to @1', zone)
local tooltip = 'tooltip[new_offset_'..zone..';'..infotext..']'
local button = template:gsub('%+%w+',{
['+position'] = position,
['+texture'] = 'mtimer_transparent.png',
['+id'] = 'new_offset_'..zone
})
buttons = buttons..' '..button..tooltip
end
return table.concat({
'image[0,0;10,5;mtimer_world_map.png^[opacity:96]',
'box[0,0;10,5;#00000060]', -- background
'box['..marker_pos..',0;0.4,5;#729fcf]',
buttons
}, ' ')
end
mtimer.dialog.timezone_offset = function (player_name)
local time_data = mtimer.get_times(player_name).real_time
local offset = time_data.times.offset
local dst_info = esc(S('Please note that daylight saving time (DST) is ignored entirely due to minimizing implementation complexity. You need to manually adjust the time zone in order to adapt to any DST changes. This messes up the visual representation a bit (but its not very accurate anyways …).'))
mtimer.show_formspec('mtimer:timezone_offset', {
title = S('Timezone Offset'),
show_to = player_name,
width = 10,
height = 9.5,
formspec = {
'container[0,0]',
'field_close_on_enter[offset;false]',
'label[3.25,0.25;'..S('set a value between -12 and +12 hours')..']',
'field[0,0;3,0.5;offset;;'..offset..']',
'box[0,0.75;+contentWidth,0.02;#ffffff]',
'container_end[]',
'container[0,1]',
render_world_map(offset),
'box[0,5.25;+contentWidth,0.02;#ffffff]',
'container_end[]',
'container[0,6.625]',
'label[0,0;'..S('Current server time: @1', time_data.times.server_time)..']',
'label[0,0.4;'.. S('Calculated local time: @1', time_data.times.local_time)..']',
'box[0,0.75;+contentWidth,0.02;#ffffff]',
'textarea[0,1;10,3;;;'..dst_info..']',
'container_end[]',
}
})
end

@ -85,8 +85,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == 'mtimer:timezone_offset' then
local attr = m.meta.timezone_offset
local value = tonumber(fields.offset) or attr.default
if math.abs(value) > os.time() then value = 0 end
-- Check if a timezone offset button was clicked
for p,_ in pairs(fields) do
if string.sub(p,1,11) == 'new_offset_' then
value = tonumber((p:gsub('new_offset_', '')))
end
end
-- Validate and set new timezone offset
if fields.offset then
if value > 12 then value = 12 end
if value < -12 then value = -12 end
meta:set_string(attr.key, value)
end
if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then d.timezone_offset(name) end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB