mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-24 16:23:44 +01:00
add HUD element scaling using HUD's size parameter
This commit is contained in:
parent
52a937ef88
commit
dc8729c0f5
1
init.lua
1
init.lua
@ -20,6 +20,7 @@ mtimer = {
|
||||
visible = { key = 'mtimer:visible', default = 'true' },
|
||||
position = { key = 'mtimer:position', default = 'bl' },
|
||||
color = { key = 'mtimer:color', default = '#ffffff' },
|
||||
hud_element_size = { key = 'mtimer:hud_element_size', default = '1' },
|
||||
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
||||
ingame_time = {
|
||||
key = 'mtimer:ingame_time_format',
|
||||
|
@ -8,6 +8,7 @@ Position=Ausrichtung
|
||||
Real-World Time Format=Realzeit-Format
|
||||
Host Time Format=Hostzeit-Format
|
||||
Reset Everything=Alles zurücksetzen
|
||||
HUD Element Size=Anzeigegröße
|
||||
Session Duration Format=Sitzungsdauer-Format
|
||||
Session Start Time Format=Sitzungsstartzeit-Format
|
||||
Timer Format=Timerformat
|
||||
|
@ -34,6 +34,7 @@ end
|
||||
-- ht host time d.host_time_format(name)
|
||||
-- st start time d.session_start_time_format(name)
|
||||
-- sd session duration d.session_duration_format(name)
|
||||
-- hs HUD size d.hud_element_size(name)
|
||||
-- tf timer format d.timer_format(name)
|
||||
-- -------------------------------------------------------------------
|
||||
-- help Prints the help output showing the parameters
|
||||
@ -57,6 +58,7 @@ minetest.register_chatcommand('mtimer', {
|
||||
if action == 'ht' then d.host_time_format(name) end
|
||||
if action == 'st' then d.session_start_time_format(name) end
|
||||
if action == 'sd' then d.session_duration_format(name) end
|
||||
if action == 'hs' then d.hud_element_size(name) end
|
||||
if action == 'tf' then d.timer_format(name) end
|
||||
|
||||
if action == 'help' then
|
||||
@ -70,6 +72,7 @@ minetest.register_chatcommand('mtimer', {
|
||||
command('ht')..S('Host Time Format'),
|
||||
command('st')..S('Session Start Time Format'),
|
||||
command('sd')..S('Session Duration Format'),
|
||||
command('hs')..S('HUD Element Size'),
|
||||
command('tf')..S('Timer Format'),
|
||||
command(' ')..S('Open Main Menu')
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ mtimer.dialog.main_menu = function (player_name)
|
||||
'button[0,0.25;3,0.5;set_visibility;'..S('Visibility')..']',
|
||||
'button[0,1;3,0.5;set_position;'..S('Position')..']',
|
||||
'button[0,1.75;3,0.5;set_color;'..S('Color')..']',
|
||||
'button[0,2.5;3,0.5;hud_element_size;'..S('HUD Element Size')..']',
|
||||
'container_end[]',
|
||||
'container[3.25,0]',
|
||||
'label[0,0;'..S('Time Representation')..']',
|
||||
@ -232,6 +233,24 @@ mtimer.dialog.session_duration_format = function (player_name)
|
||||
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)
|
||||
|
||||
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,0.75;'..S('Information')..']'
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
mtimer.dialog.timer_format = function (player_name)
|
||||
local timer_data = mtimer.get_timer_data(player_name)
|
||||
|
||||
|
@ -22,6 +22,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
number = '0x000000',
|
||||
position = {x=0,y=0},
|
||||
alignment = {x=0,y=0},
|
||||
size = {x=0,y=0},
|
||||
offset = {x=0,y=0}
|
||||
}))
|
||||
end)
|
||||
|
@ -26,6 +26,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if fields.session_duration_format then
|
||||
d.session_duration_format(name)
|
||||
end
|
||||
if fields.hud_element_size then d.hud_element_size(name) end
|
||||
if fields.timer_format then d.timer_format(name) end
|
||||
end
|
||||
|
||||
@ -130,6 +131,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
|
||||
-- Set size (scaling) of the timer HUD element
|
||||
if formname == 'mtimer:hud_element_size' then
|
||||
local attr = m.meta.hud_element_size
|
||||
local value = tonumber(fields.hud_element_size or attr.default)
|
||||
|
||||
if fields.add then value = value + 1 end
|
||||
if fields.substract then value = value - 1 end
|
||||
if value < 1 then value = 1 end
|
||||
|
||||
meta:set_string(attr.key, value)
|
||||
|
||||
if fields.default then meta:set_string(attr.key, attr.default) end
|
||||
if not fields.quit then d.hud_element_size(name) end
|
||||
end
|
||||
|
||||
|
||||
-- Set timer text
|
||||
if formname == 'mtimer:timer_format' then
|
||||
local attr = m.meta.timer_format
|
||||
|
@ -62,6 +62,7 @@ mtimer.update_timer = function (player_name)
|
||||
local text = mtimer.get_timer_data(player_name).formatted
|
||||
local number = meta:get_string(m.color.key):gsub('#', '0x')
|
||||
local orientation = get_hud_positions(meta:get_string(m.position.key))
|
||||
local size = meta:get_string(m.hud_element_size.key)
|
||||
|
||||
if meta:get_string(m.visible.key) == 'false' then text = '' end
|
||||
|
||||
@ -69,5 +70,6 @@ mtimer.update_timer = function (player_name)
|
||||
player:hud_change(hud_id, 'number', number)
|
||||
player:hud_change(hud_id, 'position', orientation.position)
|
||||
player:hud_change(hud_id, 'alignment', orientation.alignment)
|
||||
player:hud_change(hud_id, 'size', {x=size, y=size})
|
||||
player:hud_change(hud_id, 'offset', orientation.offset)
|
||||
end
|
||||
|
BIN
textures/mtimer_icon_hud_element_size.png
Normal file
BIN
textures/mtimer_icon_hud_element_size.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Loading…
Reference in New Issue
Block a user