Added a connection status element that shows current link usage and packet loss.

This commit is contained in:
RedNicStone committed 2026-11-09 18:17:42 +01:00
1 parent 26c29df4ad
commit 2d91487c6a
12 files changed
+415

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
extends VBoxContainer
var elapsed := 0.0
@onready var panel = $LinkPanel
func _ready() -> void:
$Controls/Contrast.toggled.connect(func(high: bool) -> void:
theme = load("res://themes/theme_highcontrast.tres" if high else "res://themes/theme.tres")
)
$Controls/State.item_selected.connect(func(index: int) -> void:
if index == 6: panel.clear_telemetry()
)
func _process(delta: float) -> void:
elapsed += delta
match $Controls/State.selected:
0: panel.set_telemetry(6.42 + sin(elapsed) * 0.12, 1.08, 0.02)
1: panel.set_telemetry(8.65, 7.9, 0.02)
2: panel.set_telemetry(9.72, 10.2, 0.02)
3: panel.set_telemetry(3.2, 0.4, 2.3, 1)
4: panel.set_telemetry(0, 0, 0, 2)
5, 6: pass
+1
View File
@@ -0,0 +1 @@
uid://i5dbrwr8d2gr
+74
View File
@@ -0,0 +1,74 @@
@tool
extends PanelContainer
enum Connection { CONNECTED, DEGRADED, DISCONNECTED }
@export var downlink_capacity_gbps := 10.0
@export var uplink_capacity_gbps := 10.0
@export_range(0, 1) var warning_fraction := 0.8
@export_range(0, 1) var fault_fraction := 0.95
@export var loss_window_seconds := 10.0
@export var stale_after_seconds := 2.0
@export var link_icon: Texture2D:
set(value):
link_icon = value
if is_node_ready():
%LinkIcon.texture = value
var _received_ms := -1
var _state := Connection.CONNECTED
var _down := 0.0
var _up := 0.0
var _loss := 0.0
var _stale := false
func _ready() -> void:
%LinkIcon.texture = link_icon
theme_changed.connect(_update_icon)
_update_icon()
_refresh()
## Rates in Gbps; loss in percent over loss_window_seconds.
func set_telemetry(down: float, up: float, loss_percent: float, state: int = Connection.CONNECTED) -> bool:
if not is_finite(down) or not is_finite(up) or not is_finite(loss_percent) or down < 0 or up < 0 or loss_percent < 0 or loss_percent > 100 or state < 0 or state > 2:
return false
_down = down
_up = up
_loss = loss_percent
_state = state
_received_ms = Time.get_ticks_msec()
_refresh()
return true
func clear_telemetry() -> void:
_received_ms = -1
_refresh()
func _process(_delta: float) -> void:
var stale := _received_ms >= 0 and Time.get_ticks_msec() - _received_ms > stale_after_seconds * 1000
if stale != _stale:
_refresh()
func _refresh() -> void:
if not is_node_ready():
return
var missing := _received_ms < 0
_stale = not missing and Time.get_ticks_msec() - _received_ms > stale_after_seconds * 1000
var measured := not missing and _state != Connection.DISCONNECTED
%State.text = "NO TELEMETRY" if missing else ("STALE" if _stale else ["CONNECTED", "DEGRADED", "DISCONNECTED"][_state])
%State.theme_type_variation = "LinkMuted" if missing else ("LinkRateWarning" if _stale or _state == Connection.DEGRADED else ("LinkRateFault" if _state == Connection.DISCONNECTED else "Label"))
var gauges := [%Downlink, %Uplink]
for index in range(2):
gauges[index].capacity_gbps = maxf([downlink_capacity_gbps, uplink_capacity_gbps][index], 0.001)
gauges[index].warning_fraction = warning_fraction
gauges[index].fault_fraction = maxf(warning_fraction, fault_fraction)
gauges[index].rate_gbps = [_down, _up][index]
gauges[index].available = measured
gauges[index].refresh()
%LossValue.text = "%.2f%%" % _loss if measured else "—"
%LossWindow.text = "%.0f s window" % loss_window_seconds + (" · held" if _stale else "")
func _update_icon() -> void:
var tint := get_theme_color("status_icon", "SurfaceSide")
tint.a = 0.06
%LinkIcon.self_modulate = tint
+1
View File
@@ -0,0 +1 @@
uid://84jt1vgxm2ei
+44
View File
@@ -0,0 +1,44 @@
@tool
extends Control
@export var direction := "↓ DOWNLINK"
var capacity_gbps := 10.0
var warning_fraction := 0.8
var fault_fraction := 0.95
var rate_gbps := 0.0
var available := false
func _ready() -> void:
resized.connect(queue_redraw)
theme_changed.connect(queue_redraw)
refresh()
func utilization() -> float:
return rate_gbps / maxf(capacity_gbps, 0.001)
func severity() -> int:
if not available:
return 0
return 2 if utilization() >= fault_fraction else (1 if utilization() >= warning_fraction else 0)
func refresh() -> void:
if not is_node_ready():
return
%Direction.text = direction
%Direction.theme_type_variation = "LinkMuted" if not available else ["LinkRateNormal", "LinkRateWarning", "LinkRateFault"][severity()]
%Value.text = "%.2f" % rate_gbps if available else "—"
%Capacity.text = "%s Gbps max" % String.num(capacity_gbps, 2)
queue_redraw()
func _draw() -> void:
var radius := maxf(1.0, minf(size.x, size.y) / 2 - 6)
var center := size / 2
var start := deg_to_rad(140)
var sweep := deg_to_rad(260)
draw_arc(center, radius, start, start + sweep, 96, get_theme_color("instrument_grid", "SurfaceSide"), 3, true)
for fraction in [warning_fraction, fault_fraction]:
var radial := Vector2.from_angle(start + sweep * fraction)
draw_line(center + radial * (radius - 4), center + radial * (radius + 4), get_theme_color("instrument_axis", "SurfaceSide"), 1, true)
if available and rate_gbps > 0:
var role: String = ["instrument_accent", "warning", "fault"][severity()]
draw_arc(center, radius, start, start + sweep * clampf(utilization(), 0, 1), 96, get_theme_color(role, "SurfaceSide"), 4, true)
+1
View File
@@ -0,0 +1 @@
uid://b1pcqygbaipjh