diff --git a/SecretAPI/Features/UserSettings/CustomButtonSetting.cs b/SecretAPI/Features/UserSettings/CustomButtonSetting.cs index 3076fb3..7ef676c 100644 --- a/SecretAPI/Features/UserSettings/CustomButtonSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomButtonSetting.cs @@ -40,13 +40,34 @@ protected CustomButtonSetting(int? id, string label, string buttonText, float? h public TimeSpan LastPress => Base.SyncLastPress.Elapsed; /// - /// Gets the text of the button. + /// Gets or sets the text of the button. /// - public string Text => Base.ButtonText; + public string Text + { + get => Base.ButtonText; + set + { + Base.ButtonText = value; + SendButtonUpdate(); + } + } + + /// + /// Gets or sets the amount of time to hold the button in seconds. + /// + public float RequiredHoldTime + { + get => Base.HoldTimeSeconds; + set + { + Base.HoldTimeSeconds = value; + SendButtonUpdate(); + } + } /// - /// Gets the amount of time to hold the button in seconds. + /// Sends an update to that or has updated. /// - public float HoldTime => Base.HoldTimeSeconds; + private void SendButtonUpdate() => Base.SendButtonUpdate(Text, RequiredHoldTime, false, IsKnownOwnerHub); } } \ No newline at end of file diff --git a/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs b/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs index 00626a1..02ac34b 100644 --- a/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs @@ -27,14 +27,18 @@ protected CustomDropdownSetting(SSDropdownSetting setting) /// The default option (int index). /// The entry type. /// The hint to show. + /// The . + /// See . protected CustomDropdownSetting( int? id, string label, string[] options, int defaultOptionIndex = 0, SSDropdownSetting.DropdownEntryType entryType = SSDropdownSetting.DropdownEntryType.Regular, - string? hint = null) - : this(new SSDropdownSetting(id, label, options, defaultOptionIndex, entryType, hint)) + string? hint = null, + byte collectionId = byte.MaxValue, + bool isServerSetting = false) + : this(new SSDropdownSetting(id, label, options, defaultOptionIndex, entryType, hint, collectionId, isServerSetting)) { } @@ -58,12 +62,33 @@ protected CustomDropdownSetting( public string[] Options { get => Base.Options; - set => Base.Options = value; + set + { + Base.Options = value; + SendDropdownUpdate(); + } } /// /// Gets the selected option as string. /// public string SelectedOption => Options[ValidatedSelectedIndex]; + + /// + /// Gets the . + /// + /// Refer to https://github.com/HubertMoszka/Server-Specific-Settings-System/blob/main/SSDropdownSetting.cs#L151 for proper documentation. + public SSDropdownSetting.DropdownEntryType EntryType => Base.EntryType; + + /// + /// Sends an update to that this has been updated on Server. Only works if is true. + /// + /// The new ID selected. + public void SendServerUpdate(int selectionId) => Base.SendValueUpdate(selectionId, false, IsKnownOwnerHub); + + /// + /// Sends an update to that has been updated. + /// + private void SendDropdownUpdate() => Base.SendDropdownUpdate(Options, false, IsKnownOwnerHub); } } \ No newline at end of file diff --git a/SecretAPI/Features/UserSettings/CustomHeader.cs b/SecretAPI/Features/UserSettings/CustomHeader.cs index bc7c7b5..d638121 100644 --- a/SecretAPI/Features/UserSettings/CustomHeader.cs +++ b/SecretAPI/Features/UserSettings/CustomHeader.cs @@ -1,5 +1,6 @@ namespace SecretAPI.Features.UserSettings { + using System; using global::UserSettings.ServerSpecific; /// @@ -21,6 +22,7 @@ public CustomHeader(string label, bool reducedPadding = false, string? hint = nu /// /// Gets a for Gameplay purposes. /// + [Obsolete("3.0 will remove this - Please handle your setting header yourself!")] public static CustomHeader Gameplay { get; } = new("Gameplay", hint: "Features that affect gameplay"); /// diff --git a/SecretAPI/Features/UserSettings/CustomKeybindSetting.cs b/SecretAPI/Features/UserSettings/CustomKeybindSetting.cs index 1b8d094..32ae2aa 100644 --- a/SecretAPI/Features/UserSettings/CustomKeybindSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomKeybindSetting.cs @@ -27,14 +27,16 @@ protected CustomKeybindSetting(SSKeybindSetting setting) /// Whether to prevent interaction in a GUI. /// Whether to allow spectators to trigger. /// The hint to show. + /// The . protected CustomKeybindSetting( int? id, string label, KeyCode suggestedKey = KeyCode.None, bool preventInteractionOnGui = true, bool allowSpectatorTrigger = true, - string? hint = null) - : this(new SSKeybindSetting(id, label, suggestedKey, preventInteractionOnGui, allowSpectatorTrigger, hint)) + string? hint = null, + byte collectionId = byte.MaxValue) + : this(new SSKeybindSetting(id, label, suggestedKey, preventInteractionOnGui, allowSpectatorTrigger, hint, collectionId)) { } diff --git a/SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs b/SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs index 963f93d..d8750b4 100644 --- a/SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs @@ -1,5 +1,6 @@ namespace SecretAPI.Features.UserSettings { + using System; using global::UserSettings.ServerSpecific; using TMPro; @@ -47,18 +48,53 @@ protected CustomPlainTextSetting( public string InputText => Base.SyncInputText; /// - /// Gets the content type. + /// Gets or sets the content type. /// - public TMP_InputField.ContentType ContentType => Base.ContentType; + public TMP_InputField.ContentType ContentType + { + get => Base.ContentType; + set + { + Base.ContentType = value; + SendPlaintextUpdate(); + } + } + + /// + /// Gets or sets the placeholder. + /// + public string Placeholder + { + get => Base.Placeholder; + set + { + Base.Placeholder = value; + SendPlaintextUpdate(); + } + } + + /// + /// Gets or sets the character limit. + /// + public int CharacterLimit + { + get => Base.CharacterLimit; + set + { + Base.CharacterLimit = value; + SendPlaintextUpdate(); + } + } /// - /// Gets the placeholder. + /// Sends an update to that this has been updated on Server. Only works if is true. /// - public string Placeholder => Base.Placeholder; + /// The new text. + public void SendServerUpdate(string text) => Base.SendValueUpdate(text, false, IsKnownOwnerHub); /// - /// Gets the character limit. + /// Sends an update to the that or has changed values. /// - public int CharacterLimit => Base.CharacterLimit; + private void SendPlaintextUpdate() => Base.SendPlaintextUpdate(Placeholder, (ushort)Math.Clamp(CharacterLimit, ushort.MinValue, ushort.MaxValue), ContentType, false, IsKnownOwnerHub); } } \ No newline at end of file diff --git a/SecretAPI/Features/UserSettings/CustomSetting.cs b/SecretAPI/Features/UserSettings/CustomSetting.cs index 9f65019..0db54cf 100644 --- a/SecretAPI/Features/UserSettings/CustomSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSetting.cs @@ -21,7 +21,7 @@ public abstract class CustomSetting : ISetting static CustomSetting() { - SecretApi.Harmony?.PatchCategory(nameof(CustomSetting)); + SecretApi.Harmony?.PatchCategory(nameof(CustomSetting), SecretApi.Assembly); ServerSpecificSettingsSync.SendOnJoinFilter = null; ServerSpecificSettingsSync.DefinedSettings ??= []; // fix null ref @@ -66,22 +66,31 @@ protected CustomSetting(ServerSpecificSettingBase setting) public abstract CustomHeader Header { get; } /// - /// Gets or sets a value indicating whether the setting is server side only. + /// Gets or sets a value indicating whether the setting is server side. /// - /// The setting value cannot be updated from client side and can be used to indicate server features being toggled. - public bool IsServerOnly + /// This will result in client not saving the setting values and allows the server to change the setting . + public bool IsServerSetting { get => Base.IsServerOnly; set => Base.IsServerOnly = value; } + /// + /// Gets a value indicating whether the setting is the default and not tied to a . + /// + public bool IsDefaultSetting => KnownOwner == null; + /// /// Gets or sets the current label. /// public string Label { get => Base.Label; - set => Base.Label = value; + set + { + Base.Label = value; + SendSettingUpdate(); + } } /// @@ -90,7 +99,11 @@ public string Label public string DescriptionHint { get => Base.HintDescription; - set => Base.HintDescription = value; + set + { + Base.HintDescription = value; + SendSettingUpdate(); + } } /// @@ -138,13 +151,13 @@ public bool IsShared /// Unregisters collection of settings. /// /// The settings to unregister. - public static void UnRegister(params CustomSetting[] settings) => CustomSettings.RemoveAll(s => settings.Contains(s)); + public static void UnRegister(params CustomSetting[] settings) => CustomSettings.RemoveAll(settings.Contains); /// /// Unregisters a collection of settings. /// /// The settings to unregister. - public static void UnRegister(IEnumerable settings) => CustomSettings.RemoveAll(s => settings.Contains(s)); + public static void UnRegister(IEnumerable settings) => CustomSettings.RemoveAll(settings.Contains); /// /// Tries to get player specific setting. @@ -252,6 +265,13 @@ public static void SendSettingsToPlayer(Player player, int? version = null) ListPool.Shared.Return(ordered); } + /// + /// Checks whether a is equal to . + /// + /// The to check. + /// Whether is equal to Owner . + internal bool IsKnownOwnerHub(ReferenceHub? hub) => hub && KnownOwner?.ReferenceHub == hub; + /// /// Resyncs the setting to its owner. /// @@ -326,5 +346,10 @@ private static CustomSetting EnsurePlayerSpecificSetting(Player player, CustomSe return currentSetting; } + + /// + /// Sends an update to that or has changed. + /// + private void SendSettingUpdate() => Base.SendUpdate(Label, DescriptionHint, false, IsKnownOwnerHub); } } diff --git a/SecretAPI/Features/UserSettings/CustomSliderSetting.cs b/SecretAPI/Features/UserSettings/CustomSliderSetting.cs index 98b7e4e..d3877b6 100644 --- a/SecretAPI/Features/UserSettings/CustomSliderSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSliderSetting.cs @@ -29,6 +29,8 @@ protected CustomSliderSetting(SSSliderSetting setting) /// Value to string format. /// The final display format. /// The hint to display. + /// The . + /// See . protected CustomSliderSetting( int? id, string label, @@ -38,7 +40,9 @@ protected CustomSliderSetting( bool integer = false, string valueToStringFormat = "0.##", string finalDisplayFormat = "{0}", - string? hint = null) + string? hint = null, + byte collectionId = byte.MaxValue, + bool isServerSetting = false) : this(new SSSliderSetting(id, label, minValue, maxValue, defaultValue, integer, valueToStringFormat, finalDisplayFormat, hint)) { } @@ -56,13 +60,43 @@ protected CustomSliderSetting( /// public int SelectedValueInt => Base.SyncIntValue; + /// + /// Gets or sets the value to string format. + /// + public string ValueToStringFormat + { + get => Base.ValueToStringFormat; + set + { + Base.ValueToStringFormat = value; + SendSliderUpdate(); + } + } + + /// + /// Gets or sets the final display format. + /// + public string FinalDisplayFormat + { + get => Base.FinalDisplayFormat; + set + { + Base.FinalDisplayFormat = value; + SendSliderUpdate(); + } + } + /// /// Gets or sets the minimum value of the setting. /// public float MinimumValue { get => Base.MinValue; - set => Base.MinValue = value; + set + { + Base.MinValue = value; + SendSliderUpdate(); + } } /// @@ -71,17 +105,44 @@ public float MinimumValue public float MaximumValue { get => Base.MaxValue; - set => Base.MaxValue = value; + set + { + Base.MaxValue = value; + SendSliderUpdate(); + } + } + + /// + /// Gets or sets the default value of the setting. + /// + public float DefaultValue + { + get => Base.DefaultValue; + set => Base.DefaultValue = value; + } + + /// + /// Gets or sets a value indicating whether to use integer. False will use float. + /// + public bool UseInteger + { + get => Base.Integer; + set + { + Base.Integer = value; + SendSliderUpdate(); + } } /// - /// Gets the default value of the setting. + /// Sends an update to that this has been updated on Server. Only works if is true. /// - public float DefaultValue => Base.DefaultValue; + /// The new value that this is set to. + public void SendServerUpdate(float value) => Base.SendValueUpdate(value, false, IsKnownOwnerHub); /// - /// Gets a value indicating whether to use integer. False will use float. + /// Sends an update that any of the slider values have been updated. /// - public bool UseInteger => Base.Integer; + private void SendSliderUpdate() => Base.SendSliderUpdate(MinimumValue, MaximumValue, UseInteger, ValueToStringFormat, FinalDisplayFormat, false, IsKnownOwnerHub); } } \ No newline at end of file diff --git a/SecretAPI/Features/UserSettings/CustomTextAreaSetting.cs b/SecretAPI/Features/UserSettings/CustomTextAreaSetting.cs index ea4b4d8..e70c67c 100644 --- a/SecretAPI/Features/UserSettings/CustomTextAreaSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomTextAreaSetting.cs @@ -39,6 +39,15 @@ protected CustomTextAreaSetting( /// public new SSTextArea Base { get; } + /// + /// Gets or sets the current content. This is equal to . + /// + public string Content + { + get => Label; + set => Label = value; + } + /// /// Gets the foldout mode. /// diff --git a/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs b/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs index 4a48a2a..f3db69d 100644 --- a/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs @@ -26,14 +26,50 @@ protected CustomTwoButtonSetting(SSTwoButtonsSetting button) /// The second option. /// Whether the second option should be default. Default: false. /// The hint to show. - protected CustomTwoButtonSetting(int? id, string label, string optionA, string optionB, bool defaultIsB = false, string? hint = null) - : this(new SSTwoButtonsSetting(id, label, optionA, optionB, defaultIsB, hint)) + /// The . + /// See . + protected CustomTwoButtonSetting( + int? id, + string label, + string optionA, + string optionB, + bool defaultIsB = false, + string? hint = null, + byte collectionId = byte.MaxValue, + bool isServerSetting = false) + : this(new SSTwoButtonsSetting(id, label, optionA, optionB, defaultIsB, hint, collectionId, isServerSetting)) { } /// public new SSTwoButtonsSetting Base { get; } + /// + /// Gets or sets the current text for the first option. + /// + public string OptionA + { + get => Base.OptionA; + set + { + Base.OptionA = value; + SendOptionsUpdate(); + } + } + + /// + /// Gets or sets the current text for the second option. + /// + public string OptionB + { + get => Base.OptionB; + set + { + Base.OptionB = value; + SendOptionsUpdate(); + } + } + /// /// Gets a value indicating whether the selected option is currently the first. /// @@ -48,5 +84,16 @@ protected CustomTwoButtonSetting(int? id, string label, string optionA, string o /// Gets a value indicating whether the selected option is currently set to the default. /// public bool IsDefault => Base.DefaultIsB ? IsOptionB : IsOptionA; + + /// + /// Sends an update to that this has been updated on Server. Only works if is true. + /// + /// Whether the setting is set to B value now. + public void SendServerUpdate(bool isB) => Base.SendValueUpdate(isB, false, IsKnownOwnerHub); + + /// + /// Sends an update to the that or has changed values. + /// + private void SendOptionsUpdate() => Base.SendTwoButtonUpdate(OptionA, OptionB, false, IsKnownOwnerHub); } } \ No newline at end of file diff --git a/SecretAPI/SecretApi.cs b/SecretAPI/SecretApi.cs index 72634a7..7f58deb 100644 --- a/SecretAPI/SecretApi.cs +++ b/SecretAPI/SecretApi.cs @@ -38,7 +38,7 @@ public class SecretApi : Plugin /// /// Gets the harmony to use for the API. /// - internal static Harmony? Harmony { get; private set; } + internal static Harmony? Harmony { get; } = new("SecretAPI" + DateTime.Now); /// /// Gets the Assembly of the API. @@ -48,7 +48,6 @@ public class SecretApi : Plugin /// public override void Enable() { - Harmony = new Harmony("SecretAPI" + DateTime.Now); CallOnLoadAttribute.Load(Assembly); }