2021-04-02 08:57:00 +02:00
|
|
|
|
-- # vim: nowrap
|
|
|
|
|
--
|
|
|
|
|
-- Set Vim to no-wrapping mode because of some lines not fitting within the 80
|
|
|
|
|
-- characters width limit due to overall readability of the code.
|
|
|
|
|
|
|
|
|
|
|
2021-04-02 04:07:40 +02:00
|
|
|
|
-- Localise needed functions
|
|
|
|
|
local m = mtimer
|
|
|
|
|
local S = m.translator
|
2021-04-02 08:57:00 +02:00
|
|
|
|
local esc = minetest.formspec_escape
|
2021-04-02 04:07:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Create buttons at the given position in the main menu formspec
|
|
|
|
|
--
|
|
|
|
|
-- This function takes a column and a row and translates that to values used
|
|
|
|
|
-- by the icon button function. All buttons are 5 units wide and the image
|
|
|
|
|
-- size is 0.5 units.
|
|
|
|
|
--
|
|
|
|
|
-- @param column The desired column, starting with 1
|
|
|
|
|
-- @param row The desired row, starting with 1
|
|
|
|
|
-- @param id The button’s ID
|
|
|
|
|
-- @param label The button’s label
|
|
|
|
|
-- @return string The parsed main menu button
|
|
|
|
|
local button = function (column, row, id, label)
|
|
|
|
|
local b_width = 5
|
|
|
|
|
local i_size = 0.5
|
|
|
|
|
|
|
|
|
|
-- Calculations
|
|
|
|
|
local b_padding = i_size / 4
|
|
|
|
|
local b_height = (b_padding * 2) + i_size
|
|
|
|
|
local b_top_position = (row - 1) * b_height
|
|
|
|
|
local b_top_spacing = b_top_position == 0 and 0 or b_padding * 1.5
|
|
|
|
|
local c_position = (column - 1) * b_width
|
|
|
|
|
local c_spacing = c_position == 0 and 0 or b_padding * 3
|
|
|
|
|
local bc_top = b_top_position + (b_top_spacing * (row - 1))
|
|
|
|
|
local bc_left = c_position + (c_spacing * (column - 1))
|
|
|
|
|
|
|
|
|
|
return mtimer.get_icon_button(id, {
|
2021-04-02 08:57:00 +02:00
|
|
|
|
label = esc(label),
|
2021-04-02 04:07:40 +02:00
|
|
|
|
width = b_width,
|
|
|
|
|
image_size = i_size,
|
|
|
|
|
container = {
|
|
|
|
|
top = bc_top,
|
|
|
|
|
left = bc_left
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Main Menu generation
|
|
|
|
|
--
|
|
|
|
|
-- @see mtimer.show_formspec
|
|
|
|
|
-- @see https://dev.minetest.net/formspec
|
|
|
|
|
mtimer.dialog.main_menu = function (player_name)
|
|
|
|
|
mtimer.show_formspec('mtimer:main_menu', {
|
|
|
|
|
title = S('mTimer'),
|
|
|
|
|
width = 16,
|
|
|
|
|
height = 6.9,
|
|
|
|
|
prefix = '',
|
|
|
|
|
add_buttons = false,
|
|
|
|
|
show_to = player_name,
|
|
|
|
|
formspec = {
|
|
|
|
|
-- Visuals
|
|
|
|
|
button(1, 1, 'set_visibility', S('Visibility')),
|
|
|
|
|
button(1, 2, 'set_position', S('Position')),
|
|
|
|
|
button(1, 3, 'set_color', S('Color')),
|
|
|
|
|
button(1, 4, 'hud_element_size', S('HUD Element Size')),
|
|
|
|
|
button(1, 5, 'hud_element_offset', S('HUD Element Offset')),
|
|
|
|
|
-- Time Representation
|
|
|
|
|
button(2, 1, 'ingame_time_format', S('Ingame Time Format')),
|
|
|
|
|
button(2, 2, 'real_world_time_format', S('Real-World Time Format')),
|
|
|
|
|
button(2, 3, 'session_start_time_format', S('Session Start Time Format')),
|
|
|
|
|
button(2, 4, 'session_duration_format', S('Session Duration Format')),
|
|
|
|
|
button(2, 5, 'host_time_format', S('Host Time Format')),
|
|
|
|
|
-- Timer configuration
|
|
|
|
|
button(3, 1, 'timer_format', S('Timer Format')),
|
|
|
|
|
button(3, 2, 'timezone_offset', S('Timezone Offset')),
|
|
|
|
|
button(3, 3, 'custom_timer', S('Custom Timer')),
|
|
|
|
|
'container[0,4.75]',
|
2021-04-02 08:52:29 +02:00
|
|
|
|
' box[0,0;+contentWidth,0.04;#ffffff]',
|
|
|
|
|
' container[+contentWidth,0]',
|
|
|
|
|
mtimer.get_icon_button('reset_everything', { label = S('Reset Everything'), width = 4, container = { top = 0.25, left = -6.75 } }),
|
|
|
|
|
mtimer.get_icon_button('exit', { label = S('Exit'), exit_button = true, width = 2.5, container = { top = 0.25, left = -2.5 } }),
|
2021-04-02 04:07:40 +02:00
|
|
|
|
' container_end[]',
|
|
|
|
|
'container_end[]'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
end
|