修复UI报错问题

This commit is contained in:
ZouJin 2024-03-19 01:55:25 +08:00
parent ea785811da
commit 7ebf90bb22
4 changed files with 49 additions and 36 deletions

View File

@ -82,6 +82,9 @@ namespace VPet_Simulator.Core
PetGrid2.Visibility = Visibility.Collapsed;
Task.Run(() =>
{
EventTimer.Elapsed += (s, e) => EventTimer_Elapsed();
MoveTimer.Elapsed += MoveTimer_Elapsed;
SmartMoveTimer.Elapsed += SmartMoveTimer_Elapsed;
//while (!ig.IsReady)
//{
// Thread.Sleep(100);
@ -111,10 +114,6 @@ namespace VPet_Simulator.Core
DisplayNomal();
});
});
EventTimer.Elapsed += (s, e) => EventTimer_Elapsed();
MoveTimer.Elapsed += MoveTimer_Elapsed;
SmartMoveTimer.Elapsed += SmartMoveTimer_Elapsed;
}
private void Labledisplaytimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

View File

@ -43,7 +43,7 @@ namespace VPet_Simulator.Core
closePanelTimer = new Timer();
closePanelTimer.Elapsed += ClosePanelTimer_Tick;
m.TimeUIHandle += M_TimeUIHandle;
LoadWork();
//LoadWork();
}
public void LoadClean()
{

View File

@ -314,13 +314,20 @@ public partial class MPFriends : WindowX
/// </summary>
public void Quit()
{
Main.Display(GraphType.Shutdown, AnimatType.Single, () => Dispatcher.Invoke(Close));
Task.Run(() =>
try
{
Thread.Sleep(5000);
if (Loaded)
Dispatcher.Invoke(Close);
});
Main.Display(GraphType.Shutdown, AnimatType.Single, () => Dispatcher.Invoke(Close));
Task.Run(() =>
{
Thread.Sleep(5000);
if (Loaded)
Dispatcher.Invoke(Close);
});
}
catch
{
Close();
}
}
/// <summary>
@ -420,16 +427,20 @@ public partial class MPFriends : WindowX
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;
}
});

View File

@ -199,14 +199,18 @@ public partial class winMutiPlayer : Window
}
}
}
GraphInfo lastgraph = new GraphInfo() { Type = GraphType.Common };
private void Main_GraphDisplayHandler(GraphInfo info)
{
if (info.Type == GraphType.Shutdown || info.Type == GraphType.Common || info.Type == GraphType.Move
|| info.Type == GraphType.Raised_Dynamic || info.Type == GraphType.Raised_Static || info.Type == GraphType.Default)
|| info.Type == GraphType.Raised_Dynamic || info.Type == GraphType.Raised_Static)
{
return;
}
//如果是同一个动画就不发送
if (lastgraph.Type == info.Type && lastgraph.Animat == info.Animat && info.Name == lastgraph.Name)
return;
lastgraph = info;
MPMessage msg = new MPMessage();
msg.Type = MSGType.DispayGraph;
msg.SetContent(info);
@ -260,36 +264,35 @@ public partial class winMutiPlayer : Window
}
private void LoopP2PPacket()
{
try
{
while (SteamNetworking.IsP2PPacketAvailable())
while (isOPEN)
try
{
var packet = SteamNetworking.ReadP2PPacket();
if (packet.HasValue)
while (SteamNetworking.IsP2PPacketAvailable())
{
var From = packet.Value.SteamId;
var MSG = ConverTo(packet.Value.Data);
var To = MPFriends.Find(x => x.friend.Id == MSG.To);
switch (MSG.Type)
var packet = SteamNetworking.ReadP2PPacket();
if (packet.HasValue)
{
case MSGType.DispayGraph:
To.DisplayGraph(MSG.GetContent<GraphInfo>());
break;
case MSGType.Chat:
To.DisplayMessage(MSG.GetContent<Chat>());
break;
var From = packet.Value.SteamId;
var MSG = ConverTo(packet.Value.Data);
var To = MPFriends.Find(x => x.friend.Id == MSG.To);
switch (MSG.Type)
{
case MSGType.DispayGraph:
To.DisplayGraph(MSG.GetContent<GraphInfo>());
break;
case MSGType.Chat:
To.DisplayMessage(MSG.GetContent<Chat>());
break;
}
}
Thread.Sleep(100);
}
Thread.Sleep(100);
Thread.Sleep(1000);
}
Thread.Sleep(1000);
if (isOPEN)
LoopP2PPacket();
}
catch
{
catch
{
}
}
}
private void Window_Closed(object sender, EventArgs e)
{