重构动画播放系统: 修复

This commit is contained in:
ZouJin 2023-07-18 01:38:06 +10:00
parent 59c1253886
commit 0deb2b5f5e
13 changed files with 124 additions and 89 deletions

View File

@ -242,7 +242,7 @@ namespace VPet_Simulator.Core
private void MainGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
isPress = false;
if (DisplayType.ToString().StartsWith("Raised"))
if (DisplayType.Type.ToString().StartsWith("Raised"))
{
MainGrid.MouseMove -= MainGrid_MouseMove;
MainGrid.MouseMove += MainGrid_MouseWave;
@ -272,7 +272,7 @@ namespace VPet_Simulator.Core
var x = mp.X - Core.Graph.GraphConfig.RaisePoint[(int)Core.Save.Mode].X;
var y = mp.Y - Core.Graph.GraphConfig.RaisePoint[(int)Core.Save.Mode].Y;
Core.Controller.MoveWindows(x, y);
if (Math.Abs(x) + Math.Abs(y) > 10)
if (Math.Abs(x) + Math.Abs(y) > 20 && rasetype >= 1)
rasetype = 0;
}

View File

@ -62,6 +62,8 @@ namespace VPet_Simulator.Core
var graph = Core.Graph.FindGraph(DisplayType.Name, AnimatType.C_End, Core.Save.Mode);
if (graph != null)
{
if(State == WorkingState.Sleep)
State = WorkingState.Nomal;
Display(graph, EndAction);
return true;
}
@ -206,8 +208,8 @@ namespace VPet_Simulator.Core
looptimes = 0;
CountNomal = 0;
var name = Core.Graph.FindName(GraphType.State_ONE);
var list = Core.Graph.FindGraphs(name, AnimatType.A_Start, Core.Save.Mode).FindAll(x => x.GraphInfo.Type == GraphType.State_ONE);
if (list.Count > 0)
var list = Core.Graph.FindGraphs(name, AnimatType.A_Start, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == GraphType.State_ONE);
if (list != null && list.Count > 0)
Display(list[Function.Rnd.Next(list.Count)], () => DisplayIdel_StateONEing(name));
else
Display(GraphType.State_ONE, AnimatType.A_Start, DisplayIdel_StateONEing);
@ -344,6 +346,7 @@ namespace VPet_Simulator.Core
/// </summary>
private void DisplayRaising(string name = null)
{
Console.WriteLine(rasetype);
switch (rasetype)
{
case int.MinValue:
@ -423,8 +426,8 @@ namespace VPet_Simulator.Core
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(string name, AnimatType animat, GraphType Type, Action<string> EndAction = null)
{
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode).FindAll(x => x.GraphInfo.Type == Type);
if (list.Count > 0)
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == Type);
if (list != null && list.Count > 0)
Display(list[Function.Rnd.Next(list.Count)], () => EndAction(name));
else
Display(Type, animat, EndAction);
@ -438,7 +441,7 @@ namespace VPet_Simulator.Core
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(string name, AnimatType animat, GraphType Type, Action EndAction = null)
{
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode).FindAll(x => x.GraphInfo.Type == Type);
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == Type);
if (list.Count > 0)
Display(list[Function.Rnd.Next(list.Count)], EndAction);
else

View File

