diff --git a/.idea/.idea.SSMenuSystem/.idea/discord.xml b/.idea/.idea.SSMenuSystem/.idea/discord.xml index 30bab2a..912db82 100644 --- a/.idea/.idea.SSMenuSystem/.idea/discord.xml +++ b/.idea/.idea.SSMenuSystem/.idea/discord.xml @@ -1,7 +1,14 @@ - \ No newline at end of file diff --git a/EventHandler.cs b/EventHandler.cs index 6a82991..92251d3 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -36,6 +36,7 @@ private static void SyncChangedGroup(ReferenceHub hub) public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase ss) { + Log.Debug("Received input for hub " + hub.nicknameSync.MyNick + ": " + ss.Label + " - " + ss.SettingId + "(" + ss.GetType().Name + ")"); try { if (Parameters.SyncCache.TryGetValue(hub, out List value)) @@ -45,6 +46,13 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase return; } + // return to menu + if (ss.SettingId == -999) + { + Menu.LoadForPlayer(hub, null); + return; + } + if (ss.OriginalDefinition != null) { ss.Label = ss.OriginalDefinition.Label; @@ -54,12 +62,7 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase else // is a pin or header ss.SettingId -= Menu.GetCurrentPlayerMenu(hub)?.Hash ?? 0; - // return to menu - if (ss.SettingId == -999) - { - Menu.LoadForPlayer(hub, null); - return; - } + Log.Debug("Values after Originial definition: " + ss.Label + " - " + ss.SettingId + "(" + ss.GetType().Name + ")"); // check permissions Menu menu = Menu.GetCurrentPlayerMenu(hub); @@ -91,8 +94,9 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase // load method when input is used on specific menu. else if (menu != null) { - if (ss.SettingId < 0) - Menu.LoadForPlayer(hub, menu.TryGetSubMenu(ss.SettingId)); + //if (ss.SettingId < 0) + if (menu.TryGetSubMenu(ss.SettingId, out Menu subMenu)) + Menu.LoadForPlayer(hub, subMenu); else { if (menu.InternalSettingsSync[hub].Any(x => x.SettingId == ss.SettingId)) @@ -100,10 +104,29 @@ public static void OnReceivingInput(ReferenceHub hub, ServerSpecificSettingBase else menu.InternalSettingsSync[hub].Add(ss); - ServerSpecificSettingBase s = menu.SentSettings.TryGetValue(hub, out ServerSpecificSettingBase[] customSettings) ? customSettings.FirstOrDefault(b => b.SettingId == ss.SettingId) : null; + ServerSpecificSettingBase s = menu.SentSettings.TryGetValue(hub, out ServerSpecificSettingBase[] customSettings) + ? customSettings.FirstOrDefault(b => b.SettingId == ss.SettingId) + : null; + + s ??= customSettings?.FirstOrDefault(b => b.SettingId == ss.SettingId - menu.Hash); + + s ??= customSettings?.First(b => b.SettingId - menu.Hash == ss.SettingId); + + if (customSettings != null) + { + foreach (ServerSpecificSettingBase tkt in customSettings) + { + Log.Debug("Values found in sent settings for target hub: " + tkt.Label + " - " + tkt.SettingId + "(removed hash: " + (tkt.SettingId - menu.Hash) + ")" + "(" + tkt.GetType().Name + ")"); + } + } + else + Log.Error("No sent settings found."); + if (s == null) throw new Exception("Failed to find the sent setting."); + Log.Debug("Value found in sent settings " + s.Label + " - " + s.SettingId + "(" + s.GetType().Name + ")"); + switch (s) { case Button wBtn: diff --git a/Examples/LightSpawnerExample.cs b/Examples/LightSpawnerExample.cs index 7a9cdcc..7728845 100644 --- a/Examples/LightSpawnerExample.cs +++ b/Examples/LightSpawnerExample.cs @@ -9,6 +9,7 @@ using SSMenuSystem.Features; using SSMenuSystem.Features.Wrappers; using UserSettings.ServerSpecific; +using Log = SSMenuSystem.Features.Log; namespace SSMenuSystem.Examples { diff --git a/Examples/PrimitiveSpawnerExample.cs b/Examples/PrimitiveSpawnerExample.cs index 270d70e..f4939de 100644 --- a/Examples/PrimitiveSpawnerExample.cs +++ b/Examples/PrimitiveSpawnerExample.cs @@ -3,7 +3,6 @@ using System.Globalization; using System.Linq; using AdminToys; -using Exiled.Events.Commands.Hub; using GameCore; using Mirror; using SSMenuSystem.Features; diff --git a/Features/Menu.cs b/Features/Menu.cs index ac941af..f2433bd 100644 --- a/Features/Menu.cs +++ b/Features/Menu.cs @@ -171,8 +171,10 @@ public static void Register(Menu menu) Log.Debug($"loading Server Specific menu {menu.Name}..."); if (CheckSameId(menu)) throw new ArgumentException($"another menu with id {menu.Id} is already registered. can't load {menu.Name}."); - if (menu.Id >= 0) - throw new ArgumentException($"menus ids must be < 0 (to let space for parameters and 0 is only for Main Menu)."); + if (menu.Id == 0) + throw new ArgumentException("Menus id must not be equal to 0. 0 is reserved for Main Menu."); + /*if (menu.Id >= 0) + //throw new ArgumentException($"menus ids must be < 0 (to let space for parameters and 0 is only for Main Menu).");*/ if (string.IsNullOrEmpty(menu.Name)) throw new ArgumentException($"menus name cannot be null or empty."); if (Menus.Any(x => x.Name == menu.Name)) @@ -301,11 +303,8 @@ private static ServerSpecificSettingBase[] GetMainMenu(ReferenceHub hub) return mainMenu.ToArray(); mainMenu.Add(new SSGroupHeader("Main Menu")); - foreach (Menu menu in LoadedMenus.Where(x => x.CheckAccess(hub))) - { - if (menu.MenuRelated == null) - mainMenu.Add(new SSButton(menu.Id, string.Format(Plugin.Instance.Translation.OpenMenu.Label, menu.Name), Plugin.Instance.Translation.OpenMenu.ButtonText, null, string.IsNullOrEmpty(menu.Description) ? null : menu.Description)); - } + foreach (Menu menu in LoadedMenus.Where(x => x.CheckAccess(hub) && x.MenuRelated == null)) + mainMenu.Add(new SSButton(menu.Id, string.Format(Plugin.Instance.Translation.OpenMenu.Label, menu.Name), Plugin.Instance.Translation.OpenMenu.ButtonText, null, string.IsNullOrEmpty(menu.Description) ? null : menu.Description)); mainMenu.AddRange(GetGlobalKeybindings(hub, null)); @@ -406,7 +405,7 @@ private static ServerSpecificSettingBase[] GetGlobalKeybindings(ReferenceHub hub foreach (KeyValuePair> menuKeybinds in GlobalKeybindingSync.Where(x => x.Key.CheckAccess(hub) && x.Key != menu)) { foreach (Keybind keybind in menuKeybinds.Value) - keybindings.Add(new SSKeybindSetting(keybind.SettingId + menuKeybinds.Key.Hash, keybind.Label, keybind.SuggestedKey, keybind.PreventInteractionOnGUI, keybind.HintDescription)); + keybindings.Add(new SSKeybindSetting(keybind.SettingId + menuKeybinds.Key.Hash, keybind.Label, keybind.SuggestedKey, keybind.PreventInteractionOnGUI, keybind.AllowSpectatorTrigger, keybind.HintDescription)); } } @@ -493,8 +492,16 @@ internal static void DeletePlayer(ReferenceHub hub) /// /// The sub menu id. /// the sub- if found. + [Obsolete("Use TryGetSubMenu(int, out Menu) instead", true)] public Menu TryGetSubMenu(int id) => LoadedMenus.FirstOrDefault(x => x.Id == id && x.MenuRelated == GetType() && x != this); + /// + /// Try get sub menu related to this menu. + /// + /// The sub menu id. + /// the sub- if found. + public bool TryGetSubMenu(int id, out Menu menu) => (menu = LoadedMenus.FirstOrDefault(x => x.Id == id && x.MenuRelated == GetType() && x != this)) != null; + /// /// Gets the first keybind linked to . /// @@ -546,6 +553,22 @@ public void ReloadAll() LoadForPlayer(hub, this); } + + /// + /// Reload all for all + /// + public static void ReloadAllPlayers() + { + foreach (ReferenceHub hub in ReferenceHub.AllHubs) + LoadForPlayer(hub, GetCurrentPlayerMenu(hub)); + } + + /// + /// Reload the menu of the specified . + /// + /// The target hub. + public static void ReloadPlayer(ReferenceHub hub) => LoadForPlayer(hub, GetCurrentPlayerMenu(hub)); + /// /// Register that will be displayed on the top of all pages. /// @@ -572,5 +595,6 @@ public virtual ServerSpecificSettingBase[] GetSettingsFor(ReferenceHub hub) { return null; } + } } \ No newline at end of file diff --git a/Features/Parameters.cs b/Features/Parameters.cs index 1c7904b..d760bb0 100644 --- a/Features/Parameters.cs +++ b/Features/Parameters.cs @@ -63,7 +63,8 @@ internal static IEnumerator SyncAll(ReferenceHub hub) } Log.Debug($"syncing {hub.nicknameSync.MyNick} registered parameters for menu {menu.Name} {(menu.MenuRelated != null ? $"SubMenu of {Menu.GetMenu(menu.MenuRelated).Name} ({menu.MenuRelated.Name})" : string.Empty)}."); - foreach (ServerSpecificSettingBase t in menu.Settings.Concat(menu.GetSettingsFor(hub))) + ServerSpecificSettingBase[] settingsPerHub = menu.GetSettingsFor(hub); + foreach (ServerSpecificSettingBase t in settingsPerHub is { Length: > 0 } ? menu.Settings.Concat(settingsPerHub) : menu.Settings) { if (t.ResponseMode != ServerSpecificSettingBase.UserResponseMode.AcquisitionAndChange) continue; diff --git a/Features/Utils.cs b/Features/Utils.cs index abfab0d..debbcd7 100644 --- a/Features/Utils.cs +++ b/Features/Utils.cs @@ -12,8 +12,6 @@ internal static void SendToPlayer(ReferenceHub hub, Menu relatedMenu, ServerSpec { foreach (ServerSpecificSettingBase c in collection) { - if (c is SSGroupHeader && c.Label == Plugin.Instance.Translation.GlobalKeybindingTitle.Label && c.HintDescription == Plugin.Instance.Translation.GlobalKeybindingTitle.Hint) - break; if (c.SettingId < relatedMenu.Hash) c.SetId(c.SettingId + relatedMenu.Hash, c.Label); } diff --git a/Features/Wrappers/Keybind.cs b/Features/Wrappers/Keybind.cs index 7358ac4..68f2ba0 100644 --- a/Features/Wrappers/Keybind.cs +++ b/Features/Wrappers/Keybind.cs @@ -20,16 +20,16 @@ public class Keybind : SSKeybindSetting, ISetting /// Triggered when the player press or release the keybind. /// The key server will suggest to the client (displayed with a star). Does not mean the default value. /// If false, the keybind won't work when any gui (like Main menu, Inventory, RA, etc...) is opened. + /// /// The hint (located in "?"). If null, no hint will be displayed. - /// - public Keybind(int? id, string label, Action onUsed = null, KeyCode suggestedKey = KeyCode.None, bool preventInteractionOnGui = true, - string hint = null, bool isGlobal = true) : base(id+Increment, label, suggestedKey, preventInteractionOnGui, hint) + /// Define if the keybind would be visible in the entire menus system + public Keybind(int? id, string label, Action onUsed = null, KeyCode suggestedKey = KeyCode.None, bool preventInteractionOnGui = true, bool allowSpectatorTrigger = true, + string hint = null, bool isGlobal = true) : base(id+Increment, label, suggestedKey, preventInteractionOnGui, allowSpectatorTrigger, hint) { IsGlobal = isGlobal; Action = onUsed; - Base = new SSKeybindSetting(id + Increment, label, suggestedKey, preventInteractionOnGui, hint); + Base = new SSKeybindSetting(id + Increment, label, suggestedKey, preventInteractionOnGui, allowSpectatorTrigger, hint); } - /// /// Gets or Sets whether the would be shown and enabled on all pages or not. /// diff --git a/Patchs/TemporaryPatch.cs b/Patchs/TemporaryPatch.cs new file mode 100644 index 0000000..690813c --- /dev/null +++ b/Patchs/TemporaryPatch.cs @@ -0,0 +1,15 @@ +using HarmonyLib; +using UserSettings.ServerSpecific; + +namespace SSMenuSystem.Patchs +{ + [HarmonyPatch(typeof(SSPlaintextSetting), nameof(SSPlaintextSetting.CharacterLimitOriginal), MethodType.Getter)] + internal class TemporaryPatch + { + internal static bool Prefix(SSPlaintextSetting __instance, ref int __result) + { + __result = 64; + return false; + } + } +} \ No newline at end of file diff --git a/Plugin.cs b/Plugin.cs index 60fe0c8..5ce4002 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -39,7 +39,7 @@ public class Plugin : Plugin /// Gets the version of the plugin. /// - public override Version Version => new(2, 0, 7); + public override Version Version => new(2, 1, 0); #if EXILED /// @@ -102,6 +102,17 @@ public override void Enable() return; _handler = new EventHandler(); + + CustomHandlersManager.RegisterEventsHandler(_handler); + GenericEnable(); + Log.Info($"{Name}@{Version} has been enabled!"); + } + + /// + /// + /// + public override void LoadConfigs() + { if (!this.TryLoadConfig("translation.yml", out Translation translation)) { Log.Error("There is an error while loading translation. Using default one."); @@ -109,10 +120,7 @@ public override void Enable() } Translation = translation; - - CustomHandlersManager.RegisterEventsHandler(_handler); - GenericEnable(); - Log.Info($"{Name}@{Version} has been enabled!"); + base.LoadConfigs(); } /// diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 0fa6149..4074394 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.7")] +[assembly: AssemblyVersion("2.1.0")] [assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/SSMenuSystem-EXILED.nuspec b/SSMenuSystem-EXILED.nuspec index a162595..34a24de 100644 --- a/SSMenuSystem-EXILED.nuspec +++ b/SSMenuSystem-EXILED.nuspec @@ -3,19 +3,19 @@ SSMenuSystem SS Menu System - 2.0.7-EXILED + 2.1.0-EXILED Sky Sky Copyright © Sky 2025 false https://github.com/skyfr0676/SSMenuSystem - An api that add a menu system into SCP: Secret Laboratory. Builded for EXILED 9.5.0. + An api that add a menu system into SCP: Secret Laboratory. Builded for EXILED 9.6.0. docs\README.md - + diff --git a/SSMenuSystem-LABAPI.nuspec b/SSMenuSystem-LABAPI.nuspec index 6370010..52a201a 100644 --- a/SSMenuSystem-LABAPI.nuspec +++ b/SSMenuSystem-LABAPI.nuspec @@ -3,7 +3,7 @@ SSMenuSystem SS Menu System - 2.0.7-LABAPI + 2.1.0-LABAPI Sky Sky Copyright © Sky 2025 diff --git a/SSMenuSystem.csproj b/SSMenuSystem.csproj index 9e82033..1b0c335 100644 --- a/SSMenuSystem.csproj +++ b/SSMenuSystem.csproj @@ -122,6 +122,7 @@ + @@ -139,7 +140,7 @@ - +