Steam状态提示 可加入/组队显示

This commit is contained in:
ZouJin 2024-03-21 15:53:03 +08:00
parent abd339c222
commit 7fa99f1e70
5 changed files with 48 additions and 14 deletions

View File

@ -25,7 +25,11 @@ public interface IMPWindows
/// <summary>
/// 主持人SteamID
/// </summary>
ulong OwnerID { get; }
ulong HostID { get; }
/// <summary>
/// 当前玩家是否是主持人
/// </summary>
bool IsHost { get; }
/// <summary>
/// 事件:成员退出
@ -71,4 +75,8 @@ public interface IMPWindows
/// 获取访客表菜单栏,可以插入自己的菜单
/// </summary>
TabControl TabControl { get; }
/// <summary>
/// 是否可加入
/// </summary>
bool Joinable { get; }
}

View File

@ -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)
{

View File

@ -631,7 +631,7 @@ public partial class MPFriends : WindowX, IMPFriend
}
}
}
winMPBetterBuy.Close();
winMPBetterBuy?.Close();
Main?.Dispose();
mw.Windows.Remove(this);
}

View File

@ -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"/>
</Grid>
</Window>

View File

@ -32,7 +32,7 @@ namespace VPet_Simulator.Windows;
/// </summary>
public partial class winMutiPlayer : Window, IMPWindows
{
Steamworks.Data.Lobby lb;
public Lobby lb;
MainWindow mw;
/// <summary>
/// 好友宠物模块
@ -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<IMPFriend> 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);
}