From 0171a7fb35fc619337d3ebe7aa704a428e290294 Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Tue, 25 Aug 2026 19:05:47 +0800 Subject: [PATCH] feat(runtime): route knockout review through controller --- runtime/entry/entry_shell.gd | 69 +++++++++++++++++++----- runtime/tests/dev5/battle_result_test.gd | 2 + 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/runtime/entry/entry_shell.gd b/runtime/entry/entry_shell.gd index 6f0396ac..451df780 100644 --- a/runtime/entry/entry_shell.gd +++ b/runtime/entry/entry_shell.gd @@ -20,6 +20,7 @@ const RiskCommitmentPageControllerScript = preload("res://entry/risk_commitment_ const BattleOpeningPageControllerScript = preload("res://entry/battle_opening_page_controller.gd") const BattleLivePageControllerScript = preload("res://entry/battle_live_page_controller.gd") const BattleResultPageControllerScript = preload("res://entry/battle_result_page_controller.gd") +const KnockoutReviewPageControllerScript = preload("res://entry/knockout_review_page_controller.gd") const MarketPageControllerScript = preload("res://entry/market_page_controller.gd") const RecruitReviewPageControllerScript = preload("res://entry/recruit_review_page_controller.gd") const ContractChoicePageControllerScript = preload("res://entry/contract_choice_page_controller.gd") @@ -123,6 +124,7 @@ var risk_commitment_page_controller := RiskCommitmentPageControllerScript.new() var battle_opening_page_controller := BattleOpeningPageControllerScript.new() var battle_live_page_controller := BattleLivePageControllerScript.new() var battle_result_page_controller := BattleResultPageControllerScript.new() +var knockout_review_page_controller := KnockoutReviewPageControllerScript.new() var market_page_controller := MarketPageControllerScript.new() var recruit_review_page_controller := RecruitReviewPageControllerScript.new() var contract_choice_page_controller := ContractChoicePageControllerScript.new() @@ -206,6 +208,7 @@ var battle_playback_generation := 0 var battle_playback_timer: Timer var battle_result_diagnosis_open := false var battle_result_notice := "" +var battle_knockout_notice := "" var battle_reward_selected_id := "" var battle_reward_notice := "" var battle_opening_mode := false @@ -225,6 +228,7 @@ var battle_live_interruption: Dictionary = {} var battle_pause_log_open := false var battle_live_view_data: Dictionary = {} var battle_result_view_data: Dictionary = {} +var battle_knockout_view_data: Dictionary = {} var battle_live_rendering := false var battle_live_render_requested := false var title_master_design_canvas: Control @@ -276,6 +280,7 @@ func _ready() -> void: app_services.register_service(&"battle_opening_page_controller", battle_opening_page_controller) app_services.register_service(&"battle_live_page_controller", battle_live_page_controller) app_services.register_service(&"battle_result_page_controller", battle_result_page_controller) + app_services.register_service(&"knockout_review_page_controller", knockout_review_page_controller) app_services.register_service(&"market_page_controller", market_page_controller) app_services.register_service(&"recruit_review_page_controller", recruit_review_page_controller) app_services.register_service(&"contract_choice_page_controller", contract_choice_page_controller) @@ -6541,6 +6546,26 @@ func show_battle_knockout_review(company := {}) -> void: var frame_safe := _framed_page_safe("BattleKnockout") frame_safe.add_child(_entry_chrome("BattleKnockoutFrame", "initial_company_scene_frame")) var safe := _content_page_safe("BattleKnockout") + var battle: Dictionary = resolved.active_contract.get("battle_state", {}) + battle_knockout_notice = "" + var view_data := _refresh_battle_knockout_view_data(resolved, battle) + if view_data.is_empty(): + var invalid := VBoxContainer.new() + invalid.name = "BattleKnockoutInvalid" + invalid.set_anchors_and_offsets_preset(Control.PRESET_CENTER) + invalid.custom_minimum_size = Vector2(420, 120) + invalid.add_theme_constant_override("separation", 8) + safe.add_child(invalid) + var invalid_title := _label(_tr("击倒回顾不可用", "KNOCKOUT REVIEW UNAVAILABLE"), _scaled(20), Color("#f5ead0")) + invalid_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + invalid.add_child(invalid_title) + var invalid_detail := _label(battle_knockout_notice, _scaled(11), Color("#ffd4d4")) + invalid_detail.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + invalid_detail.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + invalid.add_child(invalid_detail) + return + var knockouts: Dictionary = Dictionary(view_data.get("knockouts", {})) + var identities: Array = knockouts.get("identities", []) var layout := VBoxContainer.new() layout.name = "BattleKnockoutLayout" layout.add_theme_constant_override("separation", 5) @@ -6567,16 +6592,16 @@ func show_battle_knockout_review(company := {}) -> void: scene.size_flags_stretch_ratio = 1.2 scene.add_theme_constant_override("separation", 3) body.add_child(scene) - var battle: Dictionary = resolved.active_contract.get("battle_state", {}) - var knocked: Array = battle.get("result", {}).get("knocked_out_ids", []) - if knocked.is_empty(): + if identities.is_empty(): scene.add_child(_label(_tr("本场没有击倒成员。", "No Recruit was knocked out in this battle."), _scaled(15), Color("#9ed7aa"))) else: - for recruit_id in knocked: - var recruit := _recruit_by_id(resolved, String(recruit_id)) + for identity in identities: + if not identity is Dictionary: + continue + var recruit: Dictionary = Dictionary(identity.get("recruit", {})) if recruit.is_empty(): continue - scene.add_child(_readiness_member(0, recruit)) + scene.add_child(_readiness_member(maxi(0, int(identity.get("position", 0))), recruit)) scene.add_child(_label(_tr("%s · %s", "%s · %s") % [_recruit_name(recruit), _recruit_profession_name(recruit)], _scaled(16), Color("#f0ca75"))) scene.add_child(_label(_tr("特质:%s\n等级 %d · XP %d\n装备:%s", "Trait: %s\nLevel %d · XP %d\nEquipment: %s") % [_recruit_trait_name(recruit), int(recruit.level), int(recruit.xp), _recruit_item_name(recruit)], _scaled(11), Color("#f5ead0"))) var context := VBoxContainer.new() @@ -6607,18 +6632,38 @@ func show_battle_knockout_review(company := {}) -> void: var acknowledge := _company_button("BattleKnockoutAcknowledge", _tr("确认击倒", "Acknowledge"), acknowledge_battle_knockout.bind(resolved), "company_primary", "confirm") acknowledge.custom_minimum_size = Vector2(230, footer.custom_minimum_size.y) acknowledge.tooltip_text = _tr("确认已提交的战斗内后果;不会删除成员", "Acknowledge the committed battle-local consequence; the member is not deleted") + acknowledge.disabled = not bool(Dictionary(view_data.get("acknowledgement", {})).get("eligible", false)) footer.add_child(acknowledge) back.call_deferred("grab_focus") +func _refresh_battle_knockout_view_data(company: Dictionary, battle: Dictionary) -> Dictionary: + var snapshot: Dictionary = knockout_review_page_controller.snapshot( + company, + battle, + Dictionary(battle.get("result", {})), + battle_knockout_notice, + String(settings.get("locale", "zh_CN")) + ) + if not bool(snapshot.get("ok", false)): + battle_knockout_view_data = {} + battle_knockout_notice = _battle_error_text(String(snapshot.get("code", "KNOCKOUT_RESULT_REQUIRED"))) + return {} + battle_knockout_view_data = snapshot + return snapshot + + func acknowledge_battle_knockout(company := {}) -> void: var resolved: Dictionary = Dictionary(company).duplicate(true) if company is Dictionary else guild_company.duplicate(true) - var battle: Dictionary = resolved.get("active_contract", {}).get("battle_state", {}) - var reward_draft: Dictionary = battle.get("reward_draft", {}) - if not reward_draft.is_empty() and String(reward_draft.get("status", "open")) == "open": - show_battle_reward_choice(resolved) - else: - show_battle_recovery(resolved) + var view_data: Dictionary = battle_knockout_view_data + if view_data.is_empty(): + var battle: Dictionary = resolved.get("active_contract", {}).get("battle_state", {}) + view_data = _refresh_battle_knockout_view_data(resolved, battle) + if view_data.is_empty() or not bool(Dictionary(view_data.get("acknowledgement", {})).get("eligible", false)): + return + match String(Dictionary(view_data.get("acknowledgement", {})).get("target", "")): + "battle_reward_choice": show_battle_reward_choice(resolved) + "battle_recovery": show_battle_recovery(resolved) func show_battle_reward_choice(company := {}) -> void: diff --git a/runtime/tests/dev5/battle_result_test.gd b/runtime/tests/dev5/battle_result_test.gd index 467614f2..87516f65 100644 --- a/runtime/tests/dev5/battle_result_test.gd +++ b/runtime/tests/dev5/battle_result_test.gd @@ -100,6 +100,8 @@ func verify_result_ui(company: Dictionary, locale: String) -> void: var continue_target := shell.find_child("BattleResultContinue", true, false) as Button await _touch(continue_target) expect(shell.current_screen == "battle_knockout_review" and shell.find_child("BattleKnockoutCurrentGap", true, false) != null, "%s Continue reaches knockout review with the current battle gap" % locale) + expect(shell.app_services.has_service(&"knockout_review_page_controller") and shell.battle_knockout_view_data.ok, "%s Knockout Review crosses the explicit Controller/AppServices boundary" % locale) + expect(shell.battle_knockout_view_data.knockouts.ids == [String(shell.guild_company.active_contract.battle_state.result.knocked_out_ids[0])] and shell.battle_knockout_view_data.acknowledgement.target == "battle_recovery", "%s Knockout Review consumes controller identity and acknowledgement facts" % locale) var acknowledge := shell.find_child("BattleKnockoutAcknowledge", true, false) as Button expect(acknowledge != null and not acknowledge.disabled, "%s knockout review exposes an acknowledge action" % locale) await _touch(acknowledge)