Map: other players in your land shown on a co-op server, never with PvP on

This commit is contained in:
Paul Bailey
2026-11-06 22:33:14 +00:00
parent 109fff22d0
commit 6544862885
3 changed files with 31 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ var _tex: TextureRect
var _marks: Control
var _title: Label
var _facing: Label
var _others_key: Label
func setup(w: Node3D, p: Node3D) -> void:
world = w
@@ -75,6 +76,9 @@ func setup(w: Node3D, p: Node3D) -> void:
var you := UITheme.label("● You", 14)
you.add_theme_color_override("font_color", Color(1, 1, 1))
legend.add_child(you)
_others_key = UITheme.label("● Other players (co-op)", 14)
_others_key.add_theme_color_override("font_color", Color(0.6, 1.0, 0.65))
legend.add_child(_others_key)
for k in MARKS:
var l := UITheme.label("■ %s" % MARKS[k][1], 14)
l.add_theme_color_override("font_color", MARKS[k][0])
@@ -92,6 +96,7 @@ func is_open() -> bool:
func open() -> void:
_tex.texture = ImageTexture.create_from_image(render(world))
_title.text = "The %s" % preload("res://scripts/world/terrain.gd").worldlet_name(world.worldlet_id())
_others_key.visible = world.is_online() and not bool(Net.server_info.get("pvp", true))
visible = true
player.ui_open = true
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
@@ -132,6 +137,13 @@ func _draw_marks() -> void:
_marks.draw_rect(Rect2(at - Vector2(r, r), Vector2(r, r) * 2.0), Color(0, 0, 0, 0.7), false, 1.0)
if m.kind in ["den", "barrow", "stones", "seam", "pier", "cave"]:
_marks.draw_string(font, at + Vector2(9, 5), String(m.label), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, col)
# Other players in this land: only on a co-op server (with PvP on, the
# map never gives anyone away). Green dots with their names.
for o in others(world):
var at2 := _to_map(o.pos)
_marks.draw_circle(at2, 5.5, Color(0, 0, 0, 0.8))
_marks.draw_circle(at2, 4.0, Color(0.45, 0.95, 0.5))
_marks.draw_string(font, at2 + Vector2(8, 5), String(o.name), HORIZONTAL_ALIGNMENT_LEFT, -1, 13, Color(0.6, 1.0, 0.65))
# You: a dot (the way you're facing is on the compass).
var p := player.global_position
if world.underground_at(p) and world.tunnel != null:
@@ -143,6 +155,19 @@ func _draw_marks() -> void:
_marks.draw_string(font, Vector2(SIDE - 26, 24), "N", HORIZONTAL_ALIGNMENT_LEFT, -1, 18, Color(1.0, 0.55, 0.35))
_marks.draw_line(Vector2(SIDE - 20, 30), Vector2(SIDE - 20, 48), Color(1.0, 0.55, 0.35), 2.0)
## The other players to show: [{name, pos}], everyone in this land on a
## server with PvP off; nobody single-player or with PvP on (rivals and
## adversarial), so the map can't be used to hunt anyone down.
static func others(w: Node3D) -> Array:
var out: Array = []
if not w.is_online() or bool(Net.server_info.get("pvp", true)) or w.net_sync == null:
return out
for peer in w.net_sync.avatars:
var a: Node3D = w.net_sync.avatars[peer]
if is_instance_valid(a) and a.visible:
out.append({"name": String(a.info.get("name", "?")), "pos": a.global_position})
return out
## The map image: the terrain, coloured and shaded, blank where unexplored.
static func render(w: Node3D) -> Image:
var t: Node3D = w.terrain