57 lines
2.4 KiB
GDScript
57 lines
2.4 KiB
GDScript
extends Button
|
|
|
|
const FONT := preload("res://assets/fonts/font2.ttf")
|
|
var player: CharacterBody2D
|
|
var _texture: Texture2D
|
|
var _ship_name := ""
|
|
|
|
func _ready() -> void:
|
|
focus_mode = Control.FOCUS_NONE
|
|
text = ""
|
|
for state in ["normal", "hover", "pressed", "focus"]:
|
|
add_theme_stylebox_override(state, StyleBoxEmpty.new())
|
|
var ship := ShipCatalog.for_path(GameState.selected_ship_path)
|
|
_ship_name = ship["name"]
|
|
_texture = load(ShipCatalog.texture_path(ship)) as Texture2D
|
|
|
|
func _process(_delta: float) -> void:
|
|
queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
if not is_instance_valid(player):
|
|
return
|
|
var portrait_center := Vector2(size.x - 54, 55)
|
|
var color := Color("91dbea") if is_hovered() else Color("376779")
|
|
var style := StyleBoxFlat.new()
|
|
style.bg_color = Color("091522f5")
|
|
style.border_color = color
|
|
style.set_border_width_all(1)
|
|
style.set_corner_radius_all(12)
|
|
draw_style_box(style, Rect2(0, 9, size.x - 48, 94))
|
|
draw_circle(portrait_center, 50, Color("0a1725"))
|
|
draw_arc(portrait_center, 50, 0, TAU, 64, color, 3, true)
|
|
draw_arc(portrait_center, 44, 0, TAU, 64, Color("efb568"), 1, true)
|
|
if _texture != null:
|
|
var dimensions := _texture.get_size()
|
|
var display_size := dimensions * (70.0 / maxf(dimensions.x, dimensions.y))
|
|
draw_texture_rect(_texture, Rect2(portrait_center - display_size * 0.5, display_size), false)
|
|
draw_string(FONT, Vector2(14, 29), _ship_name.to_upper(), HORIZONTAL_ALIGNMENT_LEFT, size.x - 120, 13, Color("c9e8ff"))
|
|
_bar(Rect2(12, 38, size.x - 118, 24), float(player.get("hull")), float(player.get("max_hull")), Color("df7158"), "KADŁUB")
|
|
_bar(Rect2(12, 68, size.x - 118, 24), float(player.get("shields")), float(player.get("max_shields")), Color("478ddd"), "TARCZE")
|
|
|
|
func _bar(rect: Rect2, value: float, maximum: float, color: Color, caption: String) -> void:
|
|
var background := StyleBoxFlat.new()
|
|
background.bg_color = Color("060e18")
|
|
background.border_color = color.darkened(0.4)
|
|
background.set_border_width_all(1)
|
|
background.set_corner_radius_all(7)
|
|
draw_style_box(background, rect)
|
|
var fill_rect := rect.grow(-3)
|
|
fill_rect.size.x *= clampf(value / maxf(1.0, maximum), 0.0, 1.0)
|
|
if fill_rect.size.x > 0:
|
|
var fill := StyleBoxFlat.new()
|
|
fill.bg_color = color
|
|
fill.set_corner_radius_all(4)
|
|
draw_style_box(fill, fill_rect)
|
|
draw_string(FONT, rect.position + Vector2(0, 16), "%s %.0f / %.0f" % [caption, value, maximum], HORIZONTAL_ALIGNMENT_CENTER, rect.size.x, 10, Color.WHITE)
|