From df9140ed2c6e53db1fff3489e412def16278ab96 Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 9 Mar 2026 22:48:26 -0400 Subject: [PATCH] Fix: ability panel position + visibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Panel now appears to the right of the clicked spirit by projecting its 3D world position to screen space via Camera3D.unproject_position, with viewport-edge clamping so it never goes off-screen - Removed ScrollContainer (height=0 caused buttons to be invisible); replaced with plain VBoxContainer — panel auto-sizes to content Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index ec42523..db6a122 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -1179,6 +1179,18 @@ func _normalize_keys(value: Variant) -> Variant: return value +## Clamp a panel's desired top-left position so it stays within the viewport. +## Called after the panel has been added to the tree so size is valid. +func _clamp_panel_pos(desired: Vector2, panel: Control) -> Vector2: + var vp := get_viewport().get_visible_rect().size + var sz := panel.size # may still be zero the first frame; safe fallback + if sz == Vector2.ZERO: + sz = panel.custom_minimum_size + return Vector2( + clampf(desired.x, 4.0, vp.x - sz.x - 4.0), + clampf(desired.y, 4.0, vp.y - sz.y - 4.0)) + + func _show_ability_panel(unit_id: String, unit: Dictionary) -> void: _hide_ability_panel() # Null trap: server sends "abilitiesJson": null for units with no abilities. @@ -1203,11 +1215,11 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void: if actives.is_empty(): return - # Build a floating panel anchored near the bottom-left above the hand area. + # Build a floating panel positioned to the right of the unit in screen space. var panel := PanelContainer.new() - panel.position = Vector2(12, 420) var vbox := VBoxContainer.new() vbox.add_theme_constant_override("separation", 4) + vbox.custom_minimum_size = Vector2(160, 0) var title := Label.new() title.text = "Abilities" @@ -1216,14 +1228,6 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void: vbox.add_child(title) vbox.add_child(HSeparator.new()) - # Wrap buttons in a ScrollContainer in case there are many. - var scroll := ScrollContainer.new() - scroll.custom_minimum_size = Vector2(180, 0) - scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED - var btn_vbox := VBoxContainer.new() - btn_vbox.add_theme_constant_override("separation", 4) - btn_vbox.size_flags_horizontal = Control.SIZE_EXPAND_FILL - for ab: Dictionary in actives: var btn := Button.new() btn.text = ab.get("name", "") @@ -1238,14 +1242,20 @@ func _show_ability_panel(unit_id: String, unit: Dictionary) -> void: _ability_targets = [] _ability_cur_action_idx = 0 _start_ability_targeting()) - btn_vbox.add_child(btn) + vbox.add_child(btn) - scroll.add_child(btn_vbox) - vbox.add_child(scroll) panel.add_child(vbox) _hud.add_child(panel) _ability_panel = panel + # Position panel to the right of the unit after one layout frame so size is known. + var body := _unit_bodies.get(unit_id) as StaticBody3D + if is_instance_valid(body): + var screen_pos := _camera.unproject_position(body.global_position) + panel.set_deferred("position", _clamp_panel_pos(screen_pos + Vector2(36, -40), panel)) + else: + panel.position = Vector2(12, 420) + func _hide_ability_panel() -> void: if is_instance_valid(_ability_panel):