move helper function out of fs creation function

This commit is contained in:
Dirk Sohler 2021-05-15 01:03:59 +02:00
parent 1218243a2d
commit 57a9284bca
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A

@ -2,6 +2,13 @@ local m = mtimer
local S = m.translator
-- Image width and height for setting the screenshot in position and do the
-- button calculations
local i_width = 10
local i_height = 6
-- Position names for the current position information string
local p_names = {
['t'] = S('top'),
['m'] = S('middle'),
@ -12,31 +19,40 @@ local p_names = {
}
-- Return parsed position button
--
-- This function shows a button on the given position that sets the position
-- of the GUI element accordingly. The `position` is one of the following.
--
-- tl, tc, tr = top left, center, right
-- ml, mc, mr = middle left, center, right
-- bl, bc, br = bottom left, center right
--
-- @param top The position of the button from the top
-- @param left The position of the button from the left
-- @param position GUI element position to set with this button
local b_define = function(top, left, position)
return ('image_button[+l,+t;+w,+h;+i;pos_+p;d;;false]'):gsub('%+%w', {
['+l'] = (left - 1) * (i_width / 3),
['+t'] = (top - 1) * (i_height / 3),
['+w'] = i_width / 3,
['+h'] = i_height / 3,
['+i'] = 'mtimer_transparent.png',
['+p'] = position,
})
end
mtimer.dialog.set_position = function (player_name)
local player = minetest.get_player_by_name(player_name)
local howto = S('Click the position you want to place the timer at.')
local image = 'mtimer_positions_orientation.png'
-- Get current position name
local p_value = player:get_meta():get_string(m.meta.position.key)
local p_name = p_names[p_value:sub(1,1)]..' '..p_names[p_value:sub(2,2)]
local p_info = S('Current position: @1', p_name)
-- Set up image
local image = 'mtimer_positions_orientation.png'
local i_width = 10
local i_height = 6
-- Return the parsed button
local b_define = function(t, l, p)
return ('image_button[+l,+t;+w,+h;+i;pos_+p;d;;false]'):gsub('%+%w', {
['+l'] = (l - 1) * (i_width / 3),
['+t'] = (t - 1) * (i_height / 3),
['+w'] = i_width / 3,
['+h'] = i_height / 3,
['+i'] = 'mtimer_transparent.png',
['+p'] = p,
})
end
mtimer.show_formspec('mtimer:set_position', {
title = S('Position'),