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.
This commit is contained in:
Dirk Sohler 2021-04-03 15:10:05 +02:00
parent dc0b0dc03d
commit 50e44e2e32
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
3 changed files with 88 additions and 79 deletions

@ -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

@ -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

@ -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,