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..f2ae73c 100644 --- a/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomDropdownSetting.cs @@ -58,12 +58,27 @@ 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]; + + /// + /// 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/CustomPlainTextSetting.cs b/SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs index 963f93d..6b947b2 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..9c46abf 100644 --- a/SecretAPI/Features/UserSettings/CustomSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSetting.cs @@ -75,13 +75,22 @@ public bool 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(); + } } /// @@ -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..17912a9 100644 --- a/SecretAPI/Features/UserSettings/CustomSliderSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomSliderSetting.cs @@ -56,13 +56,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 +101,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..f9f4bdf 100644 --- a/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs +++ b/SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs @@ -34,6 +34,32 @@ protected CustomTwoButtonSetting(int? id, string label, string optionA, string o /// 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 +74,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