diff --git a/runtime/entry/entry_shell.gd b/runtime/entry/entry_shell.gd index 0f8e6620..66d59789 100644 --- a/runtime/entry/entry_shell.gd +++ b/runtime/entry/entry_shell.gd @@ -2033,11 +2033,21 @@ func open_contract_return_review() -> void: show_title() return var contract: Dictionary = loaded.company.get("active_contract", {}) - if contract.is_empty() or String(contract.get("status", "")) != "market": - contract_return_notice = _tr("当前委托已不在可返回的 Market 阶段。", "The current Contract is no longer in a returnable Market phase.") - show_market(loaded.company) + var return_state: Dictionary = market_page_controller.return_command_state(contract) + if not bool(return_state.get("enabled", false)): + var reason := String(return_state.get("reason", "market_required")) + var code := "CONTRACT_RETURN_FORMATION_LOCKED" if reason == "formation_locked" else "CONTRACT_RETURN_MARKET_REQUIRED" + var notice := _contract_return_error_text(code) + contract_return_notice = "" + if String(contract.get("status", "")) == "market": + market_notice = notice + show_market(loaded.company) + else: + guild_notice = notice + show_guild_handoff(loaded.company) return guild_company = loaded.company.duplicate(true) + market_notice = "" current_screen = "contract_return_review" _build_world_base() var frame_safe := _framed_page_safe("ContractReturnReview") @@ -2120,7 +2130,7 @@ func open_contract_return_review() -> void: confirm.custom_minimum_size = Vector2(170 if size.y < 500.0 else 190, footer.custom_minimum_size.y) confirm.tooltip_text = _tr("保留全部 Company 成长并返回公会", "Retain all Company growth and return to Guild") footer.add_child(confirm) - confirm.call_deferred("grab_focus") + cancel.call_deferred("grab_focus") func cancel_contract_return() -> void: @@ -2291,6 +2301,7 @@ func _on_market_view_intent(intent_id: String, payload: Dictionary) -> void: "recruit_review": open_recruit_review() "equipment_review": open_equipment_review() "route": show_market(guild_company) + "return_contract": open_contract_return_review() "back": back_to_guild() "settings": _market_open_settings() diff --git a/runtime/entry/market_page_controller.gd b/runtime/entry/market_page_controller.gd index 9a8bb2fc..2c8542ff 100644 --- a/runtime/entry/market_page_controller.gd +++ b/runtime/entry/market_page_controller.gd @@ -35,6 +35,7 @@ func snapshot( if selected_offer.is_empty(): selected_kind = "" selected_offer_id = "" + var return_command := return_command_state(contract) var offers := { "recruit": _copy_array(contract.market_board.get("recruit_offers", [])), "equipment": _copy_array(contract.market_board.get("equipment_offers", [])), @@ -76,6 +77,11 @@ func snapshot( "market_index": int(contract.get("market_index", 0)), "board_hash": String(contract.get("market_board", {}).get("board_hash", "")), }, + "commands": { + "return_contract": return_command.duplicate(true), + "return_contract_enabled": bool(return_command.get("enabled", false)), + "return_contract_reason": String(return_command.get("reason", "market_required")), + }, "review": review_state(selected_kind, selected_offer), "locale": String(locale), "content": catalog, @@ -129,6 +135,18 @@ func review_state(kind: String, offer: Dictionary) -> Dictionary: return {"available": false, "action": "none", "reason": "battle_inspect_only"} +func return_command_state(contract: Dictionary) -> Dictionary: + var status := String(contract.get("status", "")) + if status != "market": + return {"enabled": false, "reason": "market_required"} + # GuildContractService treats the presence of Formation as a lock, even when + # an older save happens to contain an empty placeholder dictionary. Mirror + # that boundary here so the View never presents a command that will no-op. + if contract.has("formation"): + return {"enabled": false, "reason": "formation_locked"} + return {"enabled": true, "reason": "ready"} + + func offer_title(kind: String, offer: Dictionary, locale: String, content: Dictionary) -> String: match kind: "recruit": diff --git a/runtime/entry/views/market_page_view.gd b/runtime/entry/views/market_page_view.gd index 680517bc..6a60ff94 100644 --- a/runtime/entry/views/market_page_view.gd +++ b/runtime/entry/views/market_page_view.gd @@ -73,6 +73,13 @@ func _build_overlay(data: Dictionary) -> void: var selected_offer_id := String(page_data.get("selected_offer_id", "")) var company_facts: Dictionary = Dictionary(page_data.get("company", {})) var contract_facts: Dictionary = Dictionary(page_data.get("contract", {})) + var command_facts: Dictionary = Dictionary(page_data.get("commands", {})) + var return_command_facts: Dictionary = Dictionary(command_facts.get("return_contract", {})) + if return_command_facts.is_empty(): + return_command_facts = { + "enabled": bool(command_facts.get("return_contract_enabled", false)), + "reason": String(command_facts.get("return_contract_reason", "market_required")), + } var offers: Dictionary = Dictionary(page_data.get("offers", {})) var recruit_offers: Array = Array(offers.get("recruit", [])) var equipment_offers: Array = Array(offers.get("equipment", [])) @@ -188,6 +195,45 @@ func _build_overlay(data: Dictionary) -> void: _market_label(back, "ButtonLabel", Rect2(0.05, 0.18, 0.90, 0.64), _tr("返回公会", "BACK TO GUILD", page_data), 6, Color("#fff4d2"), HORIZONTAL_ALIGNMENT_CENTER) overlay.add_child(back) + var return_enabled := bool(return_command_facts.get("enabled", false)) + var return_reason := String(return_command_facts.get("reason", "market_required")) + var return_tooltip := _return_contract_tooltip(return_reason, page_data) + # This is a field-attached exit command, not another offer card. Keep it in + # the open lower-right socket of the approved SHP-001 master and give it a + # distinct warning treatment so it cannot be mistaken for inspection. + var return_contract := _market_hit_button( + "MarketReturnContract", + Rect2(0.665, 0.82, 0.115, 0.16), + "return_contract", + {}, + return_tooltip, + not return_enabled + ) + return_contract.z_index = 40 + return_contract.custom_minimum_size = Vector2(0, 44) + return_contract.set_meta("market_command_role", "contract_return") + return_contract.set_meta("disabled_reason", return_reason) + var return_style := _flat_style( + Color("#7b3c32", 0.90) if return_enabled else Color("#5a5550", 0.64), + Color("#efc875", 0.96) if return_enabled else Color("#8c8880", 0.58), + 2, + 6 + ) + return_contract.add_theme_stylebox_override("normal", return_style) + return_contract.add_theme_stylebox_override("disabled", return_style) + return_contract.add_theme_stylebox_override("hover", _flat_style(Color("#a04c3c", 0.94), Color("#f3d991", 1.0), 2, 6) if return_enabled else return_style) + var return_label := _market_label( + return_contract, + "ButtonLabel", + Rect2(0.04, 0.10, 0.92, 0.80), + _tr("返回委托", "RETURN CONTRACT", page_data), + 5, + Color("#fff0d0") if return_enabled else Color("#b7b1a6"), + HORIZONTAL_ALIGNMENT_CENTER + ) + return_label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + overlay.add_child(return_contract) + var settings_button := _market_hit_button("MarketSettings", Rect2(0.90, 0.00, 0.10, 0.14), "settings", {}, _tr("打开设置", "Open settings", page_data)) settings_button.z_index = 40 _market_label(settings_button, "ButtonLabel", Rect2(0.10, 0.12, 0.80, 0.76), "⚙", 11, Color("#3b3125"), HORIZONTAL_ALIGNMENT_CENTER) @@ -207,6 +253,7 @@ func _build_overlay(data: Dictionary) -> void: review_focus = overlay.find_child("MarketReviewEquipment", true, false) as Control if review_focus != null: focus_nodes.append(review_focus) + focus_nodes.append(return_contract) focus_nodes.append(back) var compact_focus: Array[Control] = [] for node in focus_nodes: @@ -475,5 +522,14 @@ func _flat_style(background: Color, border: Color, width: int, radius: int) -> S return style +func _return_contract_tooltip(reason: String, data: Dictionary) -> String: + match reason: + "formation_locked": + return _tr("队列已锁定;请先返回未准备的 Market。", "The Line is locked; return to an unprepared Market first.", data) + "market_required": + return _tr("主动返回只在 Market 阶段可用。", "Voluntary return is only available during Market.", data) + return _tr("主动结束当前委托;金币、成员、等级、装备与历史均保留。", "Voluntarily leave this Contract; Coin, members, levels, equipment and history are retained.", data) + + func _tr(zh: String, en: String, data: Dictionary = view_data) -> String: return zh if page_locale(data) == "zh_CN" else en diff --git a/runtime/tests/dev6/contract_return_test.gd b/runtime/tests/dev6/contract_return_test.gd index a496526d..425865df 100644 --- a/runtime/tests/dev6/contract_return_test.gd +++ b/runtime/tests/dev6/contract_return_test.gd @@ -88,6 +88,7 @@ func verify_contract_return(company: Dictionary) -> void: expect(return_button != null and not return_button.disabled, "Market exposes a real Contract Return action") await _touch(return_button) expect(shell.current_screen == "contract_return_review" and shell.find_child("ContractReturnWarning", true, false) != null, "Contract Return review explicitly distinguishes voluntary withdrawal") + expect(shell.get_viewport().gui_get_focus_owner() == shell.find_child("ContractReturnCancel", true, false), "Contract Return review defaults focus to Cancel") await _touch(shell.find_child("ContractReturnConfirm", true, false)) await _frames(3) expect(shell.current_screen == "guild_handoff" and shell.find_child("GuildRosterButton", true, false) != null, "Confirmed Contract Return reaches Guild") diff --git a/runtime/tests/foundation/market_page_controller_test.gd b/runtime/tests/foundation/market_page_controller_test.gd index ec6979be..c81fa6b3 100644 --- a/runtime/tests/foundation/market_page_controller_test.gd +++ b/runtime/tests/foundation/market_page_controller_test.gd @@ -20,6 +20,7 @@ func run_test() -> void: expect(snapshot.company.owned_count == 2 and snapshot.company.coin == 38, "snapshot exposes copied Company and Coin facts") expect(snapshot.categories.size() == 3 and snapshot.categories[1].available_count == 2, "snapshot exposes all Market categories and available counts") expect(snapshot.review.action == "recruit_review" and snapshot.review.available, "Recruit selection exposes its review boundary") + expect(snapshot.commands.return_contract.enabled and snapshot.commands.return_contract.reason == "ready", "Market exposes an enabled Contract Return command before formation") var selected: Dictionary = controller.select_offer(company, "equipment", "e-001") expect(selected.ok and selected.review.action == "equipment_review", "Equipment selection exposes its review boundary") @@ -31,6 +32,10 @@ func run_test() -> void: var copied: Dictionary = snapshot.offers.recruit[0] copied.display_name_tokens[0] = "changed" expect(company.active_contract.market_board.recruit_offers[0].display_name_tokens[0] == "name.ari", "view data is isolated from Company input") + var locked := company.duplicate(true) + locked.active_contract.formation = {"status": "draft"} + var locked_snapshot: Dictionary = controller.snapshot(locked, "recruit", "", "", "zh_CN", content) + expect(not locked_snapshot.commands.return_contract.enabled and locked_snapshot.commands.return_contract.reason == "formation_locked", "Market disables Contract Return when Formation exists") if failures.is_empty(): print("ABG_M17_MARKET_CONTROLLER_OK snapshot=true categories=3 selection=true missing=true review=recruit,equipment,battle_inspect_only copies=true") quit(0) diff --git a/runtime/tests/foundation/market_page_view_test.gd b/runtime/tests/foundation/market_page_view_test.gd index 66b2e919..dfe0f86f 100644 --- a/runtime/tests/foundation/market_page_view_test.gd +++ b/runtime/tests/foundation/market_page_view_test.gd @@ -33,12 +33,13 @@ func run_test() -> void: expect(view.find_child("MarketStaticMaster", true, false) != null, "View owns SHP-001 static master") expect(view.find_child("MarketLayout", true, false) != null, "MarketLayout identity is retained") expect(view.find_child("MarketOfferList", true, false).get_child_count() == 3, "three Recruit offers are rendered") - for node_name in ["MarketCompanyStatus", "MarketCoinStatus", "MarketCategoryEquipment", "MarketCategoryBattle", "MarketContextSurface", "MarketReviewRecruit", "MarketBackGuild", "MarketSettings"]: + for node_name in ["MarketCompanyStatus", "MarketCoinStatus", "MarketCategoryEquipment", "MarketCategoryBattle", "MarketContextSurface", "MarketReviewRecruit", "MarketBackGuild", "MarketReturnContract", "MarketSettings"]: expect(view.find_child(node_name, true, false) != null, "%s is rendered" % node_name) var selected := view.find_child("MarketOfferR-001", true, false) as Button var equipment_mode := view.find_child("MarketCategoryEquipment", true, false) as Button var review := view.find_child("MarketReviewRecruit", true, false) as Button var back := view.find_child("MarketBackGuild", true, false) as Button + var return_contract := view.find_child("MarketReturnContract", true, false) as Button var settings := view.find_child("MarketSettings", true, false) as Button if selected != null: selected.emit_signal("pressed") @@ -52,18 +53,25 @@ func run_test() -> void: if back != null: back.emit_signal("pressed") await process_frame + if return_contract != null: + return_contract.emit_signal("pressed") + await process_frame if settings != null: settings.emit_signal("pressed") await process_frame - expect(intents.size() == 5, "View emits five explicit Market intents") - if intents.size() == 5: + expect(intents.size() == 6, "View emits six explicit Market intents") + if intents.size() == 6: expect(intents[0].get("intent_id") == "select_offer", "selection intent is named") expect(intents[0].get("payload", {}).get("kind") == "recruit", "selection carries kind") expect(intents[1].get("intent_id") == "category", "category intent is named") expect(intents[1].get("payload", {}).get("category") == "equipment", "category carries target") expect(intents[2].get("intent_id") == "recruit_review", "Recruit review intent is named") expect(intents[3].get("intent_id") == "back", "Back intent is named") - expect(intents[4].get("intent_id") == "settings", "Settings intent is named") + expect(intents[4].get("intent_id") == "return_contract", "Contract Return intent is named") + expect(intents[5].get("intent_id") == "settings", "Settings intent is named") + expect(return_contract != null and not return_contract.disabled and return_contract.get_meta("market_command_role", "") == "contract_return", "Contract Return is enabled and role-labelled") + if return_contract != null: + expect(return_contract.get_global_rect().size.y >= 44.0, "Contract Return hit area meets the 44px minimum") view.render({"ok": false, "locale": "en", "notice": "Market unavailable"}) await process_frame @@ -77,7 +85,7 @@ func run_test() -> void: view.queue_free() await process_frame if failures.is_empty(): - print("ABG_M41_MARKET_VIEW_CONTRACT_OK mount=true normalized_canvas=true static_master=true layout=true offers=3 categories=3 context=true commands=review,back,settings intents=select_offer,category,recruit_review,back,settings invalid=true forbidden_imports=true") + print("ABG_M41_MARKET_VIEW_CONTRACT_OK mount=true normalized_canvas=true static_master=true layout=true offers=3 categories=3 context=true commands=review,back,return,settings intents=select_offer,category,recruit_review,back,return_contract,settings invalid=true forbidden_imports=true") quit(0) else: for failure in failures: @@ -106,6 +114,7 @@ func _fixture_view_data() -> Dictionary: "available": {"recruit": ["R-001", "R-002", "R-003"], "equipment": ["E-001"], "battle": ["B-001"]}, "company": {"company_id": "company-001", "owned_count": 2, "line_capacity": 4, "coin": 38}, "contract": {"contract_id": "CTR-R1-01", "run_id": "run-001", "status": "market", "board_hash": "board-001"}, + "commands": {"return_contract": {"enabled": true, "reason": "ready"}}, "content": {}, }