This commit is contained in:
gamer147
2026-04-10 13:13:01 -04:00
parent 6d9d08d78c
commit 2d74e15006
4 changed files with 30 additions and 11 deletions

View File

@@ -23,7 +23,7 @@ class_name ChipBar extends Control
# The texture for a filled chip
@export var filled_chip_texture: Texture2D
@onready var _container: HFlowContainer = $HFlowContainer
@onready var _container: VBoxContainer = $VBoxContainer
func _ready() -> void:
@@ -38,11 +38,29 @@ func _refresh() -> void:
var chip_width := filled_chip_texture.get_width()
_container.custom_minimum_size.x = chip_width * max_chips_per_row
var empty_count := max_value - value
for i in max_value:
var tex_rect := TextureRect.new()
if i < empty_count:
if max_chips_per_row <= 0:
return
var filled_remaining := value
var chips_laid_out := 0
while chips_laid_out < max_value:
var row := HBoxContainer.new()
row.alignment = BoxContainer.ALIGNMENT_END
row.add_theme_constant_override("separation", 0)
var chips_in_row := mini(max_chips_per_row, max_value - chips_laid_out)
var filled_in_row := mini(filled_remaining, chips_in_row)
var empty_in_row := chips_in_row - filled_in_row
for i in empty_in_row:
var tex_rect := TextureRect.new()
tex_rect.texture = empty_chip_texture
else:
row.add_child(tex_rect)
for i in filled_in_row:
var tex_rect := TextureRect.new()
tex_rect.texture = filled_chip_texture
_container.add_child(tex_rect)
row.add_child(tex_rect)
filled_remaining -= filled_in_row
chips_laid_out += chips_in_row
_container.add_child(row)