use formspec checkbox for timer type

Unfortunately the formspec seems not to be properly updated when
unchecking a checkbox, even if fields are sent and thus the formspec
action should be triggered. This causes unselecting the currently
selected timer type to be unselected when uinselecting it – instead of
updating the formspec and show the selected option again.

This is just a “visual glitch” and does not affect the timer
functionality. When re-opening the timer window the type is selected
correctly again.

addresses https://gitlab.com/4w/mtimer/-/issues/11
This commit is contained in:
Dirk Sohler 2021-04-03 15:25:52 +02:00
parent 50e44e2e32
commit b179c6f8c1
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
2 changed files with 17 additions and 9 deletions

@ -1,3 +1,10 @@
-- # 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
@ -18,9 +25,9 @@ mtimer.dialog.custom_timer = function (player_name)
local minutes = ctv.values.minutes or 0 local minutes = ctv.values.minutes or 0
local seconds = ctv.values.seconds or 0 local seconds = ctv.values.seconds or 0
local a_countdown = ctv.timer_mode == 'countdown' and 'x' or '' local a_countdown = ctv.timer_mode == 'countdown' and 'true' or 'false'
local a_timer = ctv.timer_mode == 'timer' and 'x' or '' local a_timer = ctv.timer_mode == 'timer' and 'true' or 'false'
local a_continuous = ctv.timer_mode == 'continuous' and 'x' or '' local a_continuous = ctv.timer_mode == 'continuous' and 'true' or 'false'
local format_running = ctv.format.running or '' local format_running = ctv.format.running or ''
local format_stopped = ctv.format.stopped or '' local format_stopped = ctv.format.stopped or ''
@ -78,9 +85,9 @@ mtimer.dialog.custom_timer = function (player_name)
' container_end[]', ' container_end[]',
'container_end[]', 'container_end[]',
'container[0,3.6]', 'container[0,3.6]',
' button[0,0;0.25,0.25;mode_countdown;'..a_countdown..'] label[0.35,0.125;'..S('Countdown')..']', ' checkbox[0,0;mode_countdown;'..S('Countdown')..';'..a_countdown..']',
' button[0,0.4;0.25,0.25;mode_timer;'..a_timer..'] label[0.35,0.525;'..S('Timer Mode')..']', ' checkbox[0,0.4;mode_timer;'..S('Timer Mode')..';'..a_timer..']',
' button[0,0.8;0.25,0.25;mode_continuous;'..a_continuous..'] label[0.35,0.925;'..S('Continuous Run')..']', ' checkbox[0,0.8;mode_continuous;'..S('Continuous Run')..';'..a_continuous..']',
'container_end[]', 'container_end[]',
} }
}) })

@ -189,9 +189,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local entered = fields.key_enter_field or '' local entered = fields.key_enter_field or ''
-- Set mode -- Set mode
if fields.mode_countdown then ctv.timer_mode = 'countdown' end print(dump(fields))
if fields.mode_timer then ctv.timer_mode = 'timer' end if fields.mode_countdown ~= nil then ctv.timer_mode='countdown' end
if fields.mode_continuous then ctv.timer_mode = 'continuous' end if fields.mode_timer ~= nil then ctv.timer_mode='timer' end
if fields.mode_continuous ~= nil then ctv.timer_mode='continuous' end
-- Validate direct input -- Validate direct input
local days = tonumber(fields.v_days) or 0 local days = tonumber(fields.v_days) or 0