diff --git a/VPet-Simulator.Windows.Interface/MutiPlayer/IMPWindows.cs b/VPet-Simulator.Windows.Interface/MutiPlayer/IMPWindows.cs index b4af216..fa5e338 100644 --- a/VPet-Simulator.Windows.Interface/MutiPlayer/IMPWindows.cs +++ b/VPet-Simulator.Windows.Interface/MutiPlayer/IMPWindows.cs @@ -25,7 +25,11 @@ public interface IMPWindows /// /// 主持人SteamID /// - ulong OwnerID { get; } + ulong HostID { get; } + /// + /// 当前玩家是否是主持人 + /// + bool IsHost { get; } /// /// 事件:成员退出 @@ -71,4 +75,8 @@ public interface IMPWindows /// 获取访客表菜单栏,可以插入自己的菜单 /// TabControl TabControl { get; } + /// + /// 是否可加入 + /// + bool Joinable { get; } } diff --git a/VPet-Simulator.Windows/MainWindow.cs b/VPet-Simulator.Windows/MainWindow.cs index a684890..6c08727 100644 --- a/VPet-Simulator.Windows/MainWindow.cs +++ b/VPet-Simulator.Windows/MainWindow.cs @@ -859,6 +859,14 @@ namespace VPet_Simulator.Windows private void Handle_Steam(Main obj) { + string jointab = " "; + if (winMutiPlayer != null) + { + if (winMutiPlayer.Joinable) + jointab += "可加入".Translate(); + SteamFriends.SetRichPresence("steam_player_group", winMutiPlayer.LobbyID.ToString("x")); + SteamFriends.SetRichPresence("steam_player_group_size", winMutiPlayer.lb.MemberCount.ToString()); + } if (App.MainWindows.Count > 1) { if (App.MainWindows.FirstOrDefault() != this) @@ -897,11 +905,11 @@ namespace VPet_Simulator.Windows SteamFriends.SetRichPresence("usernames", str.Trim(',')); if (lv > 0) { - SteamFriends.SetRichPresence("lv", $" (lv{lv}/{App.MainWindows.Count})"); + SteamFriends.SetRichPresence("lv", $" (lv{lv}/{App.MainWindows.Count})" + jointab); } else { - SteamFriends.SetRichPresence("lv", " "); + SteamFriends.SetRichPresence("lv", " " + jointab); } if (workcount > allcount) { @@ -924,11 +932,11 @@ namespace VPet_Simulator.Windows { if (HashCheck) { - SteamFriends.SetRichPresence("lv", $" (lv{GameSavesData.GameSave.Level})"); + SteamFriends.SetRichPresence("lv", $" (lv{GameSavesData.GameSave.Level})" + jointab); } else { - SteamFriends.SetRichPresence("lv", " "); + SteamFriends.SetRichPresence("lv", " " + jointab); } if (Core.Save.Mode == IGameSave.ModeType.Ill) { diff --git a/VPet-Simulator.Windows/MutiPlayer/MPFriends.xaml.cs b/VPet-Simulator.Windows/MutiPlayer/MPFriends.xaml.cs index fa6fb25..56f1608 100644 --- a/VPet-Simulator.Windows/MutiPlayer/MPFriends.xaml.cs +++ b/VPet-Simulator.Windows/MutiPlayer/MPFriends.xaml.cs @@ -631,7 +631,7 @@ public partial class MPFriends : WindowX, IMPFriend } } } - winMPBetterBuy.Close(); + winMPBetterBuy?.Close(); Main?.Dispose(); mw.Windows.Remove(this); } diff --git a/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml b/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml index bcfd632..8f38143 100644 --- a/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml +++ b/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml @@ -38,7 +38,7 @@ Foreground="{DynamicResource DARKPrimaryDarker}" CheckedBackground="{DynamicResource Primary}" CheckedBorderBrush="{DynamicResource Primary}" CheckedToggleBrush="{DynamicResource DARKPrimaryText}" Content="{ll:Str 允许好友加入}" ToggleBrush="{DynamicResource PrimaryDark}" ToggleShadowColor="{x:Null}" - ToggleSize="14" IsChecked="True" Visibility="Collapsed" Checked="swAllowJoin_Checked" - Unchecked="swAllowJoin_Unchecked" /> + ToggleSize="14" IsChecked="True" Checked="swAllowJoin_Checked" + Unchecked="swAllowJoin_Unchecked" IsEnabled="False"/> diff --git a/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml.cs b/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml.cs index af8db53..d17f1a5 100644 --- a/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml.cs +++ b/VPet-Simulator.Windows/MutiPlayer/winMutiPlayer.xaml.cs @@ -32,7 +32,7 @@ namespace VPet_Simulator.Windows; /// public partial class winMutiPlayer : Window, IMPWindows { - Steamworks.Data.Lobby lb; + public Lobby lb; MainWindow mw; /// /// 好友宠物模块 @@ -72,7 +72,8 @@ public partial class winMutiPlayer : Window, IMPWindows lb = lbt.Value; lb.SetJoinable(true); lb.SetPublic(); - swAllowJoin.Visibility = Visibility.Visible; + IsHost = true; + swAllowJoin.IsEnabled = true; ShowLobbyInfo(); } public static ImageSource ConvertToImageSource(Steamworks.Data.Image? img) @@ -111,10 +112,13 @@ public partial class winMutiPlayer : Window, IMPWindows return result; } - public ulong OwnerID { get; set; } + public ulong HostID { get; set; } + public bool IsHost { get; set; } = false; public ulong LobbyID => lb.Id.Value; + public bool Joinable { get; set; } = true; + public IEnumerable Friends => MPFriends; public bool IsGameRunning { get; set; } @@ -137,7 +141,7 @@ public partial class winMutiPlayer : Window, IMPWindows Dispatcher.Invoke(() => { hostName.Text = lb.Owner.Name; - OwnerID = lb.Owner.Id.Value; + HostID = lb.Owner.Id.Value; lbLid.Text = lb.Id.Value.ToString("x"); HostHead.Source = ConvertToImageSource(img.Value); }); @@ -150,7 +154,7 @@ public partial class winMutiPlayer : Window, IMPWindows //给自己动画添加绑定 mw.Main.GraphDisplayHandler += Main_GraphDisplayHandler; - if (lb.Owner.IsMe) + if (IsHost) { Dispatcher.Invoke(() => { @@ -199,9 +203,21 @@ public partial class winMutiPlayer : Window, IMPWindows if (lb.GetData("kick") == SteamClient.SteamId.Value.ToString()) { Task.Run(() => MessageBox.Show("访客表已被房主{0}关闭".Translate(lb.Owner.Name)));//温柔的谎言 + lb.Leave(); lb = default(Lobby); Close(); } + + if (lb.GetData("nojoin") == "true") + { + Joinable = false; + Dispatcher.Invoke(() => swAllowJoin.IsChecked = false); + } + else + { + Joinable = true; + Dispatcher.Invoke(() => swAllowJoin.IsChecked = true); + } } } @@ -210,7 +226,7 @@ public partial class winMutiPlayer : Window, IMPWindows { if (lobby.Id != lb.Id) return; OnMemberLeave?.Invoke(friend.Id); - if (friend.Id == OwnerID) + if (friend.Id == HostID) { Task.Run(() => MessageBox.Show("访客表已被房主{0}关闭".Translate(friend.Name))); lb = default(Lobby); @@ -418,11 +434,13 @@ public partial class winMutiPlayer : Window, IMPWindows private void swAllowJoin_Checked(object sender, RoutedEventArgs e) { + lb.SetData("nojoin", "false"); lb.SetJoinable(true); } private void swAllowJoin_Unchecked(object sender, RoutedEventArgs e) { + lb.SetData("nojoin", "true"); lb.SetJoinable(false); }