diff --git a/init.lua b/init.lua index 6faa3eb..ea8526d 100644 --- a/init.lua +++ b/init.lua @@ -10,6 +10,7 @@ mtimer = { position = { key = 'mtimer:position', default = 'bl' }, color = { key = 'mtimer:color', default = '#ffffffFF' }, timezone_offset = { key = 'mtimer:timezone_offset', default = '0' }, + ingame_time = {key='mtimer:ingame_time_format',default='{24h}:{min}'}, } } diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index ea3b066..2c0628e 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -6,8 +6,8 @@ Set Visibility=Sichtbarkeit einstellen Set Position=Position setzen Set Color=Farbe einstellen Timezone Offset=Zeitzonenunterschied -Ingame Time Representation=Spielzeit-Repräsentation -Real World Time Representation=Realzeit-Repräsentation +Ingame Time Format=Spielzeit-Format +Real-World Time Format=Realzeit-Format Set Timer Text=Timertext einstellen Open Main Menu=Hauptmenü öffnen diff --git a/system/chat_command.lua b/system/chat_command.lua index 1435fcd..2f3df7b 100644 --- a/system/chat_command.lua +++ b/system/chat_command.lua @@ -21,8 +21,8 @@ minetest.register_chatcommand('mtimer', { 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(name) end - if action == 're' then fs.real_time(name) end + if action == 'in' then fs.ingame_time_format(name) end + if action == 're' then fs.real_time_format(name) end if action == 'te' then fs.timer_text(name) end if action == 'help' then @@ -31,8 +31,8 @@ minetest.register_chatcommand('mtimer', { command('po')..S('Set Position'), command('co')..S('Set Color'), command('tz')..S('Timezone Offset'), - command('in')..S('Ingame Time Representation'), - command('re')..S('Real World Time Representation'), + command('in')..S('Ingame Time Format'), + command('re')..S('Real-World Time Format'), command('te')..S('Set Timer Text'), command(' ')..S('Open Main Menu') } diff --git a/system/formspec_creation.lua b/system/formspec_creation.lua index 8b87a9f..e3f7c8a 100644 --- a/system/formspec_creation.lua +++ b/system/formspec_creation.lua @@ -37,8 +37,8 @@ mtimer.show_formspec.main_menu = function (player_name) button[0,1.5;4,1;set_position;]]..S('Set Position')..[[] button[0,2.5;4,1;set_color;]]..S('Set Color')..[[] button[0,3.5;4,1;timezone_offset;]]..S('Timezone Offset')..[[] - button[0,4.5;4,1;ingame_time;]]..S('Ingame Time Representation')..[[] - button[0,5.5;4,1;real_time;]]..S('Real World Time Representation')..[[] + button[0,4.5;4,1;ingame_time_format;]]..S('Ingame Time Format')..[[] + button[0,5.5;4,1;real_world_time_format;]]..S('Real-World Time Format')..[[] button[0,6.5;4,1;timer_text;]]..S('Set Timer Text')..[[] button_exit[0,7.5;4,1;exit;]]..S('Exit')..[[] ]]) @@ -122,3 +122,42 @@ mtimer.show_formspec.timezone_offset = function (player_name) label[0,1.45;]]..time_information..[[] ]]) end + + +mtimer.show_formspec.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', + build_frame(7, 4.85, S('Ingame Time Format'))..[[ + field_close_on_enter[format;false] + field[0.25,0.75;7,1;format;;]]..time_data.format..[[] + container[0,1.425] + + label[2.5,0;]]..S('Variable')..[[] + label[4.25,0;]]..S('Current value')..[[] + + box[0,0.45;6.75,0.02;#ffffff] + + label[0,0.5;]]..S('Hours (24h)')..[[] + label[2.5,0.5;{24h}] + label[4.25,0.5;]]..time_data.hours_24..[[] + + label[0,0.9;]]..S('Hours (12h)')..[[] + label[2.5,0.9;{12h}] + label[4.25,0.9;]]..time_data.hours_12..[[] + + label[0,1.3;]]..S('Minutes')..[[] + label[2.5,1.3;{min}] + label[4.25,1.3;]]..time_data.minutes..[[] + + label[0,1.7;]]..S('Ingame Timestamp')..[[] + label[2.5,1.7;{its}] + label[4.25,1.7;]]..time_data.ingame_timestamp..[[] + + box[0,2.2;6.75,0.02;#ffffff] + + label[0,2.25;]]..S('Current Result')..[[] + label[2.5,2.25;]]..time_data.formatted..[[] + container_end[] + ]]) +end diff --git a/system/get_times.lua b/system/get_times.lua index 7bb1c6e..e4487d1 100644 --- a/system/get_times.lua +++ b/system/get_times.lua @@ -14,8 +14,34 @@ local get_real_time = function (player_name) end +local get_ingame_time = function (player_name) + local player = minetest.get_player_by_name(player_name) + local format = player:get_meta():get_string(m.meta.ingame_time.key) + local time_of_day = tostring((minetest.get_timeofday() * 24000) * 3.6) + local ingame_timestamp = tonumber(string.format("%.0f", time_of_day)) + + local values = { + hours_24 = os.date('!%H', ingame_timestamp), + hours_12 = os.date('!%I', ingame_timestamp), + minutes = os.date('!%M', ingame_timestamp), + ingame_timestamp = ingame_timestamp, + format = format + } + + values['formatted'] = format:gsub('{[a-z0-9]+}', { + ['{24h}'] = values.hours_24, + ['{12h}'] = values.hours_12, + ['{min}'] = values.minutes, + ['{its}'] = values.ingame_timestamp + }) + + return values +end + + mtimer.get_times = function (player_name) return { - real_time = get_real_time(player_name) + real_time = get_real_time(player_name), + ingame_time = get_ingame_time(player_name) } end diff --git a/system/on_joinplayer.lua b/system/on_joinplayer.lua index f6cebfe..f61d82f 100644 --- a/system/on_joinplayer.lua +++ b/system/on_joinplayer.lua @@ -6,4 +6,5 @@ minetest.register_on_joinplayer(function(player) local current = meta:get_string(def.key) if current == '' then meta:set_string(def.key, def.default) end end + meta:set_string('mtimer:session_start', os.time()) end) diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index 975410b..ae982c7 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -12,6 +12,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) 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 end @@ -65,6 +66,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end + -- Set ingame time format + if formname == 'mtimer:ingame_time_format' then + local attr = m.meta.ingame_time + 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 + end + + -- Back to menu from all formspecs if fields.main_menu then f.main_menu(name) end