diff --git a/system/formspecs/formspec_creation.lua b/system/formspecs/formspec_creation.lua index 5cc9d80..6b7194a 100644 --- a/system/formspecs/formspec_creation.lua +++ b/system/formspecs/formspec_creation.lua @@ -48,123 +48,6 @@ mtimer.dialog.set_visibility = function (player_name) end -mtimer.dialog.set_position = function (player_name) - local player = minetest.get_player_by_name(player_name) - local howto = S('Click the position you want to place the timer at.') - - -- Get current position name - local p_value = player:get_meta():get_string(m.meta.position.key) - local p_names = { - ['t'] = S('top'), ['m'] = S('middle'), ['b'] = S('bottom'), - ['l'] = S('left'), ['c'] = S('center'), ['r'] = S('right') - } - local p_name = p_names[p_value:sub(1,1)]..' '..p_names[p_value:sub(2,2)] - local p_info = S('Current position: @1', p_name) - - -- Set up image - local image = 'mtimer_positions_orientation.png' - local i_width = 10 - local i_height = 6 - - -- Return the parsed button - local b_define = function(t, l, p) - return ('image_button[+l,+t;+w,+h;+i;pos_+p;d;;false]'):gsub('%+%w', { - ['+l'] = (l - 1) * (i_width / 3), - ['+t'] = (t - 1) * (i_height / 3), - ['+w'] = i_width / 3, - ['+h'] = i_height / 3, - ['+i'] = 'mtimer_transparent.png', - ['+p'] = p, - }) - end - - mtimer.show_formspec('mtimer:set_position', { - title = S('Position'), - height = 7.2, - width = 10, - show_to = player_name, - formspec = { - 'image[0,0;'..i_width..','..i_height..';'..image..']', - b_define(1, 1, 'tl'), b_define(1, 2, 'tc'), b_define(1, 3, 'tr'), - b_define(2, 1, 'ml'), b_define(2, 2, 'mc'), b_define(2, 3, 'mr'), - b_define(3, 1, 'bl'), b_define(3, 2, 'bc'), b_define(3, 3, 'br'), - 'label[0,6.5;'..howto..'\n'..p_info..']' - } - }) -end - - -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) - local palette = {} - local col = 0 - local row = 1 - - local hexformat = table.concat({ - '#', - minetest.colorize('#ce5c00', 'rr'), - minetest.colorize('#4e9a06', 'gg'), - minetest.colorize('#729fcf', 'bb') - }) - - -- Tango palette - -- - -- @see http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines - local palette_entries = { - 'fce94f', 'edd400', 'c4a000', 'fcaf3e', 'f57900', 'ce5c00', 'e9b96e', - 'c17d11', '8f5902', '8ae234', '73d216', '4e9a06', '729fcf', '3465a4', - '204a87', 'ad7fa8', '75507b', '5c3566', 'ef2929', 'cc0000', 'a40000', - 'eeeeec', 'd3d7cf', 'babdb6', '888a85', '555753', '2e3436', '000000', - 'ff0000', '00ff00', '0000ff', 'ffff00', '00ffff', 'ff00ff', 'c0c0c0', - '808080', '800000', '808000', '008000', '800080', '008080', '000080', - } - - for _,color in pairs(palette_entries) do - local cb_height = 0.6 - local cb_width = 1.39 - local cb_style = 'style[+name;bgcolor=#+color;textcolor=#+color]' - local cb_button = 'button[+left,+top;+width,+height;+name;+label]' - local cb_complete = cb_style..' '..cb_button - - col = col + 1 - if col > 7 then - col = 1 - row = row + 1 - end - - table.insert(palette, ((cb_complete):gsub('%+%w+', { - ['+top'] = (row - 1) * (cb_height + 0.05), - ['+left'] = (col - 1) * (cb_width + 0.05), - ['+width'] = cb_width, - ['+height'] = cb_height, - ['+name'] = 'set_color', - ['+color'] = color, - ['+label'] = color - }))) - end - - mtimer.show_formspec('mtimer:set_color', { - title = S('Color'), - show_to = player_name, - width = 10, - height = 6.2, - formspec = { - 'field_close_on_enter[color;false]', - 'field[0,0;3,0.5;color;;'..color..']', - 'box[3.25,0;0.5,0.5;'..color..'ff]', - 'tooltip[3.25,0;0.5,0.5;'..S('Current color: @1', color)..']', - 'label[0,1;'..S('Use `@1` format only!', hexformat)..']', - 'container[0,1.85]', - ' box[0,-0.4;+contentWidth,0.04;#ffffff]', - ' label[0,0;'..esc(S('Set a predefined color'))..']', - ' container[0,0.4]'..table.concat(palette, ' ')..'container_end[]', - 'container_end[]' - } - }) -end - - mtimer.dialog.timezone_offset = function (player_name) local time_data = mtimer.get_times(player_name).real_time diff --git a/system/formspecs/set_color.lua b/system/formspecs/set_color.lua new file mode 100644 index 0000000..8ec13e3 --- /dev/null +++ b/system/formspecs/set_color.lua @@ -0,0 +1,76 @@ +local m = mtimer +local S = m.translator +local esc = minetest.formspec_escape + + +-- Tango palette +-- +-- @see http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines +local palette_entries = { + 'fce94f', 'edd400', 'c4a000', 'fcaf3e', 'f57900', 'ce5c00', 'e9b96e', + 'c17d11', '8f5902', '8ae234', '73d216', '4e9a06', '729fcf', '3465a4', + '204a87', 'ad7fa8', '75507b', '5c3566', 'ef2929', 'cc0000', 'a40000', + 'eeeeec', 'd3d7cf', 'babdb6', '888a85', '555753', '2e3436', '000000', + 'ff0000', '00ff00', '0000ff', 'ffff00', '00ffff', 'ff00ff', 'c0c0c0', + '808080', '800000', '808000', '008000', '800080', '008080', '000080', +} + + +local hexformat = table.concat({ + '#', + minetest.colorize('#ce5c00', 'rr'), + minetest.colorize('#4e9a06', 'gg'), + minetest.colorize('#729fcf', 'bb') +}) + + +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) + local palette = {} + local col = 0 + local row = 1 + + for _,color in pairs(palette_entries) do + local cb_height = 0.6 + local cb_width = 1.39 + local cb_style = 'style[+name;bgcolor=#+color;textcolor=#+color]' + local cb_button = 'button[+left,+top;+width,+height;+name;+label]' + local cb_complete = cb_style..' '..cb_button + + col = col + 1 + if col > 7 then + col = 1 + row = row + 1 + end + + table.insert(palette, ((cb_complete):gsub('%+%w+', { + ['+top'] = (row - 1) * (cb_height + 0.05), + ['+left'] = (col - 1) * (cb_width + 0.05), + ['+width'] = cb_width, + ['+height'] = cb_height, + ['+name'] = 'set_color', + ['+color'] = color, + ['+label'] = color + }))) + end + + mtimer.show_formspec('mtimer:set_color', { + title = S('Color'), + show_to = player_name, + width = 10, + height = 6.2, + formspec = { + 'field_close_on_enter[color;false]', + 'field[0,0;3,0.5;color;;'..color..']', + 'box[3.25,0;0.5,0.5;'..color..'ff]', + 'tooltip[3.25,0;0.5,0.5;'..S('Current color: @1', color)..']', + 'label[0,1;'..S('Use `@1` format only!', hexformat)..']', + 'container[0,1.85]', + ' box[0,-0.4;+contentWidth,0.04;#ffffff]', + ' label[0,0;'..esc(S('Set a predefined color'))..']', + ' container[0,0.4]'..table.concat(palette, ' ')..'container_end[]', + 'container_end[]' + } + }) +end diff --git a/system/formspecs/set_position.lua b/system/formspecs/set_position.lua new file mode 100644 index 0000000..63062fc --- /dev/null +++ b/system/formspecs/set_position.lua @@ -0,0 +1,54 @@ +local m = mtimer +local S = m.translator + + +local p_names = { + ['t'] = S('top'), + ['m'] = S('middle'), + ['b'] = S('bottom'), + ['l'] = S('left'), + ['c'] = S('center'), + ['r'] = S('right') +} + + +mtimer.dialog.set_position = function (player_name) + local player = minetest.get_player_by_name(player_name) + local howto = S('Click the position you want to place the timer at.') + + -- Get current position name + local p_value = player:get_meta():get_string(m.meta.position.key) + local p_name = p_names[p_value:sub(1,1)]..' '..p_names[p_value:sub(2,2)] + local p_info = S('Current position: @1', p_name) + + -- Set up image + local image = 'mtimer_positions_orientation.png' + local i_width = 10 + local i_height = 6 + + -- Return the parsed button + local b_define = function(t, l, p) + return ('image_button[+l,+t;+w,+h;+i;pos_+p;d;;false]'):gsub('%+%w', { + ['+l'] = (l - 1) * (i_width / 3), + ['+t'] = (t - 1) * (i_height / 3), + ['+w'] = i_width / 3, + ['+h'] = i_height / 3, + ['+i'] = 'mtimer_transparent.png', + ['+p'] = p, + }) + end + + mtimer.show_formspec('mtimer:set_position', { + title = S('Position'), + height = 7.2, + width = 10, + show_to = player_name, + formspec = { + 'image[0,0;'..i_width..','..i_height..';'..image..']', + b_define(1, 1, 'tl'), b_define(1, 2, 'tc'), b_define(1, 3, 'tr'), + b_define(2, 1, 'ml'), b_define(2, 2, 'mc'), b_define(2, 3, 'mr'), + b_define(3, 1, 'bl'), b_define(3, 2, 'bc'), b_define(3, 3, 'br'), + 'label[0,6.5;'..howto..'\n'..p_info..']' + } + }) +end