From b179c6f8c171c7d2c002f04619f5eebbb747dc90 Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Sat, 3 Apr 2021 15:25:52 +0200 Subject: [PATCH] use formspec checkbox for timer type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- system/formspecs/custom_timer.lua | 19 +++++++++++++------ system/on_receive_fields.lua | 7 ++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/system/formspecs/custom_timer.lua b/system/formspecs/custom_timer.lua index 4c8fef2..e339f5b 100644 --- a/system/formspecs/custom_timer.lua +++ b/system/formspecs/custom_timer.lua @@ -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 S = m.translator local esc = minetest.formspec_escape @@ -18,9 +25,9 @@ mtimer.dialog.custom_timer = function (player_name) local minutes = ctv.values.minutes or 0 local seconds = ctv.values.seconds or 0 - local a_countdown = ctv.timer_mode == 'countdown' and 'x' or '' - local a_timer = ctv.timer_mode == 'timer' and 'x' or '' - local a_continuous = ctv.timer_mode == 'continuous' and 'x' or '' + local a_countdown = ctv.timer_mode == 'countdown' and 'true' or 'false' + local a_timer = ctv.timer_mode == 'timer' and 'true' or 'false' + local a_continuous = ctv.timer_mode == 'continuous' and 'true' or 'false' local format_running = ctv.format.running or '' local format_stopped = ctv.format.stopped or '' @@ -78,9 +85,9 @@ mtimer.dialog.custom_timer = function (player_name) ' container_end[]', 'container_end[]', 'container[0,3.6]', - ' button[0,0;0.25,0.25;mode_countdown;'..a_countdown..'] label[0.35,0.125;'..S('Countdown')..']', - ' button[0,0.4;0.25,0.25;mode_timer;'..a_timer..'] label[0.35,0.525;'..S('Timer Mode')..']', - ' button[0,0.8;0.25,0.25;mode_continuous;'..a_continuous..'] label[0.35,0.925;'..S('Continuous Run')..']', + ' checkbox[0,0;mode_countdown;'..S('Countdown')..';'..a_countdown..']', + ' checkbox[0,0.4;mode_timer;'..S('Timer Mode')..';'..a_timer..']', + ' checkbox[0,0.8;mode_continuous;'..S('Continuous Run')..';'..a_continuous..']', 'container_end[]', } }) diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index ead8abe..fd8b785 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -189,9 +189,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local entered = fields.key_enter_field or '' -- Set mode - if fields.mode_countdown then ctv.timer_mode = 'countdown' end - if fields.mode_timer then ctv.timer_mode = 'timer' end - if fields.mode_continuous then ctv.timer_mode = 'continuous' end + print(dump(fields)) + if fields.mode_countdown ~= nil then ctv.timer_mode='countdown' 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 local days = tonumber(fields.v_days) or 0