cartographer/marker_formspec.lua

30 lines
1.5 KiB
Lua

-- Generates formspec data for the map marker editor
-- selected_id: The id of the currently selected marker, or nil if no marker is
-- selected
-- detail: The map's detail level
-- bg: A 9-slice background skin table
-- button: A button skin table
--
-- Returns a formspec string for use in containers
function _cartographer.generate_marker_formspec(selected_id, detail, bg, button)
local fs = string.format("background9[0,0;3.25,3.875;%s.png;false;%s]", bg.texture, tostring(bg.radius))
.. string.format("style_type[button,image_button;border=false;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png;bgimg_middle=%s;textcolor=%s]", button.texture, button.hovered_texture, button.pressed_texture, tostring(button.radius), button.font_color)
.. "button[0.125,0.125;1.125,0.5;clear_marker;Erase]";
if selected_id then
fs = fs .. string.format("style[marker-%s;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", selected_id, button.selected_texture, button.selected_texture, button.selected_texture);
end
-- TODO: Support pagination if _cartographer.marker_count is too high
local i = 0;
for id in pairs(_cartographer.marker_lookup) do
fs = fs .. string.format("image_button[%f,%f;0.5,0.5;%s.png;marker-%s;]",
i % 5 * 0.625 + 0.125,
math.floor(i / 5) * 0.625 + 0.75,
cartographer.get_marker_texture(id, detail),
id);
i = i + 1;
end
return fs;
end