fully implement hud element offset

This commit is contained in:
Dirk Sohler 2020-08-11 21:30:16 +02:00
parent 93771fbbaf
commit a7e89e6c2e
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
2 changed files with 17 additions and 8 deletions

@ -257,8 +257,7 @@ mtimer.dialog.hud_element_size = function (player_name)
}) })
end end
-- TODO Remove debug information when done
-- Debug offsets: y=20 x=50
mtimer.dialog.hud_element_offset = function (player_name) mtimer.dialog.hud_element_offset = function (player_name)
local player = minetest.get_player_by_name(player_name) local player = minetest.get_player_by_name(player_name)
local timer_data = fe(mtimer.get_timer_data(player_name).format) local timer_data = fe(mtimer.get_timer_data(player_name).format)
@ -284,17 +283,16 @@ mtimer.dialog.hud_element_offset = function (player_name)
'box[0,0;5,2.25;#ffffff33]', 'box[0,0;5,2.25;#ffffff33]',
'textarea[0,0;5,2.25;;;'..timer_data..']', 'textarea[0,0;5,2.25;;;'..timer_data..']',
'container[0,2.5]', 'container[0,2.5]',
' button[0,0;0.5,0.5;x_substract;'..S('-')..']', ' button[0,0;0.5,0.5;x_substract_1;'..S('-')..']',
' field[0.75,0;0.75,0.5;x_offset;;'..offset.x..']', ' field[0.75,0;0.75,0.5;x_offset;;'..offset.x..']',
' button[1.75,0;0.5,0.5;x_add;'..S('+')..']', ' button[1.75,0;0.5,0.5;x_add_1;'..S('+')..']',
'container_end[]', 'container_end[]',
'container[5.25,0]', 'container[5.25,0]',
' button[0,0;0.5,0.5;y_add;'..S('+')..']', ' button[0,0;0.5,0.5;y_add_1;'..S('+')..']',
' field[0,0.75;0.75,0.5;y_offset;;'..offset.y..']', ' field[0,0.75;0.75,0.5;y_offset;;'..offset.y..']',
' button[0,1.5;0.5,0.5;y_substract;'..S('-')..']', ' button[0,1.5;0.5,0.5;y_substract_1;'..S('-')..']',
'container_end[]', 'container_end[]',
'label[0.025,3.5;'..information..']', 'label[0.025,3.5;'..information..']',
} }
}) })
end end

@ -151,8 +151,19 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Set offset (used as border/padding) of the timer HUD element -- Set offset (used as border/padding) of the timer HUD element
if formname == 'mtimer:hud_element_offset' then if formname == 'mtimer:hud_element_offset' then
local attr = m.meta.hud_element_offset local attr = m.meta.hud_element_offset
local default = minetest.deserialize(attr.default)
local x_offset = tonumber(fields.x_offset) or default.x
local y_offset = tonumber(fields.y_offset) or default.y
-- TODO Implement Logic for sanitizig and setting the offset if fields.x_add_1 then x_offset = x_offset + 1 end
if fields.y_add_1 then y_offset = y_offset + 1 end
if fields.x_substract_1 then x_offset = x_offset - 1 end
if fields.y_substract_1 then y_offset = y_offset - 1 end
meta:set_string(attr.key, minetest.serialize({
x = x_offset,
y = y_offset
}))
if fields.default then meta:set_string(attr.key, attr.default) end if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then d.hud_element_offset(name) end if not fields.quit then d.hud_element_offset(name) end