mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-24 16:23:44 +01:00
249 lines
8.8 KiB
Lua
249 lines
8.8 KiB
Lua
-- # 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.
|
||
|
||
|
||
-- Localise needed functions
|
||
local m = mtimer
|
||
local S = m.translator
|
||
local esc = minetest.formspec_escape
|
||
local line = mtimer.get_table_line
|
||
|
||
|
||
-- Formspecs are loaded and shown by individual functions. The function name
|
||
-- correlates with the formspec to show. All of the names are self-explanatory
|
||
-- and within the functions no logic is used.
|
||
--
|
||
-- The Main menu is a bit more complex and is generated seperately.
|
||
--
|
||
-- @see mtimer.show_formspec
|
||
-- @see mtimer.get_times
|
||
-- @see ./system/on_receive_fields.lua
|
||
-- @see ./system/chat_command.lua
|
||
-- @see ./system/formspec/main_menu.lua
|
||
-- @see https://dev.minetest.net/formspec
|
||
|
||
|
||
mtimer.dialog.set_visibility = function (player_name)
|
||
local player = minetest.get_player_by_name(player_name)
|
||
local visible = player:get_meta():get_string(m.meta.visible.key)
|
||
local status = visible == 'true' and S('visible') or S('invisible')
|
||
|
||
mtimer.show_formspec('mtimer:set_visibility', {
|
||
title = S('Visibility'),
|
||
show_to = player_name,
|
||
formspec = {
|
||
mtimer.get_icon_button('set_visible', {
|
||
width = 4,
|
||
label = S('Make visible')
|
||
}),
|
||
mtimer.get_icon_button('set_invisible', {
|
||
width = 4,
|
||
label = S('Make invisible'),
|
||
container = { left = 4.25 }
|
||
}),
|
||
'label[0,1.25;'..S('The timer is currently @1.', status)..']'
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.timezone_offset = function (player_name)
|
||
local time_data = mtimer.get_times(player_name).real_time
|
||
|
||
local format = {
|
||
conversion = S('30 minutes @= 0.5, 60 minutes @= 1'),
|
||
arbitrarity = S('“Arbitrary” values are possible.')
|
||
}
|
||
|
||
local time_information = {
|
||
s = S('Server Time: @1', time_data.times.server_time),
|
||
l = S('Local Time: @1', time_data.times.local_time)
|
||
}
|
||
|
||
mtimer.show_formspec('mtimer:timezone_offset', {
|
||
title = S('Timezone Offset'),
|
||
show_to = player_name,
|
||
formspec = {
|
||
'field_close_on_enter[offset;false]',
|
||
'field[0,0;3,0.5;offset;;'..time_data.times.offset..']',
|
||
'container[3.25,0.1]',
|
||
'label[0,0;'..format.conversion..']',
|
||
'label[0,0.3;'..format.arbitrarity..']',
|
||
'container_end[]',
|
||
'container[0,0.9]',
|
||
'label[0,0;'..time_information.s..']',
|
||
'label[0,0.3;'..time_information.l..']',
|
||
'container_end[]'
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.ingame_time_format = function (player_name)
|
||
local time_data = mtimer.get_times(player_name).ingame_time
|
||
|
||
mtimer.show_formspec('mtimer:ingame_time_format', {
|
||
title = S('Ingame Time Format'),
|
||
show_to = player_name,
|
||
formspec = {
|
||
'field_close_on_enter[format;false]',
|
||
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
|
||
'container[0,1.5]',
|
||
line(0, '', S('Variable'), S('Current Value')),
|
||
line(1, '-'),
|
||
line(2, S('Hours (24h)'), '{24h}', time_data.hours_24),
|
||
line(3, S('Hours (12h)'), '{12h}', time_data.hours_12),
|
||
line(4, S('Minutes'), '{min}', time_data.minutes),
|
||
line(5, S('Ingame Timestamp'), '{its}', time_data.ingame_timestamp),
|
||
line(6, '-'),
|
||
line(7, S('Current Result'), esc(time_data.formatted), ''),
|
||
'container_end[]'
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.real_world_time_format = function (player_name)
|
||
mtimer.dialog.real_time_universal(player_name, {
|
||
time_type = 'real_time',
|
||
formspec_name = 'mtimer:real_world_time_format',
|
||
title = S('Real-World Time Format')
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.host_time_format = function (player_name)
|
||
mtimer.dialog.real_time_universal(player_name, {
|
||
time_type = 'host_time',
|
||
formspec_name = 'mtimer:host_time_format',
|
||
title = S('Host Time Format')
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.session_start_time_format = function (player_name)
|
||
mtimer.dialog.real_time_universal(player_name, {
|
||
time_type = 'session_start_time',
|
||
formspec_name = 'mtimer:session_start_time_format',
|
||
title = S('Session Start Time Format')
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.session_duration_format = function (player_name)
|
||
local time_data = mtimer.get_times(player_name).session_duration
|
||
|
||
mtimer.show_formspec('mtimer:session_duration_format', {
|
||
title = S('Session Duration Format'),
|
||
show_to = player_name,
|
||
formspec = {
|
||
'field_close_on_enter[format;false]',
|
||
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
|
||
'container[0,1.5]',
|
||
line(0, '', S('Variable'), S('Current Value')),
|
||
line(1, '-'),
|
||
line(2, S('Days'), '{days}', time_data.days),
|
||
line(3, S('Hours'), '{hours}', time_data.hours),
|
||
line(4, S('Minutes'), '{minutes}', time_data.minutes),
|
||
line(5, S('Seconds'), '{seconds}', time_data.seconds),
|
||
line(6, '-'),
|
||
line(7, S('Current Result'), esc(time_data.formatted), ''),
|
||
'container_end[]'
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.hud_element_size = function (player_name)
|
||
local player = minetest.get_player_by_name(player_name)
|
||
local size = player:get_meta():get_string(m.meta.hud_element_size.key)
|
||
|
||
local information = table.concat({
|
||
S('If set to 1 the HUD element is unscaled.'),
|
||
S('All values larger than 1 scale the element up.'),
|
||
S('Clicking the +/- button changes the size by 1.')
|
||
}, '\n')
|
||
|
||
mtimer.show_formspec('mtimer:hud_element_size', {
|
||
title = S('HUD Element Size'),
|
||
show_to = player_name,
|
||
formspec = {
|
||
'field_close_on_enter[hud_element_size;false]',
|
||
'button[0,0;0.5,0.5;substract;'..S('-')..']',
|
||
'field[0.75,0;0.75,0.5;hud_element_size;;'..size..']',
|
||
'button[1.75,0;0.5,0.5;add;'..S('+')..']',
|
||
'label[0.025,1;'..information..']',
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.hud_element_offset = function (player_name)
|
||
local player = minetest.get_player_by_name(player_name)
|
||
local timer_data = esc(mtimer.get_timer_data(player_name).format)
|
||
|
||
local information = table.concat({
|
||
S('HUD element offset is used like a border/padding.'),
|
||
S('Timer format can’t be set here. Go to the timer format dialog for that.')
|
||
}, '\n')
|
||
|
||
-- Get current offset values or 0 for use in formspec
|
||
local key = m.meta.hud_element_offset.key
|
||
local offset = minetest.deserialize(player:get_meta():get_string(key))
|
||
offset.x = offset.x and offset.x or 0
|
||
offset.y = offset.y and offset.y or 0
|
||
|
||
mtimer.show_formspec('mtimer:hud_element_offset', {
|
||
title = S('HUD Element Offset'),
|
||
show_to = player_name,
|
||
height = 4.75,
|
||
formspec = {
|
||
'field_close_on_enter[x_offset;false]',
|
||
'field_close_on_enter[y_offset;false]',
|
||
'box[0,0;5,2.25;#ffffff33]',
|
||
'textarea[0,0;5,2.25;;;'..timer_data..']',
|
||
'container[0,2.5]',
|
||
' button[0,0;0.5,0.5;x_substract_1;'..S('-')..']',
|
||
' field[0.75,0;0.75,0.5;x_offset;;'..offset.x..']',
|
||
' button[1.75,0;0.5,0.5;x_add_1;'..S('+')..']',
|
||
'container_end[]',
|
||
'container[5.25,0]',
|
||
' button[0,0;0.5,0.5;y_add_1;'..S('+')..']',
|
||
' field[0,0.75;0.75,0.5;y_offset;;'..offset.y..']',
|
||
' button[0,1.5;0.5,0.5;y_substract_1;'..S('-')..']',
|
||
'container_end[]',
|
||
'label[0.025,3.5;'..information..']',
|
||
}
|
||
})
|
||
end
|
||
|
||
|
||
mtimer.dialog.timer_format = function (player_name)
|
||
local td = mtimer.get_timer_data(player_name)
|
||
|
||
mtimer.show_formspec('mtimer:timer_format', {
|
||
title = S('Timer Format'),
|
||
show_to = player_name,
|
||
height = 6,
|
||
width = 11,
|
||
formspec = {
|
||
'textarea[0,0;6,2.5;format;;'..esc(td.format)..']',
|
||
'container[0,3.4]',
|
||
line(0, '', S('Variable'), S('Current Value')),
|
||
line(1, '-'),
|
||
line(2, S('Real-World Date'), '{rd}', esc(td.real_world_date)),
|
||
line(3, S('In-Game Time'), '{it}', esc(td.ingame_time)),
|
||
line(4, S('Session Start Time'),'{st}', esc(td.session_start_time)),
|
||
line(5, S('Session Duration'), '{sd}', esc(td.session_duration)),
|
||
line(6, S('Host Time'), '{ht}', esc(td.host_time)),
|
||
line(7, S('Custom Timer'), '{ct}', esc(td.custom_timer)),
|
||
'container_end[]',
|
||
'container[6.25,0]',
|
||
mtimer.get_icon_button('apply', { label = S('Apply') }),
|
||
'container_end[]'
|
||
}
|
||
})
|
||
end
|