Skip to content
Merged

Dev #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .idea/.idea.SSMenuSystem/.idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 32 additions & 9 deletions EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerSpecificSettingBase> value))
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -91,19 +94,39 @@ 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))
menu.InternalSettingsSync[hub][menu.InternalSettingsSync[hub].FindIndex(x => x.SettingId == ss.SettingId)] = ss;
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:
Expand Down
1 change: 1 addition & 0 deletions Examples/LightSpawnerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SSMenuSystem.Features;
using SSMenuSystem.Features.Wrappers;
using UserSettings.ServerSpecific;
using Log = SSMenuSystem.Features.Log;

namespace SSMenuSystem.Examples
{
Expand Down
1 change: 0 additions & 1 deletion Examples/PrimitiveSpawnerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Globalization;
using System.Linq;
using AdminToys;
using Exiled.Events.Commands.Hub;
using GameCore;
using Mirror;
using SSMenuSystem.Features;
Expand Down
40 changes: 32 additions & 8 deletions Features/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -406,7 +405,7 @@ private static ServerSpecificSettingBase[] GetGlobalKeybindings(ReferenceHub hub
foreach (KeyValuePair<Menu, List<Keybind>> 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));
}
}

Expand Down Expand Up @@ -493,8 +492,16 @@ internal static void DeletePlayer(ReferenceHub hub)
/// </summary>
/// <param name="id">The sub menu id.</param>
/// <returns>the sub-<see cref="Menu"/> if found.</returns>
[Obsolete("Use TryGetSubMenu(int, out Menu) instead", true)]
public Menu TryGetSubMenu(int id) => LoadedMenus.FirstOrDefault(x => x.Id == id && x.MenuRelated == GetType() && x != this);

/// <summary>
/// Try get sub menu related to this menu.
/// </summary>
/// <param name="id">The sub menu id.</param>
/// <returns>the sub-<see cref="Menu"/> if found.</returns>
public bool TryGetSubMenu(int id, out Menu menu) => (menu = LoadedMenus.FirstOrDefault(x => x.Id == id && x.MenuRelated == GetType() && x != this)) != null;

/// <summary>
/// Gets the first keybind linked to <see cref="ServerSpecificSettingBase"/>.
/// </summary>
Expand Down Expand Up @@ -546,6 +553,22 @@ public void ReloadAll()
LoadForPlayer(hub, this);
}


/// <summary>
/// Reload all <see cref="ReferenceHub"/> for all <see cref="Menu"/>
/// </summary>
public static void ReloadAllPlayers()
{
foreach (ReferenceHub hub in ReferenceHub.AllHubs)
LoadForPlayer(hub, GetCurrentPlayerMenu(hub));
}

/// <summary>
/// Reload the menu of the specified <see cref="ReferenceHub"/>.
/// </summary>
/// <param name="hub">The target hub.</param>
public static void ReloadPlayer(ReferenceHub hub) => LoadForPlayer(hub, GetCurrentPlayerMenu(hub));

/// <summary>
/// Register <see cref="ServerSpecificSettingBase"/> that will be displayed on the top of all pages.
/// </summary>
Expand All @@ -572,5 +595,6 @@ public virtual ServerSpecificSettingBase[] GetSettingsFor(ReferenceHub hub)
{
return null;
}

}
}
3 changes: 2 additions & 1 deletion Features/Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ internal static IEnumerator<float> 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;
Expand Down
2 changes: 0 additions & 2 deletions Features/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions Features/Wrappers/Keybind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public class Keybind : SSKeybindSetting, ISetting
/// <param name="onUsed">Triggered when the player press or release the keybind.</param>
/// <param name="suggestedKey">The key server will suggest to the client (displayed with a star). Does not mean the default value.</param>
/// <param name="preventInteractionOnGui">If false, the keybind won't work when any gui (like Main menu, Inventory, RA, etc...) is opened.</param>
/// <param name="allowSpectatorTrigger"></param>
/// <param name="hint">The hint (located in "?"). If null, no hint will be displayed.</param>
/// <param name="isGlobal"><inheritdoc cref="IsGlobal"/></param>
public Keybind(int? id, string label, Action<ReferenceHub, bool> onUsed = null, KeyCode suggestedKey = KeyCode.None, bool preventInteractionOnGui = true,
string hint = null, bool isGlobal = true) : base(id+Increment, label, suggestedKey, preventInteractionOnGui, hint)
/// <param name="isGlobal"><inheritdoc cref="IsGlobal"/>Define if the keybind would be visible in the entire menus system</param>
public Keybind(int? id, string label, Action<ReferenceHub, bool> 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);
}

