From 77ff151591eaa135aceb4ff48937384f4d3024b7 Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Wed, 6 Oct 2021 01:43:53 +0200 Subject: [PATCH] adapt timezone offset to new style --- locale/mtimer.de.tr | 12 ++-- system/formspecs/formspec_creation.lua | 32 ---------- system/formspecs/timezone_offset.lua | 79 +++++++++++++++++++++++++ system/on_receive_fields.lua | 17 +++++- textures/ui/mtimer_world_map.png | Bin 0 -> 2104 bytes 5 files changed, 102 insertions(+), 38 deletions(-) create mode 100644 system/formspecs/timezone_offset.lua create mode 100644 textures/ui/mtimer_world_map.png diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index 7b549f8..c19ef51 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -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 it’s 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 diff --git a/system/formspecs/formspec_creation.lua b/system/formspecs/formspec_creation.lua index b07c100..06d58cb 100644 --- a/system/formspecs/formspec_creation.lua +++ b/system/formspecs/formspec_creation.lua @@ -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 diff --git a/system/formspecs/timezone_offset.lua b/system/formspecs/timezone_offset.lua new file mode 100644 index 0000000..d6da058 --- /dev/null +++ b/system/formspecs/timezone_offset.lua @@ -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 it’s 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 diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index 533b35f..6d3a4fa 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -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 - meta:set_string(attr.key, value) + + -- 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 diff --git a/textures/ui/mtimer_world_map.png b/textures/ui/mtimer_world_map.png new file mode 100644 index 0000000000000000000000000000000000000000..eb78c5c33edd163b6e80ef499cdad9c5b6257edc GIT binary patch literal 2104 zcmeAS@N?(olHy`uVBq!ia0y~yVDeyKVASDY28!_e?(qR~4h8sxxB|KVN5N1IfvZnL zt%0#PwIs+dn1PXrg_Vt+gNvJomtR0gL`*_bN=9B$Nm)}%SI@xE*u>Pr(%Qz((aFWt z!_(W>KPWgnDkd&1JtH$KJHN2Bth}3 z^}6*NwrtzJW9P0tdygDDaq7(3^A|2&x_a&U%{zDR-GA`#(UYgoU%Y(v=Iy)pA3lEi z^7Z?VpTBdplQ2G$9lE{-7;x8B~3e38m5bD+>TrF*8%%}x2jH>b`G+Sa*I zL@N4}m}=!C$0-@v~Egm2~ydV<~z-eO)@yepe*^#9*x@gyz6i4|NsB_`RAU0 z@Bhy$KL7KZHGlf-om@T*GtC&CoIE%ejR_E8P$Y< z(h4ddX(0|yMMaes7LfXv@~e-}D@==#Oh3~0(Q}SS@#7N~HhkTo$-CYxm)sb+MpjJ- zsB;si0ETvxU6&Vs|L|UTuit|EpF;PDg&*A{u_dkk*dmF_-A7m4-xT&nPW_l@VPuS~ z_|d|R;a|MCg*n^JAhvQUHUgaianO-3e3^4CRL}MPG}NDV?9mSkyPnpITdhs^^_nMN z$geTn*YR-s6|=(3FQ?iq3mxW&?w$8=kA;a@*Seco7nj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