diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index 529545b..a74ece2 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -3,7 +3,6 @@ # mTimer Configuration Names Open Main Menu=Hauptmenü öffnen -Reset Everything=Alles zurücksetzen mTimer Configuration=mTimer-Konfiguration @@ -99,6 +98,19 @@ Stop stop custom timer=Individuellen Timer anhalten Restart the custom timer=Individuellen Timer neu starten +# Dialog: Reset Everything (also messages) +Reset Everything=Alles zurücksetzen +Soft-reset all values to their defaults=Alle Werte auf die definierten Standards setzen +Request hard-reset (kicks you from the server!)=Löschen anfordern (führt einen Kick vom Server aus!) +All configuration was reset. Server time of the requested: @1=Alle Konfiguration wurde zurückgesetzt. Serverzeit der Anfrage: @1 +You requested a hard reset of the mTimer configuration. This request was stored. As described, you were kicked from the server in order to have the hard reset performed. Please rejoin the server. On rejoin all previously stored configuration regarding mTimer will be deleted.=Ein hartes Zurücksetzen der mTimer-Konfiguration wurde angefordert. Die Anfrage wurde gespeichert. Wie beschrieben wurde ein Kick vom Server ausgeführt. Um das harte Zurücksetzen der Konfiguration abzuschließen ist ein Neuverbinden zum Server erforderlich. Dabei wird die gesamte mTimer-bezogene Konfiguration entfernt. +Cancel reset and return to main menu=Zurücksetzen abbrechen und zurück zum Hauptmenü +For resetting the configuration you have two options.=Für das zurücksetzen der Konfiguration bestehen zwei Optionen. +Usually using a soft reset is enough. The soft reset sets all values based on mTimer functionality to the default values while staying connected.=Üblicher weise reicht ein sanftes Zurücksetzen. Dies setzt direkt alle Werte mittels mTimer-Funktionen auf die entsprecheden Standardwerte. +If the soft reset does not work you can hard reset the configuration. This stores a request and then kicks you from the server. On rejoining mTimer forcefully removes all stored configuration and sets the current default values.=Sollte dies nicht funktionieren kann ein hartes Zurücksetzen angefordert werden. Es wird ein entsprechender Eintrag gesetzt und eine Trennung vom Server ausgeführt. Beim Neuverbinden wird zwangsweise die Standardkonfiguration geladen. + + + # Default custom timer status messages The custom timer is already running=Der individuelle Timer läuft bereits The custom timer is not running=Der individuelle Timer läuft nicht diff --git a/system/chat_command.lua b/system/chat_command.lua index d2645d6..ebfebb3 100644 --- a/system/chat_command.lua +++ b/system/chat_command.lua @@ -37,13 +37,14 @@ end -- os OffSet d.hud_element_offset(name) -- tf timer format d.timer_format(name) -- ct custom timer d.custom_timer(name) +-- re reset everything d.reset_everything(name) -- ------------------------------------------------------------------- -- help Prints the help output showing the parameters -- -- Providing unknown parameters has no effect. minetest.register_chatcommand('mtimer', { description = S('Configure timer display'), - params = '', + params = '', func = function(name, parameters) local action = parameters:match('%a+') @@ -63,6 +64,7 @@ minetest.register_chatcommand('mtimer', { if action == 'os' then d.hud_element_offset(name) end if action == 'tf' then d.timer_format(name) end if action == 'ct' then d.custom_timer(name) end + if action == 're' then d.reset_everything(name) end if action == 'ctstart' then mtimer.update_custom_timer(name, { action = 'start' }) end if action == 'ctstop' then mtimer.update_custom_timer(name, { action = 'stop' }) end @@ -83,6 +85,7 @@ minetest.register_chatcommand('mtimer', { command('hs')..S('HUD Element Scale'), command('os')..S('HUD Element Offset'), command('tf')..S('Timer Format'), + command('re')..S('Reset Everything'), '', command('ct ')..S('Configure the custom timer'), command('ctstart ')..S('Start the custom timer'), diff --git a/system/formspecs/formspec_creation.lua b/system/formspecs/formspec_creation.lua index 9f4e499..4e5bccf 100644 --- a/system/formspecs/formspec_creation.lua +++ b/system/formspecs/formspec_creation.lua @@ -146,3 +146,41 @@ mtimer.dialog.timer_format = function (player_name) } }) end + + +mtimer.dialog.reset_everything = function (player_name) + local td = mtimer.get_timer_data(player_name) + local infotext = table.concat({ + S('For resetting the configuration you have two options.'), + S('Usually using a soft reset is enough. The soft reset sets all values based on mTimer functionality to the default values while staying connected.'), + S('If the soft reset does not work you can hard reset the configuration. This stores a request and then kicks you from the server. On rejoining mTimer forcefully removes all stored configuration and sets the current default values.') + }, '\n\n') + + mtimer.show_formspec('mtimer:reset_everything', { + title = S('Reset Everything'), + show_to = player_name, + width = 10, + height = 6.3, + hide_buttons = true, + formspec = { + 'textarea[0,0;+contentWidth,3.5;;;'..esc(infotext)..']', + 'container[0,3.8]', + line(0, '-'), + mtimer.get_icon_button('reset_soft', { + width = 10, + label = S('Soft-reset all values to their defaults') + }), + mtimer.get_icon_button('reset_hard', { + label = S('Request hard-reset (kicks you from the server!)'), + width = 10, + container = { top = 1 } + }), + mtimer.get_icon_button('reset_cancel', { + label = S('Cancel reset and return to main menu'), + width = 10, + container = { top = 2 } + }), + 'container_end[]', + } + }) +end diff --git a/system/load_configuration.lua b/system/load_configuration.lua index 214708d..c56ee3a 100644 --- a/system/load_configuration.lua +++ b/system/load_configuration.lua @@ -126,3 +126,7 @@ set('timer_format', table.concat({ S('Session Start: @1', '{st}'), S('Session Duration: @1', '{sd}') }, '{_n}'), false, { n = '\n' }) + + +-- Hard reset indicator +set('hard_reset_everything', 'false') diff --git a/system/on_joinplayer.lua b/system/on_joinplayer.lua index 6a04f74..77abb0d 100644 --- a/system/on_joinplayer.lua +++ b/system/on_joinplayer.lua @@ -3,19 +3,37 @@ local m = mtimer -- When a player joins -- --- 1. Set default values if not set --- 2. Set session start timestamp --- 3. Set “empty” HUD element and write ID to meta data for later use +-- 1. Check if a hard reset was requested and perform it if it was +-- 2. Set default values if not set +-- 3. Set session start timestamp +-- 4. Set “empty” HUD element and write ID to meta data for later use minetest.register_on_joinplayer(function(player) local meta = player:get_meta() + local name = player:get_player_name() + local re = meta:get_int('mtimer:hard_reset_everything') + -- Forecefully remove all meta data set in the player object that starts + -- with `mtimer:` prefix (perform the requested reset everything). + if re > 0 then + local message = m.translator('All configuration was reset. Server time of the requested: @1', os.date('%c', re)) + for fname,fvalue in pairs(meta:to_table().fields) do + if fname:sub(1,7) == 'mtimer:' then + meta:set_string(fname, '') + end + end + minetest.chat_send_player(name, '[mTimer] '..message) + end + + -- Set all unset metadata to their defined default values for _,def in pairs(m.meta) do local current = meta:get_string(def.key) if current == '' then meta:set_string(def.key, def.default) end end + -- Always set session start timestamp for using it within the custom timer meta:set_string('mtimer:session_start', os.time()) + -- Initially set empty HUD element to store the ID for updates meta:set_string('mtimer:hud_id', player:hud_add({ hud_elem_type = 'text', text = '', diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index 56ef44f..9f92cac 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -31,6 +31,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.hud_element_offset then d.hud_element_offset(name) end if fields.timer_format then d.timer_format(name) end if fields.custom_timer then d.custom_timer(name) end + if fields.reset_everything then d.reset_everything(name) end end @@ -320,17 +321,30 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end - -- Back to menu from all formspecs and conditionally update timer - if fields.main_menu then d.main_menu(name) end - if formname ~= 'mtimer:main_menu' then m.update_timer(name) end - - -- Reset everything - if fields.reset_everything then - for _,def in pairs(m.meta) do - meta:set_string(def.key, def.default) + if formname == 'mtimer:reset_everything' then + local kick_message = m.translator('You requested a hard reset of the mTimer configuration. This request was stored. As described, you were kicked from the server in order to have the hard reset performed. Please rejoin the server. On rejoin all previously stored configuration regarding mTimer will be deleted.') + + -- Perform a soft reset + if fields.reset_soft then + for _,def in pairs(m.meta) do + meta:set_string(def.key, def.default) + end end + + -- Request hard reset and kick the player with informational message + if fields.reset_hard then + meta:set_int(m.meta.hard_reset_everything.key, os.time()) + minetest.kick_player(name, kick_message) + end + + -- Show main menu formspec when cancelled or close on fields.quit + if fields.reset_cancel then d.main_menu(name) return end + if not fields.quit then d.reset_everything(name) end end + -- Back to menu from all formspecs and conditionally update timer + if fields.main_menu then d.main_menu(name) end + if formname ~= 'mtimer:main_menu' then m.update_timer(name) end end) diff --git a/textures/buttons/actions/mtimer_reset_cancel.png b/textures/buttons/actions/mtimer_reset_cancel.png new file mode 100644 index 0000000..11305c7 Binary files /dev/null and b/textures/buttons/actions/mtimer_reset_cancel.png differ diff --git a/textures/buttons/actions/mtimer_reset_hard.png b/textures/buttons/actions/mtimer_reset_hard.png new file mode 100644 index 0000000..8e1614e Binary files /dev/null and b/textures/buttons/actions/mtimer_reset_hard.png differ diff --git a/textures/buttons/actions/mtimer_reset_soft.png b/textures/buttons/actions/mtimer_reset_soft.png new file mode 100644 index 0000000..c6076d4 Binary files /dev/null and b/textures/buttons/actions/mtimer_reset_soft.png differ