36 lines
1.8 KiB
GDScript
36 lines
1.8 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 color := Color("77e8bc") if bool(game.get("system_cleared")) else Color("ffbd83")
|
|
_draw_target(planet.global_position, str(planet.get("display_name")) + " — zamieszkana", color)
|
|
var portal: Node2D = game.get("wormhole")
|
|
if is_instance_valid(portal):
|
|
_draw_target(portal.global_position, "WORMHOLE — następny układ", Color("89e8ff"))
|
|
|
|
func _draw_target(world_position: Vector2, label_text: String, color: Color) -> void:
|
|
var screen_position := get_viewport().get_canvas_transform() * world_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)
|
|
draw_colored_polygon(PackedVector2Array([point + direction * 10, point - direction * 7 + side * 7, point - direction * 7 - side * 7]), color)
|
|
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)
|