Skip to content
Open
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
29 changes: 25 additions & 4 deletions SecretAPI/Features/UserSettings/CustomButtonSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,34 @@ protected CustomButtonSetting(int? id, string label, string buttonText, float? h
public TimeSpan LastPress => Base.SyncLastPress.Elapsed;

/// <summary>
/// Gets the text of the button.
/// Gets or sets the text of the button.
/// </summary>
public string Text => Base.ButtonText;
public string Text
{
get => Base.ButtonText;
set
{
Base.ButtonText = value;
SendButtonUpdate();
}
}

/// <summary>
/// Gets or sets the amount of time to hold the button in seconds.
/// </summary>
public float RequiredHoldTime
{
get => Base.HoldTimeSeconds;
set
{
Base.HoldTimeSeconds = value;
SendButtonUpdate();
}
}

/// <summary>
/// Gets the amount of time to hold the button in seconds.
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that <see cref="Text"/> or <see cref="RequiredHoldTime"/> has updated.
/// </summary>
public float HoldTime => Base.HoldTimeSeconds;
private void SendButtonUpdate() => Base.SendButtonUpdate(Text, RequiredHoldTime, false, IsKnownOwnerHub);
}
}
17 changes: 16 additions & 1 deletion SecretAPI/Features/UserSettings/CustomDropdownSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,27 @@ protected CustomDropdownSetting(
public string[] Options
{
get => Base.Options;
set => Base.Options = value;
set
{
Base.Options = value;
SendDropdownUpdate();
}
}

/// <summary>
/// Gets the selected option as string.
/// </summary>
public string SelectedOption => Options[ValidatedSelectedIndex];

/// <summary>
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that this has been updated on Server. Only works if <see cref="CustomSetting.IsServerOnly"/> is true.
/// </summary>
/// <param name="selectionId">The new ID selected.</param>
public void SendServerUpdate(int selectionId) => Base.SendValueUpdate(selectionId, false, IsKnownOwnerHub);

/// <summary>
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that <see cref="Options"/> has been updated.
/// </summary>
private void SendDropdownUpdate() => Base.SendDropdownUpdate(Options, false, IsKnownOwnerHub);
}
}
2 changes: 2 additions & 0 deletions SecretAPI/Features/UserSettings/CustomHeader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace SecretAPI.Features.UserSettings
{
using System;
using global::UserSettings.ServerSpecific;

/// <summary>
Expand All @@ -21,6 +22,7 @@ public CustomHeader(string label, bool reducedPadding = false, string? hint = nu
/// <summary>
/// Gets a <see cref="CustomHeader"/> for Gameplay purposes.
/// </summary>
[Obsolete("3.0 will remove this - Please handle your setting header yourself!")]
public static CustomHeader Gameplay { get; } = new("Gameplay", hint: "Features that affect gameplay");

/// <summary>
Expand Down
48 changes: 42 additions & 6 deletions SecretAPI/Features/UserSettings/CustomPlainTextSetting.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace SecretAPI.Features.UserSettings
{
using System;
using global::UserSettings.ServerSpecific;
using TMPro;

Expand Down Expand Up @@ -47,18 +48,53 @@ protected CustomPlainTextSetting(
public string InputText => Base.SyncInputText;

/// <summary>
/// Gets the content type.
/// Gets or sets the content type.
/// </summary>
public TMP_InputField.ContentType ContentType => Base.ContentType;
public TMP_InputField.ContentType ContentType
{
get => Base.ContentType;
set
{
Base.ContentType = value;
SendPlaintextUpdate();
}
}

/// <summary>
/// Gets or sets the placeholder.
/// </summary>
public string Placeholder
{
get => Base.Placeholder;
set
{
Base.Placeholder = value;
SendPlaintextUpdate();
}
}

/// <summary>
/// Gets or sets the character limit.
/// </summary>
public int CharacterLimit
{
get => Base.CharacterLimit;
set
{
Base.CharacterLimit = value;
SendPlaintextUpdate();
}
}

/// <summary>
/// Gets the placeholder.
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that this has been updated on Server. Only works if <see cref="CustomSetting.IsServerOnly"/> is true.
/// </summary>
public string Placeholder => Base.Placeholder;
/// <param name="text">The new text.</param>
public void SendServerUpdate(string text) => Base.SendValueUpdate(text, false, IsKnownOwnerHub);

/// <summary>
/// Gets the character limit.
/// Sends an update to the <see cref="CustomSetting.KnownOwner"/> that <see cref="Placeholder"/> <see cref="CharacterLimit"/> or <see cref="ContentType"/> has changed values.
/// </summary>
public int CharacterLimit => Base.CharacterLimit;
private void SendPlaintextUpdate() => Base.SendPlaintextUpdate(Placeholder, (ushort)Math.Clamp(CharacterLimit, ushort.MinValue, ushort.MaxValue), ContentType, false, IsKnownOwnerHub);
}
}
29 changes: 27 additions & 2 deletions SecretAPI/Features/UserSettings/CustomSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,22 @@ public bool IsServerOnly
set => Base.IsServerOnly = value;
}

/// <summary>
/// Gets a value indicating whether the setting is the default and not tied to a <see cref="Player"/>.
/// </summary>
public bool IsDefaultSetting => KnownOwner == null;

/// <summary>
/// Gets or sets the current label.
/// </summary>
public string Label
{
get => Base.Label;
set => Base.Label = value;
set
{
Base.Label = value;
SendSettingUpdate();
}
}

/// <summary>
Expand All @@ -90,7 +99,11 @@ public string Label
public string DescriptionHint
{
get => Base.HintDescription;
set => Base.HintDescription = value;
set
{
Base.HintDescription = value;
SendSettingUpdate();
}
}

/// <summary>
Expand Down Expand Up @@ -252,6 +265,13 @@ public static void SendSettingsToPlayer(Player player, int? version = null)
ListPool<ServerSpecificSettingBase>.Shared.Return(ordered);
}

