mirror of
https://gitlab.com/4w/mtimer.git
synced 2025-01-22 12:31:28 +01:00
implement offset dialogs+i18n and setting logic
Formspec, menu entry, and logic are done. Logic for setting the timer offsets on receiving formspec fields needs to be done.
This commit is contained in:
parent
471f3aac80
commit
93771fbbaf
4
init.lua
4
init.lua
@ -22,6 +22,10 @@ mtimer = {
|
||||
color = { key = 'mtimer:color', default = '#ffffff' },
|
||||
hud_element_size = { key = 'mtimer:hud_element_size', default = '1' },
|
||||
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
||||
hud_element_offset = {
|
||||
key = 'mtimer:hud_element_offset',
|
||||
default = minetest.serialize({ x = 0, y = 0 })
|
||||
},
|
||||
ingame_time = {
|
||||
key = 'mtimer:ingame_time_format',
|
||||
default = '{24h}:{min}'
|
||||
|
@ -9,6 +9,7 @@ Real-World Time Format=Realzeit-Format
|
||||
Host Time Format=Hostzeit-Format
|
||||
Reset Everything=Alles zurücksetzen
|
||||
HUD Element Size=Anzeigegröße
|
||||
HUD Element Offset=Anzeigeversatz
|
||||
Session Duration Format=Sitzungsdauer-Format
|
||||
Session Start Time Format=Sitzungsstartzeit-Format
|
||||
Timer Format=Timerformat
|
||||
@ -57,6 +58,10 @@ If set to 1 the HUD element is unscaled.=Mit 1 als Wert wird die Anzeige nicht v
|
||||
All values larger than 1 scale the element up.=Alle Werte über 1 vergrößern die Anzeige.
|
||||
Clicking the +/- button changes the size by 1.=Ein Klick auf +/- verändert die Größe um 1.
|
||||
|
||||
# HUD Element Offset Information
|
||||
HUD element offset is used like a border/padding.=Der Anzeigeversatz wird wie ein Rahmen (Umrandung) benutzt.
|
||||
Timer format can’t be set here. Go to the timer format dialog for that.=Das Timerformat kann nur im Timerformat-Dialog eingestellt werden.
|
||||
|
||||
# Timer Format Variables
|
||||
In-Game Time=Spielzeit
|
||||
Real-World Date=Reale Zeit
|
||||
|
@ -35,6 +35,7 @@ end
|
||||
-- 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)
|
||||
-- os OffSet d.hud_element_offset(name)
|
||||
-- tf timer format d.timer_format(name)
|
||||
-- -------------------------------------------------------------------
|
||||
-- help Prints the help output showing the parameters
|
||||
@ -59,6 +60,7 @@ minetest.register_chatcommand('mtimer', {
|
||||
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 == 'os' then d.hud_element_offset(name) end
|
||||
if action == 'tf' then d.timer_format(name) end
|
||||
|
||||
if action == 'help' then
|
||||
@ -73,6 +75,7 @@ minetest.register_chatcommand('mtimer', {
|
||||
command('st')..S('Session Start Time Format'),
|
||||
command('sd')..S('Session Duration Format'),
|
||||
command('hs')..S('HUD Element Size'),
|
||||
command('os')..S('HUD Element Offset'),
|
||||
command('tf')..S('Timer Format'),
|
||||
command(' ')..S('Open Main Menu')
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ mtimer.dialog.main_menu = function (player_name)
|
||||
'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')..']',
|
||||
'button[0,3.25;3,0.5;hud_element_offset;'..S('HUD Element Offset')..']',
|
||||
'container_end[]',
|
||||
'container[3.25,0]',
|
||||
'label[0,0;'..S('Time Representation')..']',
|
||||
@ -256,6 +257,48 @@ mtimer.dialog.hud_element_size = function (player_name)
|
||||
})
|
||||
end
|
||||
|
||||
-- TODO Remove debug information when done
|
||||
-- Debug offsets: y=20 x=50
|
||||
mtimer.dialog.hud_element_offset = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local timer_data = fe(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;'..S('-')..']',
|
||||
' field[0.75,0;0.75,0.5;x_offset;;'..offset.x..']',
|
||||
' button[1.75,0;0.5,0.5;x_add;'..S('+')..']',
|
||||
'container_end[]',
|
||||
'container[5.25,0]',
|
||||
' button[0,0;0.5,0.5;y_add;'..S('+')..']',
|
||||
' field[0,0.75;0.75,0.5;y_offset;;'..offset.y..']',
|
||||
' button[0,1.5;0.5,0.5;y_substract;'..S('-')..']',
|
||||
'container_end[]',
|
||||
'label[0.025,3.5;'..information..']',
|
||||
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
mtimer.dialog.timer_format = function (player_name)
|
||||
local timer_data = mtimer.get_timer_data(player_name)
|
||||
|
@ -27,6 +27,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
d.session_duration_format(name)
|
||||
end
|
||||
if fields.hud_element_size then d.hud_element_size(name) end
|
||||
if fields.hud_element_offset then d.hud_element_offset(name) end
|
||||
if fields.timer_format then d.timer_format(name) end
|
||||
end
|
||||
|
||||
@ -147,6 +148,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
|
||||
-- Set offset (used as border/padding) of the timer HUD element
|
||||
if formname == 'mtimer:hud_element_offset' then
|
||||
local attr = m.meta.hud_element_offset
|
||||
|
||||
-- TODO Implement Logic for sanitizig and setting the offset
|
||||
|
||||
if fields.default then meta:set_string(attr.key, attr.default) end
|
||||
if not fields.quit then d.hud_element_offset(name) end
|
||||
end
|
||||
|
||||
|
||||
-- Set timer text
|
||||
if formname == 'mtimer:timer_format' then
|
||||
local attr = m.meta.timer_format
|
||||
|
@ -1,4 +1,5 @@
|
||||
local m = mtimer
|
||||
local deserialize = minetest.deserialize
|
||||
|
||||
|
||||
-- Calculate HUD positions and offsets
|
||||
@ -21,22 +22,62 @@ local m = mtimer
|
||||
-- `bc` is the location of the hotbar and health bars, etc.
|
||||
-- Both are valid positions but should not be used.
|
||||
--
|
||||
-- Provided offsets will be added or substracted according to the position. In
|
||||
-- result the pffset behaves like a border
|
||||
--
|
||||
-- @param pos A positional string as described
|
||||
-- @param poffset An offset table like { x=1, y=1 }
|
||||
-- @return table a Table containing the positional tables based on the string
|
||||
local get_hud_positions = function (pos)
|
||||
local get_hud_positions = function (pos, offset)
|
||||
local p = { x = 0, y = 0 }
|
||||
local a = { x = 0, y = 0 }
|
||||
local o = { x = 0, y = 0 }
|
||||
|
||||
if pos == 'tl' then p = {x=0, y=0 } a = {x=1, y=1 } o = {x=5, y=3} end
|
||||
if pos == 'tc' then p = {x=0.5,y=0 } a = {x=0, y=1 } o = {x=0, y=3} end
|
||||
if pos == 'tr' then p = {x=1, y=0 } a = {x=-1,y=1 } o = {x=-6,y=3} end
|
||||
if pos == 'ml' then p = {x=0, y=0.5} a = {x=1, y=0 } o = {x=5, y=0} end
|
||||
if pos == 'mc' then p = {x=0.5,y=0.5} a = {x=0, y=0 } o = {x=0, y=0} end
|
||||
if pos == 'mr' then p = {x=1, y=0.5} a = {x=-1,y=0 } o = {x=-6,y=0} end
|
||||
if pos == 'bl' then p = {x=0, y=1 } a = {x=1, y=-1} o = {x=5, y=0} end
|
||||
if pos == 'bc' then p = {x=0.5,y=1 } a = {x=0, y=-1} o = {x=0, y=0} end
|
||||
if pos == 'br' then p = {x=1, y=1 } a = {x=-1,y=-1} o = {x=-6,y=0} end
|
||||
if pos == 'tl' then
|
||||
p = { x = 0, y = 0 }
|
||||
a = { x = 1, y = 1 }
|
||||
o = { x = 5 + offset.x, y = 3 + offset.y }
|
||||
end
|
||||
if pos == 'tc' then
|
||||
p = { x = 0.5, y = 0 }
|
||||
a = { x = 0, y = 1 }
|
||||
o = { x = 0 - offset.x, y = 3 + offset.y }
|
||||
end
|
||||
if pos == 'tr' then
|
||||
p = { x = 1, y = 0 }
|
||||
a = { x=-1, y = 1 }
|
||||
o = { x = -6 - offset.x, y = 3 + offset.y }
|
||||
end
|
||||
if pos == 'ml' then
|
||||
p = { x = 0, y = 0.5 }
|
||||
a = { x = 1, y = 0 }
|
||||
o = { x = 5 + offset.x, y = 0 + offset.y }
|
||||
end
|
||||
if pos == 'mc' then
|
||||
p = { x = 0.5,y = 0.5 }
|
||||
a = { x = 0, y = 0 }
|
||||
o = { x = 0 + offset.x, y = 0 + offset.y }
|
||||
end
|
||||
if pos == 'mr' then
|
||||
p = { x = 1, y = 0.5 }
|
||||
a = { x = -1,y = 0 }
|
||||
o = { x = -6 - offset.x, y = 0 + offset.y }
|
||||
end
|
||||
if pos == 'bl' then
|
||||
p = { x = 0, y = 1 }
|
||||
a = { x = 1, y = -1 }
|
||||
o = { x = 5 + offset.x, y = 0 - offset.y }
|
||||
end
|
||||
if pos == 'bc' then
|
||||
p = { x = 0.5, y = 1 }
|
||||
a = { x = 0, y = -1 }
|
||||
o = { x = 0 + offset.x, y = 0 - offset.y }
|
||||
end
|
||||
if pos == 'br' then
|
||||
p = { x = 1, y = 1 }
|
||||
a = { x = -1, y = -1 }
|
||||
o = { x = -6 - offset.x, y = 0 - offset.y }
|
||||
end
|
||||
|
||||
return { position = p, alignment = a, offset = o }
|
||||
end
|
||||
@ -61,9 +102,12 @@ 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)
|
||||
|
||||
local position = meta:get_string(m.position.key)
|
||||
local offset = deserialize(meta:get_string(m.hud_element_offset.key))
|
||||
local orientation = get_hud_positions(position, offset)
|
||||
|
||||
if meta:get_string(m.visible.key) == 'false' then text = '' end
|
||||
|
||||
player:hud_change(hud_id, 'text', text)
|
||||
|
BIN
textures/mtimer_icon_hud_element_offset.png
Normal file
BIN
textures/mtimer_icon_hud_element_offset.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
Loading…
Reference in New Issue
Block a user