4 Commits

Author SHA1 Message Date
Yue-bin
610cca5ef6 chore(PlayerManager): 更新插件版本号从4.0.1到4.0.2
Some checks failed
Publish Release / build (push) Failing after 5m16s
- 将stick.plugins.playermanager.csproj中的版本号从4.0.1升级到4.0.2
2026-05-07 04:54:19 +08:00
Yue-bin
d9e01bbf0f fix(PlayerManager): 修复房间公开性判断逻辑
- 移除HostLeverHandler依赖,直接通过MatchmakingHandler.LobbyType判断房间是否公开
- 修复LobbyType切换时的目标类型逻辑错误,现在正确地将公开房间设为ELobbyType.k_ELobbyTypePublic,
  私有房间设为ELobbyType.k_ELobbyTypeFriendsOnly
- 移除PlayerManagerGUI.InitializeStyles()调用,该方法已被默认组件注册替代
2026-05-07 04:53:36 +08:00
Yue-bin
31cf778524 refactor(Gui): 移除废弃样式引用并优化玩家信息按钮样式处理
移除了多个内部组件中的废弃XML文档注释和未使用的CommonButtonStyle引用,
为PlayerInfoButton添加了动态样式管理机制以替代静态样式引用。
2026-05-07 04:53:22 +08:00
Yue-bin
07d2320c71 refactor(gui): 将公开的GUI样式字段改为私有并优化样式管理
将PlayerManagerGUI中的公开静态样式字段改为私有访问修饰符,
同时为Widget组件添加默认样式属性,统一管理UI控件的外观,
提高代码封装性和样式的一致性
2026-05-07 04:53:09 +08:00
10 changed files with 82 additions and 46 deletions

View File

@@ -2,9 +2,6 @@ using MultiplayerBasicExample;
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 踢人按钮的纯工厂
/// </summary>
public static class KickButton public static class KickButton
{ {
public static IPlayerRowWidget Create() public static IPlayerRowWidget Create()
@@ -19,7 +16,6 @@ public static class KickButton
OnClick = player => OnClick = player =>
PlayerManager.KickPlayer(player.SteamId, MultiplayerManager.KickResponse.DidNotRecievePackages), PlayerManager.KickPlayer(player.SteamId, MultiplayerManager.KickResponse.DidNotRecievePackages),
Width = 100f, Width = 100f,
Style = PlayerManagerGUI.CommonButtonStyle,
}; };
} }
} }

View File

@@ -1,8 +1,5 @@
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 曾用名切换按钮的纯工厂
/// </summary>
public static class NameToggleButton public static class NameToggleButton
{ {
public static IPlayerRowWidget Create() public static IPlayerRowWidget Create()
@@ -14,7 +11,6 @@ public static class NameToggleButton
GetText = player => player.DisplayNameRecorded ? "显示现用名" : "显示曾用名", GetText = player => player.DisplayNameRecorded ? "显示现用名" : "显示曾用名",
OnClick = player => player.DisplayNameRecorded = !player.DisplayNameRecorded, OnClick = player => player.DisplayNameRecorded = !player.DisplayNameRecorded,
Width = 120f, Width = 120f,
Style = PlayerManagerGUI.CommonButtonStyle,
}; };
} }
} }

View File

