2020-06-02 14:01:11 +02:00
|
|
|
local gui = {};
|
|
|
|
|
2020-06-08 00:09:58 +02:00
|
|
|
function gui.formspec(args)
|
|
|
|
local data = string.format("formspec_version[%d] size[%f,%f]", args.version or 3, args.w, args.h);
|
|
|
|
|
|
|
|
if args.bg then
|
|
|
|
data = data .. gui.bg9 {
|
|
|
|
skin = args.bg,
|
|
|
|
fullsize = true,
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
|
|
|
|
2020-06-02 14:01:11 +02:00
|
|
|
function gui.bg9(args)
|
2020-06-03 01:36:33 +02:00
|
|
|
return string.format("background9[%f,%f;%f,%f;%s;%s;%s]",
|
2020-06-08 00:09:58 +02:00
|
|
|
args.x or 0, args.y or 0,
|
|
|
|
args.w or 1 * (args.size or 1), args.h or 1 * (args.size or 1),
|
2020-06-03 01:36:33 +02:00
|
|
|
args.skin.texture .. ".png",
|
|
|
|
args.fullsize or false,
|
|
|
|
tostring(args.skin.radius));
|
2020-06-02 14:01:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function gui.button(args)
|
2020-06-08 00:09:58 +02:00
|
|
|
if args.disabled then
|
|
|
|
return string.format("button[%f,%f;%f,%f;disabled_button;%s]", args.x, args.y, args.w, args.h, args.text);
|
|
|
|
end
|
|
|
|
|
2020-06-02 14:01:11 +02:00
|
|
|
local data = string.format("button[%f,%f;%f,%f;%s;%s]", args.x, args.y, args.w, args.h, args.id, args.text);
|
|
|
|
|
|
|
|
if args.tooltip then
|
|
|
|
data = data .. gui.tooltip {
|
|
|
|
id = args.id,
|
|
|
|
text = args.tooltip
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
|
|
|
|
2020-06-08 00:09:58 +02:00
|
|
|
function gui.container(args)
|
|
|
|
local data = string.format("container[%f,%f]", args.x, args.y);
|
2020-06-08 02:35:17 +02:00
|
|
|
|
|
|
|
if args.bg then
|
|
|
|
data = data .. gui.bg9 {
|
|
|
|
x = 0,
|
|
|
|
y = 0,
|
|
|
|
w = args.w,
|
|
|
|
h = args.h,
|
|
|
|
|
|
|
|
skin = args.bg,
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
2020-06-08 00:09:58 +02:00
|
|
|
for _,element in ipairs(args) do
|
|
|
|
data = data .. element;
|
|
|
|
end
|
|
|
|
|
|
|
|
return data .. "container_end[]";
|
|
|
|
end
|
|
|
|
|
|
|
|
function gui.image(args)
|
|
|
|
return string.format("image[%f,%f;%f,%f;%s]", args.x, args.y, args.w, args.h, args.image);
|
|
|
|
end
|
|
|
|
|
2020-06-02 14:01:11 +02:00
|
|
|
function gui.image_button(args)
|
2020-06-03 01:36:33 +02:00
|
|
|
local data = string.format("image_button[%f,%f;%f,%f;%s;%s;%s]",
|
|
|
|
args.x, args.y,
|
|
|
|
args.w, args.h,
|
|
|
|
args.image,
|
|
|
|
args.id,
|
|
|
|
args.text or "");
|
2020-06-02 14:01:11 +02:00
|
|
|
|
|
|
|
if args.tooltip then
|
|
|
|
data = data .. gui.tooltip {
|
|
|
|
id = args.id,
|
|
|
|
text = args.tooltip
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
|
|
|
|
2020-06-08 00:09:58 +02:00
|
|
|
function gui.inventory(args)
|
|
|
|
local data = "";
|
|
|
|
|
|
|
|
if args.bg then
|
|
|
|
for i = 0,args.w - 1 do
|
|
|
|
for j = 0,args.h - 1 do
|
|
|
|
data = data .. gui.bg9 {
|
|
|
|
x = args.x + (i * 1.25),
|
|
|
|
y = args.y + (j * 1.25),
|
|
|
|
|
|
|
|
skin = args.bg,
|
|
|
|
};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
data = data .. string.format("list[%s;%s;%f,%f;%f,%f;]", args.location, args.id, args.x, args.y, args.w, args.h);
|
|
|
|
|
|
|
|
if args.tooltip then
|
|
|
|
data = data .. gui.tooltip {
|
|
|
|
x = args.x,
|
|
|
|
y = args.y,
|
|
|
|
w = args.w,
|
|
|
|
h = args.h,
|
|
|
|
text = args.tooltip,
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
|
|
|
|
2020-06-02 14:01:11 +02:00
|
|
|
function gui.label(args)
|
2020-06-08 00:09:58 +02:00
|
|
|
if args.textcolor then
|
|
|
|
return string.format("label[%f,%f;%s%s]",
|
|
|
|
args.x,
|
|
|
|
args.y,
|
|
|
|
minetest.get_color_escape_sequence(args.textcolor),
|
|
|
|
args.text);
|
|
|
|
end
|
|
|
|
|
2020-06-02 14:01:11 +02:00
|
|
|
return string.format("label[%f,%f;%s]", args.x, args.y, args.text);
|
|
|
|
end
|
|
|
|
|
|
|
|
function gui.style_internal(selector, properties)
|
|
|
|
local data = "[" .. selector;
|
|
|
|
for name,value in pairs(properties) do
|
|
|
|
data = data .. string.format(";%s=%s", name, tostring(value));
|
|
|
|
end
|
|
|
|
return data .. "]";
|
|
|
|
end
|
|
|
|
|
|
|
|
function gui.style(args)
|
|
|
|
return "style" .. gui.style_internal(args.selector, args.properties);
|
|
|
|
end
|
|
|
|
|
|
|
|
function gui.style_type(args)
|
|
|
|
return "style_type" .. gui.style_internal(args.selector, args.properties);
|
|
|
|
end
|
|
|
|
|
|
|
|
function gui.tooltip(args)
|
2020-06-08 00:09:58 +02:00
|
|
|
if args.id then
|
|
|
|
return string.format("tooltip[%s;%s]", args.id, args.text);
|
|
|
|
else
|
|
|
|
return string.format("tooltip[%f,%f;%f,%f;%s]", args.x, args.y, args.w, args.h, args.text);
|
|
|
|
end
|
2020-06-02 14:01:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return gui;
|