From 761b7f729e820e1ce6ac51b5b35d25ba2eab918e Mon Sep 17 00:00:00 2001 From: Wickedness Date: Fri, 19 Jun 2026 20:26:05 +0900 Subject: [PATCH] Keep command panels attached while scrolling --- docs/ARCHITECTURE.md | 2 +- scripts/scenes/battle_scene.gd | 8 +++++- tools/smoke_post_move_action_flow.gd | 40 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2230d98..410c384 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -61,6 +61,6 @@ Inventory and campaign flags are copied from `CampaignState` into `BattleState` The battle scene owns presentation feedback: briefing and result states use menu BGM, briefing headers combine `CampaignState` chapter ranges, campaign order, and title data with `BattleState` briefing, objective text, condition-progress text, and defeat-risk text, active battles use battle BGM and show an objective/progress/risk panel fed by `BattleState`, objective-update signals show a short HUD notice and refresh the objective panel immediately, dialogue lines can show optional cached portrait textures or speaker-initial fallback panels in an expanded visual-novel-style panel, can place the portrait on the left or right side of that panel, and expose progress plus previous-line controls while a sequence is open, the side HUD reuses cached officer portrait textures or class sprites for the selected unit or hovered unit and formats focus text with role, movement type, facing, current terrain move cost, defense/avoid bonuses, core stats, status effects, guard-zone AI hints, and gear, board maps can draw a scenario background texture under translucent terrain overlays, connected road segments, terrain detail patterns, shoreline/castle/forest/hill edge blends, compact recovery markers for healing terrain, compact side-event markers for visible item/gold pickups, and move-attack target badges for enemies that can be struck after movement, board units render class sprite tokens or generic-enemy transparent class cutouts, team rings, class badges, facing markers, generic-enemy marks, officer pins, low-HP warning rings, HP bar color states, active support/debuff/poison/seal/snare/disarm status pips, and a scene-clocked idle stance whose intensity reacts to selected, acted, and low-HP unit state, item buttons can show optional cached item icons, hover previews are rendered as target badges from existing `BattleState` forecast APIs and include compact side/rear attack bonuses when facing matters, equipment option menus show stat/range/effect deltas, result and inventory summaries show named equipment with compact rarity tags, selected area tactics highlight their affected cells, the Threat toggle overlays enemy physical and hostile tactic reach while tile info names threat sources, estimates physical damage, and summarizes hostile tactic damage or status effects against occupied cells, log/result hooks trigger placeholder SFX, support, debuff, poison, seal, snare, disarm, objective updates, AI target-focus changes, and item/gold pickup effects use distinct feedback, `BattleState.unit_motion_requested` asks the scene to interpolate a unit's draw position during movement, `BattleState.unit_action_motion_requested` keeps its rules-facing signal shape while the scene maps attacker class ids to infantry, archer, cavalry, command, and heavy attack presentation profiles, and `BattleState.combat_feedback_requested` asks the scene to draw transient floating combat text without changing battle rules. -Large tactical maps are presented through a fixed visible map window rather than by shrinking the whole board, including the opening chapter-one battle. `BattleScene` keeps a clamped `board_scroll_offset`, scrolls the board while the mouse is near or slightly outside the visible map edge, brightens the scrollable frame edge under the cursor, ignores board clicks outside the visible map window, and draws a small minimap plate only when the board actually exceeds the visible map view; clicking or dragging the minimap recenters the tactical viewport, while compact maps keep the lower-right tiles unobstructed. Battle start focuses the board on the deployed player group, pre-battle Formation can focus the board on the selected unit even before the battle opens, and action feedback can focus the board on off-screen cells before motion or combat effects play. +Large tactical maps are presented through a fixed visible map window rather than by shrinking the whole board, including the opening chapter-one battle. `BattleScene` keeps a clamped `board_scroll_offset`, scrolls the board while the mouse is near or slightly outside the visible map edge, brightens the scrollable frame edge under the cursor, ignores board clicks outside the visible map window, and draws a small minimap plate only when the board actually exceeds the visible map view; clicking or dragging the minimap recenters the tactical viewport, while compact maps keep the lower-right tiles unobstructed. Board-attached command panels are repositioned after map scrolling so post-move choices stay beside the moved unit. Battle start focuses the board on the deployed player group, pre-battle Formation can focus the board on the selected unit even before the battle opens, and action feedback can focus the board on off-screen cells before motion or combat effects play. The `New Campaign` button clears `user://campaign_save.json`, resets campaign state to the first scenario, and reloads the opening briefing. diff --git a/scripts/scenes/battle_scene.gd b/scripts/scenes/battle_scene.gd index 4ff241b..7289420 100644 --- a/scripts/scenes/battle_scene.gd +++ b/scripts/scenes/battle_scene.gd @@ -5173,6 +5173,7 @@ func _scroll_board_to_minimap_position(screen_position: Vector2) -> bool: hover_cell = next_hover if status_label != null: _update_hud() + _refresh_board_attached_panels() queue_redraw() return previous_offset.distance_squared_to(board_scroll_offset) > 0.01 @@ -5219,13 +5220,17 @@ func _focus_board_on_cell(cell: Vector2i, force_center := false, allow_prebattle board_scroll_offset = _board_scroll_offset_for_cell_focus(cell, force_center) if previous_offset.distance_squared_to(board_scroll_offset) <= 0.01: return false + _refresh_board_attached_panels() + return true + + +func _refresh_board_attached_panels() -> void: if post_move_menu != null and post_move_menu.visible: _position_post_move_menu() if post_move_picker_panel != null and post_move_picker_panel.visible: _position_post_move_picker() if targeting_hint_panel != null and targeting_hint_panel.visible: _update_targeting_hint_panel() - return true func _player_deployment_focus_cell() -> Vector2i: @@ -5437,6 +5442,7 @@ func _update_edge_scroll(delta: float) -> bool: if next_hover != hover_cell: hover_cell = next_hover _update_hud() + _refresh_board_attached_panels() return true diff --git a/tools/smoke_post_move_action_flow.gd b/tools/smoke_post_move_action_flow.gd index c0249b4..78070c7 100644 --- a/tools/smoke_post_move_action_flow.gd +++ b/tools/smoke_post_move_action_flow.gd @@ -10,6 +10,7 @@ func _init() -> void: _check_scene_post_move_menu_flow(failures) _check_scene_post_move_edge_positioning(failures) _check_scene_post_move_scrolled_view_positioning(failures) + _check_scene_post_move_menu_tracks_map_scroll(failures) _check_scene_post_move_text_fit(failures) _check_scene_post_move_tactic_picker_flow(failures) _check_scene_post_move_item_picker_flow(failures) @@ -204,6 +205,45 @@ func _check_scene_post_move_scrolled_view_positioning(failures: Array[String]) - scene.free() +func _check_scene_post_move_menu_tracks_map_scroll(failures: Array[String]) -> void: + var scene = BattleSceneScript.new() + scene._create_hud() + if not scene.state.load_battle("res://data/scenarios/001_yellow_turbans.json"): + failures.append("could not load opening battle for scroll-tracking menu") + scene.free() + return + scene.battle_started = true + scene.campaign_complete_screen = false + scene.briefing_panel.visible = false + scene.result_panel.visible = false + scene._clear_pending_move_state() + + var pending_cell := Vector2i(10, 6) + var cao_cao: Dictionary = scene.state.get_unit("cao_cao") + cao_cao["pos"] = pending_cell + cao_cao["moved"] = true + cao_cao["acted"] = false + scene.state.select_unit("cao_cao") + scene.pending_move_unit_id = "cao_cao" + scene.pending_move_from_cell = Vector2i(9, 6) + scene.pending_move_to_cell = pending_cell + scene._show_post_move_menu() + if scene.post_move_menu == null or not scene.post_move_menu.visible: + failures.append("scroll-tracking post-move menu should be visible") + scene.free() + return + + scene.post_move_menu.position = Vector2(1.0, 1.0) + var map_rect: Rect2 = scene._minimap_map_rect() + if not scene._scroll_board_to_minimap_position(map_rect.end): + failures.append("minimap scroll should move the opening large map") + var expected_position: Vector2 = scene._local_command_panel_position_for_cell(pending_cell, scene.POST_MOVE_MENU_SIZE) + if scene.post_move_menu.position.distance_squared_to(expected_position) > 0.01: + failures.append("post-move menu should track board scroll: %s vs %s" % [str(scene.post_move_menu.position), str(expected_position)]) + _check_local_panel_position(failures, scene, scene.post_move_menu, pending_cell, "scroll-tracking post-move action menu") + scene.free() + + func _check_scene_post_move_text_fit(failures: Array[String]) -> void: var scene = BattleSceneScript.new() scene._create_hud()