using LinePutScript.Dictionary; using LinePutScript; using Panuon.WPF.UI; using Steamworks; using Steamworks.Data; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using LinePutScript.Localization.WPF; using System.Threading; using VPet_Simulator.Windows.Interface; using VPet_Simulator.Core; using static VPet_Simulator.Core.GraphHelper; using System.Drawing; using Point = System.Windows.Point; using Size = System.Windows.Size; using static VPet_Simulator.Core.GraphInfo; using System.Xml.Linq; using System.Windows.Interop; using LinePutScript.Converter; using static VPet_Simulator.Windows.Interface.MPMessage; using System.Windows.Input; namespace VPet_Simulator.Windows; /// /// MPFriends.xaml 的交互逻辑 /// public partial class MPFriends : WindowX { public Lobby lb; MainWindow mw; public Friend friend; public winMutiPlayer wmp; public GameCore Core { get; set; } = new GameCore(); public List Foods { get; } = new List(); public ImageResources ImageSources { get; } = new ImageResources(); public List Pets { get; set; } = new List(); public ILine OnMod { get; set; } public string SetPetGraph; public bool IsOnMod(string ModName) { if (CoreMOD.OnModDefList.Contains(ModName)) return true; return OnMod.Find(ModName.ToLower()) != null; } public MPFriends(winMutiPlayer wmp, MainWindow mw, Lobby lb, Friend friend) { this.wmp = wmp; this.mw = mw; this.lb = lb; this.friend = friend; mw.Windows.Add(this); try { InitializeComponent(); //MGrid.Height = 500 * mw.Set.ZoomLevel; MGrid.Width = 500 * mw.Set.ZoomLevel; double L = 0, T = 0; if (mw.Set.StartRecordLast) { var point = mw.Set.StartRecordLastPoint; if (point.X != 0 || point.Y != 0) { L = point.X; T = point.Y; } } else { var point = mw.Set.StartRecordPoint; L = point.X; T = point.Y; } Left = L; Top = T; // control position inside bounds Core.Controller = new MPController(this, mw); Task.Run(() => { double dist; if ((dist = Core.Controller.GetWindowsDistanceLeft()) < 0) { Thread.Sleep(100); Dispatcher.Invoke(() => Left -= dist); } if ((dist = Core.Controller.GetWindowsDistanceRight()) < 0) { Thread.Sleep(100); Dispatcher.Invoke(() => Left += dist); } if ((dist = Core.Controller.GetWindowsDistanceUp()) < 0) { Thread.Sleep(100); Dispatcher.Invoke(() => Top -= dist); } if ((dist = Core.Controller.GetWindowsDistanceDown()) < 0) { Thread.Sleep(100); Dispatcher.Invoke(() => Top += dist); } }); if (mw.Set.TopMost) { Topmost = true; } } catch { Close(); return; } ImageSources.AddRange(mw.ImageSources); //加载所有MOD List Path = new List(); Path.AddRange(new DirectoryInfo(mw.ModPath).EnumerateDirectories()); var workshop = mw.Set["workshop"]; foreach (Sub ws in workshop) { Path.Add(new DirectoryInfo(ws.Name)); } Task.Run(async () => { //加载lobby传过来的数据 string tmp = lb.GetMemberData(friend, "save"); while (string.IsNullOrEmpty(tmp)) { Thread.Sleep(500); tmp = lb.GetMemberData(friend, "save"); } Core.Save = GameSave_VPet.Load(new Line(tmp)); tmp = lb.GetMemberData(friend, "onmod"); while (string.IsNullOrEmpty(tmp)) { Thread.Sleep(100); tmp = lb.GetMemberData(friend, "onmod"); } OnMod = new Line(tmp); tmp = lb.GetMemberData(friend, "petgraph"); while (string.IsNullOrEmpty(tmp)) { Thread.Sleep(100); tmp = lb.GetMemberData(friend, "onmod"); } SetPetGraph = tmp; await GameLoad(Path); }); } public List MPMODs = new List(); public Main Main { get; set; } /// /// 加载游戏 /// /// MOD地址 public async Task GameLoad(List Path) { Path = Path.Distinct().ToList(); await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "Loading MOD")); //加载mod foreach (DirectoryInfo di in Path) { if (!File.Exists(di.FullName + @"\info.lps")) continue; await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = $"Loading MOD: {di.Name}")); MPMODs.Add(new MPMOD(di, this)); } await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏MOD".Translate())); //当前桌宠动画 var petloader = Pets.Find(x => x.Name == SetPetGraph); petloader ??= Pets[0]; ////加载数据合理化:食物 //foreach (Food f in Foods) //{ // if (f.IsOverLoad()) // { // f.Price = Math.Max((int)f.RealPrice, 1); // f.isoverload = false; // } //} await Dispatcher.InvokeAsync(new Action(() => { LoadingText.Content = "尝试加载动画和生成缓存\n该步骤可能会耗时比较长\n请耐心等待".Translate(); Core.Graph = petloader.Graph(mw.Set.Resolution); Main = new Main(Core); Main.EventTimer.AutoReset = false; Main.EventTimer.Enabled = false; //清空资源 Main.Resources = Application.Current.Resources; Main.MsgBar.This.Resources = Application.Current.Resources; Main.ToolBar.Resources = Application.Current.Resources; Main.ToolBar.LoadClean(); HideForDesign.Children.Remove(MPTalkBox); Main.ToolBar.MainGrid.Children.Add(MPTalkBox); cbTalk.Items.Add("私聊".Translate()); cbTalk.Items.Add("公聊".Translate()); cbTalk.Items.Add("大家".Translate()); cbTalk.SelectedIndex = 1; LoadingText.Content = "正在加载游戏\n该步骤可能会耗时比较长\n请耐心等待".Translate(); Main.PlayVoiceVolume = mw.Set.VoiceVolume; DisplayGrid.Child = Main; //Main.SetMoveMode(mw.Set.AllowMove, mw.Set.SmartMove, mw.Set.SmartMoveInterval * 1000); //Main.SetLogicInterval(1500); if (mw.Set.MessageBarOutside) Main.MsgBar.SetPlaceOUT(); //Main.WorkCheck = mw.WorkCheck; //添加捏脸动画(若有) if (Core.Graph.GraphConfig.Data.ContainsLine("pinch")) { var pin = Core.Graph.GraphConfig.Data["pinch"]; Main.Core.TouchEvent.Insert(0, new TouchArea( new Point(pin[(gdbe)"px"], pin[(gdbe)"py"]), new Size(pin[(gdbe)"sw"], pin[(gdbe)"sh"]) , DisplayPinch, true)); } LoadingText.Content = "{0}的{1}".Translate(friend.Name, Core.Save.Name); LoadingText.Background = Function.ResourcesBrush(Function.BrushType.DARKPrimaryTransA); LoadingText.VerticalAlignment = VerticalAlignment.Top; Loaded = true; })); } public new bool Loaded = false; /// /// 显示捏脸情况 /// public bool DisplayPinch() { if (Core.Graph.FindGraphs("pinch", AnimatType.A_Start, Core.Save.Mode) == null) { return false; } Main.CountNomal = 0; if (Core.Controller.EnableFunction && Core.Save.Strength >= 10 && Core.Save.Feeling < 100) { Core.Save.StrengthChange(-2); Core.Save.FeelingChange(1); Core.Save.Mode = Core.Save.CalMode(); Main.LabelDisplayShowChangeNumber(LocalizeCore.Translate("体力-{0:f0} 心情+{1:f0}"), 2, 1); } if (Main.DisplayType.Name == "pinch") { if (Main.DisplayType.Animat == AnimatType.A_Start) return false; else if (Main.DisplayType.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Name == "pinch" && ig.GraphInfo.Animat == AnimatType.B_Loop) { ig.IsContinue = true; return true; } else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Name == "pinch" && ig2.GraphInfo.Animat == AnimatType.B_Loop) { ig2.IsContinue = true; return true; } } Main.Display("pinch", AnimatType.A_Start, () => Main.Display("pinch", AnimatType.B_Loop, DisplayPinch_loop)); return true; } private void DisplayPinch_loop() { if (Main.isPress && Main.DisplayType.Name == "pinch" && Main.DisplayType.Animat == AnimatType.B_Loop) { if (Core.Controller.EnableFunction && Core.Save.Strength >= 10 && Core.Save.Feeling < 100) { Core.Save.StrengthChange(-2); Core.Save.FeelingChange(1); Core.Save.Mode = Core.Save.CalMode(); Main.LabelDisplayShowChangeNumber(LocalizeCore.Translate("体力-{0:f0} 心情+{1:f0}"), 2, 1); } Main.Display("pinch", AnimatType.B_Loop, DisplayPinch_loop); } else { Main.DisplayCEndtoNomal("pinch"); } } /// /// 播放关闭动画并关闭,如果10秒后还未关闭则强制关闭 /// public void Quit() { try { Main.Display(GraphType.Shutdown, AnimatType.Single, () => Dispatcher.Invoke(Close)); Task.Run(() => { Thread.Sleep(5000); if (Loaded) Dispatcher.Invoke(Close); }); } catch { Close(); } } /// /// 智能化显示后续过度动画 /// public void DisplayAuto(GraphInfo gi) { switch (gi.Animat) { case AnimatType.A_Start: gi.Animat = AnimatType.B_Loop; Main.Display(gi.Name, AnimatType.B_Loop, () => DisplayAuto(gi)); break; case AnimatType.B_Loop: Main.Display(gi.Name, AnimatType.B_Loop, () => DisplayAuto(gi)); break; case AnimatType.C_End: case AnimatType.Single: Main.DisplayToNomal(); break; } } /// /// 根据好友数据显示动画 /// public bool DisplayGraph(GraphInfo gi) { if (!Loaded || Main.DisplayType.Type == GraphType.StartUP || Main.DisplayType.Type == GraphType.Raised_Dynamic || Main.DisplayType.Type == GraphType.Raised_Static) { return false; } if (gi.Type == Main.DisplayType.Type && gi.Animat == Main.DisplayType.Animat) { if (gi.Type != GraphType.Common) return false; } var img = Core.Graph.FindGraph(gi.Name, gi.Animat, Core.Save.Mode); if (img != null) { Main.Display(img, () => DisplayAuto(gi)); return true; } return false; } public void DisplayMessage(Chat msg) { switch (msg.ChatType) { case Chat.Type.Private: Main.Say("{0} 悄悄地对你说: {1}".Translate(msg.SendName, msg.Content)); break; case Chat.Type.Internal: Main.Say("{0} 对你说: {1}".Translate(msg.SendName, msg.Content)); break; case Chat.Type.Public: Main.Say("{0} 对大家说: {1}".Translate(msg.SendName, msg.Content)); break; } } private void WindowX_Closed(object sender, EventArgs e) { mw.Windows.Remove(this); } 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; Main.ToolBar.Visibility = Visibility.Collapsed; return; } if (tbTalk.Text.Length > 0) { Main.ToolBar.CloseTimer.Stop(); } else { Main.ToolBar.CloseTimer.Start(); } } private void Send_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbTalk.Text)) { return; } var cont = tbTalk.Text; tbTalk.Text = ""; Main.ToolBar.Visibility = Visibility.Collapsed; int talktype = cbTalk.SelectedIndex; Task.Run(() => { MPMessage msg = new MPMessage(); msg.Type = MSGType.Chat; msg.SetContent(new Chat() { Content = cont, ChatType = (Chat.Type)talktype, SendName = SteamClient.Name }); msg.To = SteamClient.SteamId; switch (talktype) { case 0: wmp.SendMessage(friend.Id, msg); mw.Main.Say("{0} 悄悄地对你说: {1}".Translate(SteamClient.Name, cont)); break; case 1: wmp.SendMessageALL(msg); mw.Main.Say("{0} 对你说: {1}".Translate(SteamClient.Name, cont)); break; case 2: wmp.SendMessageALL(msg); mw.Main.Say("{0} 对大家说: {1}".Translate(SteamClient.Name, cont)); break; } }); } private void cbTalk_SelectionChanged(object sender, SelectionChangedEventArgs e) { switch (cbTalk.SelectedIndex) { case 0: Panuon.WPF.UI.TextBoxHelper.SetWatermark(tbTalk, "和{0}悄悄说".Translate(friend.Name)); break; case 1: Panuon.WPF.UI.TextBoxHelper.SetWatermark(tbTalk, "和{0}说".Translate(friend.Name)); break; case 2: Panuon.WPF.UI.TextBoxHelper.SetWatermark(tbTalk, "和大家说"); break; } } }