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
|
2021-03-07 14:18:17 +01:00
|
|
|
local ui = unified_inventory
|
2021-07-17 12:24:22 +02:00
|
|
|
local COUNT = 5
|
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")},
|
|
|
|
}
|
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
-- Storage compatibility code
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
--[[
|
|
|
|
Stores temporary player data (persists until player leaves)
|
|
|
|
[player_name] = {
|
|
|
|
[<waypoint index>] = {
|
|
|
|
edit = <edit current waypoint?>,
|
|
|
|
hud = <hud ID>,
|
|
|
|
},
|
|
|
|
[<waypoint index>] = { ... },
|
|
|
|
...
|
|
|
|
}
|
|
|
|
]]
|
2014-07-06 23:39:20 +02:00
|
|
|
local waypoints_temp = {}
|
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
--[[
|
|
|
|
Datastorage format (per-player):
|
|
|
|
{
|
|
|
|
selected = <waypoint index>,
|
|
|
|
[<waypoint index>] = {
|
|
|
|
name = <name or nil>
|
|
|
|
world_pos = <coordinates vector>,
|
|
|
|
color = <"hud_colors" index>,
|
|
|
|
active = <hud show waypoint?>,
|
|
|
|
display_pos = <hud display coorinates?>,
|
|
|
|
},
|
|
|
|
[<waypoint index>] = { ... },
|
|
|
|
...
|
|
|
|
}
|
|
|
|
Player metadata format:
|
|
|
|
{
|
|
|
|
selected = <selected number>,
|
|
|
|
-- Cannot mix integer/string keys in JSON
|
|
|
|
data = {
|
|
|
|
[<waypoint index>] = { same as above },
|
|
|
|
...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
|
|
|
|
local function set_waypoint_data(player, waypoints)
|
|
|
|
local meta = player:get_meta()
|
|
|
|
if not next(waypoints.data or {}) then
|
|
|
|
-- Empty data. Do not save anything, or delete
|
|
|
|
meta:set_string("ui_waypoints", "")
|
|
|
|
else
|
|
|
|
meta:set_string("ui_waypoints", minetest.write_json(waypoints))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function migrate_datastorage(player, waypoints)
|
|
|
|
-- Copy values from old table
|
|
|
|
local new_data = {
|
|
|
|
selected = waypoints.selected,
|
|
|
|
data = {}
|
|
|
|
}
|
|
|
|
for i = 1, COUNT do
|
|
|
|
new_data.data[i] = waypoints[i]
|
|
|
|
end
|
|
|
|
|
|
|
|
set_waypoint_data(player, new_data)
|
|
|
|
|
|
|
|
-- Delete values, but keep one entry so that it's saved by datastorage
|
|
|
|
for k, _ in pairs(waypoints) do
|
|
|
|
waypoints[k] = nil
|
|
|
|
end
|
|
|
|
waypoints[1] = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
local have_datastorage = minetest.get_modpath("datastorage") ~= nil
|
|
|
|
local function get_waypoint_data(player)
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
|
|
|
|
-- Migration step
|
|
|
|
if have_datastorage then
|
|
|
|
local waypoints = datastorage.get(player_name, "waypoints")
|
|
|
|
if waypoints.selected then
|
|
|
|
migrate_datastorage(player, waypoints)
|
|
|
|
minetest.log("action", "[unified_inventory] " ..
|
|
|
|
"Migrated waypoints of player: " .. player_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Get directly from metadata
|
|
|
|
local waypoints = player:get_meta():get("ui_waypoints")
|
|
|
|
waypoints = waypoints and minetest.parse_json(waypoints) or {}
|
|
|
|
waypoints.data = waypoints.data or {}
|
|
|
|
|
|
|
|
return waypoints
|
|
|
|
end
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_page("waypoints", {
|
2014-05-05 09:39:03 +02:00
|
|
|
get_formspec = function(player)
|
2014-07-06 23:39:20 +02:00
|
|
|
local player_name = player:get_player_name()
|
2021-03-07 14:18:17 +01:00
|
|
|
local wp_info_x = ui.style_full.form_header_x + 1.25
|
|
|
|
local wp_info_y = ui.style_full.form_header_y + 0.5
|
|
|
|
local wp_bottom_row = ui.style_full.std_inv_y - 1
|
|
|
|
local wp_buttons_rj = ui.style_full.std_inv_x + 10.1 - ui.style_full.btn_spc
|
|
|
|
local wp_edit_w = ui.style_full.btn_spc * 4 - 0.1
|
2015-10-08 11:56:04 +02:00
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
local waypoints = get_waypoint_data(player)
|
|
|
|
local sel = waypoints.selected or 1
|
2015-10-08 11:56:04 +02:00
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
local formspec = {
|
|
|
|
ui.style_full.standard_inv_bg,
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
string.format("label[%f,%f;%s]",
|
2021-07-17 12:24:22 +02:00
|
|
|
ui.style_full.form_header_x, ui.style_full.form_header_y, F(S("Waypoints"))),
|
2021-03-05 16:58:18 +01:00
|
|
|
"image["..wp_info_x..","..wp_info_y..";1,1;ui_waypoints_icon.png]"
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
}
|
|
|
|
local n=4
|
2014-05-05 09:39:03 +02:00
|
|
|
|
|
|
|
-- Tabs buttons:
|
2021-07-17 12:24:22 +02:00
|
|
|
for i = 1, COUNT do
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
local sw="select_waypoint"..i
|
|
|
|
formspec[n] = string.format("image_button[%f,%f;%f,%f;%sui_%i_icon.png;%s;]",
|
|
|
|
ui.style_full.main_button_x, wp_bottom_row - (5-i) * ui.style_full.btn_spc,
|
|
|
|
ui.style_full.btn_size, ui.style_full.btn_size,
|
2021-07-17 12:24:22 +02:00
|
|
|
(i == sel) and "ui_blue_icon_background.png^" or "",
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
i, sw)
|
|
|
|
formspec[n+1] = "tooltip["..sw..";"..S("Select Waypoint #@1", i).."]"
|
|
|
|
n = n + 2
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
local waypoint = waypoints.data[sel] or {}
|
|
|
|
local temp = waypoints_temp[player_name][sel] or {}
|
|
|
|
local default_name = S("Waypoint @1", sel)
|
2014-07-06 23:39:20 +02:00
|
|
|
|
2014-05-05 09:39:03 +02:00
|
|
|
-- Main buttons:
|
2021-03-05 16:58:18 +01:00
|
|
|
local btnlist = {
|
2021-07-17 12:24:22 +02:00
|
|
|
set_waypoint = {
|
|
|
|
"ui_waypoint_set_icon.png",
|
|
|
|
S("Set waypoint to current location")
|
|
|
|
},
|
|
|
|
toggle_waypoint = {
|
|
|
|
waypoint.active and "ui_on_icon.png" or "ui_off_icon.png",
|
|
|
|
waypoint.active and S("Hide waypoint") or S("Show waypoint")
|
|
|
|
},
|
|
|
|
toggle_display_pos = {
|
|
|
|
waypoint.display_pos and "ui_green_icon_background.png^ui_xyz_icon.png" or "ui_red_icon_background.png^ui_xyz_icon.png^(ui_no.png^[transformR90)",
|
|
|
|
waypoint.display_pos and S("Hide coordinates") or S("Show coordinates")
|
|
|
|
},
|
|
|
|
toggle_color = {
|
|
|
|
"ui_circular_arrows_icon.png",
|
|
|
|
S("Change color of waypoint display")
|
|
|
|
},
|
|
|
|
rename_waypoint = {
|
|
|
|
"ui_pencil_icon.png",
|
|
|
|
S("Edit waypoint name")
|
|
|
|
}
|
2021-03-05 16:58:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local x = 4
|
2021-07-17 12:24:22 +02:00
|
|
|
for name, def in pairs(btnlist) do
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("image_button[%f,%f;%f,%f;%s;%s%i;]",
|
|
|
|
wp_buttons_rj - ui.style_full.btn_spc * x, wp_bottom_row,
|
|
|
|
ui.style_full.btn_size, ui.style_full.btn_size,
|
2021-07-17 12:24:22 +02:00
|
|
|
def[1], name, sel)
|
|
|
|
formspec[n+1] = "tooltip["..name..sel..";"..F(def[2]).."]"
|
2021-03-05 16:58:18 +01:00
|
|
|
x = x - 1
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 2
|
2021-03-05 16:58:18 +01:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
|
|
|
-- Waypoint's info:
|
2021-07-17 12:24:22 +02:00
|
|
|
formspec[n] = ("label[%f,%f;%s]"):format(
|
|
|
|
wp_info_x, wp_info_y + 1.1,
|
|
|
|
F(waypoint.active and S("Waypoint active") or S("Waypoint inactive"))
|
|
|
|
)
|
|
|
|
n = n + 1
|
2014-05-05 09:39:03 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
if temp.edit then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("field[%f,%f;%f,%f;rename_box%i;;%s]",
|
|
|
|
wp_buttons_rj - wp_edit_w - 0.1, wp_bottom_row - ui.style_full.btn_spc,
|
2021-07-17 12:24:22 +02:00
|
|
|
wp_edit_w, ui.style_full.btn_size, sel, (waypoint.name or default_name))
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n+1] = string.format("image_button[%f,%f;%f,%f;ui_ok_icon.png;confirm_rename%i;]",
|
|
|
|
wp_buttons_rj, wp_bottom_row - ui.style_full.btn_spc,
|
2021-07-17 12:24:22 +02:00
|
|
|
ui.style_full.btn_size, ui.style_full.btn_size, sel)
|
|
|
|
formspec[n+2] = "tooltip[confirm_rename"..sel..";"..F(S("Finish editing")).."]"
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 3
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2014-07-06 23:39:20 +02:00
|
|
|
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[%f,%f;%s: %s]",
|
|
|
|
wp_info_x, wp_info_y+1.6, F(S("World position")),
|
|
|
|
minetest.pos_to_string(waypoint.world_pos or vector.new()))
|
|
|
|
formspec[n+1] = string.format("label[%f,%f;%s: %s]",
|
|
|
|
wp_info_x, wp_info_y+2.10, F(S("Name")), (waypoint.name or default_name))
|
|
|
|
formspec[n+2] = string.format("label[%f,%f;%s: %s]",
|
|
|
|
wp_info_x, wp_info_y+2.60, F(S("HUD text color")), hud_colors[waypoint.color or 1][3])
|
2014-07-06 23:39:20 +02:00
|
|
|
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
return {formspec=table.concat(formspec)}
|
2014-05-05 09:39:03 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("waypoints", {
|
2014-05-05 09:39:03 +02:00
|
|
|
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)
|
2021-07-17 12:24:22 +02:00
|
|
|
local waypoint = waypoints.data[i]
|
2014-07-06 23:39:20 +02:00
|
|
|
if not waypoint then return end
|
2021-07-17 12:24:22 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
temp[i] = temp[i] or {}
|
|
|
|
temp = temp[i]
|
2021-07-17 12:24:22 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
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
|
2021-07-17 12:24:22 +02:00
|
|
|
name = waypoint.name or S("Waypoint @1", i)
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2021-07-17 12:24:22 +02:00
|
|
|
|
|
|
|
-- Perform HUD updates
|
2014-07-06 23:39:20 +02:00
|
|
|
if temp.hud then
|
|
|
|
player:hud_remove(temp.hud)
|
2021-07-17 12:24:22 +02:00
|
|
|
temp.hud = nil
|
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
|
|
|
})
|
|
|
|
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
|
|
|
|
2021-07-17 12:24:22 +02:00
|
|
|
local waypoints = get_waypoint_data(player)
|
2014-07-06 23:39:20 +02:00
|
|
|
local temp = waypoints_temp[player_name]
|
2021-07-17 12:24:22 +02:00
|
|
|
for i = 1, COUNT do
|
|
|
|
local waypoint = waypoints.data[i] or {}
|
|
|
|
|
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
|
2021-07-17 12:24:22 +02:00
|
|
|
waypoint.active = not (waypoint.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
|
2021-07-17 12:24:22 +02:00
|
|
|
local pos = vector.round(player:get_pos())
|
|
|
|
waypoint.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
|
2021-07-17 12:24:22 +02:00
|
|
|
waypoint.display_pos = not waypoint.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
|
2021-07-17 12:24:22 +02:00
|
|
|
local color = waypoint.color or 0
|
2014-05-05 09:39:03 +02:00
|
|
|
color = color + 1
|
2021-07-17 12:24:22 +02:00
|
|
|
if color > #hud_colors then
|
2014-05-05 09:39:03 +02:00
|
|
|
color = 1
|
|
|
|
end
|
2021-07-17 12:24:22 +02:00
|
|
|
waypoint.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
|
2021-07-17 12:24:22 +02:00
|
|
|
temp[i] = temp[i] or {}
|
2014-07-06 23:39:20 +02:00
|
|
|
temp[i].edit = false
|
2021-07-17 12:24:22 +02:00
|
|
|
waypoint.name = fields["rename_box"..i]
|
2014-07-06 23:39:20 +02:00
|
|
|
need_update_hud = true
|
2014-05-05 09:39:03 +02:00
|
|
|
update_formspec = true
|
|
|
|
end
|
2021-07-17 12:24:22 +02:00
|
|
|
|
|
|
|
if hit then
|
|
|
|
-- Save first
|
|
|
|
waypoints.data[i] = waypoint
|
|
|
|
set_waypoint_data(player, waypoints)
|
|
|
|
end
|
|
|
|
-- Update after
|
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
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, "waypoints")
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
2021-07-17 12:24:22 +02:00
|
|
|
|
2014-07-06 23:39:20 +02:00
|
|
|
if hit then return end
|
2014-05-05 09:39:03 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2021-08-29 07:47:32 +02:00
|
|
|
-- waypoints_temp must be initialized before the general unified_inventory
|
|
|
|
-- joinplayer callback is run for updating the inventory
|
|
|
|
table.insert(minetest.registered_on_joinplayers, 1, function(player)
|
2014-07-06 23:39:20 +02:00
|
|
|
local player_name = player:get_player_name()
|
2021-07-17 12:24:22 +02:00
|
|
|
local waypoints = get_waypoint_data(player)
|
|
|
|
|
|
|
|
waypoints_temp[player_name] = {}
|
|
|
|
for i = 1, COUNT do
|
|
|
|
update_hud(player, waypoints, waypoints_temp[player_name], i)
|
2014-07-06 23:39:20 +02:00
|
|
|
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
|
|
|
|