2019-09-19 14:00:26 +02:00
|
|
|
local S = minetest.get_translator("unified_inventory")
|
2018-04-02 13:33:36 +02:00
|
|
|
local F = minetest.formspec_escape
|
2014-06-21 12:44:31 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
local hud_colors = {
|
|
|
|
{"#FFFFFF", 0xFFFFFF, S("White")},
|
|
|
|
{"#DBBB00", 0xf1d32c, S("Yellow")},
|
|
|
|
{"#DD0000", 0xDD0000, S("Red")},
|
|
|
|
{"#2cf136", 0x2cf136, S("Green")},
|
|
|
|
{"#2c4df1", 0x2c4df1, S("Blue")},
|
|
|
|
}
|
|
|
|
|
|
|
|
local hud_colors_max = #hud_colors
|
|
|
|
|
|
|
|
-- Stores temporary player data (persists until player leaves)
|
|
|
|
local waypoints_temp = {}
|
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
unified_inventory.register_page("waypoints", {
|
|
|
|
get_formspec = function(player)
|
2014-07-06 23:39:20 +02:00
|
|
|
local player_name = player:get_player_name()
|
2015-10-08 11:56:04 +02:00
|
|
|
|
|
|
|
-- build a "fake" temp entry if the server took too long
|
|
|
|
-- during sign-on and returned an empty entry
|
|
|
|
if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end
|
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
local waypoints = datastorage.get(player_name, "waypoints")
|
Improve consistency of inventory (and alike) imagery
In a number of places, background[] is misused to place the
inventory backdrop images. Where appropriate, image[] is used
instead, so that "ui_form_bg.png" actually serves as the one
and only true background image.
In so doing, I was able to remake the bag inventory images,
making them only big as is actually needed to hold 1, 2, or 3
rows of inventory slots.
This, in turn, allows a standardized main inventory image to
occupy the lower part of the window, which allows for
consistent inventory image positioning and sizing from one
page to another.
I also removed ui_misc_form.png. Nothing in UI uses it, and
any external mods that used it can just use the standard
inventory and its background.
Lastly, I reduced the background image to 512x384 px. It was
unnecessarily large before, considering it has no real detail.
The larger inventory images are all 512px wide, and multiples
of 64px in height. Before, they were oddly sized.
2021-02-24 13:00:29 +01:00
|
|
|
local formspec = string.gsub(unified_inventory.standard_inv_bg, "YYY", "4.4") ..
|
2014-06-24 12:39:12 +02:00
|
|
|
"image[0,0;1,1;ui_waypoints_icon.png]" ..
|
2018-04-02 13:33:36 +02:00
|
|
|
"label[1,0;" .. F(S("Waypoints")) .. "]"
|
2014-05-05 09:39:03 +02:00
|
|
|
|
|
|
|
-- Tabs buttons:
|
|
|
|
for i = 1, 5, 1 do
|
2014-06-22 00:34:35 +02:00
|
|
|
formspec = formspec ..
|
2014-06-24 12:39:12 +02:00
|
|
|
"image_button[0.0," .. 0.2 + i * 0.7 .. ";.8,.8;" ..
|
|
|
|
(i == waypoints.selected and "ui_blue_icon_background.png^" or "") ..
|
|
|
|
"ui_" .. i .. "_icon.png;" ..
|
|
|
|
"select_waypoint" .. i .. ";]" ..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[select_waypoint" .. i .. ";"
|
2019-09-19 14:15:10 +02:00
|
|
|
.. S("Select Waypoint #@1", i).."]"
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
|
|
|
local i = waypoints.selected or 1
|
|
|
|
local waypoint = waypoints[i] or {}
|
|
|
|
local temp = waypoints_temp[player_name][i] or {}
|
2019-09-19 14:15:10 +02:00
|
|
|
local default_name = S("Waypoint @1", i)
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
-- Main buttons:
|
2014-07-06 23:39:20 +02:00
|
|
|
formspec = formspec ..
|
2014-06-22 00:34:35 +02:00
|
|
|
"image_button[4.5,3.7;.8,.8;"..
|
|
|
|
"ui_waypoint_set_icon.png;"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"set_waypoint"..i..";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[set_waypoint" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("Set waypoint to current location")).."]"
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-06-22 00:34:35 +02:00
|
|
|
formspec = formspec ..
|
|
|
|
"image_button[5.2,3.7;.8,.8;"..
|
2014-07-06 23:39:20 +02:00
|
|
|
(waypoint.active and "ui_on_icon.png" or "ui_off_icon.png")..";"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"toggle_waypoint"..i..";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[toggle_waypoint" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("Make waypoint @1",
|
|
|
|
waypoint.active and S("invisible") or S("visible"))).."]"
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
formspec = formspec ..
|
2014-06-22 00:34:35 +02:00
|
|
|
"image_button[5.9,3.7;.8,.8;"..
|
2014-07-06 23:39:20 +02:00
|
|
|
(waypoint.display_pos and "ui_green_icon_background.png" or "ui_red_icon_background.png").."^ui_xyz_icon.png;"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"toggle_display_pos" .. i .. ";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[toggle_display_pos" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("@1 display of waypoint coordinates",
|
|
|
|
waypoint.display_pos and S("Disable") or S("Enable"))) .."]"
|
2014-06-22 00:34:35 +02:00
|
|
|
|
|
|
|
formspec = formspec ..
|
|
|
|
"image_button[6.6,3.7;.8,.8;"..
|
|
|
|
"ui_circular_arrows_icon.png;"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"toggle_color"..i..";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[toggle_color" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("Change color of waypoint display")).."]"
|
2014-06-24 12:39:12 +02:00
|
|
|
|
2014-06-22 00:34:35 +02:00
|
|
|
formspec = formspec ..
|
|
|
|
"image_button[7.3,3.7;.8,.8;"..
|
|
|
|
"ui_pencil_icon.png;"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"rename_waypoint"..i..";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[rename_waypoint" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("Edit waypoint name")).."]"
|
2014-07-06 23:39:20 +02:00
|
|
|
|
|
|
|
-- Waypoint's info:
|
|
|
|
if waypoint.active then
|
2018-04-02 13:33:36 +02:00
|
|
|
formspec = formspec .. "label[1,0.8;"..F(S("Waypoint active")).."]"
|
2014-07-06 23:39:20 +02:00
|
|
|
else
|
2018-04-02 13:33:36 +02:00
|
|
|
formspec = formspec .. "label[1,0.8;"..F(S("Waypoint inactive")).."]"
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
if temp.edit then
|
2014-05-05 09:39:03 +02:00
|
|
|
formspec = formspec ..
|
2014-07-06 23:39:20 +02:00
|
|
|
"field[1.3,3.2;6,.8;rename_box" .. i .. ";;"
|
|
|
|
..(waypoint.name or default_name).."]" ..
|
2014-06-22 00:34:35 +02:00
|
|
|
"image_button[7.3,2.9;.8,.8;"..
|
|
|
|
"ui_ok_icon.png;"..
|
2014-06-24 12:39:12 +02:00
|
|
|
"confirm_rename"..i.. ";]"..
|
2014-07-06 23:39:20 +02:00
|
|
|
"tooltip[confirm_rename" .. i .. ";"
|
2018-04-02 13:33:36 +02:00
|
|
|
.. F(S("Finish editing")).."]"
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2018-04-02 13:33:36 +02:00
|
|
|
formspec = formspec .. "label[1,1.3;"..F(S("World position"))..": " ..
|
2014-07-06 23:39:20 +02:00
|
|
|
minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" ..
|
2018-04-02 13:33:36 +02:00
|
|
|
"label[1,1.8;"..F(S("Name"))..": ".. (waypoint.name or default_name) .. "]" ..
|
|
|
|
"label[1,2.3;"..F(S("HUD text color"))..": " ..
|
2014-07-06 23:39:20 +02:00
|
|
|
hud_colors[waypoint.color or 1][3] .. "]"
|
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
return {formspec=formspec}
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
unified_inventory.register_button("waypoints", {
|
|
|
|
type = "image",
|
|
|
|
image = "ui_waypoints_icon.png",
|
2014-06-22 00:34:35 +02:00
|
|
|
tooltip = S("Waypoints"),
|
2015-10-05 10:24:01 +02:00
|
|
|
hide_lite=true
|
2014-05-05 09:39:03 +02:00
|
|
|
})
|
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
local function update_hud(player, waypoints, temp, i)
|
|
|
|
local waypoint = waypoints[i]
|
|
|
|
if not waypoint then return end
|
|
|
|
temp[i] = temp[i] or {}
|
|
|
|
temp = temp[i]
|
|
|
|
local pos = waypoint.world_pos or vector.new()
|
2014-05-05 09:39:03 +02:00
|
|
|
local name
|
|
|
|
if waypoint.display_pos then
|
2014-07-06 23:39:20 +02:00
|
|
|
name = minetest.pos_to_string(pos)
|
|
|
|
if waypoint.name then
|
|
|
|
name = name..", "..waypoint.name
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
else
|
2014-07-06 23:39:20 +02:00
|
|
|
name = waypoint.name or "Waypoint "..i
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
if temp.hud then
|
|
|
|
player:hud_remove(temp.hud)
|
2014-05-26 11:43:25 +02:00
|
|
|
end
|
|
|
|
if waypoint.active then
|
2014-07-06 23:39:20 +02:00
|
|
|
temp.hud = player:hud_add({
|
2014-05-05 09:39:03 +02:00
|
|
|
hud_elem_type = "waypoint",
|
2014-07-06 23:39:20 +02:00
|
|
|
number = hud_colors[waypoint.color or 1][2] ,
|
2014-05-05 09:39:03 +02:00
|
|
|
name = name,
|
|
|
|
text = "m",
|
2014-07-06 23:39:20 +02:00
|
|
|
world_pos = pos
|
2014-05-05 09:39:03 +02:00
|
|
|
})
|
2014-07-06 23:39:20 +02:00
|
|
|
else
|
|
|
|
temp.hud = nil
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
2014-07-06 23:39:20 +02:00
|
|
|
if formname ~= "" then return end
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
local player_name = player:get_player_name()
|
2014-05-05 09:39:03 +02:00
|
|
|
local update_formspec = false
|
2014-07-06 23:39:20 +02:00
|
|
|
local need_update_hud = false
|
|
|
|
local hit = false
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
local waypoints = datastorage.get(player_name, "waypoints")
|
|
|
|
local temp = waypoints_temp[player_name]
|
|
|
|
for i = 1, 5, 1 do
|
2014-05-05 09:39:03 +02:00
|
|
|
if fields["select_waypoint"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
2014-05-05 09:39:03 +02:00
|
|
|
waypoints.selected = i
|
|
|
|
update_formspec = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["toggle_waypoint"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
|
|
|
waypoints[i] = waypoints[i] or {}
|
2014-05-05 09:39:03 +02:00
|
|
|
waypoints[i].active = not (waypoints[i].active)
|
2014-07-06 23:39:20 +02:00
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
if fields["set_waypoint"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
2019-06-16 10:26:40 +02:00
|
|
|
local pos = player:get_pos()
|
2014-05-05 09:39:03 +02:00
|
|
|
pos.x = math.floor(pos.x)
|
|
|
|
pos.y = math.floor(pos.y)
|
|
|
|
pos.z = math.floor(pos.z)
|
2014-07-06 23:39:20 +02:00
|
|
|
waypoints[i] = waypoints[i] or {}
|
2014-05-05 09:39:03 +02:00
|
|
|
waypoints[i].world_pos = pos
|
2014-07-06 23:39:20 +02:00
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
if fields["rename_waypoint"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
2014-09-07 21:08:52 +02:00
|
|
|
temp[i] = temp[i] or {}
|
2014-07-06 23:39:20 +02:00
|
|
|
temp[i].edit = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["toggle_display_pos"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
|
|
|
waypoints[i] = waypoints[i] or {}
|
2014-05-05 09:39:03 +02:00
|
|
|
waypoints[i].display_pos = not waypoints[i].display_pos
|
2014-07-06 23:39:20 +02:00
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["toggle_color"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
|
|
|
waypoints[i] = waypoints[i] or {}
|
|
|
|
local color = waypoints[i].color or 1
|
2014-05-05 09:39:03 +02:00
|
|
|
color = color + 1
|
2014-07-06 23:39:20 +02:00
|
|
|
if color > hud_colors_max then
|
2014-05-05 09:39:03 +02:00
|
|
|
color = 1
|
|
|
|
end
|
|
|
|
waypoints[i].color = color
|
2014-07-06 23:39:20 +02:00
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if fields["confirm_rename"..i] then
|
2014-07-06 23:39:20 +02:00
|
|
|
hit = true
|
|
|
|
waypoints[i] = waypoints[i] or {}
|
|
|
|
temp[i].edit = false
|
|
|
|
waypoints[i].name = fields["rename_box"..i]
|
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
if need_update_hud then
|
|
|
|
update_hud(player, waypoints, temp, i)
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
if update_formspec then
|
|
|
|
unified_inventory.set_inventory_formspec(player, "waypoints")
|
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
if hit then return end
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
2014-07-06 23:39:20 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local waypoints = datastorage.get(player_name, "waypoints")
|
|
|
|
local temp = {}
|
|
|
|
waypoints_temp[player_name] = temp
|
|
|
|
for i = 1, 5 do
|
|
|
|
update_hud(player, waypoints, temp, i)
|
|
|
|
end
|
|
|
|
end)
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
waypoints_temp[player:get_player_name()] = nil
|
2014-05-05 09:39:03 +02:00
|
|
|
end)
|
2014-07-06 23:39:20 +02:00
|
|
|
|