Browse Source

Add height mode toggle to maps

tags/1.0
Hugues Ross 3 months ago
parent
commit
e16893f82e
4 changed files with 26 additions and 7 deletions
  1. +23
    -7
      items.lua
  2. +3
    -0
      skin_api.lua
  3. BIN
      textures/cartographer_flat_button.png
  4. BIN
      textures/cartographer_height_button.png

+ 23
- 7
items.lua View File

@@ -6,22 +6,33 @@ local player_maps = {};
-- player_x: The X position (in world coordinates)
-- player_z: The Z position (in world coordinates)
-- 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
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);

player_maps[player_name] = {
id = id,
page = marker_page or 1,
height_mode = height_mode,
};
local map = cartographer.get_map(id);

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
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)
.. "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
minetest.show_formspec(player_name, "cartographer:map", formspec);
end
@@ -61,7 +72,7 @@ local function show_map_meta(meta, player)
id = map_from_meta(meta, player_x, player_z);
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

-- 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)
if name == "cartographer:map" then
local data = player_maps[player:get_player_name()];
if not data then
return;
end

local map = cartographer.get_map(data.id);
if not map then
@@ -88,9 +102,11 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
cartographer.map_sound("cartographer_write", player);
show_map_id_formspec(map.id, pos.x, pos.z, player:get_player_name(), data.page);
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
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
player_maps[player:get_player_name()] = nil;
end


+ 3
- 0
skin_api.lua View File

@@ -177,4 +177,7 @@ cartographer.skin = {
pressed_texture = "cartographer_simple_table_button_pressed",
radius = 8,
},

height_button_texture = "cartographer_height_button",
flat_button_texture = "cartographer_flat_button",
};

BIN
textures/cartographer_flat_button.png View File

Before After
Width: 16  |  Height: 16  |  Size: 1.0KB

BIN
textures/cartographer_height_button.png View File

Before After
Width: 16  |  Height: 16  |  Size: 1.0KB

Loading…
Cancel
Save