diff --git a/init.lua b/init.lua index 2984f3b..d241f3b 100644 --- a/init.lua +++ b/init.lua @@ -8,6 +8,7 @@ mtimer = { meta = { visible = { key = 'mtimer:visible', default = 'true' }, position = { key = 'mtimer:position', default = 'bl' }, + color = { key = 'mtimer:color', default = '#ffffffFF' }, } } diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index c1d6c17..219f052 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -20,6 +20,10 @@ Invisible=Unsichtbar mTimer Position=mTimer-Position Click the position you want to place the timer at.=Auf die Stelle klicken, an der der Timer angezeigt werden soll. +# Set Color +mTimer Color=mTimer-Farbe +Use `@1` format only!=Ausschließlich `@1`-Format benutzen! + # Generic Formspec Strings Default=Standard Exit=Verlassen diff --git a/system/formspec_creation.lua b/system/formspec_creation.lua index ced8937..2f31317 100644 --- a/system/formspec_creation.lua +++ b/system/formspec_creation.lua @@ -27,6 +27,7 @@ mtimer.show_formspec.set_visibility = function (player_name) button[0,0.5;2,1;visible;]]..S('Visible')..[[] button[2,0.5;2,1;invisible;]]..S('Invisible')..[[] button[4,0.5;2,1;default;]]..S('Default')..[[] + button_exit[0,1.5;3,1;exit;]]..S('Exit')..[[] button[3,1.5;3,1;back;]]..S('Main Menu')..[[] ]]) @@ -57,9 +58,34 @@ mtimer.show_formspec.set_position = function (player_name) button_exit[0,5.5;2,1;exit;]]..S('Exit')..[[] button[2,5.5;2,1;back;]]..S('Main Menu')..[[] button[4,5.5;2,1;default;]]..S('Default')..[[] - ]]) end +mtimer.show_formspec.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) + local hexcolor = table.concat({ + '#', + minetest.colorize('#ce5c00', 'rr'), + minetest.colorize('#4e9a06', 'gg'), + minetest.colorize('#729fcf', 'bb'), + 'AA' + }) + + minetest.show_formspec(player_name, 'mtimer:set_color', [[ + size[6.85,2.7] + label[0,-0.125;]]..S('mTimer Color')..[[] + field_close_on_enter[color;false] + + field[0.25,0.75;3,1;color;;]]..color..[[] + box[3,0.55;0.65,0.65;]]..color..[[] + button[3.85,0.45;3,1;default;]]..S('Default')..[[] + + label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[] + + button_exit[-0.05,2;3.45,1;exit;]]..S('Exit')..[[] + button[3.44,2;3.4,1;back;]]..S('Main Menu')..[[] + ]]) +end diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index e61e620..a0b3962 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -10,6 +10,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) 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 end @@ -36,6 +37,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end + -- Set timer text color + if formname == 'mtimer:set_color' then + local attr = m.meta.color + local color = '' + + if fields.color then + local valid = fields.color:match('^#'..('[0-9a-fA-F]'):rep(8)..'$') + local color = valid and fields.color or attr.default + meta:set_string(attr.key, color) + 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 + end + + -- Back to menu from all formspecs if fields.back then f.main_menu(name) end