修复已知功能
1. 添加章节开始 UI 介绍 2. 清理不使用的资源 3. 补充 AIChat 入口 UI 4. 接上所有的正常对话流程
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
using System.Collections.Generic;
|
||||
using GameFramework.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public sealed class AIChatEntryFormController : IFormController<AIChatEntryFormContext>
|
||||
{
|
||||
private AIChatEntryFormContext _entryContext;
|
||||
private AIChatEntryForm _entryForm;
|
||||
private int? _entryFormSerialId;
|
||||
private bool _pendingEntryRefresh;
|
||||
|
||||
private AIChatFormController _chatFormController;
|
||||
private AIChatFormContext _chatContext;
|
||||
|
||||
public AIChatEntryFormController()
|
||||
{
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(CloseUIFormCompleteEventArgs.EventId, OnCloseUIFormComplete);
|
||||
}
|
||||
|
||||
~AIChatEntryFormController()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(CloseUIFormCompleteEventArgs.EventId, OnCloseUIFormComplete);
|
||||
}
|
||||
|
||||
public int? OpenUI(AIChatEntryFormContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
Log.Warning("AIChatEntryFormController open failed. context is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Controller = this;
|
||||
_entryContext = context;
|
||||
SyncEntryContextState();
|
||||
|
||||
if (_entryForm != null)
|
||||
{
|
||||
_entryForm.RefreshUI(_entryContext);
|
||||
return _entryFormSerialId;
|
||||
}
|
||||
|
||||
UGuiForm openedForm = GameEntry.UI.GetUIForm(UIFormId.AIChatEntryForm);
|
||||
if (openedForm is AIChatEntryForm existingForm)
|
||||
{
|
||||
_entryForm = existingForm;
|
||||
_entryFormSerialId = existingForm.UIForm.SerialId;
|
||||
_entryForm.RefreshUI(_entryContext);
|
||||
return _entryFormSerialId;
|
||||
}
|
||||
|
||||
_pendingEntryRefresh = true;
|
||||
_entryFormSerialId = GameEntry.UI.OpenUIForm(UIFormId.AIChatEntryForm, _entryContext);
|
||||
return _entryFormSerialId;
|
||||
}
|
||||
|
||||
public void CloseUI()
|
||||
{
|
||||
_pendingEntryRefresh = false;
|
||||
|
||||
if (_entryFormSerialId.HasValue)
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(_entryFormSerialId.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entryForm != null)
|
||||
{
|
||||
_entryForm.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleAIChatForm()
|
||||
{
|
||||
UGuiForm openedChatForm = GameEntry.UI.GetUIForm(UIFormId.AIChatForm);
|
||||
if (openedChatForm != null)
|
||||
{
|
||||
if (_chatFormController != null)
|
||||
{
|
||||
_chatFormController.CloseUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
GameEntry.UI.CloseUIForm(openedChatForm.UIForm);
|
||||
}
|
||||
|
||||
RefreshEntryState();
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureChatContext();
|
||||
_chatContext.Controller = _chatFormController;
|
||||
_chatFormController.OpenUI(_chatContext);
|
||||
RefreshEntryState();
|
||||
}
|
||||
|
||||
private void EnsureChatContext()
|
||||
{
|
||||
if (_chatFormController == null)
|
||||
{
|
||||
_chatFormController = new AIChatFormController();
|
||||
}
|
||||
|
||||
if (_chatContext == null)
|
||||
{
|
||||
_chatContext = new AIChatFormContext
|
||||
{
|
||||
ClearHistoryOnOpen = false,
|
||||
LanguageMode = 0,
|
||||
Messages = new List<AIChatMessageContext>()
|
||||
};
|
||||
}
|
||||
|
||||
_chatContext.Controller = _chatFormController;
|
||||
_chatContext.Messages ??= new List<AIChatMessageContext>();
|
||||
}
|
||||
|
||||
private void SyncEntryContextState()
|
||||
{
|
||||
if (_entryContext == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_entryContext.IsChatOpened = GameEntry.UI.GetUIForm(UIFormId.AIChatForm) != null;
|
||||
}
|
||||
|
||||
private void RefreshEntryState()
|
||||
{
|
||||
SyncEntryContextState();
|
||||
|
||||
if (_entryForm == null || _entryContext == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_entryForm.SetChatOpened(_entryContext.IsChatOpened);
|
||||
}
|
||||
|
||||
private void OnOpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entryFormSerialId.HasValue &&
|
||||
args.UIForm != null &&
|
||||
args.UIForm.SerialId == _entryFormSerialId.Value &&
|
||||
args.UserData == _entryContext)
|
||||
{
|
||||
_entryForm = args.UIForm.Logic as AIChatEntryForm;
|
||||
if (_entryForm == null)
|
||||
{
|
||||
Log.Warning("AIChatEntryFormController open success but form logic is invalid.");
|
||||
}
|
||||
else if (_pendingEntryRefresh)
|
||||
{
|
||||
_entryForm.RefreshUI(_entryContext);
|
||||
_pendingEntryRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
RefreshEntryState();
|
||||
}
|
||||
|
||||
private void OnCloseUIFormComplete(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is CloseUIFormCompleteEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.SerialId == _entryFormSerialId)
|
||||
{
|
||||
_entryForm = null;
|
||||
_entryFormSerialId = null;
|
||||
_pendingEntryRefresh = false;
|
||||
}
|
||||
|
||||
RefreshEntryState();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f9ad5dc60834e1cb1aa5d0f04d2756c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user