Add height mode toggle to maps
This commit is contained in:
parent
777f09fbe7
commit
e16893f82e
30
items.lua
30
items.lua
@ -6,22 +6,33 @@ local player_maps = {};
|
|||||||
-- player_x: The X position (in world coordinates)
|
-- player_x: The X position (in world coordinates)
|
||||||
-- player_z: The Z position (in world coordinates)
|
-- player_z: The Z position (in world coordinates)
|
||||||
-- player_name: The name of the player to show to
|
-- player_name: The name of the player to show to
|
||||||
|
-- height_mode: Whether or not to display the map in height mode
|
||||||
-- (Optional) marker_page: The current page that the marker editor is on
|
-- (Optional) marker_page: The current page that the marker editor is on
|
||||||
local function show_map_id_formspec(id, player_x, player_z, player_name, marker_page)
|
local function show_map_id_formspec(id, player_x, player_z, player_name, height_mode, marker_page)
|
||||||
cartographer.fill_local(id, player_x, player_z);
|
cartographer.fill_local(id, player_x, player_z);
|
||||||
|
|
||||||
player_maps[player_name] = {
|
player_maps[player_name] = {
|
||||||
id = id,
|
id = id,
|
||||||
page = marker_page or 1,
|
page = marker_page or 1,
|
||||||
|
height_mode = height_mode,
|
||||||
};
|
};
|
||||||
local map = cartographer.get_map(id);
|
local map = cartographer.get_map(id);
|
||||||
|
|
||||||
player_x, player_z = cartographer.to_map_coordinates(map, player_x, player_z)
|
player_x, player_z = cartographer.to_map_coordinates(map, player_x, player_z)
|
||||||
local formspec, formspec_width, formspec_height = cartographer.get_map_formspec_map(data, map, player_x, player_z);
|
local formspec, formspec_width, formspec_height = cartographer.get_map_formspec_map(data, map, player_x, player_z, height_mode);
|
||||||
if #_cartographer.marker_lookup > 0 then
|
if #_cartographer.marker_lookup > 0 then
|
||||||
formspec = formspec .. string.format("style_type[button,image_button,label;noclip=true] container[%f,0.5]", formspec_width - 0.01)
|
formspec = formspec .. string.format("style_type[button,image_button,label;noclip=true] container[%f,1.0]", formspec_width - 0.01)
|
||||||
.. _cartographer.generate_marker_formspec(cartographer.get_marker(map, player_x, player_z), map.detail, marker_page or 1, cartographer.skin.marker_bg, cartographer.skin.marker_button)
|
.. _cartographer.generate_marker_formspec(cartographer.get_marker(map, player_x, player_z), map.detail, marker_page or 1, cartographer.skin.marker_bg, cartographer.skin.marker_button)
|
||||||
.. "container_end[]";
|
.. "container_end[]"
|
||||||
|
.. string.format("container[%f,0.125]", formspec_width - 0.01)
|
||||||
|
.. string.format("background9[0,0;0.75,0.75;%s.png;false;%s]", cartographer.skin.marker_bg.texture, tostring(cartographer.skin.marker_bg.radius));
|
||||||
|
if height_mode then
|
||||||
|
formspec = formspec .. string.format("image_button[0.125,0.125;0.5,0.5;%s.png;height_button;]", cartographer.skin.height_button_texture)
|
||||||
|
else
|
||||||
|
formspec = formspec .. string.format("image_button[0.125,0.125;0.5,0.5;%s.png;height_button;]", cartographer.skin.flat_button_texture)
|
||||||
|
end
|
||||||
|
|
||||||
|
formspec = formspec .. "container_end[]";
|
||||||
end
|
end
|
||||||
minetest.show_formspec(player_name, "cartographer:map", formspec);
|
minetest.show_formspec(player_name, "cartographer:map", formspec);
|
||||||
end
|
end
|
||||||
@ -61,7 +72,7 @@ local function show_map_meta(meta, player)
|
|||||||
id = map_from_meta(meta, player_x, player_z);
|
id = map_from_meta(meta, player_x, player_z);
|
||||||
end
|
end
|
||||||
|
|
||||||
show_map_id_formspec(id, pos.x, pos.z, player:get_player_name());
|
show_map_id_formspec(id, pos.x, pos.z, player:get_player_name(), true);
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Called when a player sends input to the server from a formspec
|
-- Called when a player sends input to the server from a formspec
|
||||||
@ -72,6 +83,9 @@ end
|
|||||||
minetest.register_on_player_receive_fields(function(player, name, fields)
|
minetest.register_on_player_receive_fields(function(player, name, fields)
|
||||||
if name == "cartographer:map" then
|
if name == "cartographer:map" then
|
||||||
local data = player_maps[player:get_player_name()];
|
local data = player_maps[player:get_player_name()];
|
||||||
|
if not data then
|
||||||
|
return;
|
||||||
|
end
|
||||||
|
|
||||||
local map = cartographer.get_map(data.id);
|
local map = cartographer.get_map(data.id);
|
||||||
if not map then
|
if not map then
|
||||||
@ -88,9 +102,11 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
cartographer.map_sound("cartographer_write", player);
|
cartographer.map_sound("cartographer_write", player);
|
||||||
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page);
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page);
|
||||||
elseif k == "prev_button" then
|
elseif k == "prev_button" then
|
||||||
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page - 1);
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page - 1);
|
||||||
elseif k == "next_button" then
|
elseif k == "next_button" then
|
||||||
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page + 1);
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page + 1);
|
||||||
|
elseif k == "height_button" then
|
||||||
|
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), not data.height_mode, data.page);
|
||||||
elseif k == "quit" then
|
elseif k == "quit" then
|
||||||
player_maps[player:get_player_name()] = nil;
|
player_maps[player:get_player_name()] = nil;
|
||||||
end
|
end
|
||||||
|
@ -177,4 +177,7 @@ cartographer.skin = {
|
|||||||
pressed_texture = "cartographer_simple_table_button_pressed",
|
pressed_texture = "cartographer_simple_table_button_pressed",
|
||||||
radius = 8,
|
radius = 8,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
height_button_texture = "cartographer_height_button",
|
||||||
|
flat_button_texture = "cartographer_flat_button",
|
||||||
};
|
};
|
||||||
|
BIN
textures/cartographer_flat_button.png
Normal file
BIN
textures/cartographer_flat_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
textures/cartographer_height_button.png
Normal file
BIN
textures/cartographer_height_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue
Block a user