1
0
Fork 0
space-capture/scenes/control_planet/control_planet.gd

45 lines
1.2 KiB
GDScript3
Raw Normal View History

2024-08-06 22:46:05 +02:00
extends Node2D
2024-08-15 11:18:54 +02:00
class_name ControlPlanet
2024-08-06 22:46:05 +02:00
## The player currenly controlling this planet.
var player: Player :
set(value):
player = value
var color := Color.MAGENTA if player == null else player.color
%Selection.color = color
%PopulationLabel.modulate = color
%PopulationIcon.modulate = color
%PopulationIcon.texture = null if player == null else player.icon
## Number of units currently stationed at the planet.
@export var population: int :
set(value):
population = value
%PopulationLabel.text = "%s" % value
func _ready() -> void:
is_selected = false
@export_category("UI")
signal selected(planet: Planet)
signal pointer_entered(planet: Planet)
signal pointer_exited(planet: Planet)
var is_selected: bool :
get:
return %Selection.visible
set(value):
%Selection.visible = value
2024-08-15 11:18:54 +02:00
func _on_input_listener_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
2024-08-06 22:46:05 +02:00
# TODO: handle touch appropriately (InputEventScreenTouch).
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed():
selected.emit(self)
func _on_input_listener_mouse_entered() -> void:
pointer_entered.emit(self)
func _on_input_listener_mouse_exited() -> void:
pointer_exited.emit(self)