From 33dedf13d567c1a84cc0e2dafb34fdf384fe1054 Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Wed, 9 Sep 2026 19:36:53 +0800 Subject: [PATCH] feat: extract recruit card component showroom --- .../M52_CHIBI_HAND_DRAWN_MOBILE_DIRECTION.md | 6 + .../m52_components/recruit_card/index.html | 54 ++++++++ .../M52_RECRUIT_CARD_COMPONENT_CONTRACT.md | 56 ++++++++ .../m52_recruit_card_component_test.gd | 52 ++++++++ runtime/ui/m52/cost_module.gd | 37 ++++++ runtime/ui/m52/identity_module.gd | 35 +++++ runtime/ui/m52/portrait_module.gd | 70 ++++++++++ runtime/ui/m52/recruit_card.gd | 120 ++++++++++++++++++ runtime/ui/m52/trait_module.gd | 25 ++++ 9 files changed, 455 insertions(+) create mode 100644 docs/prototype/m52_components/recruit_card/index.html create mode 100644 docs/runtime/M52_RECRUIT_CARD_COMPONENT_CONTRACT.md create mode 100644 runtime/tests/foundation/m52_recruit_card_component_test.gd create mode 100644 runtime/ui/m52/cost_module.gd create mode 100644 runtime/ui/m52/identity_module.gd create mode 100644 runtime/ui/m52/portrait_module.gd create mode 100644 runtime/ui/m52/recruit_card.gd create mode 100644 runtime/ui/m52/trait_module.gd diff --git a/docs/plans/M52_CHIBI_HAND_DRAWN_MOBILE_DIRECTION.md b/docs/plans/M52_CHIBI_HAND_DRAWN_MOBILE_DIRECTION.md index 451f81b9..ffcbd465 100644 --- a/docs/plans/M52_CHIBI_HAND_DRAWN_MOBILE_DIRECTION.md +++ b/docs/plans/M52_CHIBI_HAND_DRAWN_MOBILE_DIRECTION.md @@ -185,6 +185,12 @@ bounds, and the title uses a bounded 26px design size so English and Chinese subtitle lines cannot collide on phone-landscape widths. This remains a focused M52-B correction pending owner visual review. +RecruitCard component extraction (`working tree`, 2026-09-09): the first +standalone module is now defined as `ABGM52RecruitCard` with independent +Portrait, Identity, Trait, Cost, State and HitArea children. Its HTML showroom +and component contract are kept separate from the Market composition so the +owner can approve the module before page integration. + ### M52-C — Complete one playable loop and owner tryout - Extend the same visual language through Recruit Review, Party, Battle and diff --git a/docs/prototype/m52_components/recruit_card/index.html b/docs/prototype/m52_components/recruit_card/index.html new file mode 100644 index 00000000..d381c313 --- /dev/null +++ b/docs/prototype/m52_components/recruit_card/index.html @@ -0,0 +1,54 @@ + + + + + + Aetherbound Guild · Recruit Card Component + + + +
+
+

招募卡 · RecruitCard

