Skip to content

Commit ce79586

Browse files
authored
Make multimeter formspec usable (#173)
1 parent 64222e1 commit ce79586

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

technic/tools/multimeter.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,42 @@ local bghiglight_lcd = "#5CAA77"
1616
local textcolor = "#101010"
1717
--local bgcolor_button = "#626E41"
1818

19-
local form_width = 7
19+
local form_width = 8
20+
local form_height = 11.5
2021
local btn_count = 3
2122
local btn_spacing = 0.1
2223
local btn_width = (form_width - ((btn_count + 1) * btn_spacing)) / btn_count
2324

2425
local open_formspecs = {}
2526

2627
local formspec_escape = minetest.formspec_escape
27-
local function fmtf(n) return ("%0.3f"):format(n) end
28+
local function fmtf(n) return type(n) == "number" and ("%0.3f"):format(n) or n end
2829
local function fs_x_pos(i) return (btn_spacing * i) + (btn_width * (i - 1)) end
2930
local function create_button(index, y, h, name, label, exit, modifier)
3031
local x = fs_x_pos(index)
3132
local t1 = texture_button .. (modifier and formspec_escape(modifier) or "")
3233
local t2 = texture_button_pressed .. (modifier and formspec_escape(modifier) or "")
33-
local dimensions = ("%s,%s;%s,%s"):format(fmtf(x),y,fmtf(btn_width),h)
34+
local dimensions = ("%s,%s;%s,%s"):format(fmtf(x),fmtf(y),fmtf(btn_width),h)
3435
local properties = ("%s;%s;%s;false;false;%s"):format(t1, name, label, t2)
3536
return ("image_button%s[%s;%s]"):format(exit and "_exit" or "", dimensions, properties)
3637
end
3738

3839
local formspec_format_string = "formspec_version[3]" ..
39-
("size[%s,10;]bgcolor[%s;both;]"):format(fmtf(form_width),bgcolor) ..
40-
("style_type[*;textcolor=%s;font=mono]"):format(textcolor) ..
41-
("style_type[label;textcolor=%s;font_size=*2;font=mono]"):format(textcolor) ..
42-
("background9[0,0;%s,10;%s;false;3]"):format(form_width, texture_bg9) ..
40+
("size[%s,%s;]bgcolor[%s;both;]"):format(fmtf(form_width), fmtf(form_height), bgcolor) ..
41+
("style_type[*;textcolor=%s;font_size=*1]"):format(textcolor) ..
42+
("style_type[table;textcolor=%s;font_size=*1;font=mono]"):format(textcolor) ..
43+
("style_type[label;textcolor=%s;font_size=*2]"):format(textcolor) ..
44+
("background9[0,0;%s,%s;%s;false;3]"):format(fmtf(form_width), fmtf(form_height), texture_bg9) ..
4345
("image[0.3,0.3;5.75,1;%s]"):format(texture_logo) ..
4446
"label[0.6,1.5;Network %s]" ..
4547
("field[%s,2.5;%s,0.8;net;Network ID:;%%s]"):format(fmtf(fs_x_pos(2)),fmtf(btn_width)) ..
4648
create_button(3, "2.5", "0.8", "rs", "Remote start", false, "^[colorize:#10E010:125") ..
47-
create_button(1, "9.1", "0.8", "wp", "Waypoint", true) ..
48-
create_button(2, "9.1", "0.8", "up", "Update", false) ..
49-
create_button(3, "9.1", "0.8", "exit", "Exit", true) ..
49+
create_button(1, form_height - 0.9, "0.8", "wp", "Waypoint", true) ..
50+
create_button(2, form_height - 0.9, "0.8", "up", "Update", false) ..
51+
create_button(3, form_height - 0.9, "0.8", "exit", "Exit", true) ..
5052
("tableoptions[border=false;background=%s;highlight=%s;color=%s]"):format(bgcolor_lcd,bghiglight_lcd,textcolor) ..
51-
"tablecolumns[indent;text,width=14;text,width=14;text,align=center]" ..
52-
("table[0.1,3.4;%s,5.4;items;1,Property,Value,Unit%%s]"):format(fmtf(form_width - 0.2))
53+
"tablecolumns[indent,width=0.2;text,width=13;text,width=13;text,align=center]" ..
54+
("table[0.1,3.4;%s,%s;items;1,Property,Value,Unit%%s]"):format(fmtf(form_width - 0.2), fmtf(form_height - 4.4))
5355

5456
minetest.register_craft({
5557
output = 'technic:multimeter',

0 commit comments

Comments
 (0)