47 lines
1.5 KiB
GDScript
47 lines
1.5 KiB
GDScript
extends Node2D
|
|
|
|
var body_texture: Texture2D
|
|
var radius := 100.0
|
|
var is_star := false
|
|
var is_protected := false
|
|
var is_safe := false
|
|
var _label: Label
|
|
|
|
func _ready() -> void:
|
|
var sprite := Sprite2D.new()
|
|
sprite.texture = body_texture
|
|
sprite.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR
|
|
var longest_side := maxf(body_texture.get_width(), body_texture.get_height())
|
|
sprite.scale = Vector2.ONE * (radius * 2.0 / longest_side)
|
|
add_child(sprite)
|
|
_label = Label.new()
|
|
_label.position = Vector2(-160, radius + 14)
|
|
_label.size = Vector2(320, 54)
|
|
_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
_label.add_theme_font_size_override("font_size", 14)
|
|
_update_label()
|
|
|
|
func set_safe(value: bool) -> void:
|
|
is_safe = value
|
|
if is_node_ready():
|
|
_update_label()
|
|
queue_redraw()
|
|
|
|
func _update_label() -> void:
|
|
if _label.get_parent() == null:
|
|
add_child(_label)
|
|
if is_star:
|
|
_label.text = "GWIAZDA CENTRALNA"
|
|
_label.add_theme_color_override("font_color", Color("ffdb98"))
|
|
elif is_protected:
|
|
_label.text = "PLANETA CHRONIONEJ RASY\n" + ("USŁUGI DOSTĘPNE" if is_safe else "POKONAJ WSZYSTKICH WROGÓW")
|
|
_label.add_theme_color_override("font_color", Color("77e8bc") if is_safe else Color("ffbd83"))
|
|
else:
|
|
_label.text = "PLANETA"
|
|
_label.add_theme_color_override("font_color", Color("9baec6"))
|
|
|
|
func _draw() -> void:
|
|
if is_protected:
|
|
var color := Color("77e8bc") if is_safe else Color("ffbd83")
|
|
draw_arc(Vector2.ZERO, radius + 20.0, 0, TAU, 96, Color(color, 0.65), 2.0, true)
|