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

@@ -0,0 +1,66 @@
# WBP_Window
## 基本信息
- **类型**: WidgetBlueprint (UserWidget)
- **父类**: UserWidget
- **源文件**: /Game/Blueprints/UI/WBP_Window.WBP_Window
- **模块**: Content/Blueprints/UI
## 功能概述
可拖拽窗口 Widget实现了一个具有标题栏的基本窗口 UI。支持鼠标拖拽移动通过 On_Title_Bar_MouseButtonDown/Up 和 UpdatePosition 函数),持有 IsDraggingbool、DragStartPointVector2D、WidgetStartPointVector2D、IsTempbool四个变量管理拖拽状态。
## 设计用意
提供一个可复用的通用窗口 UI 组件,支持标题栏拖拽移动。作为游戏内各类面板的基础容器,被 BP_Hud、BP_Barrel 等持有使用。
## 职责范围
- 渲染窗口标题栏和内容区域
- 管理窗口的拖拽移动逻辑
- 标识是否为临时窗口IsTemp
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| (无) | — | — |
## 外部视角
WBP_Window 是 UserWidget 的子类,从外部调用者视角:
**公开属性(蓝图可读写)**
- `IsDragging`bool— 当前是否在拖拽状态
- `DragStartPoint`Vector2D— 拖拽起始鼠标位置
- `WidgetStartPoint`Vector2D— 拖拽起始 Widget 位置
- `IsTemp`bool— 是否为临时窗口
**公开函数**
- `On_Title_Bar_MouseButtonDown(Geometry, PointerEvent)``FEventReply` — 标题栏按下,启动拖拽
- `On_Title_Bar_MouseButtonUp(Geometry, PointerEvent)``FEventReply` — 标题栏释放,结束拖拽
- `UpdatePosition()` — 根据拖拽偏移更新 Widget 位置
**外部交互方式**
- 由 BP_Hud 或 BP_Barrel 创建并持有,作为通用窗口容器
- 外部系统通过 Widget 引用设置内容或控制显示/隐藏
**EventGraph 事件**
| 事件 | 类型 | 触发时机 | 行为 |
|------|------|----------|------|
| `事件预构造` | 原生覆盖 (PreConstruct) | Widget 在编辑器中放置或运行时创建时 | 预留(当前无连线逻辑) |
| `事件构造` | 原生覆盖 (Construct) | Widget 创建完成后 | 预留(当前无连线逻辑) |
| `事件Tick` | 原生覆盖 | 每帧 | 如果 IsDragging=true → 调用 UpdatePosition 更新窗口位置 |
| `On Clicked (Button_61)` | 组件绑定事件 | 用户点击关闭按钮时 | 如果 IsTemp=true → 从父项中移除(销毁临时窗口),否则 → 设置可视性为 Hidden隐藏持久窗口 |
## 使用方法
WBP_Window 在项目中的典型调用流程:
- **窗口拖拽流程** — 用户按住标题栏 → On_Title_Bar_MouseButtonDown 记录拖拽起始位置 → Tick 检测 IsDragging → UpdatePosition 根据鼠标偏移移动 Widget → 释放 → On_Title_Bar_MouseButtonUp 结束拖拽
- **临时窗口关闭流程** — 用户点击关闭按钮 → On Clicked (Button_61) → 判断 IsTemp → 临时窗口直接从父项移除,持久窗口仅隐藏
- **HUD 窗口创建流程** — BP_Hud.BeginPlay → 创建 WBP_WindowInventoryWindow/HintWindow→ 添加到视口 → 外部通过 BP_Hud 变量访问
## 用例
| 引用方 | 路径 | 用途 |
|--------|------|------|
| BP_Hud | `/Game/Blueprints/BP_Hud` | 作为 InventoryWindow/HintWindow 窗口容器 |
| BP_Barrel | `/Game/Blueprints/Playground/BP_Barrel` | 作为 BarrelWindow 木桶交互窗口 |