2020-03-28 14:51:38 +01:00
|
|
|
-- 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
|
2020-04-17 01:50:03 +02:00
|
|
|
-- page: The current page
|
2020-04-16 03:01:56 +02:00
|
|
|
-- bg: A 9-slice background skin table
|
|
|
|
-- button: A button skin table
|
2020-03-28 14:51:38 +01:00
|
|
|
--
|
|
|
|
-- Returns a formspec string for use in containers
|
2020-04-17 01:50:03 +02:00
|
|
|
function _cartographer.generate_marker_formspec(selected_id, detail, page, bg, button)
|
2020-04-16 03:01:56 +02:00
|
|
|
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]";
|
2020-03-28 14:51:38 +01:00
|
|
|
if selected_id then
|
2020-04-16 03:01:56 +02:00
|
|
|
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);
|
2020-03-28 14:51:38 +01:00
|
|
|
end
|
|
|
|
|
2020-04-17 01:50:03 +02:00
|
|
|
local starting_id = ((page - 1) * 20) + 1;
|
|
|
|
for i = starting_id,math.min(#_cartographer.marker_lookup,starting_id + 19),1 do
|
|
|
|
local marker = _cartographer.marker_lookup[i];
|
2020-03-28 14:51:38 +01:00
|
|
|
fs = fs .. string.format("image_button[%f,%f;0.5,0.5;%s.png;marker-%s;]",
|
2020-04-17 01:50:03 +02:00
|
|
|
(i - starting_id) % 5 * 0.625 + 0.125,
|
|
|
|
math.floor((i - starting_id) / 5) * 0.625 + 0.75,
|
|
|
|
marker.textures[math.min(detail, #marker.textures)],
|
|
|
|
marker.id);
|
|
|
|
end
|
|
|
|
|
|
|
|
if page > 1 then
|
|
|
|
fs = fs .. "button[0.125,3.25;0.5,0.5;prev_button;<]";
|
|
|
|
end
|
2020-03-28 14:51:38 +01:00
|
|
|
|
2020-04-17 01:50:03 +02:00
|
|
|
if starting_id + 19 < #_cartographer.marker_lookup then
|
|
|
|
fs = fs .. "button[2.625,3.25;0.5,0.5;next_button;>]";
|
2020-03-28 14:51:38 +01:00
|
|
|
end
|
2020-04-17 01:50:03 +02:00
|
|
|
|
|
|
|
fs = fs .. string.format("label[1.375,3.5;%d / %d]", page, math.ceil(#_cartographer.marker_lookup / 20));
|
2020-03-28 14:51:38 +01:00
|
|
|
return fs;
|
|
|
|
end
|