diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index cedb1b6..2230d98 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 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. 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 a40b544..4ff241b 100644 --- a/scripts/scenes/battle_scene.gd +++ b/scripts/scenes/battle_scene.gd @@ -5212,8 +5212,8 @@ func _board_scroll_offset_for_cell_focus(cell: Vector2i, force_center := false) return _clamped_board_scroll_offset(next_offset) -func _focus_board_on_cell(cell: Vector2i, force_center := false) -> bool: - if not battle_started or not state.is_inside(cell): +func _focus_board_on_cell(cell: Vector2i, force_center := false, allow_prebattle := false) -> bool: + if (not battle_started and not allow_prebattle) or not state.is_inside(cell): return false var previous_offset := board_scroll_offset board_scroll_offset = _board_scroll_offset_for_cell_focus(cell, force_center) @@ -5228,6 +5228,40 @@ func _focus_board_on_cell(cell: Vector2i, force_center := false) -> bool: return true +func _player_deployment_focus_cell() -> Vector2i: + var units := state.get_controllable_player_units() + if units.is_empty(): + units = state.get_living_units(BattleState.TEAM_PLAYER) + if units.is_empty(): + return Vector2i(-1, -1) + var min_x := state.map_size.x + var min_y := state.map_size.y + var max_x := 0 + var max_y := 0 + for unit in units: + var cell: Vector2i = unit.get("pos", Vector2i(-1, -1)) + if not state.is_inside(cell): + continue + min_x = mini(min_x, cell.x) + min_y = mini(min_y, cell.y) + max_x = maxi(max_x, cell.x) + max_y = maxi(max_y, cell.y) + if min_x > max_x or min_y > max_y: + return Vector2i(-1, -1) + return Vector2i(clampi(int(round(float(min_x + max_x) * 0.5)), 0, state.map_size.x - 1), clampi(int(round(float(min_y + max_y) * 0.5)), 0, state.map_size.y - 1)) + + +func _focus_board_on_player_deployment(force_center := false) -> bool: + return _focus_board_on_cell(_player_deployment_focus_cell(), force_center) + + +func _focus_board_on_formation_unit(force_center := false) -> bool: + var unit := state.get_unit(formation_unit_id) + if unit.is_empty(): + return false + return _focus_board_on_cell(unit.get("pos", Vector2i(-1, -1)), force_center, true) + + func _activate_presentation_focus_if_ready(entry: Dictionary) -> void: if bool(entry.get("focused", false)): return @@ -7375,8 +7409,10 @@ func _start_battle_from_briefing() -> void: _hide_save_menu() _clear_pending_move_state() state.run_battle_begin_events() + _focus_board_on_player_deployment(true) _show_next_dialogue() _update_hud() + queue_redraw() func _on_chapter_pressed() -> void: @@ -7937,6 +7973,7 @@ func _on_formation_pressed() -> void: _hide_save_menu() _rebuild_formation_menu() formation_menu.visible = true + _focus_board_on_formation_unit(true) _update_hud() queue_redraw() @@ -8216,6 +8253,7 @@ func _on_formation_unit_pressed(unit_id: String) -> void: _play_ui_click() formation_unit_id = unit_id _rebuild_formation_menu() + _focus_board_on_formation_unit(true) _update_hud() queue_redraw() @@ -8229,6 +8267,7 @@ func _handle_formation_board_click(screen_position: Vector2) -> void: if state.try_set_prebattle_formation(formation_unit_id, cell): _play_ui_confirm() _rebuild_formation_menu() + _focus_board_on_formation_unit() _update_hud() queue_redraw() diff --git a/tools/smoke_chapter_one_polish.gd b/tools/smoke_chapter_one_polish.gd index d1ca4b1..0449ff4 100644 --- a/tools/smoke_chapter_one_polish.gd +++ b/tools/smoke_chapter_one_polish.gd @@ -334,7 +334,10 @@ func _check_map_focus_contract(failures: Array[String]) -> void: scene.battle_started = true for method_name in [ "_board_scroll_offset_for_cell_focus", - "_focus_board_on_cell" + "_focus_board_on_cell", + "_player_deployment_focus_cell", + "_focus_board_on_player_deployment", + "_focus_board_on_formation_unit" ]: if not scene.has_method(method_name): failures.append("missing map focus helper: %s" % method_name) @@ -372,6 +375,37 @@ func _check_map_focus_contract(failures: Array[String]) -> void: failures.append("map focus action should report movement for an off-screen cell") if scene.board_scroll_offset.distance_squared_to(far_offset) > 0.01: failures.append("map focus action should apply the calculated offset: %s vs %s" % [str(scene.board_scroll_offset), str(far_offset)]) + + for unit in scene.state.get_controllable_player_units(): + var unit_id := str(unit.get("id", "")) + if unit_id == "cao_cao": + unit["pos"] = Vector2i(scene.state.map_size.x - 2, scene.state.map_size.y - 2) + elif unit_id == "xiahou_dun": + unit["pos"] = Vector2i(scene.state.map_size.x - 1, scene.state.map_size.y - 1) + else: + unit["pos"] = Vector2i(scene.state.map_size.x - 3, scene.state.map_size.y - 2) + scene.board_scroll_offset = Vector2.ZERO + var deployment_focus_cell: Vector2i = scene._player_deployment_focus_cell() + if not scene.state.is_inside(deployment_focus_cell): + failures.append("player deployment focus should produce an in-map cell: %s" % str(deployment_focus_cell)) + if not scene._focus_board_on_player_deployment(true): + failures.append("battle start deployment focus should move to far deployed units") + if scene.board_scroll_offset.x >= -0.01 or scene.board_scroll_offset.y >= -0.01: + failures.append("far deployment focus should scroll both axes on the opening large map: %s" % str(scene.board_scroll_offset)) + + scene.battle_started = false + scene.board_scroll_offset = Vector2.ZERO + if scene._focus_board_on_cell(far_cell, true): + failures.append("normal map focus should stay locked before battle start") + if not scene._focus_board_on_cell(far_cell, true, true): + failures.append("explicit prebattle map focus should support formation navigation") + + scene.formation_unit_id = "cao_cao" + scene.board_scroll_offset = Vector2.ZERO + if not scene._focus_board_on_formation_unit(true): + failures.append("formation unit focus should work before battle start") + if scene.board_scroll_offset.x >= -0.01 or scene.board_scroll_offset.y >= -0.01: + failures.append("formation unit focus should scroll to a far selected unit: %s" % str(scene.board_scroll_offset)) scene.free()