NEO-122: Fix economy HUD positioning so panel renders on screen.

Bottom anchors placed the section off-screen before layout; use explicit
position/size from viewport height and draw above HudRoot via z_index.
pull/161/head
VinPropane 2026-06-07 13:00:56 -04:00
parent d1fa08b8c4
commit f801692091
3 changed files with 28 additions and 14 deletions

View File

@ -1304,16 +1304,11 @@ autowrap_mode = 3
text = "Cooldowns: —" text = "Cooldowns: —"
[node name="EconomyHudSection" type="VBoxContainer" parent="UICanvas" unique_id=9000014] [node name="EconomyHudSection" type="VBoxContainer" parent="UICanvas" unique_id=9000014]
layout_mode = 1 z_index = 10
anchors_preset = 3
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 8.0 offset_left = 8.0
offset_top = -440.0 offset_top = 400.0
offset_right = 664.0 offset_right = 664.0
offset_bottom = -8.0 offset_bottom = 800.0
grow_horizontal = 2
grow_vertical = 0
script = ExtResource("20_economy_hud") script = ExtResource("20_economy_hud")
[node name="HeaderRow" type="HBoxContainer" parent="UICanvas/EconomyHudSection" unique_id=9000015] [node name="HeaderRow" type="HBoxContainer" parent="UICanvas/EconomyHudSection" unique_id=9000015]

View File

@ -15,11 +15,14 @@ const PANEL_WIDTH := 656.0
func _ready() -> void: func _ready() -> void:
z_index = 10
_toggle.button_pressed = true _toggle.button_pressed = true
_body_scroll.visible = true _body_scroll.visible = true
_toggle.toggled.connect(_on_toggle_toggled) _toggle.toggled.connect(_on_toggle_toggled)
get_viewport().size_changed.connect(_apply_viewport_layout) get_viewport().size_changed.connect(_apply_viewport_layout)
call_deferred("_apply_viewport_layout") call_deferred("_apply_viewport_layout")
await get_tree().process_frame
_apply_viewport_layout()
func _on_toggle_toggled(pressed: bool) -> void: func _on_toggle_toggled(pressed: bool) -> void:
@ -46,19 +49,19 @@ func scroll_body_to_recipes() -> void:
func _apply_viewport_layout() -> void: func _apply_viewport_layout() -> void:
if not is_instance_valid(_body_scroll): if not is_instance_valid(_body_scroll):
return return
var vp_height: float = get_viewport().get_visible_rect().size.y var vp_size: Vector2 = get_viewport().get_visible_rect().size
if vp_size.y <= 1.0:
return
var header_height: float = _measure_header_height() var header_height: float = _measure_header_height()
var body_height: float = max( var body_height: float = max(
MIN_BODY_SCROLL_HEIGHT, vp_height * MAX_VIEWPORT_HEIGHT_FRACTION - header_height MIN_BODY_SCROLL_HEIGHT, vp_size.y * MAX_VIEWPORT_HEIGHT_FRACTION - header_height
) )
_body_scroll.custom_minimum_size = Vector2(PANEL_WIDTH, body_height) _body_scroll.custom_minimum_size = Vector2(PANEL_WIDTH, body_height)
var panel_height: float = header_height var panel_height: float = header_height
if _body_scroll.visible: if _body_scroll.visible:
panel_height += body_height panel_height += body_height
offset_left = SIDE_MARGIN position = Vector2(SIDE_MARGIN, vp_size.y - panel_height - BOTTOM_MARGIN)
offset_right = SIDE_MARGIN + PANEL_WIDTH size = Vector2(PANEL_WIDTH, panel_height)
offset_bottom = -BOTTOM_MARGIN
offset_top = -panel_height - BOTTOM_MARGIN
func _measure_header_height() -> float: func _measure_header_height() -> float:

View File

@ -62,3 +62,19 @@ func test_toggle_expands_body_again() -> void:
await await_idle_frame() await await_idle_frame()
# Assert # Assert
assert_bool(section.call("is_body_visible")).is_true() assert_bool(section.call("is_body_visible")).is_true()
func test_viewport_layout_pins_section_above_bottom_margin() -> void:
# Arrange
var section: Control = _build_section() as Control
add_child(section)
await await_idle_frame()
await get_tree().process_frame
# Act
section.call("_apply_viewport_layout")
await get_tree().process_frame
# Assert
var vp_height: float = get_viewport().get_visible_rect().size.y
assert_that(section.position.y).is_greater(vp_height * 0.2)
assert_that(section.position.y + section.size.y).is_less_equal(vp_height)