Deployment slot UI mostly setup
This commit is contained in:
34
scripts/ui/contiguous_bar.gd
Normal file
34
scripts/ui/contiguous_bar.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
@tool
|
||||
class_name ContiguousBar extends Control
|
||||
|
||||
@onready var fill: NinePatchRect = $Fill
|
||||
|
||||
@export var value: int:
|
||||
set(v):
|
||||
value = v
|
||||
_refresh()
|
||||
|
||||
@export var max_value: int:
|
||||
set(v):
|
||||
max_value = v
|
||||
_refresh()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_refresh()
|
||||
|
||||
|
||||
func _refresh() -> void:
|
||||
if fill == null:
|
||||
return
|
||||
var ratio := 0.0
|
||||
if max_value > 0:
|
||||
ratio = clampf(float(value) / float(max_value), 0.0, 1.0)
|
||||
fill.anchor_top = 0.0
|
||||
fill.anchor_bottom = 1.0
|
||||
fill.anchor_right = 1.0
|
||||
fill.anchor_left = 1.0 - ratio
|
||||
fill.offset_top = 1.0
|
||||
fill.offset_bottom = -1.0
|
||||
fill.offset_right = -1.0
|
||||
fill.offset_left = 2.0 * ratio - 1.0
|
||||
1
scripts/ui/contiguous_bar.gd.uid
Normal file
1
scripts/ui/contiguous_bar.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cb32ywwuyi706
|
||||
Reference in New Issue
Block a user