add color configuration

This commit is contained in:
Dirk Sohler 2019-02-17 03:10:41 +01:00
parent 970bf47ec0
commit 34c78e20af
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
4 changed files with 49 additions and 1 deletions

@ -8,6 +8,7 @@ mtimer = {
meta = {
visible = { key = 'mtimer:visible', default = 'true' },
position = { key = 'mtimer:position', default = 'bl' },
color = { key = 'mtimer:color', default = '#ffffffFF' },
}
}

@ -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

@ -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

@ -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