mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 02:03:46 +01:00
use dialog instead of set_formspec
Addresses https://gitlab.com/4w/mtimer/issues/5
This commit is contained in:
parent
3fd5d23181
commit
06b4bfa77e
2
init.lua
2
init.lua
@ -15,7 +15,7 @@ local S = minetest.get_translator('mtimer')
|
||||
-- @see ./system/formspec/formspec_creation.lua
|
||||
mtimer = {
|
||||
translator = S,
|
||||
show_formspec = {},
|
||||
dialog = {},
|
||||
meta = {
|
||||
visible = { key = 'mtimer:visible', default = 'true' },
|
||||
position = { key = 'mtimer:position', default = 'bl' },
|
||||
|
@ -1,6 +1,6 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
local fs = m.show_formspec
|
||||
local d = m.dialog
|
||||
local cs = minetest.chat_send_player
|
||||
|
||||
|
||||
@ -25,15 +25,15 @@ end
|
||||
--
|
||||
-- Parameter Mnemonic Action
|
||||
-- -------------------------------------------------------------------
|
||||
-- vi visibility fs.set_visibility(name)
|
||||
-- po position fs.set_position(name)
|
||||
-- co color fs.sec_color(name)
|
||||
-- tz timezone fs.timezone_offset(name)
|
||||
-- in ingame fs.ingame_time_format(name)
|
||||
-- re real fs.real_world_time_format(name)
|
||||
-- st start time fs.session_start_time_format(name)
|
||||
-- sd session duration fs.session_duration_format(name)
|
||||
-- tf timer format fs.timer_format(name)
|
||||
-- vi visibility d.set_visibility(name)
|
||||
-- po position d.set_position(name)
|
||||
-- co color d.sec_color(name)
|
||||
-- tz timezone d.timezone_offset(name)
|
||||
-- in ingame d.ingame_time_format(name)
|
||||
-- re real d.real_world_time_format(name)
|
||||
-- st start time d.session_start_time_format(name)
|
||||
-- sd session duration d.session_duration_format(name)
|
||||
-- tf timer format d.timer_format(name)
|
||||
-- -------------------------------------------------------------------
|
||||
-- help Prints the help output showing the parameters
|
||||
--
|
||||
@ -45,17 +45,17 @@ minetest.register_chatcommand('mtimer', {
|
||||
local action = parameters:match('%a+')
|
||||
|
||||
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 == 'po' then fs.set_position(name) end
|
||||
if action == 'co' then fs.set_color(name) end
|
||||
if action == 'tz' then fs.timezone_offset(name) end
|
||||
if action == 'in' then fs.ingame_time_format(name) end
|
||||
if action == 're' then fs.real_world_time_format(name) end
|
||||
if action == 'st' then fs.session_start_time_format(name) end
|
||||
if action == 'sd' then fs.session_duration_format(name) end
|
||||
if action == 'tf' then fs.timer_format(name) end
|
||||
if action == 'vi' then d.set_visibility(name) end
|
||||
if action == 'po' then d.set_position(name) end
|
||||
if action == 'co' then d.set_color(name) end
|
||||
if action == 'tz' then d.timezone_offset(name) end
|
||||
if action == 'in' then d.ingame_time_format(name) end
|
||||
if action == 're' then d.real_world_time_format(name) end
|
||||
if action == 'st' then d.session_start_time_format(name) end
|
||||
if action == 'sd' then d.session_duration_format(name) end
|
||||
if action == 'tf' then d.timer_format(name) end
|
||||
|
||||
if action == 'help' then
|
||||
local message = {
|
||||
|
@ -15,7 +15,7 @@ local fe = minetest.formspec_escape
|
||||
-- @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', [[
|
||||
size[9.5,5.75]
|
||||
|
||||
@ -52,7 +52,7 @@ mtimer.show_formspec.main_menu = function (player_name)
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.set_visibility = function (player_name)
|
||||
mtimer.dialog.set_visibility = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:set_visibility',
|
||||
build_frame(6, 2.25, S('Visibility'))..[[
|
||||
button[0,0.5;3,1;visible;]]..S('Visible')..[[]
|
||||
@ -61,7 +61,7 @@ mtimer.show_formspec.set_visibility = function (player_name)
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.set_position = function (player_name)
|
||||
mtimer.dialog.set_position = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:set_position',
|
||||
build_frame(8, 6.2, S('Position'))..[[
|
||||
|
||||
@ -84,7 +84,7 @@ mtimer.show_formspec.set_position = function (player_name)
|
||||
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 color = player:get_meta():get_string(m.meta.color.key)
|
||||
|
||||
@ -105,7 +105,7 @@ mtimer.show_formspec.set_color = function (player_name)
|
||||
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 format_information = table.concat({
|
||||
@ -128,7 +128,7 @@ mtimer.show_formspec.timezone_offset = function (player_name)
|
||||
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
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:ingame_time_format',
|
||||
@ -167,8 +167,8 @@ mtimer.show_formspec.ingame_time_format = function (player_name)
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.real_world_time_format = function (player_name)
|
||||
mtimer.show_formspec.real_time_universal(player_name, {
|
||||
mtimer.dialog.real_world_time_format = function (player_name)
|
||||
mtimer.dialog.real_time_universal(player_name, {
|
||||
time_type = 'real_time',
|
||||
formspec_name = 'mtimer: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
|
||||
|
||||
|
||||
mtimer.show_formspec.session_start_time_format = function (player_name)
|
||||
mtimer.show_formspec.real_time_universal(player_name, {
|
||||
mtimer.dialog.session_start_time_format = function (player_name)
|
||||
mtimer.dialog.real_time_universal(player_name, {
|
||||
time_type = 'session_start_time',
|
||||
formspec_name = 'mtimer: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
|
||||
|
||||
|
||||
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
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:session_duration_format',
|
||||
@ -226,7 +226,7 @@ mtimer.show_formspec.session_duration_format = function (player_name)
|
||||
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)
|
||||
minetest.show_formspec(player_name, 'mtimer: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
|
||||
-- @return void
|
||||
-- @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]
|
||||
|
||||
minetest.show_formspec(player_name, config.formspec_name,
|
||||
|
@ -1,5 +1,5 @@
|
||||
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
|
||||
@ -13,19 +13,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Select what formspec to show basing on main menu button
|
||||
if formname == 'mtimer:main_menu' then
|
||||
if fields.set_visibility then f.set_visibility(name) end
|
||||
if fields.set_position then f.set_position(name) end
|
||||
if fields.set_color then f.set_color(name) end
|
||||
if fields.timezone_offset then f.timezone_offset(name) end
|
||||
if fields.ingame_time_format then f.ingame_time_format(name) end
|
||||
if fields.real_world_time_format then f.real_world_time_format(name) end
|
||||
if fields.set_visibility then d.set_visibility(name) end
|
||||
if fields.set_position then d.set_position(name) end
|
||||
if fields.set_color then d.set_color(name) end
|
||||
if fields.timezone_offset then d.timezone_offset(name) end
|
||||
if fields.ingame_time_format then d.ingame_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
|
||||
f.session_start_time_format(name)
|
||||
d.session_start_time_format(name)
|
||||
end
|
||||
if fields.session_duration_format then
|
||||
f.session_duration_format(name)
|
||||
d.session_duration_format(name)
|
||||
end
|
||||
if fields.timer_format then f.timer_format(name) end
|
||||
if fields.timer_format then d.timer_format(name) end
|
||||
end
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
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
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if math.abs(value) > os.time() then value = 0 end
|
||||
meta:set_string(attr.key, value)
|
||||
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
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local value = fields.format or attr.default
|
||||
meta:set_string(attr.key, value)
|
||||
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
|
||||
|
||||
|
||||
@ -95,9 +95,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local value = fields.format or attr.default
|
||||
meta:set_string(attr.key, value)
|
||||
if fields.default then meta:set_string(attr.key, attr.default) end
|
||||
if not fields.quit then
|
||||
mtimer.show_formspec.real_world_time_format(name)
|
||||
end
|
||||
if not fields.quit then d.real_world_time_format(name) end
|
||||
end
|
||||
|
||||
|
||||
@ -107,9 +105,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local value = fields.format or attr.default
|
||||
meta:set_string(attr.key, value)
|
||||
if fields.default then meta:set_string(attr.key, attr.default) end
|
||||
if not fields.quit then
|
||||
mtimer.show_formspec.session_start_time_format(name)
|
||||
end
|
||||
if not fields.quit then d.session_start_time_format(name) end
|
||||
end
|
||||
|
||||
|
||||
@ -119,9 +115,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local value = fields.format or attr.default
|
||||
meta:set_string(attr.key, value)
|
||||
if fields.default then meta:set_string(attr.key, attr.default) end
|
||||
if not fields.quit then
|
||||
mtimer.show_formspec.session_duration_format(name)
|
||||
end
|
||||
if not fields.quit then d.session_duration_format(name) end
|
||||
end
|
||||
|
||||
|
||||
@ -131,12 +125,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local value = fields.format or attr.default
|
||||
meta:set_string(attr.key, value)
|
||||
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
|
||||
|
||||
|
||||
-- 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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user