From f8016920917255218feef6d326b68490de01e8ef Mon Sep 17 00:00:00 2001 From: VinPropane Date: Sun, 7 Jun 2026 13:00:56 -0400 Subject: [PATCH] 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. --- client/scenes/main.tscn | 11 +++-------- client/scripts/prototype_economy_hud_section.gd | 15 +++++++++------ .../test/prototype_economy_hud_section_test.gd | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/client/scenes/main.tscn b/client/scenes/main.tscn index ea76b1a..0698508 100644 --- a/client/scenes/main.tscn +++ b/client/scenes/main.tscn @@ -1304,16 +1304,11 @@ autowrap_mode = 3 text = "Cooldowns: —" [node name="EconomyHudSection" type="VBoxContainer" parent="UICanvas" unique_id=9000014] -layout_mode = 1 -anchors_preset = 3 -anchor_top = 1.0 -anchor_bottom = 1.0 +z_index = 10 offset_left = 8.0 -offset_top = -440.0 +offset_top = 400.0 offset_right = 664.0 -offset_bottom = -8.0 -grow_horizontal = 2 -grow_vertical = 0 +offset_bottom = 800.0 script = ExtResource("20_economy_hud") [node name="HeaderRow" type="HBoxContainer" parent="UICanvas/EconomyHudSection" unique_id=9000015] diff --git a/client/scripts/prototype_economy_hud_section.gd b/client/scripts/prototype_economy_hud_section.gd index 3e3e5bc..45e30aa 100644 --- a/client/scripts/prototype_economy_hud_section.gd +++ b/client/scripts/prototype_economy_hud_section.gd @@ -15,11 +15,14 @@ const PANEL_WIDTH := 656.0 func _ready() -> void: + z_index = 10 _toggle.button_pressed = true _body_scroll.visible = true _toggle.toggled.connect(_on_toggle_toggled) get_viewport().size_changed.connect(_apply_viewport_layout) call_deferred("_apply_viewport_layout") + await get_tree().process_frame + _apply_viewport_layout() func _on_toggle_toggled(pressed: bool) -> void: @@ -46,19 +49,19 @@ func scroll_body_to_recipes() -> void: func _apply_viewport_layout() -> void: if not is_instance_valid(_body_scroll): 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 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) var panel_height: float = header_height if _body_scroll.visible: panel_height += body_height - offset_left = SIDE_MARGIN - offset_right = SIDE_MARGIN + PANEL_WIDTH - offset_bottom = -BOTTOM_MARGIN - offset_top = -panel_height - BOTTOM_MARGIN + position = Vector2(SIDE_MARGIN, vp_size.y - panel_height - BOTTOM_MARGIN) + size = Vector2(PANEL_WIDTH, panel_height) func _measure_header_height() -> float: diff --git a/client/test/prototype_economy_hud_section_test.gd b/client/test/prototype_economy_hud_section_test.gd index 9ad55fc..ebeecb4 100644 --- a/client/test/prototype_economy_hud_section_test.gd +++ b/client/test/prototype_economy_hud_section_test.gd @@ -62,3 +62,19 @@ func test_toggle_expands_body_again() -> void: await await_idle_frame() # Assert 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) +