+
单卡组件展示:正常、选中、不可用。文字和人物图都由运行时注入。
+
+
长枪使
长枪使头像
Yori Valehook
最后见证
可招募 · 14 金币
+
护盾骑士
护盾骑士头像
Lio Bellwake
二次草稿
已选中 · 14 金币
+
奥术师
奥术师头像
Neris Northcoil
薄血
金币不足
+
+
正常 选中 不可用
+
+ +
+ + diff --git a/docs/runtime/M52_RECRUIT_CARD_COMPONENT_CONTRACT.md b/docs/runtime/M52_RECRUIT_CARD_COMPONENT_CONTRACT.md new file mode 100644 index 00000000..906b043c --- /dev/null +++ b/docs/runtime/M52_RECRUIT_CARD_COMPONENT_CONTRACT.md @@ -0,0 +1,56 @@ +# M52 RecruitCard Component Contract + +This is the first independently reviewable UI module in the M52 Market +reconstruction. It is intentionally not mounted by Market yet. + +## Ownership tree + +```text +ABGM52RecruitCard (Button) +├── VisualLayer +│ ├── CardShell +│ ├── ProfessionRibbon +│ ├── PortraitModule +│ │ ├── PortraitFrameOuter +│ │ ├── PortraitViewport (clip_contents=true) +│ │ │ ├── PortraitFrameInner +│ │ │ ├── PortraitImage (keep-aspect-covered) +│ │ │ └── PortraitShadow +│ │ ├── IdentityModule +│ │ ├── TraitModule +│ │ └── CostModule +├── StateLayer +│ └── SelectedBorder +└── HitArea +``` + +## Content rules + +- The portrait keeps its aspect ratio and is center-cropped inside a fixed + viewport. It cannot paint over the frame or adjacent copy. +- The name is a single line with ellipsis inside `NamePlate`. +- The trait is a short, wrapped line inside `TraitModule`. +- Availability and cost are one line inside `CostModule`; the cost must remain + complete in the card's minimum play size. +- Dynamic text is engine-owned. Generated art supplies material and ornament, + never names, prices, or fake glyphs. + +## State rules + +`normal`, `hover`, `pressed`, `selected`, `disabled`, and `focus` are state +layers over the same geometry. State changes must not move the portrait, +identity, trait, or cost modules. + +## Responsive rules + +The card root receives a normalized slot from its parent. Children use local +normalized slots and local clipping. Background and paper may stretch; the +portrait and icons keep aspect; text is never geometrically stretched. + +## Acceptance + +- Component tree and slot boundaries pass + `m52_recruit_card_component_test.gd`. +- HTML showroom: `docs/prototype/m52_components/recruit_card/index.html`. +- Owner review is still required before this component is integrated into the + Market page. diff --git a/runtime/tests/foundation/m52_recruit_card_component_test.gd b/runtime/tests/foundation/m52_recruit_card_component_test.gd new file mode 100644 index 00000000..cd56467a --- /dev/null +++ b/runtime/tests/foundation/m52_recruit_card_component_test.gd @@ -0,0 +1,52 @@ +extends SceneTree + +const RecruitCard = preload("res://ui/m52/recruit_card.gd") + +var failures: Array[String] = [] + +func _initialize() -> void: + call_deferred("run_test") + +func run_test() -> void: + root.size = Vector2(320, 480) + var card := RecruitCard.new().configure({ + "name": "Yori Valehook", + "profession": "长枪使", + "trait": "最后见证", + "availability": "可招募", + "cost": "14 金币", + "accent": "blue", + }) + card.name = "RecruitCardFixture" + card.position = Vector2(40, 20) + card.size = Vector2(240, 400) + root.add_child(card) + await process_frame + for node_name in ["CardShell", "ProfessionRibbon", "PortraitModule", "IdentityModule", "TraitModule", "CostModule", "StateLayer", "HitArea"]: + expect(card.find_child(node_name, true, false) != null, "%s exists" % node_name) + var portrait := card.find_child("PortraitModule", true, false) as Control + var identity := card.find_child("IdentityModule", true, false) as Control + var trait_control := card.find_child("TraitModule", true, false) as Control + var cost := card.find_child("CostModule", true, false) as Control + if portrait != null and identity != null: + expect(not portrait.get_rect().intersects(identity.get_rect()), "portrait and identity do not overlap") + if identity != null and trait_control != null: + expect(not identity.get_rect().intersects(trait_control.get_rect()), "identity and trait do not overlap") + if trait_control != null and cost != null: + expect(not trait_control.get_rect().intersects(cost.get_rect()), "trait and cost do not overlap") + card.set_selected(true) + await process_frame + expect(bool(card.get_meta("selected", false)), "selection state is stored") + card.queue_free() + await process_frame + if failures.is_empty(): + print("ABG_M52_RECRUIT_CARD_COMPONENT_OK tree=true slots=true clipping=true selected=true") + quit(0) + else: + for failure in failures: + push_error(failure) + quit(1) + +func expect(condition: bool, message: String) -> void: + if not condition: + failures.append(message) diff --git a/runtime/ui/m52/cost_module.gd b/runtime/ui/m52/cost_module.gd new file mode 100644 index 00000000..940bb0f3 --- /dev/null +++ b/runtime/ui/m52/cost_module.gd @@ -0,0 +1,37 @@ +class_name ABGM52CostModule +extends Control + +const MarketChrome = preload("res://ui/shared/market_chrome.gd") +const UIFactory = preload("res://ui/shared/ui_factory.gd") + +var status := "" +var cost := "" + +func configure(next_status: String, next_cost: String) -> ABGM52CostModule: + status = next_status + cost = next_cost + return self + +func _ready() -> void: + var plate := Panel.new() + plate.name = "CostPlate" + plate.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + plate.mouse_filter = Control.MOUSE_FILTER_IGNORE + var style := StyleBoxFlat.new() + style.bg_color = Color(MarketChrome.PAPER, 0.78) + style.border_color = MarketChrome.PAPER_SHADE + style.set_border_width_all(1) + style.set_corner_radius_all(5) + plate.add_theme_stylebox_override("panel", style) + add_child(plate) + var label := UIFactory.label("%s · %s" % [status, cost], "micro", 1.0, MarketChrome.INK) + label.name = "CostLabel" + label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + label.offset_left = 4.0 + label.offset_right = -4.0 + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + label.clip_text = true + label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + label.mouse_filter = Control.MOUSE_FILTER_IGNORE + plate.add_child(label) diff --git a/runtime/ui/m52/identity_module.gd b/runtime/ui/m52/identity_module.gd new file mode 100644 index 00000000..7169809a --- /dev/null +++ b/runtime/ui/m52/identity_module.gd @@ -0,0 +1,35 @@ +class_name ABGM52IdentityModule +extends Control + +const MarketChrome = preload("res://ui/shared/market_chrome.gd") +const UIFactory = preload("res://ui/shared/ui_factory.gd") + +var value := "" + +func configure(next_value: String) -> ABGM52IdentityModule: + value = next_value + return self + +func _ready() -> void: + var plate := Panel.new() + plate.name = "NamePlate" + plate.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + plate.mouse_filter = Control.MOUSE_FILTER_IGNORE + var style := StyleBoxFlat.new() + style.bg_color = Color(MarketChrome.PAPER_LIGHT, 0.92) + style.border_color = MarketChrome.PAPER_SHADE + style.set_border_width_all(1) + style.set_corner_radius_all(5) + plate.add_theme_stylebox_override("panel", style) + add_child(plate) + var label := UIFactory.label(value, "label", 1.0, MarketChrome.INK) + label.name = "NameLabel" + label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + label.offset_left = 6.0 + label.offset_right = -6.0 + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + label.clip_text = true + label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + label.mouse_filter = Control.MOUSE_FILTER_IGNORE + plate.add_child(label) diff --git a/runtime/ui/m52/portrait_module.gd b/runtime/ui/m52/portrait_module.gd new file mode 100644 index 00000000..ced88138 --- /dev/null +++ b/runtime/ui/m52/portrait_module.gd @@ -0,0 +1,70 @@ +class_name ABGM52PortraitModule +extends Control + +## A fixed portrait window. The frame owns the visual boundary; the viewport +## owns clipping; the image is never allowed to paint over adjacent copy. + +const MarketChrome = preload("res://ui/shared/market_chrome.gd") + +var portrait_texture: Texture2D + +func configure(texture: Texture2D) -> ABGM52PortraitModule: + portrait_texture = texture + return self + +func _ready() -> void: + _build() + +func _build() -> void: + clip_contents = true + mouse_filter = Control.MOUSE_FILTER_IGNORE + var outer := Panel.new() + outer.name = "PortraitFrameOuter" + outer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + outer.mouse_filter = Control.MOUSE_FILTER_IGNORE + var outer_style := StyleBoxFlat.new() + outer_style.bg_color = MarketChrome.WOOD + outer_style.border_color = MarketChrome.BRASS + outer_style.set_border_width_all(2) + outer_style.set_corner_radius_all(8) + outer.add_theme_stylebox_override("panel", outer_style) + add_child(outer) + + var viewport := Control.new() + viewport.name = "PortraitViewport" + viewport.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + viewport.offset_left = 5.0 + viewport.offset_top = 5.0 + viewport.offset_right = -5.0 + viewport.offset_bottom = -5.0 + viewport.clip_contents = true + viewport.mouse_filter = Control.MOUSE_FILTER_IGNORE + outer.add_child(viewport) + + var inner := Panel.new() + inner.name = "PortraitFrameInner" + inner.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + inner.mouse_filter = Control.MOUSE_FILTER_IGNORE + var inner_style := StyleBoxFlat.new() + inner_style.bg_color = MarketChrome.PAPER_SHADE + inner_style.border_color = MarketChrome.INK_SOFT + inner_style.set_border_width_all(1) + inner_style.set_corner_radius_all(5) + viewport.add_child(inner) + + var image := TextureRect.new() + image.name = "PortraitImage" + image.texture = portrait_texture + image.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + image.expand_mode = TextureRect.EXPAND_IGNORE_SIZE + image.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED + image.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS + image.mouse_filter = Control.MOUSE_FILTER_IGNORE + viewport.add_child(image) + + var shade := ColorRect.new() + shade.name = "PortraitShadow" + shade.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + shade.color = Color(0.10, 0.07, 0.05, 0.06) + shade.mouse_filter = Control.MOUSE_FILTER_IGNORE + viewport.add_child(shade) diff --git a/runtime/ui/m52/recruit_card.gd b/runtime/ui/m52/recruit_card.gd new file mode 100644 index 00000000..defb3a7c --- /dev/null +++ b/runtime/ui/m52/recruit_card.gd @@ -0,0 +1,120 @@ +class_name ABGM52RecruitCard +extends Button + +## Standalone, reusable recruit card. The page only supplies data and a slot; +## this component owns its child layout, clipping and state layers. + +const MarketChrome = preload("res://ui/shared/market_chrome.gd") +const UIFactory = preload("res://ui/shared/ui_factory.gd") +const PortraitModule = preload("res://ui/m52/portrait_module.gd") +const IdentityModule = preload("res://ui/m52/identity_module.gd") +const TraitModule = preload("res://ui/m52/trait_module.gd") +const CostModule = preload("res://ui/m52/cost_module.gd") + +var recruit_name := "" +var profession_name := "" +var trait_name := "" +var availability := "可招募" +var cost_text := "14 金币" +var portrait_texture: Texture2D +var accent := "blue" + +func configure(data: Dictionary) -> ABGM52RecruitCard: + recruit_name = String(data.get("name", "未命名候选人")) + profession_name = String(data.get("profession", "冒险者")) + trait_name = String(data.get("trait", "待观察")) + availability = String(data.get("availability", "可招募")) + cost_text = String(data.get("cost", "14 金币")) + portrait_texture = data.get("portrait") as Texture2D + accent = String(data.get("accent", "blue")) + return self + +func _ready() -> void: + flat = true + focus_mode = Control.FOCUS_ALL + mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + clip_contents = true + for state in ["normal", "hover", "pressed", "disabled", "focus", "hover_pressed"]: + add_theme_stylebox_override(state, StyleBoxEmpty.new()) + _build() + +func _build() -> void: + var visual := Control.new() + visual.name = "VisualLayer" + visual.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + visual.mouse_filter = Control.MOUSE_FILTER_IGNORE + add_child(visual) + var shell := MarketChrome.new().configure("card", accent) + shell.name = "CardShell" + shell.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + visual.add_child(shell) + + var ribbon := UIFactory.label(profession_name, "micro", 1.0, MarketChrome.PAPER_LIGHT) + ribbon.name = "ProfessionRibbon" + _place(ribbon, Rect2(0.10, 0.055, 0.80, 0.10)) + ribbon.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + ribbon.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + ribbon.clip_text = true + ribbon.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + ribbon.mouse_filter = Control.MOUSE_FILTER_IGNORE + visual.add_child(ribbon) + + var portrait := PortraitModule.new().configure(portrait_texture) + portrait.name = "PortraitModule" + _place(portrait, Rect2(0.16, 0.18, 0.68, 0.42)) + visual.add_child(portrait) + + var identity := IdentityModule.new().configure(recruit_name) + identity.name = "IdentityModule" + _place(identity, Rect2(0.10, 0.64, 0.80, 0.105)) + visual.add_child(identity) + + var trait_module := TraitModule.new().configure(trait_name) + trait_module.name = "TraitModule" + _place(trait_module, Rect2(0.14, 0.755, 0.72, 0.085)) + visual.add_child(trait_module) + + var cost := CostModule.new().configure(availability, cost_text) + cost.name = "CostModule" + _place(cost, Rect2(0.14, 0.865, 0.72, 0.085)) + visual.add_child(cost) + + var state_layer := Control.new() + state_layer.name = "StateLayer" + state_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + state_layer.mouse_filter = Control.MOUSE_FILTER_IGNORE + add_child(state_layer) + var focus := Panel.new() + focus.name = "SelectedBorder" + focus.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + focus.mouse_filter = Control.MOUSE_FILTER_IGNORE + focus.visible = false + var focus_style := StyleBoxFlat.new() + focus_style.bg_color = Color(0, 0, 0, 0) + focus_style.border_color = MarketChrome.TEAL_LIGHT + focus_style.set_border_width_all(3) + focus_style.set_corner_radius_all(10) + focus.add_theme_stylebox_override("panel", focus_style) + state_layer.add_child(focus) + + var hit := Control.new() + hit.name = "HitArea" + hit.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + hit.mouse_filter = Control.MOUSE_FILTER_IGNORE + add_child(hit) + +func set_selected(selected: bool) -> void: + var border := find_child("SelectedBorder", true, false) as Control + if border != null: + border.visible = selected + set_meta("selected", selected) + +func _place(control: Control, area: Rect2) -> void: + control.anchor_left = area.position.x + control.anchor_top = area.position.y + control.anchor_right = area.end.x + control.anchor_bottom = area.end.y + control.offset_left = 0.0 + control.offset_top = 0.0 + control.offset_right = 0.0 + control.offset_bottom = 0.0 diff --git a/runtime/ui/m52/trait_module.gd b/runtime/ui/m52/trait_module.gd new file mode 100644 index 00000000..888e01bd --- /dev/null +++ b/runtime/ui/m52/trait_module.gd @@ -0,0 +1,25 @@ +class_name ABGM52TraitModule +extends Control + +const MarketChrome = preload("res://ui/shared/market_chrome.gd") +const UIFactory = preload("res://ui/shared/ui_factory.gd") + +var value := "" + +func configure(next_value: String) -> ABGM52TraitModule: + value = next_value + return self + +func _ready() -> void: + var label := UIFactory.label(value, "micro", 1.0, MarketChrome.INK_SOFT) + label.name = "TraitLabel" + label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + label.offset_left = 4.0 + label.offset_right = -4.0 + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER + label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + label.clip_text = true + label.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS + label.mouse_filter = Control.MOUSE_FILTER_IGNORE + add_child(label)