@ -45,7 +45,7 @@ namespace VPet_Simulator.Core
Task.Run(() =>
{
OnSay?.Invoke(text);
if (force || string.IsNullOrWhiteSpace(graphname) && DisplayType.Type == GraphType.Default)
if (force || !string.IsNullOrWhiteSpace(graphname) && DisplayType.Type == GraphType.Default)
Display(graphname, AnimatType.A_Start, () =>
{
Dispatcher.Invoke(() => MsgBar.Show(Core.Save.Name, text, graphname));

View File

@ -42,7 +42,7 @@ namespace VPet_Simulator.Core
closePanelTimer = new Timer();
closePanelTimer.Elapsed += ClosePanelTimer_Tick;
m.TimeUIHandle += M_TimeUIHandle;
LoadWork();
}
public void LoadWork()
@ -132,6 +132,7 @@ namespace VPet_Simulator.Core
else
MessageBoxX.Show(LocalizeCore.Translate("您的桌宠 {0} 生病啦,没法进行{1}", m.Core.Save.Name,
work.NameTrans), LocalizeCore.Translate("{0}取消", work.NameTrans));
Visibility = Visibility.Collapsed;
}
private void MenuWork_Click(object sender, RoutedEventArgs e)
{

View File

@ -46,7 +46,7 @@ namespace VPet_Simulator.Core
/// <param name="m"></param>
private void M_TimeUIHandle(Main m)
{
if (Visibility == Visibility.Hidden) return;
if (Visibility == Visibility.Collapsed) return;
TimeSpan ts = DateTime.Now - StartTime;
TimeSpan tleft;
if (ts.TotalMinutes > nowWork.Time)

View File

@ -84,22 +84,24 @@ namespace VPet_Simulator.Core
/// <returns>动画信息</returns>
public static GraphInfo GetGraphInfo(FileSystemInfo path, ILine info)
{
var path_name = path.Name.Substring(0, path.Name.Length - path.Extension.Length).Replace('\\', '_').ToLower().Split('_').ToList();
var pn = Sub.Split(path.FullName.Substring(0, path.FullName.Length - path.Extension.Length).ToLower(), info[(gstr)"startuppath"].ToLower()).Last();
var path_name = pn.Replace('\\', '_').Split('_').ToList();
path_name.RemoveAll(string.IsNullOrWhiteSpace);
if (!Enum.TryParse(info[(gstr)"mode"], true, out GameSave.ModeType modetype))
{
if (path_name.Contains("happy"))
if (path_name.Remove("happy"))
{
modetype = GameSave.ModeType.Happy;
}
else if (path_name.Contains("nomal"))
else if (path_name.Remove("nomal"))
{
modetype = GameSave.ModeType.Nomal;
}
else if (path_name.Contains("poorcondition"))
else if (path_name.Remove("poorcondition"))
{
modetype = GameSave.ModeType.PoorCondition;
}
else if (path_name.Contains("ill"))
else if (path_name.Remove("ill"))
{
modetype = GameSave.ModeType.Ill;
}
@ -129,6 +131,7 @@ namespace VPet_Simulator.Core
if (ismatch)
{
graphtype = (GraphType)i;
path_name.RemoveRange(index, GraphTypeValue[i].Length);
break;
}
}
@ -137,15 +140,15 @@ namespace VPet_Simulator.Core
if (!Enum.TryParse(info[(gstr)"animat"], true, out AnimatType animatType))
{
if (path_name.Contains("a") || path_name.Contains("start"))
if (path_name.Remove("a") || path_name.Remove("start"))
{
animatType = AnimatType.A_Start;
}
else if (path_name.Contains("b") || path_name.Contains("loop"))
else if (path_name.Remove("b") || path_name.Remove("loop"))
{
animatType = AnimatType.B_Loop;
}
else if (path_name.Contains("c") || path_name.Contains("end"))
else if (path_name.Remove("c") || path_name.Remove("end"))
{
animatType = AnimatType.C_End;
}
@ -154,10 +157,19 @@ namespace VPet_Simulator.Core
animatType = AnimatType.Single;
}
}
string name = info.Name;
string name = info.Info;
if (string.IsNullOrWhiteSpace(name))
{
name = graphtype.ToString();
while (path_name.Count > 0 && (double.TryParse(path_name.Last(), out _) || path_name.Last().StartsWith("~")))
{
path_name.RemoveAt(path_name.Count - 1);
}
if (path_name.Count > 0)
name = path_name.Last();
}
if (string.IsNullOrWhiteSpace(name))
{
name = graphtype.ToString().ToLower();
}
return new GraphInfo(name, graphtype, animatType, modetype);// { Info = info };
}
@ -295,10 +307,10 @@ namespace VPet_Simulator.Core
Bottom = 8
}
/// <summary>
/// 定位类型
/// 定位类型: 需要固定到屏幕边缘启用这个
/// </summary>
[Line(ignoreCase: true)]
public DirectionType LocateType { get; set; }
public DirectionType LocateType { get; set; } = DirectionType.None;
/// <summary>
/// 移动间隔
/// </summary>
@ -454,6 +466,22 @@ namespace VPet_Simulator.Core
m.CountNomal = 0;
m.Display(Graph, AnimatType.A_Start, () =>
{
switch (LocateType)
{
case DirectionType.Top:
m.Core.Controller.MoveWindows(0, -m.Core.Controller.GetWindowsDistanceUp() / m.Core.Controller.ZoomRatio - LocateLength);
break;
case DirectionType.Bottom:
m.Core.Controller.MoveWindows(0, m.Core.Controller.GetWindowsDistanceDown() / m.Core.Controller.ZoomRatio + LocateLength);
break;
case DirectionType.Left:
m.Core.Controller.MoveWindows(-m.Core.Controller.GetWindowsDistanceLeft() / m.Core.Controller.ZoomRatio - LocateLength, 0);
break;
case DirectionType.Right:
m.Core.Controller.MoveWindows(m.Core.Controller.GetWindowsDistanceRight() / m.Core.Controller.ZoomRatio + LocateLength, 0);
break;
}
m.MoveTimerPoint = new Point(SpeedX, SpeedY);
m.MoveTimer.Interval = Interval;
m.MoveTimer.Start();

View File

@ -97,10 +97,6 @@ namespace VPet_Simulator.Core
/// </summary>
Shutdown,
/// <summary>
/// 学习 (开始&循环&结束) *
/// </summary>
Study,
/// <summary>
/// 工作 (开始&循环&结束) *
/// </summary>
Work,

View File

@ -22,7 +22,7 @@ namespace VPet_Simulator.Core
{
var g = new GraphCore();
foreach (var p in path)
LoadGraph(g, new DirectoryInfo(p));
LoadGraph(g, new DirectoryInfo(p), p);
g.GraphConfig = Config;
return g;
}
@ -56,7 +56,13 @@ namespace VPet_Simulator.Core
{ "picture", Picture.LoadGraph },
{ "foodanimation", FoodAnimation.LoadGraph },
};
public static void LoadGraph(GraphCore graph, DirectoryInfo di)
/// <summary>
/// 加载图像动画
/// </summary>
/// <param name="graph">要加载的动画核心</param>
/// <param name="di">当前历遍的目录</param>
/// <param name="startuppath">起始目录</param>
public static void LoadGraph(GraphCore graph, DirectoryInfo di, string startuppath)
{
var list = di.EnumerateDirectories();
if (File.Exists(di.FullName + @"\info.lps"))
@ -67,6 +73,7 @@ namespace VPet_Simulator.Core
{
if (IGraphConvert.TryGetValue(line.Name.ToLower(), out var func))
{
line.Add(new Sub("startuppath", startuppath));
var str = line.GetString("path");
if (!string.IsNullOrEmpty(str))
{
@ -95,14 +102,14 @@ namespace VPet_Simulator.Core
if (paths.Length == 0)
return;
if (paths.Length == 1)
Picture.LoadGraph(graph, paths[0], new Line("picture"));
Picture.LoadGraph(graph, paths[0], new Line("picture", "", "", new Sub("startuppath", startuppath)));
else
PNGAnimation.LoadGraph(graph, di, new Line("pnganimation"));
PNGAnimation.LoadGraph(graph, di, new Line("pnganimation", "", "", new Sub("startuppath", startuppath)));
}
else
foreach (var p in list)
{
LoadGraph(graph, p);
LoadGraph(graph, p, startuppath);
}
}
}

View File

@ -23,9 +23,9 @@ namespace VPet_Simulator.Tool
case "1":
Animation();
break;
case "2":
FontPetNew();
break;
//case "2":
// FontPetNew();
// break;
default:
Console.WriteLine("暂无该功能");
goto start;
@ -77,56 +77,56 @@ namespace VPet_Simulator.Tool
}
}
static void FontPetNew()
{
Console.WriteLine("请输入储存位置");
DirectoryInfo directoryInfo = new DirectoryInfo(Console.ReadLine());
//static void FontPetNew()
//{
// Console.WriteLine("请输入储存位置");
// DirectoryInfo directoryInfo = new DirectoryInfo(Console.ReadLine());
var elist = Properties.Resources.laenum.Replace(" ", "").Replace("/// <summary>", "")
.Replace("/// </summary>", "").Replace("/// ", "").Replace("\r", "").Replace("\n\n", "\n")
.Replace("\n\n", "\n").Replace("\n\n", "\n").Split('\n').ToList();
elist.RemoveAll(x => x.EndsWith(","));
for (int i = 0; i < elist.Count; i++)
{
var paths = GraphTypeValue[i].Split('_');
DirectoryInfo nowpath = directoryInfo;
foreach (var path in paths)
{
nowpath = nowpath.CreateSubdirectory(path);
}
foreach (string v in Enum.GetNames(typeof(GameSave.ModeType)))
{
using (Bitmap image = new Bitmap(500, 500))
{
using (Graphics g = Graphics.FromImage(image))
{
var strs = elist[i].Split(' ');
g.DrawString(strs[0], new Font("胡晓波男神体2.0", 66, FontStyle.Bold), new SolidBrush(Color.DarkSlateBlue), 10, 100);
g.DrawString(strs[0], new Font("胡晓波男神体2.0", 64), new SolidBrush(Color.AliceBlue), 15, 100);
for (int j = 1; j < strs.Length - 1; j++)
{
g.DrawString(strs[j], new Font("胡晓波萌萌体", 50, FontStyle.Bold), new SolidBrush(Color.LightGray), 10, 150 + 50 * j);
g.DrawString(strs[j], new Font("胡晓波萌萌体", 48, FontStyle.Bold), new SolidBrush(Color.Gray), 15, 150 + 50 * j);
}
g.DrawString(v, new Font("胡晓波润圆体35", 50, FontStyle.Bold), new SolidBrush(Color.DeepSkyBlue), 10, 350);
g.DrawString(v, new Font("胡晓波润圆体35", 48, FontStyle.Bold), new SolidBrush(Color.SkyBlue), 15, 350);
int len = 2000;
var last = strs.Last();
if(last == "S")
{
len = 250;
}
else if (last == "M")
{
len = 1000;
}
image.Save(nowpath.CreateSubdirectory(v).FullName + $"\\{paths[0]}_{len}.png");
}
}
}
// var elist = Properties.Resources.laenum.Replace(" ", "").Replace("/// <summary>", "")
// .Replace("/// </summary>", "").Replace("/// ", "").Replace("\r", "").Replace("\n\n", "\n")
// .Replace("\n\n", "\n").Replace("\n\n", "\n").Split('\n').ToList();
// elist.RemoveAll(x => x.EndsWith(","));
// for (int i = 0; i < elist.Count; i++)
// {
// var paths = GraphTypeValue[i].Split('_');
// DirectoryInfo nowpath = directoryInfo;
// foreach (var path in paths)
// {
// nowpath = nowpath.CreateSubdirectory(path);
// }
// foreach (string v in Enum.GetNames(typeof(GameSave.ModeType)))
// {
// using (Bitmap image = new Bitmap(500, 500))
// {
// using (Graphics g = Graphics.FromImage(image))
// {
// var strs = elist[i].Split(' ');
// g.DrawString(strs[0], new Font("胡晓波男神体2.0", 66, FontStyle.Bold), new SolidBrush(Color.DarkSlateBlue), 10, 100);
// g.DrawString(strs[0], new Font("胡晓波男神体2.0", 64), new SolidBrush(Color.AliceBlue), 15, 100);
// for (int j = 1; j < strs.Length - 1; j++)
// {
// g.DrawString(strs[j], new Font("胡晓波萌萌体", 50, FontStyle.Bold), new SolidBrush(Color.LightGray), 10, 150 + 50 * j);
// g.DrawString(strs[j], new Font("胡晓波萌萌体", 48, FontStyle.Bold), new SolidBrush(Color.Gray), 15, 150 + 50 * j);
// }
// g.DrawString(v, new Font("胡晓波润圆体35", 50, FontStyle.Bold), new SolidBrush(Color.DeepSkyBlue), 10, 350);
// g.DrawString(v, new Font("胡晓波润圆体35", 48, FontStyle.Bold), new SolidBrush(Color.SkyBlue), 15, 350);
// int len = 2000;
// var last = strs.Last();
// if(last == "S")
// {
// len = 250;
// }
// else if (last == "M")
// {
// len = 1000;
// }
// image.Save(nowpath.CreateSubdirectory(v).FullName + $"\\{paths[0]}_{len}.png");
// }
// }
// }
}
}
// }
//}
public static string GetFileHash(FileInfo fileInfo)
{
//创建一个哈希算法对象

View File

@ -326,7 +326,7 @@ namespace VPet_Simulator.Windows
if (new TimeSpan(DateTime.Now.Ticks - lastclicktime).TotalSeconds > 20)
{
lastclicktime = DateTime.Now.Ticks;
Main.Say(rndtext[Function.Rnd.Next(rndtext.Count)]);
Main.SayRnd(rndtext[Function.Rnd.Next(rndtext.Count)]);
}
};
Main.PlayVoiceVolume = Set.VoiceVolume;
@ -435,7 +435,7 @@ namespace VPet_Simulator.Windows
notifyIcon.ShowBalloonTip(10, "你好".Translate() + (IsSteamUser ? Steamworks.SteamClient.Name : Environment.UserName),
"欢迎使用虚拟桌宠模拟器!\n如果遇到桌宠爬不见了,可以在我这里设置居中或退出桌宠".Translate(), ToolTipIcon.Info);
Thread.Sleep(2000);
Main.Say("欢迎使用虚拟桌宠模拟器\n这是个中期的测试版,若有bug请多多包涵\n欢迎加群虚拟主播模拟器430081239或在菜单栏-管理-反馈中提交bug或建议".Translate());
Main.SayRnd("欢迎使用虚拟桌宠模拟器\n这是个中期的测试版,若有bug请多多包涵\n欢迎加群虚拟主播模拟器430081239或在菜单栏-管理-反馈中提交bug或建议".Translate());
});
}
else if (Set["SingleTips"].GetDateTime("update") <= new DateTime(2023, 6, 26) && LocalizeCore.CurrentCulture.StartsWith("cn"))

