This commit is contained in:
2025-12-27 16:26:38 +08:00
parent 62f7c125ab
commit 6db785307c
18 changed files with 3878 additions and 583 deletions

1
Tools/momotalk Submodule

Submodule Tools/momotalk added at 2a3e352738

150
Tools/task.md.resolved Normal file
View File

@@ -0,0 +1,150 @@
# WulaLink UI 修复任务 - Codex 交接文档
## 项目概述
RimWorld Mod: [WulaFallenEmpire](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire)
目标: 实现 MomoTalk 风格的悬浮 AI 聊天 UI (WulaLink),同时确保原有大 UI 不被破坏。
## 关键文件路径
```
C:\Steam\steamapps\common\RimWorld\Mods\3516260226\Source\WulaFallenEmpire\
├── EventSystem\
│ ├── Dialog_CustomDisplay.cs # 基类,包含正确的按钮样式和布局逻辑
│ └── AI\
│ ├── AIIntelligenceCore.cs # AI 核心逻辑 (WorldComponent) - 已完成
│ ├── DebugActions_WulaLink.cs # Debug 入口
│ └── UI\
│ ├── Dialog_AIConversation.cs # 大 UI - 需要修复布局
│ ├── Overlay_WulaLink.cs # 小悬浮框 - 需要修复样式
│ ├── Overlay_WulaLink_Notification.cs # 通知弹窗 - 已完成
│ └── WulaLinkStyles.cs # 样式定义 - 需要调整颜色
```
---
## 问题 1: 大 UI (Dialog_AIConversation) 布局损坏
### 现状
[Dialog_AIConversation](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs#108-133) 继承自 [Dialog_CustomDisplay](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/Dialog_CustomDisplay.cs#10-668),但 [DoWindowContents](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs#1177-1328) 被完全重写,丢失了原有的沉浸式布局。
### 期望效果 (参考用户截图)
- 左侧: 大尺寸立绘 (占据约 60% 窗口)
- 右下: 半透明暗红色面板,包含:
- 标题 "「军团」,P.I.A"
- 描述文本区域
- 底部按钮 "打开通讯频道" (使用 [DrawCustomButton](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/Dialog_CustomDisplay.cs#388-449) 样式)
- 点击按钮后进入聊天模式 (显示对话历史)
### 修复方案
恢复 `base.DoWindowContents(inRect)` 的调用,或手动复制 `Dialog_CustomDisplay.DoWindowContents` 的布局逻辑。
关键代码参考 ([Dialog_CustomDisplay.cs](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/Dialog_CustomDisplay.cs) 第 144-280 行):
```csharp
// 1. 绘制背景
if (background != null) GUI.DrawTexture(inRect, background, ScaleMode.StretchToFill);
// 2. 立绘 (Config.showPortrait)
Rect portraitRect = Config.GetScaledRect(Config.portraitSize, inRect);
// 3. 标题 (Config.showLabel)
Rect labelRect = Config.GetScaledRect(Config.labelSize, inRect);
// 4. 描述 (Config.showDescriptions)
Rect descriptionRect = Config.GetScaledRect(Config.descriptionsSize, inRect);
// 5. 选项按钮 (Config.showOptions)
Rect optionsRect = Config.GetScaledRect(Config.optionsListSize, inRect);
```
---
## 问题 2: 小悬浮框 (Overlay_WulaLink) 样式问题
### 2.1 背景颜色错误
**现状**: 使用纯黑背景 `new Color(10, 10, 12, 255)`
**期望**: 半透明暗红色,与大 UI 一致
修改 [WulaLinkStyles.cs](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/WulaLinkStyles.cs):
```csharp
// 修改前
public static readonly Color BackgroundColor = new Color32(10, 10, 12, 255);
// 修改后
public static readonly Color BackgroundColor = new Color(0.2f, 0.05f, 0.05f, 0.85f); // 半透明暗红
```
### 2.2 消息间距过大
**原因**: `role == "tool"` 的消息也被渲染,占用空间但不显示内容。
修改 [Overlay_WulaLink.cs](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs) 的 [DrawMessageList](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs#265-344) 方法:
```csharp
// 在 foreach 循环中添加过滤
foreach (var msg in history)
{
// 跳过工具调用消息
if (msg.role == "tool") continue;
// ... 其余渲染逻辑
}
```
### 2.3 气泡无圆角
**问题**: RimWorld 原生 `Widgets.DrawBoxSolid` 不支持圆角。
**方案**:
- 方案 A: 使用 9-slice 圆角贴图 (`Textures/UI/BubbleRounded.png`)
- 方案 B: 接受直角,但添加边框使其更精致
### 2.4 头像无圆形处理
**方案**: 使用圆形遮罩贴图覆盖在头像上,或创建 `Textures/UI/AvatarMask.png`
### 2.5 按钮样式不一致
**现状**: 使用默认 `Widgets.ButtonText`
**期望**: 使用 `Dialog_CustomDisplay.DrawCustomButton` 样式
修改 [Overlay_WulaLink.cs](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs) 的 [DrawFooter](file:///C:/Steam/steamapps/common/RimWorld/Mods/3516260226/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs#345-385):
```csharp
// 修改前
if (Widgets.ButtonText(btnRect, ">"))
// 修改后 (需要静态化或复制 DrawCustomButton 方法)
DrawCustomButton(btnRect, ">", isEnabled: true);
```
---
## 问题 3: 样式统一 (WulaLinkStyles.cs)
需要调整以下颜色以匹配大 UI 的"军团"风格:
```csharp
// Header: 深红色,与大 UI 标题栏一致
public static readonly Color HeaderColor = new Color(0.5f, 0.15f, 0.15f, 1f);
// 背景: 半透明暗红
public static readonly Color BackgroundColor = new Color(0.2f, 0.05f, 0.05f, 0.85f);
// AI 气泡: 深灰带红色边框
public static readonly Color StudentBubbleColor = new Color(0.15f, 0.12f, 0.12f, 1f);
public static readonly Color StudentStrokeColor = new Color(0.6f, 0.2f, 0.2f, 1f);
// 玩家气泡: 暗红色
public static readonly Color SenseiBubbleColor = new Color(0.4f, 0.15f, 0.15f, 1f);
```
---
## 验证清单
- [ ] 大 UI 显示正确的立绘、标题、描述和按钮布局
- [ ] 小悬浮框背景为半透明暗红色
- [ ] 消息之间无多余空白
- [ ] 按钮使用暗红色自定义样式
- [ ] (可选) 气泡有圆角
- [ ] (可选) 头像为圆形
## 编译命令
```powershell
dotnet build C:\Steam\steamapps\common\RimWorld\Mods\3516260226\Source\WulaFallenEmpire\WulaFallenEmpire.csproj
```
## 测试入口
1. 启动 RimWorld加载存档
2. 打开 Debug Actions Menu
3. 搜索 "WulaLink" 并点击 "Open WulaLink UI"

140
Tools/task_handoff.md Normal file
View File

@@ -0,0 +1,140 @@
# WulaLink 任务交接文档
## 当前状态:需要创建 AIIntelligenceCore.cs
### 背景
WulaLink 是一个 RimWorld Mod 中的 AI 对话系统,包含两个 UI
1. **大 UI** (`Dialog_AIConversation`) - 全屏对话窗口
2. **小 UI** (`Overlay_WulaLink`) - 悬浮对话窗口
### 已完成的操作
1. ✅ 恢复了 `Dialog_AIConversation.cs` 为旧版自包含版本(从备份文件 `Tools/using System;.cs` 复制)
2. ✅ 删除了损坏的 `AIIntelligenceCore.cs`
3. ✅ 重写了 `WulaLinkStyles.cs`(颜色主题配置)
### 当前编译错误
```
error CS0246: 未能找到类型或命名空间名"AIIntelligenceCore"
```
以下文件引用了 `AIIntelligenceCore`
- `Overlay_WulaLink.cs` (第13行, 第94行)
- `Overlay_WulaLink_Notification.cs` (第89行)
- `Tool_ChangeExpression.cs` (第24行)
- `Tool_GetRecentNotifications.cs` (第113行)
---
## 需要完成的任务
### 任务:创建 AIIntelligenceCore.cs
**路径**: `Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs`
**要求**
1. 必须是 `WorldComponent`,类名 `AIIntelligenceCore`
2. 提供 `static Instance` 属性供外部访问
3.`Dialog_AIConversation`(备份文件 `Tools/using System;.cs`)提取 AI 核心逻辑
4. 暴露事件/回调供 UI 使用
**必须包含的公共接口**(根据现有代码引用):
```csharp
public class AIIntelligenceCore : WorldComponent
{
// 静态实例
public static AIIntelligenceCore Instance { get; private set; }
// 事件回调
public event Action<string> OnMessageReceived;
public event Action<bool> OnThinkingStateChanged;
public event Action<int> OnExpressionChanged;
// 公共属性
public int ExpressionId { get; }
public bool IsThinking { get; }
// 公共方法
public void InitializeConversation(string eventDefName);
public List<(string role, string message)> GetHistorySnapshot();
public void SetExpression(int id); // 供 Tool_ChangeExpression 调用
public void SendMessage(string text); // 供小 UI 调用
}
```
**参考代码**
- 备份文件 `Tools/using System;.cs` 包含完整的 AI 逻辑1549行
- 核心方法包括:
- `RunPhasedRequestAsync()` - 3阶段请求处理
- `ExecuteXmlToolsForPhase()` - 工具执行
- `BuildToolContext()` / `BuildReplyHistory()` - 上下文构建
- `ParseResponse()` - 响应解析
- `GetSystemInstruction()` / `GetToolSystemInstruction()` - 提示词生成
---
## 关键文件路径
```
C:\Steam\steamapps\common\RimWorld\Mods\3516260226\
├── Tools\
│ └── using System;.cs # 旧版 Dialog_AIConversation 备份(包含完整 AI 逻辑)
└── Source\WulaFallenEmpire\EventSystem\AI\
├── AIIntelligenceCore.cs # 【需要创建】
├── AIHistoryManager.cs # 历史记录管理
├── AIMemoryManager.cs # 记忆管理
├── SimpleAIClient.cs # API 客户端
├── Tools\ # AI 工具目录
│ ├── Tool_SpawnResources.cs
│ ├── Tool_SendReinforcement.cs
│ └── ... (其他工具)
└── UI\
├── Dialog_AIConversation.cs # 大 UI已恢复
├── Overlay_WulaLink.cs # 小 UI需要修复引用
├── Overlay_WulaLink_Notification.cs
└── WulaLinkStyles.cs # 样式配置(已重写)
```
---
## 编译命令
```powershell
dotnet build C:\Steam\steamapps\common\RimWorld\Mods\3516260226\Source\WulaFallenEmpire\WulaFallenEmpire.csproj
```
---
## 架构说明
### 目标架构
```
┌─────────────────────────────────────┐
│ AIIntelligenceCore │ ← WorldComponent (核心逻辑)
│ - 历史记录管理 │
│ - AI 请求处理 (3阶段) │
│ - 工具执行 │
│ - 表情/状态管理 │
└──────────────┬──────────────────────┘
│ 事件回调
┌──────────┴──────────┐
▼ ▼
┌─────────────┐ ┌──────────────┐
│ Dialog_AI │ │ Overlay_ │
│ Conversation│ │ WulaLink │
│ (大 UI) │ │ (小 UI) │
└─────────────┘ └──────────────┘
```
### 关键点
1. `Dialog_AIConversation` 目前是**自包含**的(既有 UI 也有 AI 逻辑)
2. `Overlay_WulaLink` 需要通过 `AIIntelligenceCore` 获取数据
3. 两个 UI 可以共享同一个 `AIIntelligenceCore` 实例
---
## 注意事项
1. **不要使用 PowerShell Get-Content 读取文件** - 会显示乱码,请使用 `view_file` 工具
2. **备份文件编码正常** - `Tools/using System;.cs` 可以正常读取
3. **命名空间**`WulaFallenEmpire.EventSystem.AI`
4. **依赖项**:需要引用 `SimpleAIClient``AIHistoryManager``AITool` 等现有类

1548
Tools/using System;.cs Normal file

File diff suppressed because it is too large Load Diff