85 lines
4.0 KiB
GDScript
85 lines
4.0 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")
|
|
var player: CharacterBody2D
|
|
var game: Node2D
|
|
var _enemy_details: Control
|
|
var _inventory: ShipInventory
|
|
|
|
func _ready() -> void:
|
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_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)
|
|
|
|
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)
|
|
var cell := (size.x - 238) / 3.0
|
|
_enemy_details.position = Vector2(218.0 + 2.0 * cell, 57)
|
|
_enemy_details.size = Vector2(cell, 56)
|
|
queue_redraw()
|
|
|
|
func _text(value: String, point: Vector2, width: float, font_size: int, color: Color) -> void:
|
|
draw_string(FONT, point, value, HORIZONTAL_ALIGNMENT_CENTER, width, font_size, color)
|
|
|
|
func _draw() -> void:
|
|
if _inventory == null or not is_instance_valid(player) or size.x < 50 or size.y < 50:
|
|
return
|
|
var outline := PackedVector2Array([Vector2(24, 0), Vector2(size.x - 24, 0), Vector2(size.x, 24), Vector2(size.x, size.y - 12), Vector2(size.x - 12, size.y), Vector2(12, size.y), Vector2(0, size.y - 12), Vector2(0, 24)])
|
|
draw_colored_polygon(outline, Color(0.025, 0.041, 0.063, 1.0))
|
|
var closed := outline.duplicate()
|
|
closed.append(outline[0])
|
|
draw_polyline(closed, Color("376779"), 1.5, true)
|
|
draw_line(Vector2(28, 2), Vector2(size.x - 28, 2), CYAN, 2, true)
|
|
# Put weapon cards beside the counters rather than stacking three rows.
|
|
_text("DPS: %.1f" % _inventory.get_total_dps(), Vector2(20, 81), 172, 12, CYAN)
|
|
_text("PRĘDKOŚĆ: %.0f" % player.velocity.length(), Vector2(20, 101), 172, 11, Color("c4d6df"))
|
|
var absorption: Vector3 = player.get("absorption")
|
|
for index in 3:
|
|
_text("%s - %.1f%%" % [DamageTypes.NAMES[index], absorption[index]], Vector2(205, 77 + index * 15), 2.0 * (size.x - 238) / 3.0, 11, Color("a9d69a"))
|
|
var cell := (size.x - 238) / 3.0
|
|
var values := [_inventory.missile_ammunition, _inventory.ammunition, int(game.call("get_remaining_enemies"))]
|
|
var captions := ["RAKIETY", "AMUNICJA", "WROGOWIE"]
|
|
var boss_alive := bool(game.call("is_boss_alive"))
|
|
for index in 3:
|
|
var x := 218.0 + index * cell
|
|
var color := AMBER if index == 0 else (CYAN if index == 1 else Color("ff8989"))
|
|
_text(captions[index], Vector2(x, 21), cell, 9, Color("8aa9bb"))
|
|
if index == 1:
|
|
_text("ZWYKŁE %02d" % _inventory.ammunition, Vector2(x, 35), cell, 11, CYAN)
|
|
_text("GAMMA %02d" % _inventory.irradiated_ammunition, Vector2(x, 49), cell, 11, Color("a9ef83"))
|
|
elif index == 2 and boss_alive:
|
|
_text("BOSS", Vector2(x, 45), cell, 21, Color("ff8989"))
|
|
else:
|
|
_text(str(values[index]).pad_zeros(2), Vector2(x, 45), cell, 21, color)
|
|
if index < 2:
|
|
draw_line(Vector2(x + cell, 14), Vector2(x + cell, 45), Color("2b4354"), 1)
|
|
var card := Rect2(20 + index * 60, 12, 52, 52)
|
|
var slot_index: int = WEAPON_DISPLAY_ORDER[index]
|
|
var item := _inventory.weapon_slots[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, 12), card.size.x, 9, CYAN)
|
|
if item != null and item.definition.icon != null:
|
|
draw_texture_rect(item.definition.icon, Rect2(card.position + Vector2(9, 16), Vector2(34, 34)), false)
|
|
else:
|
|
_text("—", card.position + Vector2(0, 36), card.size.x, 14, Color("637d90"))
|
|
|
|
func _card_style(color: Color) -> StyleBoxFlat:
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("0b1520")
|
|
style.border_color = color
|
|
style.set_border_width_all(1)
|
|
style.set_corner_radius_all(4)
|
|
return style
|