mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 02:03:46 +01:00
adapt HUD element size to new style
option was renamed to `scale` instead of `size` because `scale` describes the technical fact better than `size`. Please also see DEVELOPERS message in `hud_element_scale.lua` file if you’re interested in contributing to this project. Addresses https://gitlab.com/4w/mtimer/-/issues/16
This commit is contained in:
parent
26fd002866
commit
0e281498a3
@ -6,7 +6,6 @@ Open Main Menu=Hauptmenü öffnen
|
||||
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
|
||||
@ -52,6 +51,11 @@ Vertical=Vertikal
|
||||
Horizontal=Horizontal
|
||||
Control the HUD element offset using the input on the right side and use the screenshot and markings as orientation for what is changed. The result is shown in the HUD in real time, so check for the actual timner position using the timer HUD element itself.=Anzeigeversatz des HUD-Elements über die Eingaben an der rechten Seite konfigurieren und dafür die Markierungen zur Orientierung verwenden. Das Ergebnis wir direkt übernommen. Die getätigen Änderungen können anhand des HUD-Elements sofort überprüft werden.
|
||||
|
||||
# Dialog: HUD Element Scale
|
||||
HUD Element Scale=Anzeigeskalierung
|
||||
The HUD element can be scaled between 1x (original size) and 10x (largest size due to performance reasons). Use the slider above to adjust the scaling to your needs.=Die Anzeige kann über den oben vorhandenen Schieberegler zwischen 1x (Originalgröße) und 10x (die aus Leistungsgründen die größte Größe) skaliert werden.
|
||||
Due to technical reasons the slider position does not reset when clicking the button to set to default values. The HUD element itself resets, and when re-entering this dialog the slider position is properly set.=Aus technischen Gründen wird die Position des Schiebereglers beim einstellen der Standardwerte nicht zurückgesetzt, die Anzeige selbst wird aber zurückgesetzt. Beim erneuten öffnen des Dialogs wird der Schieberegler automatisch angepasst.
|
||||
|
||||
# Named Times
|
||||
ISO 8601 Date=Datum nach ISO 8601
|
||||
ISO 8601 Time=Zeit nach ISO 8601
|
||||
|
@ -33,7 +33,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)
|
||||
-- hs HUD element scale d.hud_element_scale(name)
|
||||
-- os OffSet d.hud_element_offset(name)
|
||||
-- tf timer format d.timer_format(name)
|
||||
-- ct custom timer d.custom_timer(name)
|
||||
@ -59,7 +59,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 == 'hs' then d.hud_element_scale(name) end
|
||||
if action == 'os' then d.hud_element_offset(name) end
|
||||
if action == 'tf' then d.timer_format(name) end
|
||||
if action == 'ct' then d.custom_timer(name) end
|
||||
@ -80,7 +80,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('hs')..S('HUD Element Scale'),
|
||||
command('os')..S('HUD Element Offset'),
|
||||
command('tf')..S('Timer Format'),
|
||||
'',
|
||||
|
@ -1,9 +1,3 @@
|
||||
-- # vim: nowrap
|
||||
--
|
||||
-- Set Vim to no-wrapping mode because of some lines not fitting within the 80
|
||||
-- characters width limit due to overall readability of the code.
|
||||
|
||||
|
||||
-- Localise needed functions
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
@ -15,13 +9,14 @@ local line = mtimer.get_table_line
|
||||
-- correlates with the formspec to show. All of the names are self-explanatory
|
||||
-- and within the functions no logic is used.
|
||||
--
|
||||
-- The Main menu is a bit more complex and is generated seperately.
|
||||
-- Some formspec functions are separated into individual files because they are
|
||||
-- very complex and/or need helper functions.
|
||||
--
|
||||
-- @see mtimer.show_formspec
|
||||
-- @see mtimer.get_times
|
||||
-- @see ./system/on_receive_fields.lua
|
||||
-- @see ./system/chat_command.lua
|
||||
-- @see ./system/formspec/main_menu.lua
|
||||
-- @see ./system/formspecs/*
|
||||
-- @see https://dev.minetest.net/formspec
|
||||
|
||||
|
||||
@ -124,30 +119,6 @@ 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)
|
||||
|
||||
local information = table.concat({
|
||||
S('If set to 1 the HUD element is unscaled.'),
|
||||
S('All values larger than 1 scale the element up.'),
|
||||
S('Clicking the +/- button changes the size by 1.')
|
||||
}, '\n')
|
||||
|
||||
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,1;'..information..']',
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
mtimer.dialog.timer_format = function (player_name)
|
||||
local td = mtimer.get_timer_data(player_name)
|
||||
|
||||
|
84
system/formspecs/hud_element_scale.lua
Normal file
84
system/formspecs/hud_element_scale.lua
Normal file
@ -0,0 +1,84 @@
|
||||
-- Localise needed functions
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
local esc = minetest.formspec_escape
|
||||
|
||||
|
||||
local draw_scale_ruler = function (steps,length,height,pos,c_odd,c_even,mark)
|
||||
local elements = ''
|
||||
local marks = ''
|
||||
local step_width = length / steps
|
||||
|
||||
-- Build scale
|
||||
for step=1,steps,1 do
|
||||
elements = elements..' '..(('box[+x,+y;+w,+h;+c]'):gsub('%+%w', {
|
||||
['+x'] = step_width * (step - 1),
|
||||
['+y'] = 0,
|
||||
['+w'] = step_width,
|
||||
['+h'] = height,
|
||||
['+c'] = (step % 2 == 0) and c_even or c_odd,
|
||||
}))
|
||||
end
|
||||
|
||||
-- Build marks (start, end)
|
||||
if type(mark) == 'number' then
|
||||
local template = 'image_button[+x,+y;+w,+h;+t;;+l;;false]'
|
||||
|
||||
local m_start = template:gsub('%+%w',{
|
||||
['+x'] = 0,
|
||||
['+y'] = 0,
|
||||
['+w'] = step_width,
|
||||
['+h'] = 0.5,
|
||||
['+t'] = 'mtimer_transparent.png',
|
||||
['+l'] = length / steps
|
||||
})
|
||||
local m_end = template:gsub('%+%w', {
|
||||
['+x'] = (step_width * steps) - step_width,
|
||||
['+y'] = 0,
|
||||
['+w'] = step_width,
|
||||
['+h'] = 0.5,
|
||||
['+t'] = 'mtimer_transparent.png',
|
||||
['+l'] = steps
|
||||
})
|
||||
|
||||
marks = 'container[0,'..mark..'] '..m_start..m_end..' container_end[]'
|
||||
end
|
||||
|
||||
return table.concat({
|
||||
'container['..pos[1]..','..pos[2]..']',
|
||||
elements,
|
||||
marks,
|
||||
'container_end[]'
|
||||
}, ' ')
|
||||
end
|
||||
|
||||
|
||||
mtimer.dialog.hud_element_scale = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local scale = player:get_meta():get_string(m.meta.hud_element_scale.key)
|
||||
|
||||
local sb_options = table.concat({
|
||||
'min=1',
|
||||
'max=10',
|
||||
'smallstep=1',
|
||||
'largestep=10',
|
||||
'thumbsize=1',
|
||||
'arrows=hide'
|
||||
}, ';')
|
||||
|
||||
local infotext = S('The HUD element can be scaled between 1x (original size) and 10x (largest size due to performance reasons). Use the slider above to adjust the scaling to your needs.')
|
||||
|
||||
infotext = infotext..'\n\n'..S('Due to technical reasons the slider position does not reset when clicking the button to set to default values. The HUD element itself resets, and when re-entering this dialog the slider position is properly set.')
|
||||
|
||||
mtimer.show_formspec('mtimer:hud_element_scale', {
|
||||
title = S('HUD Element Scale'),
|
||||
show_to = player_name,
|
||||
formspec = {
|
||||
draw_scale_ruler(10, 10, 0.25, {0,0}, '#729fcf', '#73f216', 0.45),
|
||||
'scrollbaroptions['..sb_options..']',
|
||||
'scrollbar[0,0.25;10,0.25;horizontal;new_value;'..scale..']',
|
||||
'box[0,1.13;+contentWidth,0.01;#ffffff]',
|
||||
'textarea[0,1.5;10,3;;;'..esc(infotext)..']',
|
||||
}
|
||||
})
|
||||
end
|
@ -63,7 +63,7 @@ mtimer.dialog.main_menu = function (player_name)
|
||||
menu_button(1, 1, 'set_visibility', S('Visibility')),
|
||||
menu_button(1, 2, 'set_position', S('Position')),
|
||||
menu_button(1, 3, 'set_color', S('Color')),
|
||||
menu_button(1, 4, 'hud_element_size', S('HUD Element Size')),
|
||||
menu_button(1, 4, 'hud_element_scale', S('HUD Element Scale')),
|
||||
menu_button(1, 5, 'hud_element_offset', S('HUD Element Offset')),
|
||||
-- Time Representation
|
||||
menu_button(2, 1, 'ingame_time_format', S('Ingame Time Format')),
|
||||
|
@ -72,7 +72,7 @@ set('hud_element_offset', minetest.serialize({
|
||||
|
||||
-- Display settings
|
||||
set('color', '#ffffff')
|
||||
set('hud_element_size', 1)
|
||||
set('hud_element_scale', 1)
|
||||
set('position', 'bl')
|
||||
set('timezone_offset', 0)
|
||||
set('visible', true)
|
||||
|
@ -27,7 +27,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.hud_element_scale then d.hud_element_scale(name) end
|
||||
if fields.hud_element_offset then d.hud_element_offset(name) end
|
||||
if fields.timer_format then d.timer_format(name) end
|
||||
if fields.custom_timer then d.custom_timer(name) end
|
||||
@ -155,20 +155,58 @@ 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 default = tonumber(attr.default)
|
||||
local value = tonumber(fields.hud_element_size) or default
|
||||
-- Set scale of the timer HUD element
|
||||
if formname == 'mtimer:hud_element_scale' then
|
||||
local attr = m.meta.hud_element_scale
|
||||
local value = tonumber(attr.default)
|
||||
local nv_data = minetest.explode_scrollbar_event(fields.new_value)
|
||||
|
||||
if fields.add then value = value + 1 end
|
||||
if fields.substract then value = value - 1 end
|
||||
if value < 1 then value = 1 end
|
||||
-- Set new value if value was changed
|
||||
if nv_data.type == 'CHG' then
|
||||
value = nv_data.value
|
||||
if value < 1 then value = 1 end
|
||||
if value > 10 then value = 10 end
|
||||
meta:set_string(attr.key, value)
|
||||
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
|
||||
-- DEVELOPERS: Ideally this formspec would fully reset (like when
|
||||
-- closed and re-opened) to reflect the scale position when
|
||||
-- clicking the “Default” button. But for whatever reason
|
||||
-- this does not work. The scollbar position is simply
|
||||
-- not set accordingly no matter what I tried.
|
||||
--
|
||||
-- A pesky pseudosolution is to accept what it is and just
|
||||
-- inform the player about this fact.
|
||||
--
|
||||
-- Trust me, I tried for roughly 1-2 hours before giving
|
||||
-- up, without having either the formspec not reset when
|
||||
-- clicking the default button or not being able to drag
|
||||
-- the scollbar because the formspec gets re-sent.
|
||||
--
|
||||
-- I even tried to manually closing the formspec and
|
||||
-- re-opening it via `minetest.after` to prevent race
|
||||
-- conditions. This worked with a delay of 0.1 seconds
|
||||
-- every now and then and with smaller delays the whole
|
||||
-- screen looked like it “flashed” because, well, the
|
||||
-- formspec was closed and then re-opened after the delay.
|
||||
--
|
||||
-- But I absolutely hate the solution so I just accepted
|
||||
-- how it works. If everyone ever reading this and knows
|
||||
-- a proper solution to re-sent the formspec and have it
|
||||
-- using the actual value instead of keeping the previous
|
||||
-- value I’d be glad hearing from you :)
|
||||
--
|
||||
-- Have awonderful day!
|
||||
--
|
||||
-- Kind regards,
|
||||
-- Dirk
|
||||
if fields.default then
|
||||
-- This works as expected
|
||||
meta:set_string(attr.key, attr.default)
|
||||
-- it should reset the scrollbar position here when clicking the
|
||||
-- default button but it doesn’t …
|
||||
d.hud_element_scale(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -104,7 +104,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 size = meta:get_string(m.hud_element_size.key)
|
||||
local scale = meta:get_string(m.hud_element_scale.key)
|
||||
|
||||
local position = meta:get_string(m.position.key)
|
||||
local offset = deserialize(meta:get_string(m.hud_element_offset.key))
|
||||
@ -116,7 +116,7 @@ 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, 'size', {x=scale, y=scale})
|
||||
player:hud_change(hud_id, 'offset', orientation.offset)
|
||||
end
|
||||
|
||||
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
Loading…
Reference in New Issue
Block a user