use dialog instead of set_formspec

Addresses https://gitlab.com/4w/mtimer/issues/5
This commit is contained in:
Dirk Sohler 2019-03-06 18:22:50 +01:00
parent 3fd5d23181
commit 06b4bfa77e
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
5 changed files with 52 additions and 58 deletions

@ -15,7 +15,7 @@ local S = minetest.get_translator('mtimer')
-- @see ./system/formspec/formspec_creation.lua -- @see ./system/formspec/formspec_creation.lua
mtimer = { mtimer = {
translator = S, translator = S,
show_formspec = {}, dialog = {},
meta = { meta = {
visible = { key = 'mtimer:visible', default = 'true' }, visible = { key = 'mtimer:visible', default = 'true' },
position = { key = 'mtimer:position', default = 'bl' }, position = { key = 'mtimer:position', default = 'bl' },

@ -1,6 +1,6 @@
local m = mtimer local m = mtimer
local S = m.translator local S = m.translator
local fs = m.show_formspec local d = m.dialog
local cs = minetest.chat_send_player local cs = minetest.chat_send_player
@ -25,15 +25,15 @@ end
-- --
-- Parameter Mnemonic Action -- Parameter Mnemonic Action
-- ------------------------------------------------------------------- -- -------------------------------------------------------------------
-- vi visibility fs.set_visibility(name) -- vi visibility d.set_visibility(name)
-- po position fs.set_position(name) -- po position d.set_position(name)
-- co color fs.sec_color(name) -- co color d.sec_color(name)
-- tz timezone fs.timezone_offset(name) -- tz timezone d.timezone_offset(name)
-- in ingame fs.ingame_time_format(name) -- in ingame d.ingame_time_format(name)
-- re real fs.real_world_time_format(name) -- re real d.real_world_time_format(name)
-- st start time fs.session_start_time_format(name) -- st start time d.session_start_time_format(name)
-- sd session duration fs.session_duration_format(name) -- sd session duration d.session_duration_format(name)
-- tf timer format fs.timer_format(name) -- tf timer format d.timer_format(name)
-- ------------------------------------------------------------------- -- -------------------------------------------------------------------
-- help Prints the help output showing the parameters -- help Prints the help output showing the parameters
-- --
@ -45,17 +45,17 @@ minetest.register_chatcommand('mtimer', {
local action = parameters:match('%a+') local action = parameters:match('%a+')
if not minetest.get_player_by_name(name) then return end if not minetest.get_player_by_name(name) then return end
if not action then fs.main_menu(name) end if not action then d.main_menu(name) end
if action == 'vi' then fs.set_visibility(name) end if action == 'vi' then d.set_visibility(name) end
if action == 'po' then fs.set_position(name) end if action == 'po' then d.set_position(name) end
if action == 'co' then fs.set_color(name) end if action == 'co' then d.set_color(name) end
if action == 'tz' then fs.timezone_offset(name) end if action == 'tz' then d.timezone_offset(name) end
if action == 'in' then fs.ingame_time_format(name) end if action == 'in' then d.ingame_time_format(name) end
if action == 're' then fs.real_world_time_format(name) end if action == 're' then d.real_world_time_format(name) end
if action == 'st' then fs.session_start_time_format(name) end if action == 'st' then d.session_start_time_format(name) end
if action == 'sd' then fs.session_duration_format(name) end if action == 'sd' then d.session_duration_format(name) end
if action == 'tf' then fs.timer_format(name) end if action == 'tf' then d.timer_format(name) end
if action == 'help' then if action == 'help' then
local message = { local message = {

@ -15,7 +15,7 @@ local fe = minetest.formspec_escape
-- @see https://dev.minetest.net/formspec -- @see https://dev.minetest.net/formspec
mtimer.show_formspec.main_menu = function (player_name) mtimer.dialog.main_menu = function (player_name)
minetest.show_formspec(player_name, 'mtimer:main_menu', [[ minetest.show_formspec(player_name, 'mtimer:main_menu', [[
size[9.5,5.75] size[9.5,5.75]
@ -52,7 +52,7 @@ mtimer.show_formspec.main_menu = function (player_name)
end end
mtimer.show_formspec.set_visibility = function (player_name) mtimer.dialog.set_visibility = function (player_name)
minetest.show_formspec(player_name, 'mtimer:set_visibility', minetest.show_formspec(player_name, 'mtimer:set_visibility',
build_frame(6, 2.25, S('Visibility'))..[[ build_frame(6, 2.25, S('Visibility'))..[[
button[0,0.5;3,1;visible;]]..S('Visible')..[[] button[0,0.5;3,1;visible;]]..S('Visible')..[[]
@ -61,7 +61,7 @@ mtimer.show_formspec.set_visibility = function (player_name)
end end
mtimer.show_formspec.set_position = function (player_name) mtimer.dialog.set_position = function (player_name)
minetest.show_formspec(player_name, 'mtimer:set_position', minetest.show_formspec(player_name, 'mtimer:set_position',
build_frame(8, 6.2, S('Position'))..[[ build_frame(8, 6.2, S('Position'))..[[
@ -84,7 +84,7 @@ mtimer.show_formspec.set_position = function (player_name)
end end
mtimer.show_formspec.set_color = function (player_name) mtimer.dialog.set_color = function (player_name)
local player = minetest.get_player_by_name(player_name) local player = minetest.get_player_by_name(player_name)
local color = player:get_meta():get_string(m.meta.color.key) local color = player:get_meta():get_string(m.meta.color.key)
@ -105,7 +105,7 @@ mtimer.show_formspec.set_color = function (player_name)
end end
mtimer.show_formspec.timezone_offset = function (player_name) mtimer.dialog.timezone_offset = function (player_name)
local time_data = mtimer.get_times(player_name).real_time local time_data = mtimer.get_times(player_name).real_time
local format_information = table.concat({ local format_information = table.concat({
@ -128,7 +128,7 @@ mtimer.show_formspec.timezone_offset = function (player_name)
end end
mtimer.show_formspec.ingame_time_format = function (player_name) mtimer.dialog.ingame_time_format = function (player_name)
local time_data = mtimer.get_times(player_name).ingame_time local time_data = mtimer.get_times(player_name).ingame_time
minetest.show_formspec(player_name, 'mtimer:ingame_time_format', minetest.show_formspec(player_name, 'mtimer:ingame_time_format',
@ -167,8 +167,8 @@ mtimer.show_formspec.ingame_time_format = function (player_name)
end end
mtimer.show_formspec.real_world_time_format = function (player_name) mtimer.dialog.real_world_time_format = function (player_name)
mtimer.show_formspec.real_time_universal(player_name, { mtimer.dialog.real_time_universal(player_name, {
time_type = 'real_time', time_type = 'real_time',
formspec_name = 'mtimer:real_world_time_format', formspec_name = 'mtimer:real_world_time_format',
title = S('Real-World Time Format') title = S('Real-World Time Format')
@ -176,8 +176,8 @@ mtimer.show_formspec.real_world_time_format = function (player_name)
end end
mtimer.show_formspec.session_start_time_format = function (player_name) mtimer.dialog.session_start_time_format = function (player_name)
mtimer.show_formspec.real_time_universal(player_name, { mtimer.dialog.real_time_universal(player_name, {
time_type = 'session_start_time', time_type = 'session_start_time',
formspec_name = 'mtimer:session_start_time_format', formspec_name = 'mtimer:session_start_time_format',
title = S('Session Start Time Format') title = S('Session Start Time Format')
@ -185,7 +185,7 @@ mtimer.show_formspec.session_start_time_format = function (player_name)
end end
mtimer.show_formspec.session_duration_format = function (player_name) mtimer.dialog.session_duration_format = function (player_name)
local time_data = mtimer.get_times(player_name).session_duration local time_data = mtimer.get_times(player_name).session_duration
minetest.show_formspec(player_name, 'mtimer:session_duration_format', minetest.show_formspec(player_name, 'mtimer:session_duration_format',
@ -226,7 +226,7 @@ mtimer.show_formspec.session_duration_format = function (player_name)
end end
mtimer.show_formspec.timer_format = function (player_name) mtimer.dialog.timer_format = function (player_name)
local timer_data = mtimer.get_timer_data(player_name) local timer_data = mtimer.get_timer_data(player_name)
minetest.show_formspec(player_name, 'mtimer:timer_format', minetest.show_formspec(player_name, 'mtimer:timer_format',
build_frame(9, 5.8, S('Timer Format'))..[[ build_frame(9, 5.8, S('Timer Format'))..[[

@ -15,7 +15,7 @@ local fe = minetest.formspec_escape
-- @config time_type A time type that is provided by the `get_times` function -- @config time_type A time type that is provided by the `get_times` function
-- @return void -- @return void
-- @see mtimer.get_times -- @see mtimer.get_times
mtimer.show_formspec.real_time_universal = function (player_name, config) mtimer.dialog.real_time_universal = function (player_name, config)
local time_data = mtimer.get_times(player_name)[config.time_type] local time_data = mtimer.get_times(player_name)[config.time_type]
minetest.show_formspec(player_name, config.formspec_name, minetest.show_formspec(player_name, config.formspec_name,

@ -1,5 +1,5 @@
local m = mtimer local m = mtimer
local f = mtimer.show_formspec local d = mtimer.dialog
-- When formspec data is sent to the server check for the formname and run the -- When formspec data is sent to the server check for the formname and run the
@ -13,19 +13,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Select what formspec to show basing on main menu button -- Select what formspec to show basing on main menu button
if formname == 'mtimer:main_menu' then if formname == 'mtimer:main_menu' then
if fields.set_visibility then f.set_visibility(name) end if fields.set_visibility then d.set_visibility(name) end
if fields.set_position then f.set_position(name) end if fields.set_position then d.set_position(name) end
if fields.set_color then f.set_color(name) end if fields.set_color then d.set_color(name) end
if fields.timezone_offset then f.timezone_offset(name) end if fields.timezone_offset then d.timezone_offset(name) end
if fields.ingame_time_format then f.ingame_time_format(name) end if fields.ingame_time_format then d.ingame_time_format(name) end
if fields.real_world_time_format then f.real_world_time_format(name) end if fields.real_world_time_format then d.real_world_time_format(name) end
if fields.session_start_time_format then if fields.session_start_time_format then
f.session_start_time_format(name) d.session_start_time_format(name)
end end
if fields.session_duration_format then if fields.session_duration_format then
f.session_duration_format(name) d.session_duration_format(name)
end end
if fields.timer_format then f.timer_format(name) end if fields.timer_format then d.timer_format(name) end
end end
@ -64,7 +64,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.set_color(name) end if not fields.quit then d.set_color(name) end
end end
@ -75,7 +75,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if math.abs(value) > os.time() then value = 0 end if math.abs(value) > os.time() then value = 0 end
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.timezone_offset(name) end if not fields.quit then d.timezone_offset(name) end
end end
@ -85,7 +85,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local value = fields.format or attr.default local value = fields.format or attr.default
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.ingame_time_format(name)end if not fields.quit then d.ingame_time_format(name)end
end end
@ -95,9 +95,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local value = fields.format or attr.default local value = fields.format or attr.default
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then if not fields.quit then d.real_world_time_format(name) end
mtimer.show_formspec.real_world_time_format(name)
end
end end
@ -107,9 +105,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local value = fields.format or attr.default local value = fields.format or attr.default
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then if not fields.quit then d.session_start_time_format(name) end
mtimer.show_formspec.session_start_time_format(name)
end
end end
@ -119,9 +115,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local value = fields.format or attr.default local value = fields.format or attr.default
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then if not fields.quit then d.session_duration_format(name) end
mtimer.show_formspec.session_duration_format(name)
end
end end
@ -131,12 +125,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local value = fields.format or attr.default local value = fields.format or attr.default
meta:set_string(attr.key, value) meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.timer_format(name) end if not fields.quit then d.timer_format(name) end
end end
-- Back to menu from all formspecs and conditionally update timer -- Back to menu from all formspecs and conditionally update timer
if fields.main_menu then f.main_menu(name) end if fields.main_menu then d.main_menu(name) end
if formname ~= 'mtimer:main_menu' then m.update_timer(name) end if formname ~= 'mtimer:main_menu' then m.update_timer(name) end