2023-09-03 18:55:41 +00:00
|
|
|
|
using System;
|
2023-09-04 10:19:48 +00:00
|
|
|
|
using System.IO.Packaging;
|
|
|
|
|
using System.Reflection;
|
2023-09-03 18:55:41 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Input;
|
2023-09-04 10:19:48 +00:00
|
|
|
|
using System.Windows.Markup;
|
2023-09-03 18:55:41 +00:00
|
|
|
|
using System.Windows.Navigation;
|
2024-04-17 07:39:18 +00:00
|
|
|
|
using VPet_Simulator.Core;
|
|
|
|
|
using static VPet_Simulator.Core.GraphInfo;
|
2023-09-03 18:55:41 +00:00
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows.Interface
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 聊天API接口/显示类
|
|
|
|
|
/// </summary>
|
2023-09-04 08:45:32 +00:00
|
|
|
|
public abstract partial class TalkBox : UserControl, ITalkAPI
|
2023-09-03 18:55:41 +00:00
|
|
|
|
{
|
2023-09-04 10:19:48 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 插件主体
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected MainPlugin MainPlugin;
|
2023-09-03 18:55:41 +00:00
|
|
|
|
public TalkBox(MainPlugin mainPlugin)
|
|
|
|
|
{
|
2023-09-04 10:19:48 +00:00
|
|
|
|
var baseUri = "/VPet-Simulator.Windows.Interface;component/talkbox.xaml";
|
|
|
|
|
var resourceLocater = new Uri(baseUri, UriKind.Relative);
|
|
|
|
|
var exprCa = (PackagePart)typeof(Application).GetMethod("GetResourceOrContentPart", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { resourceLocater });
|
|
|
|
|
var stream = exprCa.GetStream();
|
|
|
|
|
var uri = new Uri((Uri)typeof(BaseUriHelper).GetProperty("PackAppBaseUri", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, null), resourceLocater);
|
|
|
|
|
var parserContext = new ParserContext
|
|
|
|
|
{
|
|
|
|
|
BaseUri = uri
|
|
|
|
|
};
|
|
|
|
|
typeof(XamlReader).GetMethod("LoadBaml", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { stream, parserContext, this, true });
|
|
|
|
|
|
2023-09-03 18:55:41 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
MainPlugin = mainPlugin;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据内容进行回应 (异步)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">内容</param>
|
|
|
|
|
public abstract void Responded(string text);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 该聊天接口名字
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract string APIName { get; }
|
|
|
|
|
|
|
|
|
|
private void Send_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(tbTalk.Text))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var cont = tbTalk.Text;
|
|
|
|
|
tbTalk.Text = "";
|
2023-09-04 14:56:27 +00:00
|
|
|
|
MainPlugin.MW.Main.ToolBar.Visibility = Visibility.Collapsed;
|
2024-04-17 07:39:18 +00:00
|
|
|
|
|
2023-09-03 18:55:41 +00:00
|
|
|
|
Task.Run(() => Responded(cont));
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-04-17 07:39:18 +00:00
|
|
|
|
/// 显示思考动画
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisplayThink()
|
|
|
|
|
{
|
2024-08-10 07:52:49 +00:00
|
|
|
|
if (MainPlugin.MW.Main.DisplayType.Name == "think")
|
|
|
|
|
return;
|
|
|
|
|
|
2024-04-17 07:39:18 +00:00
|
|
|
|
var think = MainPlugin.MW.Core.Graph.FindGraphs("think", AnimatType.B_Loop, MainPlugin.MW.Core.Save.Mode);
|
2024-08-10 07:52:49 +00:00
|
|
|
|
var think2 = MainPlugin.MW.Core.Graph.FindGraphs("think", AnimatType.A_Start, MainPlugin.MW.Core.Save.Mode);
|
|
|
|
|
if (think.Count > 0 && think2.Count > 0)
|
2024-04-17 07:39:18 +00:00
|
|
|
|
{
|
|
|
|
|
MainPlugin.MW.Main.Display("think", AnimatType.A_Start, MainPlugin.MW.Main.DisplayBLoopingForce);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-04-17 21:09:46 +00:00
|
|
|
|
/// 显示思考结束并说话
|
2024-04-17 07:39:18 +00:00
|
|
|
|
/// </summary>
|
2024-04-17 21:09:46 +00:00
|
|
|
|
public void DisplayThinkToSayRnd(string text, string desc = null)
|
2024-04-17 07:39:18 +00:00
|
|
|
|
{
|
|
|
|
|
var think = MainPlugin.MW.Core.Graph.FindGraphs("think", AnimatType.C_End, MainPlugin.MW.Core.Save.Mode);
|
2024-04-17 21:09:46 +00:00
|
|
|
|
Action Next = () => { MainPlugin.MW.Main.SayRnd(text, true, desc); };
|
2024-04-17 07:39:18 +00:00
|
|
|
|
if (think.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
MainPlugin.MW.Main.Display(think[Function.Rnd.Next(think.Count)], Next);
|
|
|
|
|
}
|
2024-04-17 21:09:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Next();
|
|
|
|
|
}
|
2024-04-17 07:39:18 +00:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-09-03 18:55:41 +00:00
|
|
|
|
/// 聊天设置
|
|
|
|
|
/// </summary>
|
2023-09-04 08:45:32 +00:00
|
|
|
|
public abstract void Setting();
|
2023-09-03 18:55:41 +00:00
|
|
|
|
|
|
|
|
|
private void tbTalk_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Enter && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
|
|
|
|
|
{
|
|
|
|
|
Send_Click(sender, e);
|
|
|
|
|
e.Handled = true;
|
2023-09-04 14:56:27 +00:00
|
|
|
|
MainPlugin.MW.Main.ToolBar.Visibility = Visibility.Collapsed;
|
2023-09-03 18:55:41 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tbTalk.Text.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
MainPlugin.MW.Main.ToolBar.CloseTimer.Stop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MainPlugin.MW.Main.ToolBar.CloseTimer.Start();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-04 08:45:32 +00:00
|
|
|
|
public UIElement This => this;
|
|
|
|
|
}
|
|
|
|
|
public interface ITalkAPI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 显示的窗口
|
|
|
|
|
/// </summary>
|
|
|
|
|
UIElement This { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 该聊天接口名字
|
|
|
|
|
/// </summary>
|
|
|
|
|
string APIName { get; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 聊天设置
|
|
|
|
|
/// </summary>
|
|
|
|
|
void Setting();
|
2023-09-03 18:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|