zc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -118,7 +118,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
this.draggable = true;
|
||||
this.resizeable = true;
|
||||
|
||||
// 关键修改:ç¦<EFBFBD>æ¢Enter键自动关é—窗å<EFBFBD>?
|
||||
// 鍏抽敭淇敼锛氱姝nter閿嚜鍔ㄥ叧闂獥鍙?
|
||||
this.closeOnAccept = false;
|
||||
|
||||
_tools.Add(new Tool_SpawnResources());
|
||||
@@ -1238,14 +1238,14 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
_isThinking = _core.IsThinking;
|
||||
}
|
||||
|
||||
// 定义边è·<EFBFBD>
|
||||
// 瀹氫箟杈硅窛
|
||||
float margin = 15f;
|
||||
Rect paddedRect = inRect.ContractedBy(margin);
|
||||
|
||||
float curY = paddedRect.y;
|
||||
float width = paddedRect.width;
|
||||
|
||||
// 立绘ä¸<EFBFBD>需è¦<EFBFBD>è¾¹è·<EFBFBD>,所以使用原始inRectçš„ä½<EFBFBD>ç½?
|
||||
// 绔嬬粯涓嶉渶瑕佽竟璺濓紝鎵€浠ヤ娇鐢ㄥ師濮媔nRect鐨勪綅缃?
|
||||
if (portrait != null)
|
||||
{
|
||||
Rect scaledPortraitRect = Dialog_CustomDisplay.Config.GetScaledRect(Dialog_CustomDisplay.Config.portraitSize, inRect, true);
|
||||
@@ -1265,25 +1265,25 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
curY = portraitRect.yMax + 10f;
|
||||
}
|
||||
|
||||
// 人物å<EFBFBD><EFBFBD>å— - 居䏿˜¾ç¤º
|
||||
// 浜虹墿鍚嶅瓧 - 灞呬腑鏄剧ず
|
||||
Text.Font = GameFont.Medium;
|
||||
string name = def.characterName ?? "The Legion";
|
||||
float nameHeight = Text.CalcHeight(name, width);
|
||||
|
||||
// 创建å<EFBFBD><EFBFBD>å—的矩形,使其在窗å<EFBFBD>£æ°´å¹³å±…ä¸?
|
||||
// 鍒涘缓鍚嶅瓧鐨勭煩褰紝浣垮叾鍦ㄧ獥鍙f按骞冲眳涓?
|
||||
Rect nameRect = new Rect(paddedRect.x, curY, width, nameHeight);
|
||||
Text.Anchor = TextAnchor.UpperCenter; // 改为上ä¸å¯¹é½<EFBFBD>
|
||||
Text.Anchor = TextAnchor.UpperCenter; // 鏀逛负涓婁腑瀵归綈
|
||||
Widgets.Label(nameRect, name);
|
||||
Text.Anchor = TextAnchor.UpperLeft; // æ<EFBFBD>¢å¤<EFBFBD>左对é½?
|
||||
Text.Anchor = TextAnchor.UpperLeft; // 鎭㈠宸﹀榻?
|
||||
|
||||
curY += nameHeight + 10f;
|
||||
|
||||
// 计算输入框高度ã€<EFBFBD>选项高度和è<EFBFBD>Šå¤©åކå<EFBFBD>²é«˜åº?
|
||||
// 璁$畻杈撳叆妗嗛珮搴︺€侀€夐」楂樺害鍜岃亰澶╁巻鍙查珮搴?
|
||||
float inputHeight = 30f;
|
||||
float optionsHeight = _options.Any() ? 100f : 0f;
|
||||
float spacing = 10f;
|
||||
|
||||
// è<EFBFBD>Šå¤©åކå<EFBFBD>²åŒºåŸŸ - 使用带边è·<C3A8>的矩形
|
||||
// 鑱婂ぉ鍘嗗彶鍖哄煙 - 浣跨敤甯﹁竟璺濈殑鐭╁舰
|
||||
float descriptionHeight = paddedRect.height - curY - inputHeight - optionsHeight - spacing * 2;
|
||||
Rect descriptionRect = new Rect(paddedRect.x, curY, width, descriptionHeight);
|
||||
DrawChatHistory(descriptionRect);
|
||||
@@ -1297,7 +1297,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
|
||||
curY += descriptionHeight + spacing;
|
||||
|
||||
// 选项区域
|
||||
// 閫夐」鍖哄煙
|
||||
Rect optionsRect = new Rect(paddedRect.x, curY, width, optionsHeight);
|
||||
if (!_isThinking && _options.Count > 0)
|
||||
{
|
||||
@@ -1307,70 +1307,70 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
|
||||
curY += optionsHeight + spacing;
|
||||
|
||||
// 输入框区åŸ?- 使用带边è·<C3A8>的矩形
|
||||
// 杈撳叆妗嗗尯鍩?- 浣跨敤甯﹁竟璺濈殑鐭╁舰
|
||||
Rect inputRect = new Rect(paddedRect.x, curY, width, inputHeight);
|
||||
|
||||
// ä¿<EFBFBD>å˜å½“å‰<EFBFBD>å—体
|
||||
// 淇濆瓨褰撳墠瀛椾綋
|
||||
var originalFont = Text.Font;
|
||||
|
||||
// 设置更å°<EFBFBD>çš„å—ä½?
|
||||
// 璁剧疆鏇村皬鐨勫瓧浣?
|
||||
if (Text.Font == GameFont.Small)
|
||||
{
|
||||
// 使用 Tiny å—体
|
||||
// 浣跨敤 Tiny 瀛椾綋
|
||||
Text.Font = GameFont.Tiny;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果当å‰<EFBFBD>ä¸<EFBFBD>是 Small,é™<C3A9>一çº?
|
||||
// 濡傛灉褰撳墠涓嶆槸 Small锛岄檷涓€绾?
|
||||
Text.Font = GameFont.Small;
|
||||
}
|
||||
|
||||
// 计算输入框文本高�
|
||||
// 璁$畻杈撳叆妗嗘枃鏈珮搴?
|
||||
float textFieldHeight = Text.CalcHeight("Test", inputRect.width - 85);
|
||||
Rect textFieldRect = new Rect(inputRect.x, inputRect.y + (inputHeight - textFieldHeight) / 2, inputRect.width - 85, textFieldHeight);
|
||||
|
||||
_inputText = Widgets.TextField(textFieldRect, _inputText);
|
||||
|
||||
// å<EFBFBD>‘é€<EFBFBD>按é’?- 使用与Dialog_CustomDisplay相å<C2B8>Œçš„è‡ªå®šä¹‰æŒ‰é’®æ ·å¼<C3A5>
|
||||
// ä¿<EFBFBD>å˜å½“å‰<EFBFBD>状æ€?
|
||||
// 鍙戦€佹寜閽?- 浣跨敤涓嶥ialog_CustomDisplay鐩稿悓鐨勮嚜瀹氫箟鎸夐挳鏍峰紡
|
||||
// 淇濆瓨褰撳墠鐘舵€?
|
||||
var originalAnchor = Text.Anchor;
|
||||
var originalColor = GUI.color;
|
||||
|
||||
// 设置å—体为Tiny
|
||||
// 璁剧疆瀛椾綋涓篢iny
|
||||
Text.Font = GameFont.Tiny;
|
||||
Text.Anchor = TextAnchor.MiddleCenter;
|
||||
|
||||
// å<EFBFBD>‘é€<EFBFBD>按钮的矩形
|
||||
// 鍙戦€佹寜閽殑鐭╁舰
|
||||
Rect sendButtonRect = new Rect(inputRect.xMax - 80, inputRect.y, 80, inputHeight);
|
||||
|
||||
// 使用基类的DrawCustomButton方法绘制按钮(与Dialog_CustomDisplay一致)
|
||||
// 浣跨敤鍩虹被鐨凞rawCustomButton鏂规硶缁樺埗鎸夐挳锛堜笌Dialog_CustomDisplay涓€鑷达級
|
||||
base.DrawCustomButton(sendButtonRect, "Wula_AI_Send".Translate(), isEnabled: true);
|
||||
|
||||
// æ<EFBFBD>¢å¤<EFBFBD>状æ€?
|
||||
// 鎭㈠鐘舵€?
|
||||
GUI.color = originalColor;
|
||||
Text.Anchor = originalAnchor;
|
||||
Text.Font = originalFont;
|
||||
|
||||
// 处ç<EFBFBD>†ç‚¹å‡»äº‹ä»¶
|
||||
// 澶勭悊鐐瑰嚮浜嬩欢
|
||||
bool sendButtonPressed = Widgets.ButtonInvisible(sendButtonRect);
|
||||
|
||||
// 直接在DoWindowContentsä¸å¤„ç<EFBFBD>†Enter键,而ä¸<EFBFBD>是调用å<EFBFBD>•独的方法
|
||||
// 这是为了确ä¿<EFBFBD>事件在æ£ç¡®çš„æ—¶æœºè¢«å¤„ç<EFBFBD>?
|
||||
// 鐩存帴鍦―oWindowContents涓鐞咵nter閿紝鑰屼笉鏄皟鐢ㄥ崟鐙殑鏂规硶
|
||||
// 杩欐槸涓轰簡纭繚浜嬩欢鍦ㄦ纭殑鏃舵満琚鐞?
|
||||
if (Event.current.type == EventType.KeyDown)
|
||||
{
|
||||
// 检查是å<EFBFBD>¦æŒ‰ä¸‹äº†Enter键(主键盘或å°<EFBFBD>键盘的Enterï¼?
|
||||
// 妫€鏌ユ槸鍚︽寜涓嬩簡Enter閿紙涓婚敭鐩樻垨灏忛敭鐩樼殑Enter锛?
|
||||
if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) && !string.IsNullOrEmpty(_inputText))
|
||||
{
|
||||
// 如果AIæ£åœ¨æ€<EFBFBD>考,ä¸<EFBFBD>处ç<EFBFBD>†Enteré”?
|
||||
// 濡傛灉AI姝e湪鎬濊€冿紝涓嶅鐞咵nter閿?
|
||||
if (!_isThinking)
|
||||
{
|
||||
SelectOption(_inputText);
|
||||
_inputText = "";
|
||||
// 消费这个事件,防æ¢å®ƒä¼ 递到窗å<EFBFBD>£çš„å…³é—逻辑
|
||||
// 娑堣垂杩欎釜浜嬩欢锛岄槻姝㈠畠浼犻€掑埌绐楀彛鐨勫叧闂€昏緫
|
||||
Event.current.Use();
|
||||
}
|
||||
}
|
||||
// å<EFBFBD>¯é€‰ï¼šæ·»åŠ Escape键关é—窗å<EFBFBD>£çš„功能
|
||||
// 鍙€夛細娣诲姞Escape閿叧闂獥鍙g殑鍔熻兘
|
||||
else if (Event.current.keyCode == KeyCode.Escape)
|
||||
{
|
||||
this.Close();
|
||||
@@ -1378,7 +1378,7 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
}
|
||||
}
|
||||
|
||||
// 处ç<EFBFBD>†é¼ æ ‡ç‚¹å‡»å<EFBFBD>‘é€<EFBFBD>按é’?
|
||||
// 澶勭悊榧犳爣鐐瑰嚮鍙戦€佹寜閽?
|
||||
if (sendButtonPressed && !string.IsNullOrEmpty(_inputText))
|
||||
{
|
||||
SelectOption(_inputText);
|
||||
@@ -1395,28 +1395,28 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
float viewHeight = 0f;
|
||||
var filteredHistory = _history.Where(e => e.role != "tool" && e.role != "system" && e.role != "toolcall").ToList();
|
||||
|
||||
// æ·»åŠ å†…è¾¹è·?
|
||||
// 娣诲姞鍐呰竟璺?
|
||||
float innerPadding = 5f;
|
||||
float contentWidth = rect.width - 16f - innerPadding * 2;
|
||||
|
||||
// 预计算高åº?- 使用å°<C3A5>å—ä½?
|
||||
// 棰勮绠楅珮搴?- 浣跨敤灏忓瓧浣?
|
||||
for (int i = 0; i < filteredHistory.Count; i++)
|
||||
{
|
||||
var entry = filteredHistory[i];
|
||||
string text = entry.role == "assistant" ? ParseResponseForDisplay(entry.message) : entry.message;
|
||||
if (string.IsNullOrEmpty(text) || (entry.role == "user" && text.StartsWith("[Tool Results]"))) continue;
|
||||
if (string.IsNullOrWhiteSpace(text) || (entry.role == "user" && text.StartsWith("[Tool Results]"))) continue;
|
||||
bool isLastMessage = i == filteredHistory.Count - 1;
|
||||
|
||||
// 设置更å°<EFBFBD>çš„å—ä½?
|
||||
// 璁剧疆鏇村皬鐨勫瓧浣?
|
||||
if (isLastMessage && entry.role == "assistant")
|
||||
{
|
||||
Text.Font = GameFont.Small; // 原æ<EFBFBD>¥æ˜?Medium,改ä¸?Small
|
||||
Text.Font = GameFont.Small; // 鍘熸潵鏄?Medium锛屾敼涓?Small
|
||||
}
|
||||
else
|
||||
{
|
||||
Text.Font = GameFont.Tiny; // 原æ<EFBFBD>¥æ˜?Small,改ä¸?Tiny
|
||||
Text.Font = GameFont.Tiny; // 鍘熸潵鏄?Small锛屾敼涓?Tiny
|
||||
}
|
||||
// å¢žåŠ padding
|
||||
// 澧炲姞padding
|
||||
float padding = (isLastMessage && entry.role == "assistant") ? 30f : 15f;
|
||||
viewHeight += Text.CalcHeight(text, contentWidth) + padding + 10f;
|
||||
}
|
||||
@@ -1439,20 +1439,20 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
if (string.IsNullOrEmpty(text) || (entry.role == "user" && text.StartsWith("[Tool Results]"))) continue;
|
||||
bool isLastMessage = i == filteredHistory.Count - 1;
|
||||
|
||||
// 设置更å°<EFBFBD>çš„å—ä½?
|
||||
// 璁剧疆鏇村皬鐨勫瓧浣?
|
||||
if (isLastMessage && entry.role == "assistant")
|
||||
{
|
||||
Text.Font = GameFont.Small; // 原æ<EFBFBD>¥æ˜?Medium,改ä¸?Small
|
||||
Text.Font = GameFont.Small; // 鍘熸潵鏄?Medium锛屾敼涓?Small
|
||||
}
|
||||
else
|
||||
{
|
||||
Text.Font = GameFont.Tiny; // 原æ<EFBFBD>¥æ˜?Small,改ä¸?Tiny
|
||||
Text.Font = GameFont.Tiny; // 鍘熸潵鏄?Small锛屾敼涓?Tiny
|
||||
}
|
||||
|
||||
float padding = (isLastMessage && entry.role == "assistant") ? 30f : 15f;
|
||||
float height = Text.CalcHeight(text, contentWidth) + padding;
|
||||
|
||||
// æ·»åŠ å†…è¾¹è·?
|
||||
// 娣诲姞鍐呰竟璺?
|
||||
Rect labelRect = new Rect(innerPadding, curY, contentWidth, height);
|
||||
|
||||
if (entry.role == "user")
|
||||
@@ -1639,3 +1639,4 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user