From 50e44e2e324290e8e5c8c7f54a6d75f04555c7da Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Sat, 3 Apr 2021 15:10:05 +0200 Subject: [PATCH] split off custom timer from other formspecs Since the custom timer formspec is fairly complex (and will be a bit more complex in the future) the best thing is splitting it off from the other formspec definitions. --- system/formspecs/custom_timer.lua | 87 ++++++++++++++++++++++++++ system/formspecs/formspec_creation.lua | 78 ----------------------- system/formspecs/main_menu.lua | 2 +- 3 files changed, 88 insertions(+), 79 deletions(-) create mode 100644 system/formspecs/custom_timer.lua diff --git a/system/formspecs/custom_timer.lua b/system/formspecs/custom_timer.lua new file mode 100644 index 0000000..4c8fef2 --- /dev/null +++ b/system/formspecs/custom_timer.lua @@ -0,0 +1,87 @@ +local m = mtimer +local S = m.translator +local esc = minetest.formspec_escape + + +-- Custom Timer Formspec +-- +-- This formspec shows the custom timer configuration and controls. +-- +-- @see mtimer.show_formspec +-- @param player_name The name of the player to show the formspec to +mtimer.dialog.custom_timer = function (player_name) + local player_meta = minetest.get_player_by_name(player_name):get_meta() + local ctv = minetest.deserialize(player_meta:get_string(m.meta.custom_timer_settings.key)) + + local days = ctv.values.days or 0 + local hours = ctv.values.hours or 0 + 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 format_running = ctv.format.running or '' + local format_stopped = ctv.format.stopped or '' + local format_finished = ctv.format.finished or '' + + mtimer.show_formspec('mtimer:custom_timer', { + title = S('Custom Timer'), + show_to = player_name, + height = 5.3, + width = 9, + formspec = { + 'field_close_on_enter[v_format_running;false]', + 'field_close_on_enter[v_format_stopped;false]', + 'field_close_on_enter[v_format_finished;false]', + 'field_close_on_enter[v_days;false]', + 'field_close_on_enter[v_hours;false]', + 'field_close_on_enter[v_minutes;false]', + 'field_close_on_enter[v_seconds;false]', + 'container[0,0]', + ' label[0,0.25;'..S('Running')..'] field[2.25,0;6.5,0.5;v_format_running;;'..esc(format_running)..']', + ' label[0,0.85;'..S('Stopped')..'] field[2.25,0.6;6.5,0.5;v_format_stopped;;'..esc(format_stopped)..']', + ' label[0,1.45;'..S('Finished')..'] field[2.25,1.2;6.5,0.5;v_format_finished;;'..esc(format_finished)..']', + ' box[0,2;+contentWidth,0.04;#ffffff]', + 'container_end[]', + 'container[3.75,2.4]', + ' label[0,0;'..S('Information')..']', + ' label[1.75,0;'..S('Variable')..']', + ' label[3.25,0;'..S('Used Value')..']', + ' box[0,0.25;5,0.02;#ffffff]', + ' label[0,0.5;'..S('Days')..'] label[1.75,0.5;{days}] label[3.25,0.5;'..days..']', + ' label[0,0.9;'..S('Hours')..'] label[1.75,0.9;{hours}] label[3.25,0.9;'..hours..']', + ' label[0,1.3;'..S('Minutes')..'] label[1.75,1.3;{minutes}] label[3.25,1.3;'..minutes..']', + ' label[0,1.7;'..S('Seconds')..'] label[1.75,1.7;{seconds}] label[3.25,1.7;'..seconds..']', + 'container_end[]', + 'container[0,2.3]', + ' container[0,0]', + ' button[0,0;0.75,0.25;c_days_p;+]', + ' field[0,0.25;0.755,0.5;v_days;;'..days..']', + ' button[0,0.75;0.75,0.25;c_days_m;-]', + ' container_end[]', + ' container[0.9,0]', + ' button[0,0;0.75,0.25;c_hours_p;+]', + ' field[0,0.25;0.755,0.5;v_hours;;'..hours..']', + ' button[0,0.75;0.75,0.25;c_hours_m;-]', + ' container_end[]', + ' container[1.8,0]', + ' button[0,0;0.75,0.25;c_minutes_p;+]', + ' field[0,0.25;0.755,0.5;v_minutes;;'..minutes..']', + ' button[0,0.75;0.75,0.25;c_minutes_m;-]', + ' container_end[]', + ' container[2.7,0]', + ' button[0,0;0.75,0.25;c_seconds_p;+]', + ' field[0,0.25;0.755,0.5;v_seconds;;'..seconds..']', + ' button[0,0.75;0.75,0.25;c_seconds_m;-]', + ' 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')..']', + 'container_end[]', + } + }) +end diff --git a/system/formspecs/formspec_creation.lua b/system/formspecs/formspec_creation.lua index 520a57c..419f3e9 100644 --- a/system/formspecs/formspec_creation.lua +++ b/system/formspecs/formspec_creation.lua @@ -287,81 +287,3 @@ mtimer.dialog.timer_format = function (player_name) } }) end - - -mtimer.dialog.custom_timer = function (player_name) - local player_meta = minetest.get_player_by_name(player_name):get_meta() - local ctv = minetest.deserialize(player_meta:get_string(m.meta.custom_timer_settings.key)) - - local days = ctv.values.days or 0 - local hours = ctv.values.hours or 0 - 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 format_running = ctv.format.running or '' - local format_stopped = ctv.format.stopped or '' - local format_finished = ctv.format.finished or '' - - mtimer.show_formspec('mtimer:custom_timer', { - title = S('Custom Timer'), - show_to = player_name, - height = 5.3, - width = 9, - formspec = { - 'field_close_on_enter[v_format_running;false]', - 'field_close_on_enter[v_format_stopped;false]', - 'field_close_on_enter[v_format_finished;false]', - 'field_close_on_enter[v_days;false]', - 'field_close_on_enter[v_hours;false]', - 'field_close_on_enter[v_minutes;false]', - 'field_close_on_enter[v_seconds;false]', - 'container[0,0]', - ' label[0,0.25;'..S('Running')..'] field[2.25,0;6.5,0.5;v_format_running;;'..esc(format_running)..']', - ' label[0,0.85;'..S('Stopped')..'] field[2.25,0.6;6.5,0.5;v_format_stopped;;'..esc(format_stopped)..']', - ' label[0,1.45;'..S('Finished')..'] field[2.25,1.2;6.5,0.5;v_format_finished;;'..esc(format_finished)..']', - ' box[0,2;+contentWidth,0.04;#ffffff]', - 'container_end[]', - 'container[3.75,2.4]', - ' label[0,0;'..S('Information')..']', - ' label[1.75,0;'..S('Variable')..']', - ' label[3.25,0;'..S('Used Value')..']', - ' box[0,0.25;5,0.02;#ffffff]', - ' label[0,0.5;'..S('Days')..'] label[1.75,0.5;{days}] label[3.25,0.5;'..days..']', - ' label[0,0.9;'..S('Hours')..'] label[1.75,0.9;{hours}] label[3.25,0.9;'..hours..']', - ' label[0,1.3;'..S('Minutes')..'] label[1.75,1.3;{minutes}] label[3.25,1.3;'..minutes..']', - ' label[0,1.7;'..S('Seconds')..'] label[1.75,1.7;{seconds}] label[3.25,1.7;'..seconds..']', - 'container_end[]', - 'container[0,2.3]', - ' container[0,0]', - ' button[0,0;0.75,0.25;c_days_p;+]', - ' field[0,0.25;0.755,0.5;v_days;;'..days..']', - ' button[0,0.75;0.75,0.25;c_days_m;-]', - ' container_end[]', - ' container[0.9,0]', - ' button[0,0;0.75,0.25;c_hours_p;+]', - ' field[0,0.25;0.755,0.5;v_hours;;'..hours..']', - ' button[0,0.75;0.75,0.25;c_hours_m;-]', - ' container_end[]', - ' container[1.8,0]', - ' button[0,0;0.75,0.25;c_minutes_p;+]', - ' field[0,0.25;0.755,0.5;v_minutes;;'..minutes..']', - ' button[0,0.75;0.75,0.25;c_minutes_m;-]', - ' container_end[]', - ' container[2.7,0]', - ' button[0,0;0.75,0.25;c_seconds_p;+]', - ' field[0,0.25;0.755,0.5;v_seconds;;'..seconds..']', - ' button[0,0.75;0.75,0.25;c_seconds_m;-]', - ' 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')..']', - 'container_end[]', - } - }) -end diff --git a/system/formspecs/main_menu.lua b/system/formspecs/main_menu.lua index 2c6b222..0d7c2ac 100644 --- a/system/formspecs/main_menu.lua +++ b/system/formspecs/main_menu.lua @@ -50,7 +50,7 @@ end -- Main Menu generation -- -- @see mtimer.show_formspec --- @see https://dev.minetest.net/formspec +-- @param player_name The name of the player to show the formspec to mtimer.dialog.main_menu = function (player_name) mtimer.show_formspec('mtimer:main_menu', { width = 15.75,