/// <summary>
/// Checks whether a <see cref="ReferenceHub"/> is equal to <see cref="KnownOwner"/>.
/// </summary>
/// <param name="hub">The <see cref="ReferenceHub"/> to check.</param>
/// <returns>Whether <see cref="ReferenceHub"/> is equal to Owner <see cref="ReferenceHub"/>.</returns>
internal bool IsKnownOwnerHub(ReferenceHub? hub) => hub && KnownOwner?.ReferenceHub == hub;

/// <summary>
/// Resyncs the setting to its owner.
/// </summary>
Expand Down Expand Up @@ -326,5 +346,10 @@ private static CustomSetting EnsurePlayerSpecificSetting(Player player, CustomSe

return currentSetting;
}

/// <summary>
/// Sends an update to <see cref="KnownOwner"/> that <see cref="Label"/> or <see cref="DescriptionHint"/> has changed.
/// </summary>
private void SendSettingUpdate() => Base.SendUpdate(Label, DescriptionHint, false, IsKnownOwnerHub);
}
}
69 changes: 63 additions & 6 deletions SecretAPI/Features/UserSettings/CustomSliderSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,43 @@ protected CustomSliderSetting(
/// </summary>
public int SelectedValueInt => Base.SyncIntValue;

/// <summary>
/// Gets or sets the value to string format.
/// </summary>
public string ValueToStringFormat
{
get => Base.ValueToStringFormat;
set
{
Base.ValueToStringFormat = value;
SendSliderUpdate();
}
}

/// <summary>
/// Gets or sets the final display format.
/// </summary>
public string FinalDisplayFormat
{
get => Base.FinalDisplayFormat;
set
{
Base.FinalDisplayFormat = value;
SendSliderUpdate();
}
}

/// <summary>
/// Gets or sets the minimum value of the setting.
/// </summary>
public float MinimumValue
{
get => Base.MinValue;
set => Base.MinValue = value;
set
{
Base.MinValue = value;
SendSliderUpdate();
}
}

/// <summary>
Expand All @@ -71,17 +101,44 @@ public float MinimumValue
public float MaximumValue
{
get => Base.MaxValue;
set => Base.MaxValue = value;
set
{
Base.MaxValue = value;
SendSliderUpdate();
}
}

/// <summary>
/// Gets or sets the default value of the setting.
/// </summary>
public float DefaultValue
{
get => Base.DefaultValue;
set => Base.DefaultValue = value;
}

/// <summary>
/// Gets or sets a value indicating whether to use integer. False will use float.
/// </summary>
public bool UseInteger
{
get => Base.Integer;
set
{
Base.Integer = value;
SendSliderUpdate();
}
}

/// <summary>
/// Gets the default value of the setting.
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that this has been updated on Server. Only works if <see cref="CustomSetting.IsServerOnly"/> is true.
/// </summary>
public float DefaultValue => Base.DefaultValue;
/// <param name="value">The new value that this is set to.</param>
public void SendServerUpdate(float value) => Base.SendValueUpdate(value, false, IsKnownOwnerHub);

/// <summary>
/// Gets a value indicating whether to use integer. False will use float.
/// Sends an update that any of the slider values have been updated.
/// </summary>
public bool UseInteger => Base.Integer;
private void SendSliderUpdate() => Base.SendSliderUpdate(MinimumValue, MaximumValue, UseInteger, ValueToStringFormat, FinalDisplayFormat, false, IsKnownOwnerHub);
}
}
9 changes: 9 additions & 0 deletions SecretAPI/Features/UserSettings/CustomTextAreaSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ protected CustomTextAreaSetting(
/// <inheritdoc />
public new SSTextArea Base { get; }

/// <summary>
/// Gets or sets the current content. This is equal to <see cref="CustomSetting.Label"/>.
/// </summary>
public string Content
{
get => Label;
set => Label = value;
}

/// <summary>
/// Gets the foldout mode.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions SecretAPI/Features/UserSettings/CustomTwoButtonSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,32 @@ protected CustomTwoButtonSetting(int? id, string label, string optionA, string o
/// <inheritdoc/>
public new SSTwoButtonsSetting Base { get; }

/// <summary>
/// Gets or sets the current text for the first option.
/// </summary>
public string OptionA
{
get => Base.OptionA;
set
{
Base.OptionA = value;
SendOptionsUpdate();
}
}

/// <summary>
/// Gets or sets the current text for the second option.
/// </summary>
public string OptionB
{
get => Base.OptionB;
set
{
Base.OptionB = value;
SendOptionsUpdate();
}
}

/// <summary>
/// Gets a value indicating whether the selected option is currently the first.
/// </summary>
Expand All @@ -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.
/// </summary>
public bool IsDefault => Base.DefaultIsB ? IsOptionB : IsOptionA;

/// <summary>
/// Sends an update to <see cref="CustomSetting.KnownOwner"/> that this has been updated on Server. Only works if <see cref="CustomSetting.IsServerOnly"/> is true.
/// </summary>
/// <param name="isB">Whether the setting is set to B value now.</param>
public void SendServerUpdate(bool isB) => Base.SendValueUpdate(isB, false, IsKnownOwnerHub);

/// <summary>
/// Sends an update to the <see cref="CustomSetting.KnownOwner"/> that <see cref="OptionA"/> or <see cref="OptionB"/> has changed values.
/// </summary>
private void SendOptionsUpdate() => Base.SendTwoButtonUpdate(OptionA, OptionB, false, IsKnownOwnerHub);
}
}