mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-01-07 13:27:31 +01:00
make all dialogs use the new style buttons
This commit is contained in:
parent
f1214ba398
commit
7e0713a67a
@ -124,16 +124,16 @@ mtimer.dialog.ingame_time_format = function (player_name)
|
||||
show_to = player_name,
|
||||
formspec = {
|
||||
'field_close_on_enter[format;false]',
|
||||
'field[0,0;+linewidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'field[0,0;+contentWidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'container[0,0.9]',
|
||||
'label[2.8,0;'..S('Variable')..']',
|
||||
'label[4.25,0;'..S('Current Value')..']',
|
||||
'box[0,0.25;+linewidth,0.02;#ffffff]',
|
||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,0.5;'..S('Hours (24h)')..'] label[2.8,0.5;{24h}] label[4.25,0.5;'..time_data.hours_24..']',
|
||||
'label[0,0.9;'..S('Hours (12h)')..'] label[2.8,0.9;{12h}] label[4.25,0.9;'..time_data.hours_12..']',
|
||||
'label[0,1.3;'..S('Minutes')..'] label[2.8,1.3;{min}] label[4.25,1.3;'..time_data.minutes..']',
|
||||
'label[0,1.7;'..S('Ingame Timestamp')..'] label[2.8,1.7;{its}] label[4.25,1.7;'..time_data.ingame_timestamp..']',
|
||||
'box[0,2;+linewidth,0.02;#ffffff]',
|
||||
'box[0,2;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,2.25;'..S('Current Result')..']',
|
||||
'label[2.8,2.25;'..fe(time_data.formatted)..']',
|
||||
'container_end[]'
|
||||
@ -178,16 +178,16 @@ mtimer.dialog.session_duration_format = function (player_name)
|
||||
height = 3.8,
|
||||
formspec = {
|
||||
'field_close_on_enter[format;false]',
|
||||
'field[0,0;+linewidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'field[0,0;+contentWidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'container[0,0.9]',
|
||||
'label[2.5,0;'..S('Variable')..']',
|
||||
'label[4,0;'..S('Current Value')..']',
|
||||
'box[0,0.25;+linewidth,0.02;#ffffff]',
|
||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,0.5;'..S('Days')..'] label[2.5,0.5;{days}] label[4,0.5;'..time_data.days..']',
|
||||
'label[0,0.9;'..S('Hours')..'] label[2.5,0.9;{hours}] label[4,0.9;'..time_data.hours..']',
|
||||
'label[0,1.3;'..S('Minutes')..'] label[2.5,1.3;{minutes}] label[4,1.3;'..time_data.minutes..']',
|
||||
'label[0,1.7;'..S('Seconds')..'] label[2.5,1.7;{seconds}] label[4,1.7;'..time_data.seconds..']',
|
||||
'box[0,2;+linewidth,0.02;#ffffff]',
|
||||
'box[0,2;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,2.25;'..S('Current Result')..']',
|
||||
'label[2.5,2.25;'..fe(time_data.formatted)..']',
|
||||
'container_end[]'
|
||||
@ -273,7 +273,7 @@ mtimer.dialog.timer_format = function (player_name)
|
||||
'container[0,2.9]',
|
||||
'label[2.5,0;'..S('Variable')..']',
|
||||
'label[4,0;'..S('Current Value')..']',
|
||||
'box[0,0.25;+linewidth,0.02;#ffffff]',
|
||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,0.5;'..S('Real-World Date')..'] label[2.5,0.5;{rd}] label[4,0.5;'..fe(timer_data.real_world_date)..']',
|
||||
'label[0,0.9;'..S('In-Game Time')..'] label[2.5,0.9;{it}] label[4,0.9;'..fe(timer_data.ingame_time)..']',
|
||||
'label[0,1.3;'..S('Session Start Time')..'] label[2.5,1.3;{st}] label[4,1.3;'..fe(timer_data.session_start_time)..']',
|
||||
@ -323,7 +323,7 @@ mtimer.dialog.custom_timer = function (player_name)
|
||||
' label[0,0.25;'..S('Running')..'] field[2.25,0;6.5,0.5;v_format_running;;'..fe(format_running)..']',
|
||||
' label[0,0.85;'..S('Stopped')..'] field[2.25,0.6;6.5,0.5;v_format_stopped;;'..fe(format_stopped)..']',
|
||||
' label[0,1.45;'..S('Finished')..'] field[2.25,1.2;6.5,0.5;v_format_finished;;'..fe(format_finished)..']',
|
||||
' box[0,2;+linewidth,0.04;#ffffff]',
|
||||
' box[0,2;+contentWidth,0.04;#ffffff]',
|
||||
'container_end[]',
|
||||
'container[3.75,2.4]',
|
||||
' label[0,0;'..S('Information')..']',
|
||||
|
@ -79,7 +79,7 @@ end
|
||||
--
|
||||
-- This function builds and displays a formspec based on the input.
|
||||
--
|
||||
-- The `name` is the usual formspec name (for example `mymod:my_formspec`) and
|
||||
-- The `id` is the usual formspec ID (for example `mymod:my_formspec`) and
|
||||
-- has to be provided as a simple string all other parameters are provided via
|
||||
-- the `def` table. The following table is an example.
|
||||
--
|
||||
@ -117,74 +117,72 @@ end
|
||||
-- you can easily start at 0,0 for your definition. The function automatically
|
||||
-- places everything in relation to the formspec frame and default buttons.
|
||||
--
|
||||
-- The minimum formspec width and height are 8 units in width and 3 units in
|
||||
-- The minimum formspec width and height are 9 units in width and 4 units in
|
||||
-- height. So `width` and `height` can be omitted when all of your content fits
|
||||
-- into the default size. The resulting formspec is a minimum of 8 units wide
|
||||
-- and 4.6 units high (1.6 units are added for the title and the buttons).
|
||||
-- into the default size. The resulting formspec is a minimum of 9 units wide
|
||||
-- and 5.85 units high (1.85 units are added for the title and the buttons).
|
||||
--
|
||||
-- All formspec table entries can contain the following variables. Variables
|
||||
-- start with a plus sign (+) and are read until any character that is not
|
||||
-- a letter. Some variables are useless, some can be used quite well.
|
||||
--
|
||||
-- Variable Name Value Type
|
||||
-- Variable Name Value Type
|
||||
-- --------------------------------------------------------------------------
|
||||
-- +width width of the formspec
|
||||
-- +height height of the formspec
|
||||
-- +linewidth optimal width for a box that is used as horizontal line
|
||||
-- +title formspec’s title
|
||||
-- +content content container vertical position (+offset)
|
||||
-- +buttons default buttons vertical position
|
||||
-- +defbutton “Default” button’s horizontal position
|
||||
-- +mainbutton “Main Menu” button’s horizontal position
|
||||
-- +exitbutton “Exit” button’s horizontal position
|
||||
-- +title formspec’s title
|
||||
-- +width width of the formspec
|
||||
-- +height height of the formspec
|
||||
-- +contentWidth optimal width for the content
|
||||
-- +contentPosition content container vertical position (+offset)
|
||||
-- +buttons default buttons vertical position
|
||||
--
|
||||
-- @param name The name of the formspec
|
||||
-- @param id The ID of the formspec
|
||||
-- @param def The definition table as described
|
||||
-- @return string the constructed “frame”
|
||||
mtimer.show_formspec = function (name, def)
|
||||
mtimer.show_formspec = function (id, def)
|
||||
local add_buttons = def.add_buttons == true or def.add_buttons == nil
|
||||
local content_offset = def.content_offset or 0
|
||||
local width = (def.width or 0) <= 8 and 8 or def.width
|
||||
local height = (def.height or 0) <= 3 and 4.6 or def.height + 1.6
|
||||
local width = (def.width or 0) <= 10 and 10 or def.width
|
||||
local height = (def.height or 0) <= 4 and 5.85 or def.height + 1.85
|
||||
local prefix = def.prefix or '[mTimer] '
|
||||
if not add_buttons then height = height - 1.6 end
|
||||
|
||||
-- Calculate height
|
||||
if not add_buttons then height = height - 1.85 end
|
||||
height = height + content_offset
|
||||
|
||||
-- Set up buttons
|
||||
local buttons = not add_buttons and '' or table.concat({
|
||||
'container[0,+buttons]',
|
||||
'box[0.25,0;+linewidth,0.04;#ffffff]',
|
||||
'button[+defbutton,0.2;2,0.5;default;'..S('Default')..']',
|
||||
'button[+mainbutton,0.2;2,0.5;main_menu;'..S('Main Menu')..']',
|
||||
'button_exit[+exitbutton,0.2;2,0.5;exit;'..S('Exit')..']',
|
||||
'container[0.25,+buttons]',
|
||||
' box[0,0;+contentWidth,0.04;#ffffff]',
|
||||
mtimer.get_icon_button('main_menu', { label = S('Main Menu'), width = 2.5, container = { top = 0.25 } }),
|
||||
' container[+contentWidth,0.25]',
|
||||
mtimer.get_icon_button('exit', { label = S('Exit'), exit_button = true, width = 2.5, container = { left = -2.5 } }),
|
||||
mtimer.get_icon_button('default', { label = S('Default'), width = 2.5, container = { left = -5.25 } }),
|
||||
' container_end[]',
|
||||
'container_end[]'
|
||||
}, ' ')
|
||||
|
||||
-- Build formspec
|
||||
local formspec = table.concat({
|
||||
'formspec_version[2]',
|
||||
'size[+width,+height]',
|
||||
'image[0.25,0.2;0.3,0.3;+icon]',
|
||||
'label[0.65,0.35;+title]',
|
||||
'box[0.25,0.6;+linewidth,0.04;#ffffff]',
|
||||
'container[0.25,+content]',
|
||||
'box[0.25,0.6;+contentWidth,0.04;#ffffff]',
|
||||
'container[0.25,+contentPosition]',
|
||||
table.concat(def.formspec, ' '),
|
||||
'container_end[]',
|
||||
buttons
|
||||
}, ' ')
|
||||
|
||||
formspec = formspec:gsub('%+%a+', {
|
||||
}, ' '):gsub('%+%a+', {
|
||||
['+width'] = width+0.25,
|
||||
['+height'] = height,
|
||||
['+linewidth'] = width-0.25,
|
||||
['+contentWidth'] = width-0.25,
|
||||
['+title'] = minetest.formspec_escape(prefix..def.title),
|
||||
['+icon'] = 'mtimer_'..name:gsub('mtimer:', '')..'.png',
|
||||
['+content'] = 0.9 + content_offset,
|
||||
['+buttons'] = height-1,
|
||||
['+defbutton'] = 0.25,
|
||||
['+mainbutton'] = width-4.4+0.25,
|
||||
['+exitbutton'] = width-2.25+0.25,
|
||||
['+icon'] = 'mtimer_'..id:gsub('mtimer:', '')..'.png',
|
||||
['+contentPosition'] = 0.9 + content_offset,
|
||||
['+buttons'] = height-1.25,
|
||||
|
||||
})
|
||||
|
||||
minetest.show_formspec(def.show_to, name, formspec)
|
||||
-- Show formspec to the plauyer
|
||||
minetest.show_formspec(def.show_to, id, formspec)
|
||||
end
|
||||
|
@ -71,10 +71,10 @@ mtimer.dialog.main_menu = function (player_name)
|
||||
button(3, 2, 'timezone_offset', S('Timezone Offset')),
|
||||
button(3, 3, 'custom_timer', S('Custom Timer')),
|
||||
'container[0,4.75]',
|
||||
' box[0,0;+linewidth,0.04;#ffffff]',
|
||||
' container[+linewidth,0]',
|
||||
mtimer.get_icon_button('exit', { label = S('Exit'), exit_button = true, container = { top = 0.25, left = -7.25 } }),
|
||||
mtimer.get_icon_button('reset_everything', { label = S('Reset Everything'), width = 4, container = { top = 0.25, left = -4 } }),
|
||||
' 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 } }),
|
||||
' container_end[]',
|
||||
'container_end[]'
|
||||
}
|
||||
|
@ -31,27 +31,27 @@ mtimer.dialog.real_time_universal = function (player_name, config)
|
||||
height = 7.5,
|
||||
formspec = {
|
||||
'field_close_on_enter[format;false]',
|
||||
'field[0,0;+linewidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'field[0,0;+contentWidth,0.5;format;;'..fe(time_data.format)..']',
|
||||
'container[0,0.9]',
|
||||
'label[2.8,0;'..S('Variable')..']',
|
||||
'label[4.6,0;'..S('Current Value')..']',
|
||||
'box[0,0.25;+linewidth,0.02;#ffffff]',
|
||||
'box[0,0.25;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,0.5;'..S('Hours (24h)')..'] label[2.8,0.5;{24h}] label[4.6,0.5;'..time_data.variables.hours_24..']',
|
||||
'label[0,0.9;'..S('Hours (12h)')..'] label[2.8,0.9;{12h}] label[4.6,0.9;'..time_data.variables.hours_12..']',
|
||||
'label[0,1.3;'..S('Minutes')..'] label[2.8,1.3;{min}] label[4.6,1.3;'..time_data.variables.minutes..']',
|
||||
'label[0,1.7;'..S('Seconds')..'] label[2.8,1.7;{sec}] label[4.6,1.7;'..time_data.variables.seconds..']',
|
||||
'box[0,1.98;+linewidth,0.02;#ffffff]',
|
||||
'box[0,1.98;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,2.2;'..S('Day Name')..'] label[2.8,2.2;{dname}] label[4.6,2.2;'..time_data.variables.dayname..']',
|
||||
'label[0,2.6;'..S('Month Name')..'] label[2.8,2.6;{mname}] label[4.6,2.6;'..time_data.variables.monthname..']',
|
||||
'box[0,2.85;+linewidth,0.02;#ffffff]',
|
||||
'box[0,2.85;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,3.1;'..S('Year')..'] label[2.8,3.1;{year}] label[4.6,3.1;'..time_data.variables.year..']',
|
||||
'label[0,3.5;'..S('Month')..'] label[2.8,3.5;{month}] label[4.6,3.5;'..time_data.variables.month..']',
|
||||
'label[0,3.9;'..S('Day')..'] label[2.8,3.9;{day}] label[4.6,3.9;'..time_data.variables.day..']',
|
||||
'box[0,4.2;+linewidth,0.02;#ffffff]',
|
||||
'box[0,4.2;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,4.45;'..S('ISO 8601 Date')..'] label[2.8,4.45;{isodate}] label[4.6,4.45;'..time_data.variables.iso8601_date..']',
|
||||
'label[0,4.85;'..S('ISO 8601 Time')..'] label[2.8,4.85;{isotime}] label[4.6,4.85;'..time_data.variables.iso8601_time..']',
|
||||
'label[0,5.25;'..S('Timestamp')..'] label[2.8,5.25;{timestamp}] label[4.6,5.25;'..time_data.variables.timestamp..']',
|
||||
'box[0,5.55;+linewidth,0.02;#ffffff]',
|
||||
'box[0,5.55;+contentWidth,0.02;#ffffff]',
|
||||
'label[0,5.8;'..S('Current Result')..']',
|
||||
'label[2.8,5.8;'..fe(time_data.formatted)..']',
|
||||
'container_end[]'
|
||||
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Loading…
Reference in New Issue
Block a user