diff --git a/VPet-Simulator.Core/Display/Main.xaml.cs b/VPet-Simulator.Core/Display/Main.xaml.cs
index 46d4d21..c22bb57 100644
--- a/VPet-Simulator.Core/Display/Main.xaml.cs
+++ b/VPet-Simulator.Core/Display/Main.xaml.cs
@@ -29,7 +29,7 @@ namespace VPet_Simulator.Core
///
/// 消息栏
///
- public MessageBar MsgBar;
+ public IMassageBar MsgBar;
///
/// 工作显示栏
///
@@ -65,7 +65,7 @@ namespace VPet_Simulator.Core
UIGrid.Children.Add(ToolBar);
MsgBar = new MessageBar(this);
MsgBar.Visibility = Visibility.Collapsed;
- UIGrid.Children.Add(MsgBar);
+ UIGrid.Children.Add(MsgBar.This);
labeldisplaytimer.Elapsed += Labledisplaytimer_Elapsed;
if (loadtouchevent)
diff --git a/VPet-Simulator.Core/Display/MainLogic.cs b/VPet-Simulator.Core/Display/MainLogic.cs
index f096cd7..9a80c26 100644
--- a/VPet-Simulator.Core/Display/MainLogic.cs
+++ b/VPet-Simulator.Core/Display/MainLogic.cs
@@ -41,6 +41,9 @@ namespace VPet_Simulator.Core
/// 说话
///
/// 说话内容
+ /// 图像名
+ /// 描述
+ /// 强制显示图像
public void Say(string text, string graphname = null, bool force = false, string desc = null)
{
Task.Run(() =>
@@ -51,9 +54,8 @@ namespace VPet_Simulator.Core
{
Dispatcher.Invoke(() =>
{
- if (!string.IsNullOrWhiteSpace(desc))
- MsgBar.MessageBoxContent.Children.Add(new TextBlock() { Text = desc, FontSize = 20, ToolTip = desc, HorizontalAlignment = System.Windows.HorizontalAlignment.Right });
- MsgBar.Show(Core.Save.Name, text, graphname);
+ MsgBar.Show(Core.Save.Name, text, graphname, (string.IsNullOrWhiteSpace(desc) ? null :
+ new TextBlock() { Text = desc, FontSize = 20, ToolTip = desc, HorizontalAlignment = HorizontalAlignment.Right }));
});
DisplayBLoopingForce(graphname);
});
@@ -61,9 +63,38 @@ namespace VPet_Simulator.Core
{
Dispatcher.Invoke(() =>
{
- if (!string.IsNullOrWhiteSpace(desc))
- MsgBar.MessageBoxContent.Children.Add(new TextBlock() { Text = desc, FontSize = 20, ToolTip = desc, HorizontalAlignment = System.Windows.HorizontalAlignment.Right });
- MsgBar.Show(Core.Save.Name, text);
+ MsgBar.Show(Core.Save.Name, text, msgcontent: (string.IsNullOrWhiteSpace(desc) ? null :
+ new TextBlock() { Text = desc, FontSize = 20, ToolTip = desc, HorizontalAlignment = HorizontalAlignment.Right }));
+ });
+ }
+ });
+ }
+ ///
+ /// 说话
+ ///
+ /// 说话内容
+ /// 图像名
+ /// 消息内容
+ /// 强制显示图像
+ public void Say(string text, UIElement msgcontent, string graphname = null, bool force = false)
+ {
+ Task.Run(() =>
+ {
+ OnSay?.Invoke(text);
+ if (force || !string.IsNullOrWhiteSpace(graphname) && DisplayType.Type == GraphType.Default)//这里不使用idle是因为idle包括学习等
+ Display(graphname, AnimatType.A_Start, () =>
+ {
+ Dispatcher.Invoke(() =>
+ {
+ MsgBar.Show(Core.Save.Name, text, graphname, msgcontent);
+ });
+ DisplayBLoopingForce(graphname);
+ });
+ else
+ {
+ Dispatcher.Invoke(() =>
+ {
+ MsgBar.Show(Core.Save.Name, text, msgcontent: msgcontent);
});
}
});
diff --git a/VPet-Simulator.Core/Display/MessageBar.xaml.cs b/VPet-Simulator.Core/Display/MessageBar.xaml.cs
index 63dc1fb..e8a4489 100644
--- a/VPet-Simulator.Core/Display/MessageBar.xaml.cs
+++ b/VPet-Simulator.Core/Display/MessageBar.xaml.cs
@@ -11,11 +11,43 @@ using Timer = System.Timers.Timer;
namespace VPet_Simulator.Core
{
+ public interface IMassageBar : IDisposable
+ {
+ ///
+ /// 显示消息
+ ///
+ /// 名字
+ /// 内容
+ /// 图像名
+ /// 消息框内容
+ void Show(string name, string text, string graphname = null, UIElement msgcontent = null);
+ ///
+ /// 强制关闭
+ ///
+ void ForceClose();
+ ///
+ /// 设置位置在桌宠内
+ ///
+ void SetPlaceIN();
+ ///
+ /// 设置位置在桌宠外
+ ///
+ void SetPlaceOUT();
+ ///
+ /// 显示状态
+ ///
+ Visibility Visibility { get; set; }
+ ///
+ /// 该消息框的UIElement
+ ///
+ UIElement This { get; }
+ }
///
/// MessageBar.xaml 的交互逻辑
///
- public partial class MessageBar : UserControl, IDisposable
+ public partial class MessageBar : UserControl, IDisposable, IMassageBar
{
+ public UIElement This => this;
Main m;
public MessageBar(Main m)
{
@@ -91,7 +123,7 @@ namespace VPet_Simulator.Core
public Action EndAction;
private void EndTimer_Elapsed(object sender, ElapsedEventArgs e)
{
-
+
if (--timeleft <= 0)
{
EndTimer.Stop();
@@ -109,12 +141,13 @@ namespace VPet_Simulator.Core
///
/// 名字
/// 内容
- public void Show(string name, string text, string graphname = null)
+ public void Show(string name, string text, string graphname = null, UIElement msgcontent = null)
{
if (m.UIGrid.Children.IndexOf(this) != m.UIGrid.Children.Count - 1)
{
Panel.SetZIndex(this, m.UIGrid.Children.Count - 1);
}
+ MessageBoxContent.Children.Clear();
TText.Text = "";
outputtext = text.ToList();
LName.Content = name;
@@ -123,6 +156,10 @@ namespace VPet_Simulator.Core
this.Visibility = Visibility.Visible;
Opacity = .8;
graphName = graphname;
+ if (msgcontent != null)
+ {
+ MessageBoxContent.Children.Add(msgcontent);
+ }
}
public void Border_MouseEnter(object sender, MouseEventArgs e)
diff --git a/VPet-Simulator.Windows.Interface/VpetSave.cs b/VPet-Simulator.Windows.Interface/VpetSave.cs
new file mode 100644
index 0000000..c41f056
--- /dev/null
+++ b/VPet-Simulator.Windows.Interface/VpetSave.cs
@@ -0,0 +1,346 @@
+using LinePutScript.Converter;
+using LinePutScript;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VPet_Simulator.Core;
+using static VPet_Simulator.Core.IGameSave;
+
+namespace VPet_Simulator.Windows.Interface;
+
+///
+/// 游戏存档 桌宠桌面端订制版本
+///
+public class VpetSave : IGameSave
+{
+ ///
+ /// 宠物名字
+ ///
+ [Line(name: "name")]
+ public string Name { get; set; }
+
+ ///
+ /// 金钱
+ ///
+ [Line(Type = LPSConvert.ConvertType.ToFloat, Name = "money")]
+ public double Money { get; set; }
+ ///
+ /// 经验值
+ ///
+ [Line(type: LPSConvert.ConvertType.ToFloat, name: "exp")] public double Exp { get; set; }
+ ///
+ /// 等级
+ ///
+ public int Level => Exp < 0 ? 1 : (int)(Math.Sqrt(Exp) / 10) + 1;
+ ///
+ /// 升级所需经验值
+ ///
+ ///
+ public int LevelUpNeed() => (int)(Math.Pow((Level) * 10, 2));
+ ///
+ /// 体力 0-100
+ ///
+ public double Strength { get => strength; set => strength = Math.Min(StrengthMax, Math.Max(0, value)); }
+
+ public double StrengthMax { get; } = 100;
+
+ [Line(Type = LPSConvert.ConvertType.ToFloat, IgnoreCase = true)]
+ protected double strength { get; set; }
+ ///
+ /// 待补充的体力,随着时间缓慢加给桌宠
+ /// //让游戏更有游戏性
+ [Line(Type = LPSConvert.ConvertType.ToFloat, IgnoreCase = true)]
+ public double StoreStrength { get; set; }
+ ///
+ /// 变化 体力
+ ///
+ public double ChangeStrength { get; set; } = 0;
+ public void StrengthChange(double value)
+ {
+ ChangeStrength += value;
+ Strength += value;
+ }
+ ///
+ /// 饱腹度
+ ///
+ public double StrengthFood
+ {
+ get => strengthFood; set
+ {
+ value = Math.Min(100, value);
+ if (value <= 0)
+ {
+ Health += value;
+ strengthFood = 0;
+ }
+ else
+ strengthFood = value;
+ }
+ }
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ protected double strengthFood { get; set; }
+ ///
+ /// 待补充的饱腹度,随着时间缓慢加给桌宠
+ /// //让游戏更有游戏性
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ public double StoreStrengthFood { get; set; }
+ public void StrengthChangeFood(double value)
+ {
+ ChangeStrengthFood += value;
+ StrengthFood += value;
+ }
+ ///
+ /// 变化 食物
+ ///
+ public double ChangeStrengthFood { get; set; } = 0;
+ ///
+ /// 口渴度
+ ///
+ public double StrengthDrink
+ {
+ get => strengthDrink; set
+ {
+ value = Math.Min(100, value);
+ if (value <= 0)
+ {
+ Health += value;
+ strengthDrink = 0;
+ }
+ else
+ strengthDrink = value;
+ }
+ }
+
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ protected double strengthDrink { get; set; }
+ ///
+ /// 待补充的口渴度,随着时间缓慢加给桌宠
+ /// //让游戏更有游戏性
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ public double StoreStrengthDrink { get; set; }
+ ///
+ /// 变化 口渴度
+ ///
+ public double ChangeStrengthDrink { get; set; } = 0;
+ public void StrengthChangeDrink(double value)
+ {
+ ChangeStrengthDrink += value;
+ StrengthDrink += value;
+ }
+ ///
+ /// 心情
+ ///
+ public double Feeling
+ {
+ get => feeling; set
+ {
+
+ value = Math.Min(100, value);
+ if (value <= 0)
+ {
+ Health += value / 2;
+ Likability += value / 2;
+ feeling = 0;
+ }
+ else
+ feeling = value;
+ }
+ }
+
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ protected double feeling { get; set; }
+ ///
+ /// 待补充的心情,随着时间缓慢加给桌宠
+ /// //让游戏更有游戏性
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ public double StoreFeeling { get; set; }
+ ///
+ /// 变化 心情
+ ///
+ public double ChangeFeeling { get; set; } = 0;
+ public void FeelingChange(double value)
+ {
+ ChangeFeeling += value;
+ Feeling += value;
+ }
+ ///
+ /// 健康(生病)(隐藏)
+ ///
+ public double Health { get => health; set => health = Math.Min(100, Math.Max(0, value)); }
+
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ protected double health { get; set; }
+ ///
+ /// 好感度(隐藏)(累加值)
+ ///
+ public double Likability
+ {
+ get => likability; set
+ {
+ var max = LikabilityMax;
+ value = Math.Max(0, value);
+ if (value > max)
+ {
+ likability = max;
+ Health += value - max;
+ }
+ else
+ likability = value;
+ }
+ }
+
+ [Line(Type = LPSConvert.ConvertType.ToFloat)]
+ protected double likability { get; set; }
+
+ ///
+ /// 清除变化
+ ///
+ public void CleanChange()
+ {
+ ChangeStrength /= 2;
+ ChangeFeeling /= 2;
+ ChangeStrengthDrink /= 2;
+ ChangeStrengthFood /= 2;
+ }
+ ///
+ /// 取回被储存的体力
+ ///
+ public void StoreTake()
+ {
+ const int t = 10;
+ var s = StoreFeeling / t;
+ StoreFeeling -= s;
+ if (Math.Abs(StoreFeeling) < 1)
+ StoreFeeling = 0;
+ else
+ FeelingChange(s);
+
+ s = StoreStrength / t;
+ StoreStrength -= s;
+ if (Math.Abs(StoreStrength) < 1)
+ StoreStrength = 0;
+ else
+ StrengthChange(s);
+
+ s = StoreStrengthDrink / t;
+ StoreStrengthDrink -= s;
+ if (Math.Abs(StoreStrengthDrink) < 1)
+ StoreStrengthDrink = 0;
+ else
+ StrengthChangeDrink(s);
+
+ s = StoreStrengthFood / t;
+ StoreStrengthFood -= s;
+ if (Math.Abs(StoreStrengthFood) < 1)
+ StoreStrengthFood = 0;
+ else
+ StrengthChangeFood(s);
+ }
+ ///
+ /// 吃食物
+ ///
+ /// 食物类
+ public void EatFood(IFood food)
+ {
+ Exp += food.Exp;
+ var tmp = food.Strength / 2;
+ StrengthChange(tmp);
+ StoreStrength += tmp;
+ tmp = food.StrengthFood / 2;
+ StrengthChangeFood(tmp);
+ StoreStrengthFood += tmp;
+ tmp = food.StrengthDrink / 2;
+ StrengthChangeDrink(tmp);
+ StoreStrengthDrink += tmp;
+ tmp = food.Feeling / 2;
+ FeelingChange(tmp);
+ StoreFeeling += tmp;
+ Health += food.Health;
+ Likability += food.Likability;
+ }
+ ///
+ /// 宠物当前状态
+ ///
+ [Line(name: "mode")]
+ public ModeType Mode { get; set; } = ModeType.Nomal;
+
+ public double LikabilityMax => 90 + Level * 10;
+
+ ///
+ /// 计算宠物当前状态
+ ///
+ public ModeType CalMode()
+ {
+ int realhel = 60 - (Feeling >= 80 ? 12 : 0) - (Likability >= 80 ? 12 : (Likability >= 40 ? 6 : 0));
+ //先从最次的开始
+ if (Health <= realhel)
+ {
+ //可以确认从状态不佳和生病二选一
+ if (Health <= realhel / 2)
+ {//生病
+ return ModeType.Ill;
+ }
+ else
+ {
+ return ModeType.PoorCondition;
+ }
+ }
+ //然后判断是高兴还是普通
+ realhel = 90 - (Likability >= 80 ? 20 : (Likability >= 40 ? 10 : 0));
+ if (Feeling >= realhel)
+ {
+ return ModeType.Happy;
+ }
+ else if (Feeling <= realhel / 2)
+ {
+ return ModeType.PoorCondition;
+ }
+ return ModeType.Nomal;
+ }
+ ///
+ /// 新游戏
+ ///
+ public VpetSave(string name)
+ {
+ Name = name;
+ Money = 100;
+ Exp = 0;
+ Strength = 100;
+ StrengthFood = 100;
+ StrengthDrink = 100;
+ Feeling = 60;
+ Health = 100;
+ Likability = 0;
+ Mode = CalMode();
+ }
+ ///
+ /// 读档
+ ///
+ public VpetSave()
+ {
+ }
+ ///
+ /// 读档
+ ///
+ public static GameSave Load(ILine data) => LPSConvert.DeserializeObject(data);
+ ///
+ /// 存档
+ ///
+ /// 存档行
+ public Line ToLine()
+ {
+ //Line save = new Line("vpet", Name);
+ //save.SetFloat("money", Money);
+ //save.SetInt("exp", Exp);
+ //save.SetFloat("strength", Strength);
+ //save.SetFloat("strengthdrink", StrengthDrink);
+ //save.SetFloat("strengthfood", StrengthFood);
+ //save.SetFloat("feeling", Feeling);
+ //save.SetFloat("health", Health);
+ //save.SetFloat("Likability", Likability);
+ return LPSConvert.SerializeObject(this, "vpet");
+ }
+
+}
diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs
index 759350a..c5628f9 100644
--- a/VPet-Simulator.Windows/MainWindow.cs
+++ b/VPet-Simulator.Windows/MainWindow.cs
@@ -36,9 +36,7 @@ using static VPet_Simulator.Windows.Interface.ExtensionFunction;
using Image = System.Windows.Controls.Image;
using System.Data;
using System.Windows.Media;
-#if SteamOutput
-using VPet.Solution;
-#endif
+
namespace VPet_Simulator.Windows
{
public partial class MainWindow : IMainWindow
@@ -1523,7 +1521,7 @@ namespace VPet_Simulator.Windows
//清空资源
Main.Resources = Application.Current.Resources;
- Main.MsgBar.Resources = Application.Current.Resources;
+ //Main.MsgBar.Resources = Application.Current.Resources;
Main.ToolBar.Resources = Application.Current.Resources;
//加载主题:
@@ -1848,25 +1846,25 @@ namespace VPet_Simulator.Windows
{
Thread.Sleep(120000);
Set["v"][(gint)"rank"] = DateTime.Now.Year;
- Dispatcher.Invoke(() =>
- {
- var button = new System.Windows.Controls.Button()
- {
- Content = "点击前往查看".Translate(),
- FontSize = 20,
- HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
- Background = Function.ResourcesBrush(Function.BrushType.Primary),
- Foreground = Function.ResourcesBrush(Function.BrushType.PrimaryText),
- };
- button.Click += (x, y) =>
- {
- var panelWindow = new winCharacterPanel(this);
- panelWindow.MainTab.SelectedIndex = 2;
- panelWindow.Show();
- };
- Main.MsgBar.MessageBoxContent.Children.Add(button);
- });
- Main.Say("哼哼~主人,我的考试成绩出炉了哦,快来和我一起看我的成绩单喵".Translate(), "shining");
+ var btn = Dispatcher.Invoke(() =>
+ {
+ var button = new System.Windows.Controls.Button()
+ {
+ Content = "点击前往查看".Translate(),
+ FontSize = 20,
+ HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
+ Background = Function.ResourcesBrush(Function.BrushType.Primary),
+ Foreground = Function.ResourcesBrush(Function.BrushType.PrimaryText),
+ };
+ button.Click += (x, y) =>
+ {
+ var panelWindow = new winCharacterPanel(this);
+ panelWindow.MainTab.SelectedIndex = 2;
+ panelWindow.Show();
+ };
+ return button;
+ });
+ Main.Say("哼哼~主人,我的考试成绩出炉了哦,快来和我一起看我的成绩单喵".Translate(), btn, "shining");
});
}
#if NewYear