Add skinned styling to the marker editor

This commit is contained in:
Hugues Ross 2020-04-15 21:01:56 -04:00
parent 4cc3a4cfaa
commit 7c858d5264
4 changed files with 26 additions and 7 deletions

View File

@ -16,7 +16,7 @@ local function show_map_id_formspec(id, player_x, player_z, player_name)
local formspec = cartographer.get_map_formspec_map(data, map, player_x, player_z);
if _cartographer.marker_count > 0 then
formspec = formspec .. string.format("style_type[button,image_button;noclip=true;border=true] container[%f,0.5]", map.w * 0.25) -- TODO: Don't assume map.w * 0.25
.. _cartographer.generate_marker_formspec(cartographer.get_marker(map, player_x, player_z), map.detail)
.. _cartographer.generate_marker_formspec(cartographer.get_marker(map, player_x, player_z), map.detail, cartographer.skin.marker_bg, cartographer.skin.marker_button)
.. "container_end[]";
end
minetest.show_formspec(player_name, "cartographer:map", formspec);

View File

@ -2,21 +2,24 @@
-- 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)
local fs = "button[0,0;0.5,0.5;clear_marker;x]";
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;bgcolor=blue]", selected_id);
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.5,
math.floor(i / 5) * 0.5 + 0.5,
i % 5 * 0.625 + 0.125,
math.floor(i / 5) * 0.625 + 0.75,
cartographer.get_marker_texture(id, detail),
id);

View File

@ -132,6 +132,22 @@ cartographer.skin = {
},
},
-- The skinning data for the marker editor's background
marker_bg = {
texture = "cartographer_markers_bg",
radius = 6,
},
-- The skinning data for the marker editor's buttons
marker_button = {
font_color = "#694a3a",
texture = "cartographer_simple_table_button",
selected_texture = "cartographer_simple_table_button_pressed",
hovered_texture = "cartographer_simple_table_button_hovered",
pressed_texture = "cartographer_simple_table_button_pressed",
radius = 8,
},
-- The texture to use in maps when biome data is missing or empty
unknown_biome_texture = "cartographer_unknown_biome",
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB