101 lines
3.9 KiB
GDScript
101 lines
3.9 KiB
GDScript
extends Node2D
|
|
|
|
var enemy: CharacterBody2D
|
|
var _tier_label: Label
|
|
var _disabled_icons: Array[PanelContainer] = []
|
|
const DISABLED_ICONS := [preload("res://assets/icons/engine.png"),preload("res://assets/icons/plasma.png"),preload("res://assets/icons/shield.png")]
|
|
|
|
func _ready() -> void:
|
|
enemy = get_parent() as CharacterBody2D
|
|
top_level = true
|
|
z_index = 30
|
|
light_mask = 4
|
|
_tier_label = Label.new()
|
|
_tier_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_tier_label.light_mask = 4
|
|
_tier_label.position = Vector2(-50, -23)
|
|
_tier_label.size = Vector2(100, 16)
|
|
_tier_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
_tier_label.add_theme_font_size_override("font_size", 11)
|
|
_tier_label.add_theme_color_override("font_outline_color", Color("08111d"))
|
|
_tier_label.add_theme_constant_override("outline_size", 3)
|
|
add_child(_tier_label)
|
|
_build_disabled_icons()
|
|
_update_position()
|
|
_update_tier_label()
|
|
_update_disabled_icons()
|
|
|
|
func _process(_delta: float) -> void:
|
|
_update_position()
|
|
_update_tier_label()
|
|
_update_disabled_icons()
|
|
queue_redraw()
|
|
|
|
func _build_disabled_icons() -> void:
|
|
var material := ShaderMaterial.new()
|
|
material.shader = preload("res://resources/effects/disabled_system_icon.gdshader")
|
|
for system in 3:
|
|
var panel := PanelContainer.new()
|
|
panel.name = ["DisabledEngine","DisabledWeapon","DisabledShields"][system]
|
|
panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
panel.size = Vector2(20,20)
|
|
panel.light_mask = 4
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("17090be8")
|
|
style.border_color = Color("ff4b43")
|
|
style.set_border_width_all(1)
|
|
style.set_corner_radius_all(3)
|
|
style.set_content_margin_all(2)
|
|
panel.add_theme_stylebox_override("panel",style)
|
|
var icon := TextureRect.new()
|
|
icon.texture = DISABLED_ICONS[system]
|
|
icon.material = material
|
|
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
|
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
|
icon.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR
|
|
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
icon.light_mask = 4
|
|
panel.add_child(icon)
|
|
add_child(panel)
|
|
_disabled_icons.append(panel)
|
|
|
|
func _update_disabled_icons() -> void:
|
|
var active: Array[int] = []
|
|
if enemy.hull > 0.0 and not enemy.is_queued_for_deletion():
|
|
for system in 3:
|
|
if enemy.system_disabled(system): active.append(system)
|
|
for system in 3:
|
|
var panel := _disabled_icons[system]
|
|
panel.visible = system in active
|
|
if panel.visible:
|
|
panel.position = Vector2(-float(active.size()*22-2)*0.5+active.find(system)*22,-56)
|
|
|
|
func _update_position() -> void:
|
|
global_position = enemy.global_position + Vector2(0, -enemy.get_visual_size() * 0.5 - 12.0)
|
|
|
|
func _tier_color() -> Color:
|
|
if bool(enemy.get("virus_controlled")):
|
|
return Color("c57dff")
|
|
return Color("ff76d6") if enemy.loot_tier == 2 else (Color("ffc785") if enemy.loot_tier == 1 else Color("ef5967"))
|
|
|
|
func _update_tier_label() -> void:
|
|
_tier_label.text = "BOSS" if enemy.loot_tier == 2 else ("ELITA" if enemy.loot_tier == 1 else "")
|
|
if bool(enemy.get("virus_controlled")):
|
|
_tier_label.text = "WIRUS"
|
|
_tier_label.add_theme_color_override("font_color", _tier_color())
|
|
|
|
func get_health_ratio() -> float:
|
|
return clampf(enemy.hull / maxf(enemy.max_hull, 0.001), 0.0, 1.0)
|
|
|
|
func _draw() -> void:
|
|
if not is_instance_valid(enemy) or enemy.hull <= 0.0 or not GameState.captain.expedition.alien_skills.get("general", false):
|
|
return
|
|
var width := 72.0 if enemy.loot_tier == 2 else (56.0 if enemy.loot_tier == 1 else 44.0)
|
|
var background := Rect2(-width * 0.5, -3.0, width, 6.0)
|
|
draw_rect(background.grow(1.0), Color("08111dee"))
|
|
draw_rect(background, Color("39232bee"))
|
|
draw_rect(Rect2(-width * 0.5, 5.0, width, 3.0), Color("142a3d"))
|
|
draw_rect(Rect2(-width * 0.5, 5.0, width * clampf(enemy.shields / maxf(1.0, enemy.max_shields), 0.0, 1.0), 3.0), Color("67cfff"))
|
|
var color := _tier_color()
|
|
draw_rect(Rect2(background.position, Vector2(width * get_health_ratio(), 6.0)), color)
|