This commit is contained in:
meishibiezb
2026-06-05 03:01:15 +08:00
parent 29a3f77908
commit a8bdf281ff
41 changed files with 1935 additions and 779 deletions

View File

@@ -1,10 +1,10 @@
# WBP_InventoryView
## 基本信息
- **类型**: Widget Blueprint (UserWidget)
- **类型**: WidgetBlueprint (UserWidget)
- **父类**: UserWidget
- **源文件**: /Game/Blueprints/UI/Item/WBP_InventoryView.WBP_InventoryView
- **模块**: Content
- **模块**: Content/Blueprints/UI/Item
## 功能概述
WBP_InventoryView 是物品列表显示 Widget持有 BP_InventoryComp 组件的引用,负责将库存中的物品视图列表渲染到 UI。通过 UpdateListItems 函数刷新列表显示,使用 WBP_ItemViewBox 作为单个物品视图框的子 Widget。
@@ -22,28 +22,45 @@ WBP_InventoryView 负责显示物品列表 UI、监听库存变化并自动刷
| FItemView | 显示数据 | Item 插件 |
| WBP_ItemViewBox | 子 Widget | /Game/Blueprints/UI/Item/WBP_ItemViewBox |
## 对外接口
- **蓝图函数**
- `UpdateListItems()` -- 刷新物品列表显示,从 `Comp` (BP_InventoryComp) 的 ViewCache 读取 FItemView 数据并更新 UI 列表
- **蓝图变量**(均为 is_instance_editable
- `Bo` (bool) -- 布尔标志位,用于控制 UI 显示/隐藏或其他状态
- `Comp` (BP_InventoryComp_C*) -- 目标库存组件引用,指向要显示的 BP_InventoryComp 实例。UI 从此组件的 ViewCache 读取物品数据
- **通过 Comp 变量访问的 BP_InventoryComp 接口**
- `ViewCache` (TArray<FItemView>) -- 物品视图缓存,包含 ItemID、ItemType、ItemName、ItemDescription、Icon、ItemDataText
- `OnViewChanged` (动态多播委托) -- 绑定此委托实现库存变化时自动调用 UpdateListItems
- `CreateItemInternal` -- 可用于触发物品创建(通常不直接从此 Widget 调用)
- **EventGraph**:含 5 个事件和 8 个节点
## 外部视角
WBP_InventoryView 是 UserWidget 的子类,从外部调用者视角:
**公开属性(蓝图可读写)**
- `Comp`BP_InventoryComp_C*)— 关联的库存组件引用
- `Bo`bool— 内部状态标记
**自定义函数**
- `UpdateListItems()` — 从 Comp 的 ViewCache 刷新物品列表显示
**外部交互方式**
- 作为 BP_Hud 的子 Widget 创建,存放于 InvView 变量
- 通过 Comp 变量引用 BP_InventoryComp读取其 ViewCache 获取物品视图数据
- 绑定 Comp 的 OnViewChanged 委托,在库存变化时自动调用 UpdateListItems
- 列表项使用 WBP_ItemViewBox 作为子 Widget 渲染单个物品
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件预构造` | 原生覆盖 (PreConstruct) | Widget 创建时 | 预留(当前无连线逻辑) |
| `事件构造` | 原生覆盖 (Construct) | Widget 创建完成后 | 预留(当前无连线逻辑) |
| `事件Tick` | 原生覆盖 | 每帧 | 预留(当前无连线逻辑) |
| `BindToComp` | 自定义事件 | 外部系统(如 BP_Hud/BP_Barrel调用时 | 接收 BP_InventoryComp 引用 → 存入 Comp 变量 → 绑定 Comp 的 OnViewChanged 委托到 UpdateListItems_Event |
| `UpdateListItems_Event` | 自定义事件 | Comp 的 OnViewChanged 触发时 | 调用 UpdateListItems 刷新物品列表 UI |
## 使用方法
- 作为 UMG UserWidget被 BP_Hud 的 `InvView` 变量引用(类型为 WBP_InventoryView_C*
- 设置 `Comp` 变量指向目标 Actor 上的 BP_InventoryComp 实例,建立 UI 到数据的绑定
- 在 EventGraph 中绑定 `Comp.OnViewChanged` 委托,每次库存变化时自动调用 `UpdateListItems` 刷新列表
- `UpdateListItems``Comp.ViewCache` 读取 FItemView 数组,遍历创建 WBP_ItemViewBox 子 Widget 填充列表
- WBP_ItemViewBox 作为单个物品的视图框,显示物品图标、名称、描述等信息
- `Bo` 布尔变量用于控制 ListView 的条件显示(如空库存时隐藏列表)
- 物品系统的数据流向UDefaultContainer (存储) -> BP_InventoryComp (管理+ViewCache) -> WBP_InventoryView (显示)
WBP_InventoryView 在项目中的典型调用流程:
- **库存 UI 绑定流程** — BP_Hud/BARREL 创建 WBP_InventoryView → 调用 BindToComp → 传入 BP_InventoryComp 引用 → 绑定 OnViewChanged → 库存变化时自动触发 UpdateListItems_Event → UpdateListItems 从 ViewCache 刷新 UI
- **手动刷新流程** — 外部系统直接调用 UpdateListItems → 从 Comp.ViewCache 读取当前物品列表 → 遍历渲染 WBP_ItemViewBox 子 Widget
## 用例
- BP_Hud 的 `InvView` 变量引用,作为物品栏 UI 界面
- 通过 `Comp` 变量绑定 BP_InventoryComp显示玩家或掉落物的物品列表
- 使用 WBP_ItemViewBox 作为子 Widget 渲染单个物品视图
| 引用方 | 路径 | 用途 |
|--------|------|------|
| BP_Hud | `/Game/Blueprints/BP_Hud` | 作为 InvView 子 Widget显示物品栏 |
| BP_Barrel | `/Game/Blueprints/Playground/BP_Barrel` | 通过 HUD 访问,展示木桶库存 |
| BP_ItemViewDataView | `/Game/Blueprints/UI/Item/BP_ItemViewDataView` | 引用用于数据视图绑定 |
| WBP_ItemViewBox | `/Game/Blueprints/UI/Item/WBP_ItemViewBox` | 作为列表项模板引用 |