From a7e89e6c2e36aa0ce33f3c31f16846e44e4afaa2 Mon Sep 17 00:00:00 2001 From: Dirk Sohler Date: Tue, 11 Aug 2020 21:30:16 +0200 Subject: [PATCH] fully implement hud element offset --- system/formspec/formspec_creation.lua | 12 +++++------- system/on_receive_fields.lua | 13 ++++++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/system/formspec/formspec_creation.lua b/system/formspec/formspec_creation.lua index bca9fb4..764945a 100644 --- a/system/formspec/formspec_creation.lua +++ b/system/formspec/formspec_creation.lua @@ -257,8 +257,7 @@ 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) @@ -284,17 +283,16 @@ mtimer.dialog.hud_element_offset = function (player_name) '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('-')..']', + ' 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;'..S('+')..']', + ' 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;'..S('+')..']', + ' 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;'..S('-')..']', + ' button[0,1.5;0.5,0.5;y_substract_1;'..S('-')..']', 'container_end[]', 'label[0.025,3.5;'..information..']', - } }) end diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index e55613a..0f26aaa 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -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 if formname == 'mtimer:hud_element_offset' then 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 not fields.quit then d.hud_element_offset(name) end