mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 02:02:04 +00:00
feat(*): Add bot selection, score HUD, and winner reveal to matches, replace HUD text with aircraft-style flight instruments, and fix camera judder
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
class_name HudGauge
|
||||
extends Control
|
||||
|
||||
# Generic bar gauge (vertical or horizontal) with a short label and numeric
|
||||
# readout — used for speed, altitude, and thrust. A dumb display fed by
|
||||
# HUDController via set_value.
|
||||
|
||||
const BG_COLOR := Color(0.05, 0.07, 0.11, 0.55)
|
||||
const FRAME_COLOR := Color(0.5, 0.85, 1.0, 0.7)
|
||||
const TEXT_COLOR := Color(0.85, 0.92, 1.0, 0.9)
|
||||
|
||||
const SMOOTHING := 12.0
|
||||
|
||||
@export var label := "SPD"
|
||||
@export var max_value := 100.0
|
||||
@export var horizontal := false
|
||||
@export var fill_color := Color(0.5, 0.85, 1.0, 0.85)
|
||||
# Printf pattern for the numeric readout.
|
||||
@export var value_format := "%.0f"
|
||||
|
||||
var _target := 0.0
|
||||
var _value := 0.0
|
||||
|
||||
|
||||
func set_value(value: float) -> void:
|
||||
_target = value
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var t := 1.0 - exp(-SMOOTHING * delta) # frame-rate independent
|
||||
_value = lerpf(_value, _target, t)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
var font := ThemeDB.fallback_font
|
||||
var fraction := clampf(_value / max_value, 0.0, 1.0)
|
||||
var reading := value_format % _value
|
||||
|
||||
if horizontal:
|
||||
# [label] [======bar======] [value]
|
||||
var hbar := Rect2(34, 2, size.x - 74, size.y - 4)
|
||||
draw_string(font, Vector2(0, size.y - 4), label, HORIZONTAL_ALIGNMENT_LEFT, -1, 11, TEXT_COLOR)
|
||||
draw_rect(hbar, BG_COLOR)
|
||||
draw_rect(Rect2(hbar.position, Vector2(hbar.size.x * fraction, hbar.size.y)), fill_color)
|
||||
draw_rect(hbar, FRAME_COLOR, false, 1.0)
|
||||
draw_string(font, Vector2(hbar.end.x + 6, size.y - 4), reading, HORIZONTAL_ALIGNMENT_LEFT, -1, 11, TEXT_COLOR)
|
||||
return
|
||||
|
||||
# label / vertical bar filling upward / value
|
||||
var bar := Rect2(size.x / 2.0 - 9, 16, 18, size.y - 34)
|
||||
var label_size := font.get_string_size(label, HORIZONTAL_ALIGNMENT_CENTER, -1, 11)
|
||||
draw_string(font, Vector2(size.x / 2.0 - label_size.x / 2.0, 12), label,
|
||||
HORIZONTAL_ALIGNMENT_CENTER, -1, 11, TEXT_COLOR)
|
||||
draw_rect(bar, BG_COLOR)
|
||||
var fill_h := bar.size.y * fraction
|
||||
draw_rect(Rect2(Vector2(bar.position.x, bar.end.y - fill_h), Vector2(bar.size.x, fill_h)), fill_color)
|
||||
draw_rect(bar, FRAME_COLOR, false, 1.0)
|
||||
# Quarter tick marks up the side of the bar.
|
||||
for i in range(1, 4):
|
||||
var y := bar.end.y - bar.size.y * i / 4.0
|
||||
draw_line(Vector2(bar.position.x - 3, y), Vector2(bar.position.x, y), FRAME_COLOR, 1.0)
|
||||
var reading_size := font.get_string_size(reading, HORIZONTAL_ALIGNMENT_CENTER, -1, 11)
|
||||
draw_string(font, Vector2(size.x / 2.0 - reading_size.x / 2.0, size.y - 2), reading,
|
||||
HORIZONTAL_ALIGNMENT_CENTER, -1, 11, TEXT_COLOR)
|
||||
Reference in New Issue
Block a user