41 lines
2.1 KiB
Lua
41 lines
2.1 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
|
|
-- page: The current page
|
|
-- 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, page, 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] tooltip[clear_marker;Remove the selected marker]";
|
|
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
|
|
|
|
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];
|
|
fs = fs .. string.format("image_button[%f,%f;0.5,0.5;%s.png;marker-%s;] tooltip[marker-%s;%s]",
|
|
(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,
|
|
marker.id,
|
|
marker.name);
|
|
end
|
|
|
|
if page > 1 then
|
|
fs = fs .. "button[0.125,3.25;0.5,0.5;prev_button;<]";
|
|
end
|
|
|
|
if starting_id + 19 < #_cartographer.marker_lookup then
|
|
fs = fs .. "button[2.625,3.25;0.5,0.5;next_button;>]";
|
|
end
|
|
|
|
fs = fs .. string.format("label[1.375,3.5;%d / %d]", page, math.ceil(#_cartographer.marker_lookup / 20));
|
|
return fs;
|
|
end
|