/// <summary>
/// Gets or Sets whether the <see cref="SSKeybindSetting"/> would be shown and enabled on all pages or not.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions Patchs/TemporaryPatch.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
18 changes: 13 additions & 5 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Plugin : Plugin<Config
/// <summary>
/// Gets the version of the plugin.
/// </summary>
public override Version Version => new(2, 0, 7);
public override Version Version => new(2, 1, 0);

#if EXILED
/// <inheritdoc/>
Expand Down Expand Up @@ -102,17 +102,25 @@ public override void Enable()
return;

_handler = new EventHandler();

CustomHandlersManager.RegisterEventsHandler(_handler);
GenericEnable();
Log.Info($"{Name}@{Version} has been enabled!");
}

/// <summary>
/// <inheritdoc />
/// </summary>
public override void LoadConfigs()
{
if (!this.TryLoadConfig("translation.yml", out Translation translation))
{
Log.Error("There is an error while loading translation. Using default one.");
translation = new();
}

Translation = translation;

CustomHandlersManager.RegisterEventsHandler(_handler);
GenericEnable();
Log.Info($"{Name}@{Version} has been enabled!");
base.LoadConfigs();
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
6 changes: 3 additions & 3 deletions SSMenuSystem-EXILED.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<metadata>
<id>SSMenuSystem</id>
<title>SS Menu System</title>
<version>2.0.7-EXILED</version>
<version>2.1.0-EXILED</version>
<authors>Sky</authors>
<owners>Sky</owners>
<copyright>Copyright © Sky 2025</copyright>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<repository type="Git" url="https://github.com/skyfr0676/SSMenuSystem" />
<projectUrl>https://github.com/skyfr0676/SSMenuSystem</projectUrl>
<description>An api that add a menu system into SCP: Secret Laboratory. Builded for EXILED 9.5.0.</description>
<description>An api that add a menu system into SCP: Secret Laboratory. Builded for EXILED 9.6.0.</description>
<readme>docs\README.md</readme>

<dependencies>
<group targetFramework="net48">
<dependency id="ExMod.Exiled" version="[9.6.0-beta3]" />
<dependency id="ExMod.Exiled" version="[9.6.0,)" />
</group>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion SSMenuSystem-LABAPI.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>SSMenuSystem</id>
<title>SS Menu System</title>
<version>2.0.7-LABAPI</version>
<version>2.1.0-LABAPI</version>
<authors>Sky</authors>
<owners>Sky</owners>
<copyright>Copyright © Sky 2025</copyright>
Expand Down
3 changes: 2 additions & 1 deletion SSMenuSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Compile Include="Patchs\ExiledPatch.cs" />
<Compile Include="Patchs\OriginalDefinitionPatch.cs" />
<Compile Include="Patchs\PrevalidateResponsePatch.cs" />
<Compile Include="Patchs\TemporaryPatch.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs"/>
<Compile Include="Translation.cs" />
Expand All @@ -139,7 +140,7 @@
<Content Include="SSMenuSystem.ruleset" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ExMod.Exiled" Version="9.6.0-beta8" />
<PackageReference Include="ExMod.Exiled" Version="9.6.1" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading
Loading