87 lines
4.1 KiB
GDScript
87 lines
4.1 KiB
GDScript
extends Control
|
|
|
|
const FONT := preload("res://assets/fonts/font2.ttf")
|
|
const CYAN := Color("91dbea")
|
|
const WEAPON_DISPLAY_ORDER := [0, 2, 1]
|
|
const AMBER := Color("efb568")
|
|
const DESIGN_SIZE := Vector2(850, 144)
|
|
const SCREENS := [Rect2(80, 33, 155, 73), Rect2(272, 33, 304, 73), Rect2(619, 33, 157, 73)]
|
|
var player: CharacterBody2D
|
|
var game: Node2D
|
|
var _enemy_details: Control
|
|
var _inventory: ShipInventory
|
|
var _frame: Texture2D
|
|
var _frame_region := Rect2(1, 110, 2171, 459)
|
|
|
|
func _ready() -> void:
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_frame = load("res://assets/ui/frames/cockpit_console.png") as Texture2D
|
|
_inventory = player.get_node("ShipInventory")
|
|
_enemy_details = Control.new()
|
|
_enemy_details.name = "EnemyDetailsPanel"
|
|
_enemy_details.set_script(preload("res://scripts/ui/enemy_drawer.gd"))
|
|
add_child(_enemy_details)
|
|
_enemy_details.position = Vector2(625, 64)
|
|
_enemy_details.size = Vector2(145, 42)
|
|
|
|
func _process(delta: float) -> void:
|
|
if is_instance_valid(player):
|
|
var screen := get_viewport().get_canvas_transform() * player.global_position
|
|
var local := get_global_transform().affine_inverse() * screen
|
|
var overlaps := Rect2(Vector2.ZERO, size).grow(36).has_point(local)
|
|
modulate.a = move_toward(modulate.a, 0.18 if overlaps else 1.0, delta * 4.0)
|
|
queue_redraw()
|
|
|
|
func fitted_font_size(value: String, width: float, requested: int) -> int:
|
|
var result := requested
|
|
while result > 7 and FONT.get_string_size(value, HORIZONTAL_ALIGNMENT_LEFT, -1, result).x > width:
|
|
result -= 1
|
|
return result
|
|
|
|
func _text(value: String, point: Vector2, width: float, font_size: int, color: Color) -> void:
|
|
var fitted := fitted_font_size(value, width, font_size)
|
|
draw_string_outline(FONT, point, value, HORIZONTAL_ALIGNMENT_CENTER, width, fitted, 2, Color("030a12cc"))
|
|
draw_string(FONT, point, value, HORIZONTAL_ALIGNMENT_CENTER, width, fitted, color)
|
|
|
|
func _draw() -> void:
|
|
if _inventory == null or not is_instance_valid(player): return
|
|
for screen in SCREENS:
|
|
var glass := StyleBoxFlat.new()
|
|
glass.bg_color = Color("07151e66")
|
|
glass.set_corner_radius_all(3)
|
|
draw_style_box(glass, screen)
|
|
draw_texture_rect_region(_frame, Rect2(Vector2.ZERO, DESIGN_SIZE), _frame_region)
|
|
for index in 3:
|
|
var card := Rect2(85 + index * 48, 37, 43, 41)
|
|
var slot_index: int = WEAPON_DISPLAY_ORDER[index]
|
|
var item := _inventory.get_item("weapon", slot_index)
|
|
var border := item.get_type_color() if item != null else Color("344657")
|
|
draw_style_box(_card_style(border), card)
|
|
var binding: String = ["LPM", "PPM", "ŚPM"][slot_index]
|
|
_text(binding, card.position + Vector2(0, 10), card.size.x, 8, CYAN)
|
|
if item != null and item.definition.icon != null:
|
|
draw_texture_rect(item.definition.icon, Rect2(card.position + Vector2(8, 13), Vector2(27, 27)), false)
|
|
else:
|
|
_text("—" if _inventory.is_slot_unlocked("weapon", slot_index) else "X", card.position + Vector2(0, 31), card.size.x, 12, Color("637d90"))
|
|
_text("DPS: %.1f" % _inventory.get_total_dps(), Vector2(85, 91), 145, 10, CYAN)
|
|
_text("PRĘDKOŚĆ: %.0f" % player.velocity.length(), Vector2(85, 103), 145, 9, Color("c4d6df"))
|
|
_text("RAKIETY", Vector2(280, 44), 100, 8, Color("8aa9bb"))
|
|
_text(str(_inventory.missile_ammunition).pad_zeros(2), Vector2(280, 66), 100, 19, AMBER)
|
|
_text("AMUNICJA", Vector2(385, 44), 182, 8, Color("8aa9bb"))
|
|
_text("ZWYKŁE %02d" % _inventory.ammunition, Vector2(385, 59), 182, 10, CYAN)
|
|
_text("GAMMA %02d" % _inventory.irradiated_ammunition, Vector2(385, 72), 182, 10, Color("a9ef83"))
|
|
var absorption: Vector3 = player.get("absorption")
|
|
for index in 3:
|
|
_text("%s: %.1f%%" % [DamageTypes.NAMES[index], absorption[index]], Vector2(280, 85 + index * 10), 287, 9, Color("a9d69a"))
|
|
_text("WROGOWIE", Vector2(625, 44), 145, 8, Color("8aa9bb"))
|
|
var remaining := "BOSS" if bool(game.call("is_boss_alive")) else str(int(game.call("get_remaining_enemies"))).pad_zeros(2)
|
|
_text(remaining, Vector2(625, 61), 145, 17, Color("ff8989"))
|
|
|
|
func _card_style(color: Color) -> StyleBoxFlat:
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("0b15205c")
|
|
style.border_color = color
|
|
style.set_border_width_all(1)
|
|
style.set_corner_radius_all(3)
|
|
return style
|