@@ -1,15 +1,28 @@
using Steamworks; using Steamworks;
using UnityEngine; using UnityEngine;
using stick.plugins.playermanager.Recorder; using stick.plugins.playermanager.Recorder;
using static stick.plugins.playermanager.Gui.PlayerManagerGUI;
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 玩家信息按钮的纯工厂
/// </summary>
public static class PlayerInfoButton public static class PlayerInfoButton
{ {
private static GUIStyle _redStyle;
private static GUIStyle _yellowStyle;
private static GUIStyle _greenStyle;
private static GUIStyle _normalStyle;
private static void EnsureStyles()
{
if (_normalStyle != null) return;
_normalStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
_yellowStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
_yellowStyle.normal.textColor = Color.yellow;
_redStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
_redStyle.normal.textColor = Color.red;
_greenStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
_greenStyle.normal.textColor = Color.green;
}
public static IPlayerRowWidget Create() public static IPlayerRowWidget Create()
{ {
return new PlayerRowButtonWidget return new PlayerRowButtonWidget
@@ -22,11 +35,15 @@ public static class PlayerInfoButton
SteamFriends.ActivateGameOverlayToUser("steamid", player.SteamId); SteamFriends.ActivateGameOverlayToUser("steamid", player.SteamId);
}, },
Width = 500f, Width = 500f,
GetStyle = player => player.RecordStatus switch GetStyle = player =>
{ {
PlayerRecordStatus.Blacklisted => RedButtonStyle, EnsureStyles();
PlayerRecordStatus.Recorded => YellowButtonStyle, return player.RecordStatus switch
_ => player.IsFriend ? GreenButtonStyle : CommonButtonStyle, {
PlayerRecordStatus.Blacklisted => _redStyle,
PlayerRecordStatus.Recorded => _yellowStyle,
_ => player.IsFriend ? _greenStyle : _normalStyle,
};
}, },
}; };
} }

View File

@@ -3,9 +3,6 @@ using stick.plugins.playermanager.Recorder;
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 记录/拉黑按钮的纯工厂
/// </summary>
public static class RecordButton public static class RecordButton
{ {
public static IPlayerRowWidget Create() public static IPlayerRowWidget Create()
@@ -41,7 +38,6 @@ public static class RecordButton
PlayerManager.OnLobbyMembersChanged(); PlayerManager.OnLobbyMembersChanged();
}, },
Width = 100f, Width = 100f,
Style = PlayerManagerGUI.CommonButtonStyle,
}; };
} }
} }

View File

@@ -1,10 +1,5 @@
using static stick.plugins.playermanager.Gui.PlayerManagerGUI;
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 切换公开性按钮的纯工厂,返回 IHeaderWidget由 DefaultWidgets 放入 HeaderRow
/// </summary>
public static class RoomPublicityButton public static class RoomPublicityButton
{ {
public static IHeaderWidget Create() public static IHeaderWidget Create()
@@ -15,7 +10,6 @@ public static class RoomPublicityButton
Text = "切换公开性", Text = "切换公开性",
Action = () => PlayerManager.ToggleLobbyPublicity(), Action = () => PlayerManager.ToggleLobbyPublicity(),
Width = 150f, Width = 150f,
Style = CommonButtonStyle,
}; };
} }
} }

View File

@@ -1,10 +1,5 @@
using static stick.plugins.playermanager.Gui.PlayerManagerGUI;
namespace stick.plugins.playermanager.Gui.InternalWidgets; namespace stick.plugins.playermanager.Gui.InternalWidgets;
/// <summary>
/// 房间类型标签的纯工厂,返回 IHeaderWidget由 DefaultWidgets 放入 HeaderRow
/// </summary>
public static class RoomPublicityLabel public static class RoomPublicityLabel
{ {
public static IHeaderWidget Create() public static IHeaderWidget Create()
@@ -14,7 +9,6 @@ public static class RoomPublicityLabel
Name = "RoomPublicityLabel", Name = "RoomPublicityLabel",
Content = () => $"房间类型: {(PlayerManager.IsPublic ? "" : "")}", Content = () => $"房间类型: {(PlayerManager.IsPublic ? "" : "")}",
Width = 200f, Width = 200f,
Style = TitleStyle,
}; };
} }
} }

View File

