Added a connection status element that shows current link usage and packet loss.
This commit is contained in:
1 parent
26c29df4ad
commit
2d91487c6a
12 files changed
+415
No files matched your search
@@ -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)
|
||||
Reference in new issue
Block a user