Randoloot/scripts/ui/protected_planet_marker.gd
2026-10-10 22:38:40 +02:00

31 lines
1.6 KiB
GDScript

extends Control
const GAME_FONT := preload("res://assets/fonts/font2.ttf")
var game: Node2D
func _process(_delta: float) -> void:
queue_redraw()
func _draw() -> void:
if not is_instance_valid(game) or not is_instance_valid(game.get("protected_planet")):
return
var planet: Node2D = game.get("protected_planet")
var screen_position := get_viewport().get_canvas_transform() * planet.global_position
# Leave the bottom strip free for active extension buttons.
var bounds := Rect2(Vector2(32, 56), Vector2(maxf(100.0, size.x - 320.0), maxf(100.0, size.y - 160.0)))
if bounds.has_point(screen_position):
return
var center := bounds.get_center()
var direction := (screen_position - center).normalized()
var half_size := bounds.size * 0.5
var distance := minf(half_size.x / maxf(absf(direction.x), 0.001), half_size.y / maxf(absf(direction.y), 0.001))
var point := center + direction * distance
var side := Vector2(-direction.y, direction.x)
var color := Color("77e8bc") if bool(game.get("system_cleared")) else Color("ffbd83")
draw_colored_polygon(PackedVector2Array([point + direction * 10, point - direction * 7 + side * 7, point - direction * 7 - side * 7]), color)
var label_text := str(planet.get("display_name")) + " — zamieszkana"
var text_width := GAME_FONT.get_string_size(label_text, HORIZONTAL_ALIGNMENT_LEFT, -1, 12).x
var label_position := Vector2(clampf(point.x - text_width * 0.5, 8, maxf(8, size.x - text_width - 8)), clampf(point.y + 25, 20, size.y - 12))
draw_string(GAME_FONT, label_position, label_text, HORIZONTAL_ALIGNMENT_LEFT, -1, 12, color)