@@ -37,27 +37,27 @@ public static class PlayerManagerGUI
/// <summary> /// <summary>
/// 标题样式 /// 标题样式
/// </summary> /// </summary>
internal static GUIStyle TitleStyle; private static GUIStyle TitleStyle;
/// <summary> /// <summary>
/// 普通按钮样式 /// 普通按钮样式
/// </summary> /// </summary>
internal static GUIStyle CommonButtonStyle; private static GUIStyle CommonButtonStyle;
/// <summary> /// <summary>
/// 黄色按钮样式(已记录玩家) /// 黄色按钮样式(已记录玩家)
/// </summary> /// </summary>
internal static GUIStyle YellowButtonStyle; private static GUIStyle YellowButtonStyle;
/// <summary> /// <summary>
/// 红色按钮样式(黑名单玩家) /// 红色按钮样式(黑名单玩家)
/// </summary> /// </summary>
internal static GUIStyle RedButtonStyle; private static GUIStyle RedButtonStyle;
/// <summary> /// <summary>
/// 绿色按钮样式(好友) /// 绿色按钮样式(好友)
/// </summary> /// </summary>
internal static GUIStyle GreenButtonStyle; private static GUIStyle GreenButtonStyle;
/// <summary> /// <summary>
/// 样式是否已初始化 /// 样式是否已初始化
@@ -68,7 +68,7 @@ public static class PlayerManagerGUI
#region #region
internal static void InitializeStyles() private static void InitializeStyles()
{ {
if (StylesInitialized) return; if (StylesInitialized) return;

View File

@@ -96,6 +96,17 @@ public interface IPlayerRowWidget
/// </summary> /// </summary>
public class HeaderLabelWidget : IHeaderWidget public class HeaderLabelWidget : IHeaderWidget
{ {
private static GUIStyle _defaultStyle;
private static GUIStyle DefaultStyle
{
get
{
if (_defaultStyle == null)
_defaultStyle = new GUIStyle(GUI.skin.label) { fontSize = 22 };
return _defaultStyle;
}
}
public string Name { get; set; } public string Name { get; set; }
public Func<bool> Condition { get; set; } public Func<bool> Condition { get; set; }
public Func<string> Content { get; set; } public Func<string> Content { get; set; }
@@ -106,7 +117,7 @@ public class HeaderLabelWidget : IHeaderWidget
public void Draw(Rect rect) public void Draw(Rect rect)
{ {
GUI.Label(rect, Content?.Invoke() ?? string.Empty, Style ?? GUI.skin.label); GUI.Label(rect, Content?.Invoke() ?? string.Empty, Style ?? DefaultStyle);
} }
} }
@@ -115,6 +126,17 @@ public class HeaderLabelWidget : IHeaderWidget
/// </summary> /// </summary>
public class HeaderButtonWidget : IHeaderWidget public class HeaderButtonWidget : IHeaderWidget
{ {
private static GUIStyle _defaultStyle;
private static GUIStyle DefaultStyle
{
get
{
if (_defaultStyle == null)
_defaultStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
return _defaultStyle;
}
}
public string Name { get; set; } public string Name { get; set; }
public Func<bool> Condition { get; set; } public Func<bool> Condition { get; set; }
public string Text { get; set; } public string Text { get; set; }
@@ -126,7 +148,7 @@ public class HeaderButtonWidget : IHeaderWidget
public void Draw(Rect rect) public void Draw(Rect rect)
{ {
if (GUI.Button(rect, Text ?? string.Empty, Style ?? GUI.skin.button)) if (GUI.Button(rect, Text ?? string.Empty, Style ?? DefaultStyle))
Action?.Invoke(); Action?.Invoke();
} }
} }
@@ -159,6 +181,17 @@ public class HeaderRow : IHeaderRow
/// </summary> /// </summary>
public class PlayerRowButtonWidget : IPlayerRowWidget public class PlayerRowButtonWidget : IPlayerRowWidget
{ {
private static GUIStyle _defaultStyle;
private static GUIStyle DefaultStyle
{
get
{
if (_defaultStyle == null)
_defaultStyle = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
return _defaultStyle;
}
}
public string Name { get; set; } public string Name { get; set; }
public Func<PlayerInfo, bool> Condition { get; set; } public Func<PlayerInfo, bool> Condition { get; set; }
public Func<PlayerInfo, string> GetText { get; set; } public Func<PlayerInfo, string> GetText { get; set; }
@@ -179,7 +212,7 @@ public class PlayerRowButtonWidget : IPlayerRowWidget
public void Draw(Rect rect, PlayerInfo player) public void Draw(Rect rect, PlayerInfo player)
{ {
GUIStyle style = GetStyle?.Invoke(player) ?? Style ?? GUI.skin.button; GUIStyle style = GetStyle?.Invoke(player) ?? Style ?? DefaultStyle;
if (GUI.Button(rect, GetText?.Invoke(player) ?? string.Empty, style)) if (GUI.Button(rect, GetText?.Invoke(player) ?? string.Empty, style))
OnClick?.Invoke(player); OnClick?.Invoke(player);
} }
@@ -190,6 +223,17 @@ public class PlayerRowButtonWidget : IPlayerRowWidget
/// </summary> /// </summary>
public class PlayerRowLabelWidget : IPlayerRowWidget public class PlayerRowLabelWidget : IPlayerRowWidget
{ {
private static GUIStyle _defaultStyle;
private static GUIStyle DefaultStyle
{
get
{
if (_defaultStyle == null)
_defaultStyle = new GUIStyle(GUI.skin.label) { fontSize = 22 };
return _defaultStyle;
}
}
public string Name { get; set; } public string Name { get; set; }
public Func<PlayerInfo, bool> Condition { get; set; } public Func<PlayerInfo, bool> Condition { get; set; }
public Func<PlayerInfo, string> GetText { get; set; } public Func<PlayerInfo, string> GetText { get; set; }
@@ -200,7 +244,7 @@ public class PlayerRowLabelWidget : IPlayerRowWidget
public void Draw(Rect rect, PlayerInfo player) public void Draw(Rect rect, PlayerInfo player)
{ {
GUI.Label(rect, GetText?.Invoke(player) ?? string.Empty, Style ?? GUI.skin.label); GUI.Label(rect, GetText?.Invoke(player) ?? string.Empty, Style ?? DefaultStyle);
} }
} }

View File

@@ -125,7 +125,7 @@ public class PlayerManager : BaseUnityPlugin
/// <summary> /// <summary>
/// 房间公开性 /// 房间公开性
/// </summary> /// </summary>
public static bool IsPublic => HostLeverHandler?.isOn ?? MatchmakingHandler.LobbyType == ELobbyType.k_ELobbyTypePublic; public static bool IsPublic => MatchmakingHandler.LobbyType == ELobbyType.k_ELobbyTypePublic;
/// <summary> /// <summary>
/// 当前大厅ID /// 当前大厅ID
@@ -150,7 +150,6 @@ public class PlayerManager : BaseUnityPlugin
{ {
InitializeConfiguration(); InitializeConfiguration();
ApplyPatches(); ApplyPatches();
PlayerManagerGUI.InitializeStyles();
DefaultWidgets.RegisterAll(); DefaultWidgets.RegisterAll();
} }
@@ -298,7 +297,7 @@ public class PlayerManager : BaseUnityPlugin
{ {
if (MultiplayerManager.IsServer) if (MultiplayerManager.IsServer)
{ {
var targetType = IsPublic ? ELobbyType.k_ELobbyTypePublic : ELobbyType.k_ELobbyTypeFriendsOnly; var targetType = IsPublic ? ELobbyType.k_ELobbyTypeFriendsOnly : ELobbyType.k_ELobbyTypePublic;
MatchmakingHandler.SetNewLobbyType(targetType); MatchmakingHandler.SetNewLobbyType(targetType);
RawChangeLobbyTypeMI.Invoke(MatchmakingHandler, [targetType]); RawChangeLobbyTypeMI.Invoke(MatchmakingHandler, [targetType]);
} }

View File

@@ -4,7 +4,7 @@
<TargetFramework>net35</TargetFramework> <TargetFramework>net35</TargetFramework>
<AssemblyName>stick.plugins.playermanager</AssemblyName> <AssemblyName>stick.plugins.playermanager</AssemblyName>
<Product>PlayerManager</Product> <Product>PlayerManager</Product>
<Version>4.0.1</Version> <Version>4.0.2</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<RestoreAdditionalProjectSources> <RestoreAdditionalProjectSources>