add WaypointHUD object that shows an arrow pointing to the target
@ -48,7 +48,7 @@
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
@ -57,7 +57,7 @@
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:#ff9955;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
style="fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 16,16 20,18 16,4 12,18 Z"
|
||||
id="path76"
|
||||
sodipodi:nodetypes="ccccc" />
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
54
init.lua
@ -8,6 +8,8 @@ local ANNOUNCE_ICON = "exclamation_mark.png"
|
||||
local ANNOUNCE_TIMEOUT = 20 -- time until waypoint disappears
|
||||
local WAYPOINT_COLOR = 0xFFFFFF -- color of the waypoint label
|
||||
local ICONS_COLOR = "#E78C13"
|
||||
local ARROW_FORMAT = "arrow_%03d.png"
|
||||
local ARROW_QUADS_STEPS = 9
|
||||
local POINT_RANGE = 180 -- maximun range player can point at (raycast range)
|
||||
local POINT_TO_OBJECTS = true
|
||||
local POINT_TO_LIQUIDS = true
|
||||
@ -17,32 +19,18 @@ local CHAT_MESSAGE_COLOR = "#FF90A8" -- argument to minetest.colorize()
|
||||
waypoint_lib = dofile(minetest.get_modpath("waypoint_announce") .. "/waypoint_lib.lua")
|
||||
|
||||
local function show_hud_waypoint(player, point_pos, name, icon_name)
|
||||
local icon_waypoint = waypoint_lib.IconWaypoint:new(point_pos, name, WAYPOINT_COLOR, icon_name, ICONS_COLOR)
|
||||
|
||||
icon_waypoint:show(player)
|
||||
|
||||
local d = vector.subtract(point_pos, player:get_pos())
|
||||
local size = {x=-9,y=-16} -- scale for 16:9 displays
|
||||
local alignment = {x=100/9,y=100/16*0.7} -- int the middle above the crosshair
|
||||
local compass = waypoint_lib.CompassHUD:new(size, alignment, d, "arrow_%03d.png", ICONS_COLOR, 9)
|
||||
|
||||
compass:show(player)
|
||||
|
||||
local hud = waypoint_lib.WaypointHUD:new(player, point_pos,
|
||||
name, WAYPOINT_COLOR,
|
||||
icon_name, ICONS_COLOR,
|
||||
size, alignment, ARROW_FORMAT, ICONS_COLOR, ARROW_QUADS_STEPS)
|
||||
hud:show(player)
|
||||
|
||||
local huds = {
|
||||
icon_waypoint,
|
||||
compass,
|
||||
}
|
||||
return huds
|
||||
end
|
||||
|
||||
|
||||
local function hide_hud_waypoint(player_name, hud_ids)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then
|
||||
for _,hud_id in pairs(hud_ids) do
|
||||
player:hud_remove(hud_id)
|
||||
end
|
||||
end
|
||||
return hud
|
||||
end
|
||||
|
||||
|
||||
@ -56,8 +44,7 @@ function Announcement:new(announcer_name, radius, message, icon, timeout)
|
||||
point = nil,
|
||||
icon = icon,
|
||||
timeout = timeout,
|
||||
players_huds = {},
|
||||
players_compass = {},
|
||||
players_hud = {},
|
||||
timeout_job = nil,
|
||||
}
|
||||
self.__index = self
|
||||
@ -79,12 +66,10 @@ local posted_announcements = {}
|
||||
local function remove_announcement(announcement)
|
||||
local announcer_name = announcement.announcer_name
|
||||
posted_announcements[announcer_name] = nil
|
||||
for player_name, huds in pairs(announcement.players_huds) do
|
||||
for player_name, hud in pairs(announcement.players_hud) do
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then
|
||||
for _,hud in pairs(huds) do
|
||||
hud:hide(player)
|
||||
end
|
||||
hud:hide(player)
|
||||
end
|
||||
end
|
||||
announcement.timeout_job.cancel()
|
||||
@ -106,9 +91,8 @@ local function add_announcement(announcer, announcement)
|
||||
if object:is_player() then
|
||||
local player = object
|
||||
local player_name = player:get_player_name()
|
||||
local huds = show_hud_waypoint(player, pointed_pos, announcement.message, announcement.icon)
|
||||
announcement.players_huds[player_name] = huds
|
||||
announcement.players_compass[player_name] = huds[2] -- FIXME assumes some ordering
|
||||
local hud = show_hud_waypoint(player, pointed_pos, announcement.message, announcement.icon)
|
||||
announcement.players_hud[player_name] = hud
|
||||
end
|
||||
end
|
||||
|
||||
@ -157,11 +141,10 @@ minetest.register_globalstep(check_click_for_prepared_players)
|
||||
|
||||
|
||||
local function update_announcement(announcement)
|
||||
for player_name,compass in pairs(announcement.players_compass) do
|
||||
for player_name,hud in pairs(announcement.players_hud) do
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then
|
||||
local dir = vector.subtract(announcement.point, player:get_pos())
|
||||
compass:update(player, dir)
|
||||
hud:update(player, announcement.point)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -219,7 +202,7 @@ minetest.register_chatcommand(ANNOUNCE_COMMAND_NAME, {
|
||||
|
||||
|
||||
local test_time = 0
|
||||
function announce_waypoint_test_spam_look()
|
||||
function announce_waypoint_test_spam_look(player_name)
|
||||
minetest.register_globalstep(function(dtime)
|
||||
test_time = test_time + dtime
|
||||
if test_time < 0.2 then
|
||||
@ -227,7 +210,8 @@ function announce_waypoint_test_spam_look()
|
||||
else
|
||||
test_time = 0
|
||||
end
|
||||
local player = minetest.get_player_by_name("singleplayer")
|
||||
player_name = player_name or "singleplayer"
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then -- player is online
|
||||
local player_name = player:get_player_name()
|
||||
local param = ""
|
||||
|
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 801 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 932 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 933 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 900 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 939 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 925 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 935 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 887 B |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 898 B |
@ -75,8 +75,8 @@ end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- [[ Waypoint HUD element with distance, label an icon above it ]] --
|
||||
local IconWaypoint = {}
|
||||
function IconWaypoint:new(point_pos, label, label_color, icon, icon_color)
|
||||
local IconWaypointHUD = {}
|
||||
function IconWaypointHUD:new(point_pos, label, label_color, icon, icon_color)
|
||||
local w = {
|
||||
hud_id_label = nil,
|
||||
hud_id_icon = nil,
|
||||
@ -111,21 +111,21 @@ function IconWaypoint:new(point_pos, label, label_color, icon, icon_color)
|
||||
end
|
||||
|
||||
|
||||
function IconWaypoint:show(player)
|
||||
function IconWaypointHUD:show(player)
|
||||
--self.player_name = player:get_player_name()
|
||||
self.hud_id_label = player:hud_add(self.huddef_label)
|
||||
self.hud_id_icon = player:hud_add(self.huddef_icon)
|
||||
end
|
||||
|
||||
|
||||
function IconWaypoint:hide(player)
|
||||
function IconWaypointHUD:hide(player)
|
||||
player:hud_remove(self.hud_id_label)
|
||||
player:hud_remove(self.hud_id_icon)
|
||||
end
|
||||
|
||||
|
||||
function IconWaypoint:update(player)
|
||||
error("No reason to call IconWaypoint:update(), fix your code")
|
||||
function IconWaypointHUD:update(player)
|
||||
error("No reason to call IconWaypointHUD:update(), fix your code")
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
@ -178,6 +178,44 @@ function CompassHUD:update(player, direction)
|
||||
player:hud_change(self.hud_id_compass, "text", self:get_texture(direction))
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local WaypointHUD = {}
|
||||
function WaypointHUD:new(player, point_pos,
|
||||
label, label_color,
|
||||
point_icon, point_color,
|
||||
size, alignment, arrow_icon_format, arrow_icon_color, quad_steps)
|
||||
local w = {
|
||||
}
|
||||
self.__index = self
|
||||
setmetatable(w, self)
|
||||
|
||||
w.waypoint_hud = IconWaypointHUD:new(point_pos, label, label_color, point_icon, point_color)
|
||||
|
||||
local d = vector.subtract(point_pos, player:get_pos())
|
||||
w.compass_hud = CompassHUD:new(size, alignment, d, arrow_icon_format, arrow_icon_color, quad_steps)
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
function WaypointHUD:show(player)
|
||||
self.waypoint_hud:show(player)
|
||||
self.compass_hud:show(player)
|
||||
end
|
||||
|
||||
|
||||
function WaypointHUD:hide(player)
|
||||
self.waypoint_hud:hide(player)
|
||||
self.compass_hud:hide(player)
|
||||
end
|
||||
|
||||
|
||||
function WaypointHUD:update(player, point_pos)
|
||||
local direction = vector.subtract(point_pos, player:get_pos())
|
||||
self.compass_hud:update(player, direction)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -185,8 +223,9 @@ waypoint_lib = {
|
||||
get_pointed_position = get_pointed_position,
|
||||
player_hud_add_waypoint_compass = player_hud_add_waypoint_compass,
|
||||
player_hud_update_waypoint_compass = player_hud_update_waypoint_compass,
|
||||
IconWaypoint = IconWaypoint,
|
||||
IconWaypointHUD = IconWaypointHUD,
|
||||
CompassHUD = CompassHUD,
|
||||
WaypointHUD = WaypointHUD,
|
||||
}
|
||||
|
||||
return waypoint_lib
|
||||
|