diff --git a/prefabs/chip_bar.tscn b/prefabs/chip_bar.tscn index daa2866..0cd717d 100644 --- a/prefabs/chip_bar.tscn +++ b/prefabs/chip_bar.tscn @@ -11,13 +11,11 @@ grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_3whrn") -[node name="HFlowContainer" type="HFlowContainer" parent="." unique_id=185867767] +[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=185867767] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_override_constants/h_separation = 0 -theme_override_constants/v_separation = 0 -alignment = 2 +theme_override_constants/separation = 0 diff --git a/prefabs/combat_ui.tscn b/prefabs/combat_ui.tscn index 55471d1..71e73d0 100644 --- a/prefabs/combat_ui.tscn +++ b/prefabs/combat_ui.tscn @@ -345,6 +345,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 4 +max_chips_per_row = 100 empty_chip_texture = SubResource("AtlasTexture_eskga") filled_chip_texture = SubResource("AtlasTexture_14b7f") @@ -373,6 +374,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 4 +max_chips_per_row = 100 empty_chip_texture = SubResource("AtlasTexture_yhw6j") filled_chip_texture = SubResource("AtlasTexture_kdblo") @@ -401,6 +403,7 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 4 +max_chips_per_row = 100 empty_chip_texture = SubResource("AtlasTexture_kd55s") filled_chip_texture = SubResource("AtlasTexture_alhr0") diff --git a/reference_images/chip.png b/reference_images/chip.png index 44ac852..214f499 100644 Binary files a/reference_images/chip.png and b/reference_images/chip.png differ diff --git a/scripts/ui/chip_bar.gd b/scripts/ui/chip_bar.gd index 6ec05a6..f1deee7 100644 --- a/scripts/ui/chip_bar.gd +++ b/scripts/ui/chip_bar.gd @@ -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)