View File

@ -106,7 +106,7 @@ namespace VPet_Simulator.Windows
}
catch (Exception exp)
{
m.Say(exp.ToString());//, GraphCore.Helper.SayType.Serious);
m.SayRnd(exp.ToString());//, GraphCore.Helper.SayType.Serious);
rettype = false;
}
Dispatcher.Invoke(() => this.IsEnabled = true);

View File

@ -44,7 +44,7 @@ namespace VPet_Simulator.Windows
}
if (mw.CGPTClient == null)
{
m.Say("请先前往设置中设置 ChatGPT API".Translate());
m.SayRnd("请先前往设置中设置 ChatGPT API".Translate());
return;
}
Dispatcher.Invoke(() => this.IsEnabled = false);
@ -60,7 +60,7 @@ namespace VPet_Simulator.Windows
{
str = "请检查API token设置".Translate();
}
m.Say("API调用失败".Translate() + $",{str}\n{e}");//, GraphCore.Helper.SayType.Serious);
m.SayRnd("API调用失败".Translate() + $",{str}\n{e}");//, GraphCore.Helper.SayType.Serious);
}
Dispatcher.Invoke(() => this.IsEnabled = true);
}

View File

@ -29,8 +29,8 @@ namespace VPet_Simulator.Windows
foreach (AnimatType k in v.Value.Keys)
{
var str = v.Key.ToString() + "++" + k.ToString();
GraphListBox.Items.Add(v.Key);
GraphListPlayerBox.Items.Add(v);
GraphListBox.Items.Add(str);
GraphListPlayerBox.Items.Add(str);
}
}
if (mw.Core.Graph.GraphsName.TryGetValue(GraphType.Say, out var gl))