VPet/VPet-Simulator.Core/Display/MainDisplay.cs

679 lines
26 KiB
C#
Raw Normal View History

2022-12-13 07:10:18 +00:00
using System;
2023-06-25 18:54:34 +00:00
using System.Threading.Tasks;
2022-12-14 18:17:13 +00:00
using System.Windows;
2023-01-19 15:26:58 +00:00
using System.Windows.Controls;
2022-12-13 07:10:18 +00:00
using System.Windows.Threading;
2023-01-20 07:08:28 +00:00
using static VPet_Simulator.Core.GraphCore;
2023-06-25 18:54:34 +00:00
using Panuon.WPF.UI;
2023-07-01 07:46:08 +00:00
using LinePutScript.Localization.WPF;
2023-07-16 23:58:09 +00:00
using static VPet_Simulator.Core.GraphInfo;
using System.Xml.Linq;
using System.Linq;
2023-08-23 19:49:16 +00:00
using System.Windows.Media;
2023-07-01 07:46:08 +00:00
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Core
{
public partial class Main
{
2023-01-20 07:08:28 +00:00
/// <summary>
/// 当前动画类型
/// </summary>
2023-07-16 23:58:09 +00:00
public GraphInfo DisplayType = new GraphInfo("");
2022-12-13 07:10:18 +00:00
/// <summary>
2023-01-20 07:08:28 +00:00
/// 默认循环次数
/// </summary>
public int CountNomal = 0;
/// <summary>
2023-05-19 08:17:51 +00:00
/// 以标准形式显示当前默认状态
/// </summary>
public void DisplayToNomal()
{
switch (State)
{
default:
case WorkingState.Nomal:
DisplayNomal();
return;
case WorkingState.Sleep:
DisplaySleep(true);
return;
2023-07-16 23:58:09 +00:00
case WorkingState.Work:
2023-08-10 16:07:28 +00:00
nowWork.Display(this);
2023-05-19 08:17:51 +00:00
return;
2023-07-16 23:58:09 +00:00
case WorkingState.Travel:
//TODO
2023-05-19 08:17:51 +00:00
return;
}
}
/// <summary>
2022-12-13 07:10:18 +00:00
/// 显示默认情况
/// </summary>
public void DisplayNomal()
{
2023-01-20 07:08:28 +00:00
CountNomal++;
2023-07-16 23:58:09 +00:00
Display(GraphType.Default, AnimatType.Single, DisplayNomal);
2022-12-13 07:10:18 +00:00
}
2023-01-19 15:26:58 +00:00
/// <summary>
/// 显示结束动画
/// </summary>
2023-07-18 18:09:51 +00:00
/// <param name="EndAction">结束后接下来,不结束不运行</param>
2023-01-19 15:26:58 +00:00
/// <returns>是否成功结束</returns>
2023-07-18 18:09:51 +00:00
public bool DisplayStop(Action EndAction)
2023-01-19 15:26:58 +00:00
{
2023-07-16 23:58:09 +00:00
var graph = Core.Graph.FindGraph(DisplayType.Name, AnimatType.C_End, Core.Save.Mode);
if (graph != null)
2023-01-19 15:26:58 +00:00
{
2023-07-18 18:39:12 +00:00
if (State == WorkingState.Sleep)
2023-07-17 15:38:06 +00:00
State = WorkingState.Nomal;
2023-07-16 23:58:09 +00:00
Display(graph, EndAction);
return true;
2023-01-19 15:26:58 +00:00
}
2023-07-16 23:58:09 +00:00
//switch (DisplayType)
//{
// case GraphType.Idel:
// Display(GraphType.Boring_C_End, EndAction);
// return true;
// case GraphType.Squat_B_Loop:
// Display(GraphType.Squat_C_End, EndAction);
// return true;
// case GraphType.Crawl_Left_B_Loop:
// Display(GraphType.Crawl_Left_C_End, EndAction);
// return true;
// case GraphType.Crawl_Right_B_Loop:
// Display(GraphType.Crawl_Right_C_End, EndAction);
// return true;
// case GraphType.Fall_Left_B_Loop:
// Display(GraphType.Fall_Left_C_End,
// () => Display(GraphType.Climb_Up_Left, EndAction));
// return true;
// case GraphType.Fall_Right_B_Loop:
// Display(GraphType.Fall_Right_C_End,
// () => Display(GraphType.Climb_Up_Right, EndAction));
// return true;
// case GraphType.Walk_Left_B_Loop:
// Display(GraphType.Walk_Left_C_End, EndAction);
// return true;
// case GraphType.Walk_Right_B_Loop:
// Display(GraphType.Walk_Right_C_End, EndAction);
// return true;
// case GraphType.Sleep_B_Loop:
// State = WorkingState.Nomal;
// Display(GraphType.Sleep_C_End, EndAction);
// return true;
// case GraphType.Idel_StateONE_B_Loop:
// Display(GraphType.Idel_StateONE_C_End, EndAction);
// return true;
// case GraphType.Idel_StateTWO_B_Loop:
// Display(GraphType.Idel_StateTWO_C_End, () => Display(GraphType.Idel_StateONE_C_End, EndAction));
// return true;
// //case GraphType.Climb_Left:
// //case GraphType.Climb_Right:
// //case GraphType.Climb_Top_Left:
// //case GraphType.Climb_Top_Right:
// // DisplayFalled_Left();
// // return true;
//}
2023-01-19 15:26:58 +00:00
return false;
}
/// <summary>
2023-07-18 18:09:51 +00:00
/// 显示结束动画 无论是否结束,都强制结束
/// </summary>
/// <param name="EndAction">结束后接下来,不结束也运行</param>
public void DisplayStopForce(Action EndAction)
{
2023-07-18 18:39:12 +00:00
if (!DisplayStop(EndAction))
2023-07-18 18:09:51 +00:00
EndAction?.Invoke();
}
2023-07-24 01:52:27 +00:00
2023-07-18 18:09:51 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 尝试触发移动
/// </summary>
2023-07-16 23:58:09 +00:00
/// <returns></returns>
public bool DisplayMove()
{
2023-07-16 23:58:09 +00:00
var list = Core.Graph.GraphConfig.Moves.ToList();
for (int i = Function.Rnd.Next(list.Count); 0 != list.Count; i = Function.Rnd.Next(list.Count))
{
var move = list[i];
2023-07-18 18:09:51 +00:00
if (move.Triggered(this))
2023-07-16 23:58:09 +00:00
{
move.Display(this);
return true;
}
else
{
list.RemoveAt(i);
}
}
return false;
}
2022-12-13 07:10:18 +00:00
/// <summary>
2023-07-23 20:46:21 +00:00
/// 当发生摸头时触发改方法
/// </summary>
public event Action Event_TouchHead;
/// <summary>
2022-12-13 07:10:18 +00:00
/// 显示摸头情况
/// </summary>
public void DisplayTouchHead()
{
2023-07-16 23:58:09 +00:00
CountNomal = 0;
2023-05-10 03:13:34 +00:00
if (Core.Controller.EnableFunction && Core.Save.Strength >= 10 && Core.Save.Feeling < 100)
2023-02-20 08:47:44 +00:00
{
2023-06-18 18:11:40 +00:00
Core.Save.StrengthChange(-2);
2023-02-20 08:47:44 +00:00
Core.Save.FeelingChange(1);
Core.Save.Mode = Core.Save.CalMode();
2023-07-01 07:46:08 +00:00
LabelDisplayShowChangeNumber(LocalizeCore.Translate("体力-{0:f0} 心情+{1:f0}"), 2, 1);
2023-02-20 08:47:44 +00:00
}
2023-07-16 23:58:09 +00:00
if (DisplayType.Type == GraphType.Touch_Head)
{
if (DisplayType.Animat == AnimatType.A_Start)
2022-12-14 18:17:13 +00:00
return;
2023-07-16 23:58:09 +00:00
else if (DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
{
ig.IsContinue = true;
return;
}
else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{
ig2.IsContinue = true;
return;
}
}
2023-07-23 20:46:21 +00:00
Event_TouchHead?.Invoke();
2023-07-16 23:58:09 +00:00
Display(GraphType.Touch_Head, AnimatType.A_Start, (graphname) =>
Display(graphname, AnimatType.B_Loop, (graphname) =>
DisplayCEndtoNomal(graphname)));
2022-12-13 07:10:18 +00:00
}
2023-02-21 11:37:01 +00:00
/// <summary>
2023-07-23 20:46:21 +00:00
/// 当发生摸身体时触发改方法
/// </summary>
public event Action Event_TouchBody;
/// <summary>
2023-02-21 11:37:01 +00:00
/// 显示摸身体情况
/// </summary>
public void DisplayTouchBody()
{
2023-07-16 23:58:09 +00:00
CountNomal = 0;
2023-05-10 03:13:34 +00:00
if (Core.Controller.EnableFunction && Core.Save.Strength >= 10 && Core.Save.Feeling < 100)
2023-02-21 11:37:01 +00:00
{
2023-06-18 18:11:40 +00:00
Core.Save.StrengthChange(-2);
2023-02-21 11:37:01 +00:00
Core.Save.FeelingChange(1);
Core.Save.Mode = Core.Save.CalMode();
2023-07-01 07:46:08 +00:00
LabelDisplayShowChangeNumber(LocalizeCore.Translate("体力-{0:f0} 心情+{1:f0}"), 2, 1);
2023-02-21 11:37:01 +00:00
}
2023-07-16 23:58:09 +00:00
if (DisplayType.Type == GraphType.Touch_Body)
{
if (DisplayType.Animat == AnimatType.A_Start)
2023-02-21 11:37:01 +00:00
return;
2023-07-16 23:58:09 +00:00
else if (DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
{
ig.IsContinue = true;
return;
}
else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{
ig2.IsContinue = true;
return;
}
}
2023-07-23 20:46:21 +00:00
Event_TouchBody?.Invoke();
2023-07-16 23:58:09 +00:00
Display(GraphType.Touch_Body, AnimatType.A_Start, (graphname) =>
Display(graphname, AnimatType.B_Loop, (graphname) =>
DisplayCEndtoNomal(graphname)));
2023-02-21 11:37:01 +00:00
}
2023-01-19 15:26:58 +00:00
/// <summary>
2023-01-28 06:12:01 +00:00
/// 显示待机(模式1)情况
2023-01-19 15:26:58 +00:00
/// </summary>
2023-01-28 06:12:01 +00:00
public void DisplayIdel_StateONE()
2023-01-19 15:26:58 +00:00
{
looptimes = 0;
CountNomal = 0;
2023-07-18 18:39:12 +00:00
var name = Core.Graph.FindName(GraphType.StateONE);
var list = Core.Graph.FindGraphs(name, AnimatType.A_Start, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == GraphType.StateONE);
2023-07-17 15:38:06 +00:00
if (list != null && list.Count > 0)
2023-07-16 23:58:09 +00:00
Display(list[Function.Rnd.Next(list.Count)], () => DisplayIdel_StateONEing(name));
else
2023-07-18 18:39:12 +00:00
Display(GraphType.StateONE, AnimatType.A_Start, DisplayIdel_StateONEing);
2023-01-19 15:26:58 +00:00
}
/// <summary>
2023-01-28 06:12:01 +00:00
/// 显示待机(模式1)情况
2023-01-19 15:26:58 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
private void DisplayIdel_StateONEing(string graphname)
2023-01-19 15:26:58 +00:00
{
2023-07-16 23:58:09 +00:00
if (Function.Rnd.Next(++looptimes) > Core.Graph.GraphConfig.GetDuration(graphname))
2023-01-28 06:12:01 +00:00
switch (Function.Rnd.Next(2 + CountNomal))
{
case 0:
2023-07-16 23:58:09 +00:00
DisplayIdel_StateTWO(graphname);
2023-01-28 06:12:01 +00:00
break;
default:
2023-07-18 18:39:12 +00:00
Display(graphname, AnimatType.C_End, GraphType.StateONE, DisplayNomal);
2023-01-28 06:12:01 +00:00
break;
}
2023-01-19 15:26:58 +00:00
else
2023-07-16 23:58:09 +00:00
{
2023-07-18 18:39:12 +00:00
Display(graphname, AnimatType.B_Loop, GraphType.StateONE, DisplayIdel_StateONEing);
2023-07-16 23:58:09 +00:00
}
2023-01-28 06:12:01 +00:00
}
/// <summary>
/// 显示待机(模式2)情况
/// </summary>
2023-07-16 23:58:09 +00:00
public void DisplayIdel_StateTWO(string graphname)
2023-01-28 06:12:01 +00:00
{
looptimes = 0;
CountNomal++;
2023-07-18 18:39:12 +00:00
Display(graphname, AnimatType.A_Start, GraphType.StateTWO, DisplayIdel_StateTWOing);
2023-01-19 15:26:58 +00:00
}
2023-01-28 06:12:01 +00:00
/// <summary>
/// 显示待机(模式2)情况
/// </summary>
2023-07-16 23:58:09 +00:00
private void DisplayIdel_StateTWOing(string graphname)
2023-01-28 06:12:01 +00:00
{
2023-07-16 23:58:09 +00:00
if (Function.Rnd.Next(++looptimes) > Core.Graph.GraphConfig.GetDuration(graphname))
{
looptimes = 0;
2023-07-18 18:39:12 +00:00
Display(graphname, AnimatType.C_End, GraphType.StateTWO, DisplayIdel_StateONEing);
2023-07-16 23:58:09 +00:00
}
2023-01-28 06:12:01 +00:00
else
2023-07-16 23:58:09 +00:00
{
2023-07-18 18:39:12 +00:00
Display(graphname, AnimatType.B_Loop, GraphType.StateTWO, DisplayIdel_StateTWOing);
2023-07-16 23:58:09 +00:00
}
2023-01-28 06:12:01 +00:00
}
2023-01-19 15:26:58 +00:00
int looptimes;
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示待机情况 (只有符合条件的才会显示)
2023-01-19 15:26:58 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
public bool DisplayIdel()
2023-01-19 15:26:58 +00:00
{
2023-07-16 23:58:09 +00:00
if (Core.Graph.GraphsName.TryGetValue(GraphType.Idel, out var gl))
{
var list = gl.ToList();
for (int i = Function.Rnd.Next(list.Count); 0 != list.Count; i = Function.Rnd.Next(list.Count))
{
var idelname = list[i];
var ig = Core.Graph.FindGraphs(idelname, AnimatType.A_Start, Core.Save.Mode);
if (ig != null)
{
looptimes = 0;
CountNomal = 0;
DisplayBLoopingToNomal(idelname, Core.Graph.GraphConfig.GetDuration(idelname));
return true;
}
else
{
list.RemoveAt(i);
}
}
return false;
}
2023-01-19 15:26:58 +00:00
else
2023-07-16 23:58:09 +00:00
return false;
2023-01-19 15:26:58 +00:00
}
2023-01-28 06:12:01 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示B循环+C循环+ToNomal
2023-01-28 06:12:01 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
public Action<string> DisplayBLoopingToNomal(int looplength) => (gn) => DisplayBLoopingToNomal(gn, looplength);
2023-01-28 06:12:01 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示B循环+C循环+ToNomal
2023-01-28 06:12:01 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
public void DisplayBLoopingToNomal(string graphname, int loopLength)
2023-01-28 06:12:01 +00:00
{
2023-07-16 23:58:09 +00:00
if (Function.Rnd.Next(++looptimes) > loopLength)
DisplayCEndtoNomal(graphname);
2023-01-28 06:12:01 +00:00
else
2023-07-16 23:58:09 +00:00
Display(graphname, AnimatType.B_Loop, DisplayBLoopingToNomal(loopLength));
2023-01-28 06:12:01 +00:00
}
2023-01-25 04:49:18 +00:00
/// <summary>
/// 显示睡觉情况
/// </summary>
public void DisplaySleep(bool force = false)
{
looptimes = 0;
CountNomal = 0;
if (force)
2023-05-19 08:17:51 +00:00
{
State = WorkingState.Sleep;
2023-07-16 23:58:09 +00:00
Display(GraphType.Sleep, AnimatType.A_Start, DisplayBLoopingForce);
2023-05-19 08:17:51 +00:00
}
2023-01-25 04:49:18 +00:00
else
2023-07-18 18:39:12 +00:00
Display(GraphType.Sleep, AnimatType.A_Start, (x) => DisplayBLoopingToNomal(x, Core.Graph.GraphConfig.GetDuration(x)));
2023-01-25 04:49:18 +00:00
}
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示B循环 (强制)
2023-01-25 04:49:18 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
public void DisplayBLoopingForce(string graphname)
2023-01-25 04:49:18 +00:00
{
2023-07-16 23:58:09 +00:00
Display(graphname, AnimatType.B_Loop, DisplayBLoopingForce);
2023-01-25 04:49:18 +00:00
}
2023-07-16 23:58:09 +00:00
//显示工作现在直接由显示调用,没有DisplayWork, 学习同理
2022-12-13 07:10:18 +00:00
/// <summary>
/// 显示拖拽情况
/// </summary>
public void DisplayRaised()
{
//位置迁移: 254-128
MainGrid.MouseMove += MainGrid_MouseMove;
2023-02-20 08:47:44 +00:00
MainGrid.MouseMove -= MainGrid_MouseWave;
2022-12-13 07:10:18 +00:00
rasetype = 0;
DisplayRaising();
}
2023-01-20 07:08:28 +00:00
int rasetype = int.MinValue;
2022-12-13 07:10:18 +00:00
/// <summary>
/// 显示拖拽中
/// </summary>
2023-07-16 23:58:09 +00:00
private void DisplayRaising(string name = null)
2022-12-13 07:10:18 +00:00
{
2023-07-17 15:38:06 +00:00
Console.WriteLine(rasetype);
2023-01-23 17:31:16 +00:00
switch (rasetype)
2022-12-13 07:10:18 +00:00
{
2023-01-23 17:31:16 +00:00
case int.MinValue:
break;
2022-12-13 07:10:18 +00:00
case -1:
2023-01-20 07:08:28 +00:00
rasetype = int.MinValue;
2023-12-02 10:12:03 +00:00
Core.Controller.RePostionActive = !Core.Controller.CheckPosition();
2023-07-16 23:58:09 +00:00
if (string.IsNullOrEmpty(name))
Display(GraphType.Raised_Static, AnimatType.C_End, DisplayToNomal);
else
Display(name, AnimatType.C_End, GraphType.Raised_Static, DisplayToNomal);
2022-12-13 07:10:18 +00:00
return;
case 0:
case 1:
case 2:
2023-01-23 17:31:16 +00:00
rasetype++;
2023-07-16 23:58:09 +00:00
if (string.IsNullOrEmpty(name))
Display(GraphType.Raised_Dynamic, AnimatType.Single, DisplayRaising);
else
Display(name, AnimatType.Single, GraphType.Raised_Dynamic, DisplayRaising);
2022-12-13 07:10:18 +00:00
return;
case 3:
2023-01-23 17:31:16 +00:00
rasetype++;
2023-07-16 23:58:09 +00:00
if (string.IsNullOrEmpty(name))
Display(name, AnimatType.A_Start, DisplayRaising);
else
Display(name, AnimatType.A_Start, GraphType.Raised_Static, DisplayRaising);
2022-12-13 07:10:18 +00:00
return;
default:
rasetype = 4;
2023-07-16 23:58:09 +00:00
if (string.IsNullOrEmpty(name))
Display(name, AnimatType.B_Loop, DisplayRaising);
else
Display(name, AnimatType.B_Loop, GraphType.Raised_Static, DisplayRaising);
return;
2022-12-14 18:17:13 +00:00
}
}
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示结束动画到正常动画 (DisplayToNomal)
2022-12-14 18:17:13 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
public void DisplayCEndtoNomal(string graphname)
2022-12-14 18:17:13 +00:00
{
2023-07-16 23:58:09 +00:00
Display(graphname, AnimatType.C_End, DisplayToNomal);
2022-12-14 18:17:13 +00:00
}
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 (自动查找和匹配)
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="Type">动画类型</param>
/// <param name="EndAction">动画结束后操作(附带名字)</param>
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(GraphType Type, AnimatType animat, Action<string> EndAction = null)
{
2023-07-16 23:58:09 +00:00
var name = Core.Graph.FindName(Type);
Display(name, animat, EndAction);
}
2023-01-21 14:16:13 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 根据名字播放
2023-01-21 14:16:13 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="name">动画名称</param>
/// <param name="EndAction">动画结束后操作(附带名字)</param>
/// <param name="animat">动画的动作 Start Loop End</param>
2023-08-10 11:34:11 +00:00
public void Display(string name, AnimatType animat, Action<string> EndAction)
2023-01-21 14:16:13 +00:00
{
2023-07-16 23:58:09 +00:00
Display(Core.Graph.FindGraph(name, animat, Core.Save.Mode), new Action(() => EndAction.Invoke(name)));
2023-01-21 14:16:13 +00:00
}
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 根据名字和类型查找运行,若无则查找类型
2023-01-21 14:16:13 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="Type">动画类型</param>
/// <param name="name">动画名称</param>
/// <param name="EndAction">动画结束后操作(附带名字)</param>
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(string name, AnimatType animat, GraphType Type, Action<string> EndAction = null)
{
2023-07-17 15:38:06 +00:00
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == Type);
2023-09-24 06:27:32 +00:00
if ((list?.Count ?? -1) > 0)
2023-07-16 23:58:09 +00:00
Display(list[Function.Rnd.Next(list.Count)], () => EndAction(name));
2023-01-21 14:16:13 +00:00
else
2023-07-16 23:58:09 +00:00
Display(Type, animat, EndAction);
2023-01-21 14:16:13 +00:00
}
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 根据名字和类型查找运行,若无则查找类型
2023-01-21 14:16:13 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="Type">动画类型</param>
/// <param name="name">动画名称</param>
/// <param name="EndAction">动画结束后操作</param>
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(string name, AnimatType animat, GraphType Type, Action EndAction = null)
2023-01-21 14:16:13 +00:00
{
2023-07-17 15:38:06 +00:00
var list = Core.Graph.FindGraphs(name, animat, Core.Save.Mode)?.FindAll(x => x.GraphInfo.Type == Type);
2023-09-24 06:27:32 +00:00
if ((list?.Count ?? -1) > 0)
2023-07-16 23:58:09 +00:00
Display(list[Function.Rnd.Next(list.Count)], EndAction);
2023-01-21 14:16:13 +00:00
else
2023-07-16 23:58:09 +00:00
Display(Type, animat, EndAction);
2023-01-21 14:16:13 +00:00
}
2023-08-26 06:52:53 +00:00
2023-01-21 14:16:13 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 (自动查找和匹配)
2023-01-21 14:16:13 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="Type">动画类型</param>
/// <param name="EndAction">动画结束后操作</param>
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(GraphType Type, AnimatType animat, Action EndAction = null)
2023-01-21 14:16:13 +00:00
{
2023-07-16 23:58:09 +00:00
var name = Core.Graph.FindName(Type);
Display(name, animat, EndAction);
2023-01-21 14:16:13 +00:00
}
2023-01-25 04:49:18 +00:00
/// <summary>
2023-07-16 23:58:09 +00:00
/// 显示动画 根据名字播放
2023-01-25 04:49:18 +00:00
/// </summary>
2023-07-16 23:58:09 +00:00
/// <param name="name">动画名称</param>
2023-01-25 04:49:18 +00:00
/// <param name="EndAction">动画结束后操作</param>
2023-07-16 23:58:09 +00:00
/// <param name="animat">动画的动作 Start Loop End</param>
public void Display(string name, AnimatType animat, Action EndAction = null)
2023-01-21 14:16:13 +00:00
{
2023-07-16 23:58:09 +00:00
Display(Core.Graph.FindGraph(name, animat, Core.Save.Mode), EndAction);
2023-01-21 14:16:13 +00:00
}
2022-12-13 07:10:18 +00:00
bool petgridcrlf = true;
2023-07-24 01:52:27 +00:00
int nodisplayLoop = 0;
2022-12-13 07:10:18 +00:00
/// <summary>
/// 显示动画 (自动多层切换)
/// </summary>
/// <param name="graph">动画</param>
/// <param name="EndAction">结束操作</param>
public void Display(IGraph graph, Action EndAction = null)
{
2023-02-20 08:47:44 +00:00
if (graph == null)
2023-01-29 08:27:24 +00:00
{
2023-07-24 01:52:27 +00:00
if (nodisplayLoop++ > 20)
{//无动画时运行兼容性动画
if (nodisplayLoop < 100)
Display(GraphType.Default, AnimatType.Single, EndAction);
else
{//连Nomal都没有, 证明是未完成的动画, 修改设置+退出游戏
Dispatcher.Invoke(() =>
{
LabelDisplay.Content = "未找到可播放动画, 已停止运行桌宠模块".Translate();
LabelDisplay.Visibility = Visibility.Visible;
IsEnabled = false;
});
}
}
else
EndAction?.Invoke();
2023-01-29 08:27:24 +00:00
return;
}
2023-07-24 01:52:27 +00:00
else
{
nodisplayLoop = 0;
}
2023-01-20 07:08:28 +00:00
//if(graph.GraphType == GraphType.Climb_Up_Left)
//{
// Dispatcher.Invoke(() => Say(graph.GraphType.ToString()));
//}
2023-07-16 23:58:09 +00:00
DisplayType = graph.GraphInfo;
2023-03-26 22:35:19 +00:00
var PetGridTag = Dispatcher.Invoke(() => PetGrid.Tag);
var PetGrid2Tag = Dispatcher.Invoke(() => PetGrid2.Tag);
if (PetGridTag == graph)
2022-12-13 07:10:18 +00:00
{
petgridcrlf = true;
2023-03-26 22:35:19 +00:00
((IGraph)(PetGrid2Tag)).Stop(true);
2023-01-19 15:26:58 +00:00
Dispatcher.Invoke(() =>
{
2023-01-20 07:08:28 +00:00
PetGrid.Visibility = Visibility.Visible;
2023-01-25 16:23:09 +00:00
PetGrid2.Visibility = Visibility.Hidden;
2023-01-21 14:16:13 +00:00
});
2023-03-26 22:35:19 +00:00
graph.Run(PetGrid, EndAction);//(x) => PetGrid.Child = x
2022-12-13 07:10:18 +00:00
return;
}
2023-03-26 22:35:19 +00:00
else if (PetGrid2Tag == graph)
2022-12-13 07:10:18 +00:00
{
petgridcrlf = false;
2023-03-26 22:35:19 +00:00
((IGraph)(PetGridTag)).Stop(true);
2023-01-19 15:26:58 +00:00
Dispatcher.Invoke(() =>
{
2023-01-20 07:08:28 +00:00
PetGrid2.Visibility = Visibility.Visible;
2023-01-25 16:23:09 +00:00
PetGrid.Visibility = Visibility.Hidden;
});
2023-03-26 22:35:19 +00:00
graph.Run(PetGrid2, EndAction);
2022-12-13 07:10:18 +00:00
return;
}
2023-03-26 22:35:19 +00:00
2022-12-13 07:10:18 +00:00
if (petgridcrlf)
{
2023-03-26 22:46:23 +00:00
graph.Run(PetGrid2, EndAction);
2023-03-26 22:35:19 +00:00
((IGraph)(PetGridTag)).Stop(true);
2023-01-19 15:26:58 +00:00
Dispatcher.Invoke(() =>
{
2023-01-25 16:23:09 +00:00
PetGrid.Visibility = Visibility.Hidden;
2023-01-20 07:08:28 +00:00
PetGrid2.Visibility = Visibility.Visible;
2023-03-26 22:35:19 +00:00
//PetGrid2.Tag = graph;
2023-05-10 03:13:34 +00:00
});
2022-12-13 07:10:18 +00:00
}
else
{
2023-03-26 22:46:23 +00:00
graph.Run(PetGrid, EndAction);
2023-03-26 22:35:19 +00:00
((IGraph)(PetGrid2Tag)).Stop(true);
2023-01-19 15:26:58 +00:00
Dispatcher.Invoke(() =>
{
2023-01-25 16:23:09 +00:00
PetGrid2.Visibility = Visibility.Hidden;
2023-01-20 07:08:28 +00:00
PetGrid.Visibility = Visibility.Visible;
2023-03-26 22:35:19 +00:00
//PetGrid.Tag = graph;
2023-05-10 03:13:34 +00:00
});
2022-12-13 07:10:18 +00:00
}
petgridcrlf = !petgridcrlf;
2023-03-26 22:46:23 +00:00
GC.Collect();
2022-12-13 07:10:18 +00:00
}
2023-06-01 08:16:45 +00:00
/// <summary>
/// 查找可用与显示的Border (自动多层切换)
/// </summary>
/// <param name="graph">动画</param>
public Border FindDisplayBorder(IGraph graph)
{
2023-07-16 23:58:09 +00:00
DisplayType = graph.GraphInfo;
2023-06-01 08:16:45 +00:00
var PetGridTag = Dispatcher.Invoke(() => PetGrid.Tag);
var PetGrid2Tag = Dispatcher.Invoke(() => PetGrid2.Tag);
if (PetGridTag == graph)
{
petgridcrlf = true;
((IGraph)(PetGrid2Tag)).Stop(true);
Dispatcher.Invoke(() =>
{
PetGrid.Visibility = Visibility.Visible;
PetGrid2.Visibility = Visibility.Hidden;
});
return PetGrid;
}
else if (PetGrid2Tag == graph)
{
petgridcrlf = false;
((IGraph)(PetGridTag)).Stop(true);
Dispatcher.Invoke(() =>
{
PetGrid2.Visibility = Visibility.Visible;
PetGrid.Visibility = Visibility.Hidden;
});
return PetGrid2;
}
if (petgridcrlf)
{
((IGraph)(PetGridTag)).Stop(true);
Dispatcher.Invoke(() =>
{
PetGrid.Visibility = Visibility.Hidden;
PetGrid2.Visibility = Visibility.Visible;
//PetGrid2.Tag = graph;
});
petgridcrlf = !petgridcrlf;
GC.Collect();
return PetGrid2;
}
else
2023-06-18 18:11:40 +00:00
{
2023-06-01 08:16:45 +00:00
((IGraph)(PetGrid2Tag)).Stop(true);
Dispatcher.Invoke(() =>
{
PetGrid2.Visibility = Visibility.Hidden;
PetGrid.Visibility = Visibility.Visible;
//PetGrid.Tag = graph;
});
petgridcrlf = !petgridcrlf;
GC.Collect();
return PetGrid;
}
2023-06-18 18:11:40 +00:00
2023-06-01 08:16:45 +00:00
}
2023-08-23 19:49:16 +00:00
/// <summary>
/// 显示夹层动画
/// </summary>
/// <param name="Type">动画类型</param>
/// <param name="img">夹层内容</param>
/// <param name="EndAction">动画结束后操作</param>
public void Display(GraphType Type, ImageSource img, Action EndAction)
{
var name = Core.Graph.FindName(Type);
var ig = Core.Graph.FindGraph(name, AnimatType.Single, Core.Save.Mode);
if (ig != null)
{
var b = FindDisplayBorder(ig);
ig.Run(b, img, EndAction);
}
}
2023-08-30 15:14:41 +00:00
/// <summary>
/// 显示夹层动画
/// </summary>
/// <param name="name">动画名称</param>
/// <param name="img">夹层内容</param>
/// <param name="EndAction">动画结束后操作</param>
public void Display(string name, ImageSource img, Action EndAction)
{
var ig = Core.Graph.FindGraph(name, AnimatType.Single, Core.Save.Mode);
if (ig != null)
{
var b = FindDisplayBorder(ig);
ig.Run(b, img, EndAction);
}
}
2022-12-13 07:10:18 +00:00
}
}