Skip to content
Merged
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
13 changes: 13 additions & 0 deletions EXILED/Exiled.API/Features/Core/UserSettings/ButtonSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public float HoldTime
set => Base.HoldTimeSeconds = value;
}

/// <summary>
/// Sends updated values to clients.
/// </summary>
/// <param name="text"><inheritdoc cref="Text"/></param>
/// <param name="holdTime"><inheritdoc cref="HoldTime"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateSetting(string text, float holdTime, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendButtonUpdate(text, holdTime, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// Returns a representation of this <see cref="ButtonSetting"/>.
/// </summary>
Expand Down
56 changes: 55 additions & 1 deletion EXILED/Exiled.API/Features/Core/UserSettings/DropdownSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,46 @@ public class DropdownSetting : SettingBase, IWrapper<SSDropdownSetting>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
[Obsolete("Will be removed in Exiled 10 in favour of ctor with more params")]
public DropdownSetting(
int id,
string label,
IEnumerable<string> options,
int defaultOptionIndex,
SSDropdownSetting.DropdownEntryType dropdownEntryType,
string hintDescription,
HeaderSetting header,
Action<Player, SettingBase> onChanged)
: base(new SSDropdownSetting(id, label, options.ToArray(), defaultOptionIndex, dropdownEntryType, hintDescription), header, onChanged)
{
Base = (SSDropdownSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="DropdownSetting"/> class.
/// </summary>
/// <param name="id"><inheritdoc cref="SettingBase.Id"/></param>
/// <param name="label"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="options"><inheritdoc cref="Options"/></param>
/// <param name="defaultOptionIndex"><inheritdoc cref="DefaultOptionIndex"/></param>
/// <param name="dropdownEntryType"><inheritdoc cref="DropdownType"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="collectionId"><inheritdoc cref="SettingBase.CollectionId"/></param>
/// <param name="isServerOnly"><inheritdoc cref="SettingBase.IsServerOnly"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
public DropdownSetting(
int id,
string label,
IEnumerable<string> options,
int defaultOptionIndex = 0,
SSDropdownSetting.DropdownEntryType dropdownEntryType = SSDropdownSetting.DropdownEntryType.Regular,
string hintDescription = null,
byte collectionId = byte.MaxValue,
bool isServerOnly = false,
HeaderSetting header = null,
Action<Player, SettingBase> onChanged = null)
: base(new SSDropdownSetting(id, label, options.ToArray(), defaultOptionIndex, dropdownEntryType, hintDescription), header, onChanged)
: base(new SSDropdownSetting(id, label, options.ToArray(), defaultOptionIndex, dropdownEntryType, hintDescription, collectionId, isServerOnly), header, onChanged)
{
Base = (SSDropdownSetting)base.Base;
}
Expand Down Expand Up @@ -116,6 +146,30 @@ public string SelectedOption
set => SelectedIndex = Array.IndexOf(Base.Options, value);
}

/// <summary>
/// Sends updated values to clients.
/// </summary>
/// <param name="options"><inheritdoc cref="Options"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateSetting(string[] options, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendDropdownUpdate(options, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// If setting is server only, sends updated values to clients.
/// </summary>
/// <param name="selectedIndex"><inheritdoc cref="SelectedIndex"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateValue(int selectedIndex, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendValueUpdate(selectedIndex, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// Gets a string representation of this <see cref="DropdownSetting"/>.
/// </summary>
Expand Down
21 changes: 20 additions & 1 deletion EXILED/Exiled.API/Features/Core/UserSettings/HeaderSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.API.Features.Core.UserSettings
{
using System;

using Exiled.API.Interfaces;
using global::UserSettings.ServerSpecific;

Expand All @@ -21,14 +23,30 @@ public class HeaderSetting : SettingBase, IWrapper<SSGroupHeader>
/// <param name="name"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="paddling"><inheritdoc cref="ReducedPaddling"/></param>
public HeaderSetting(string name, string hintDescription = "", bool paddling = false)
[Obsolete("Use constructor with Id, old headers will use random number based on headers name")]
public HeaderSetting(string name, string hintDescription, bool paddling)
: this(new SSGroupHeader(name, paddling, hintDescription))
{
Base = (SSGroupHeader)base.Base;

Base.SetId(null, name);
}

/// <summary>
/// Initializes a new instance of the <see cref="HeaderSetting"/> class.
/// </summary>
/// <param name="id"><inheritdoc cref="SettingBase.Id"/></param>
/// <param name="name"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="padding"><inheritdoc cref="ReducedPaddling"/></param>
public HeaderSetting(int id, string name, string hintDescription = "", bool padding = false)
: this(new SSGroupHeader(id, name, padding, hintDescription))
{
Base = (SSGroupHeader)base.Base;

Base.SetId(id, name);
}

/// <summary>
/// Initializes a new instance of the <see cref="HeaderSetting"/> class.
/// </summary>
Expand All @@ -46,6 +64,7 @@ internal HeaderSetting(SSGroupHeader settingBase)
/// <summary>
/// Gets or sets a value indicating whether to reduce padding.
/// </summary>
// TODO: change to ReducedPadding (thanks Valera)
public bool ReducedPaddling
{
get => Base.ReducedPadding;
Expand Down
23 changes: 21 additions & 2 deletions EXILED/Exiled.API/Features/Core/UserSettings/KeybindSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class KeybindSetting : SettingBase, IWrapper<SSKeybindSetting>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
[Obsolete("This method will be removed next major version because of a new feature. Use the constructor with \"allowSpectator\" instead.")]
[Obsolete("This method will be removed next major version because of a new feature. Use the constructor with \"CollectionId\" instead.")]
public KeybindSetting(int id, string label, KeyCode suggested, bool preventInteractionOnGUI, string hintDescription, HeaderSetting header, Action<Player, SettingBase> onChanged)
: base(new SSKeybindSetting(id, label, suggested, preventInteractionOnGUI, false, hintDescription), header, onChanged)
{
Expand All @@ -46,12 +46,31 @@ public KeybindSetting(int id, string label, KeyCode suggested, bool preventInter
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
public KeybindSetting(int id, string label, KeyCode suggested, bool preventInteractionOnGUI = false, bool allowSpectatorTrigger = false, string hintDescription = "", HeaderSetting header = null, Action<Player, SettingBase> onChanged = null)
[Obsolete("Will be removed in Exiled 10 in favour of ctor with more params.")]
public KeybindSetting(int id, string label, KeyCode suggested, bool preventInteractionOnGUI, bool allowSpectatorTrigger, string hintDescription, HeaderSetting header, Action<Player, SettingBase> onChanged)
: base(new SSKeybindSetting(id, label, suggested, preventInteractionOnGUI, allowSpectatorTrigger, hintDescription), header, onChanged)
{
Base = (SSKeybindSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="KeybindSetting"/> class.
/// </summary>
/// <param name="id"><inheritdoc cref="SettingBase.Id"/></param>
/// <param name="label"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="suggested"><inheritdoc cref="KeyCode"/></param>
/// <param name="preventInteractionOnGUI"><inheritdoc cref="PreventInteractionOnGUI"/></param>
/// <param name="allowSpectatorTrigger"><inheritdoc cref="AllowSpectatorTrigger"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="collectionId"><inheritdoc cref="SettingBase.CollectionId"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
public KeybindSetting(int id, string label, KeyCode suggested, bool preventInteractionOnGUI = false, bool allowSpectatorTrigger = false, string hintDescription = "", byte collectionId = byte.MaxValue, HeaderSetting header = null, Action<Player, SettingBase> onChanged = null)
: base(new SSKeybindSetting(id, label, suggested, preventInteractionOnGUI, allowSpectatorTrigger, hintDescription, collectionId), header, onChanged)
{
Base = (SSKeybindSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="KeybindSetting"/> class.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,33 @@ public string HintDescription
set => Base.HintDescription = value;
}

/// <summary>
/// Gets or sets a value indicating whether the setting receives updates from server (and client stops sending updates).
/// </summary>
/// <remarks>
/// Useful for displaying information, you cannot receive updates from a setting with this enabled.
/// </remarks>
public bool IsServerOnly
{
get => Base.IsServerOnly;
set => Base.IsServerOnly = value;
}

/// <summary>
/// Gets or sets a value controlling if this setting is shared across servers with <b>same Ip address!</b>. Default value is 255.
/// </summary>
/// <remarks>
/// Settings with this value between 0 and 20 will store the servers Ip (or other unique identifier) instead of port, meaning the client treats a setting between 1.1.1.1:7777 and 1.1.1.1:7778 the same.
/// <br/>
/// <br/>
/// If this value is above 20, the aforementioned behavior will not occur and the setting will behave as normal.
/// </remarks>
public byte CollectionId
{
get => Base.CollectionId;
set => Base.CollectionId = value;
}

/// <summary>
/// Gets the response mode of this setting.
/// </summary>
Expand Down Expand Up @@ -334,6 +361,19 @@ public static IEnumerable<SettingBase> Unregister(Player player, IEnumerable<Set
return list2;
}

/// <summary>
/// Sends an updated label and hint to clients.
/// </summary>
/// <param name="label"><inheritdoc cref="Label"/></param>
/// <param name="hint"><inheritdoc cref="Hint"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateLabelAndHint(string label, string hint, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendUpdate(label, hint, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// Returns a string representation of this <see cref="SettingBase"/>.
/// </summary>
Expand Down
53 changes: 52 additions & 1 deletion EXILED/Exiled.API/Features/Core/UserSettings/SliderSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,35 @@ public class SliderSetting : SettingBase, IWrapper<SSSliderSetting>
/// <param name="stringFormat"><inheritdoc cref="StringFormat"/></param>
/// <param name="displayFormat"><inheritdoc cref="DisplayFormat"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
public SliderSetting(int id, string label, float minValue, float maxValue, float defaultValue, bool isInteger = false, string stringFormat = "0.##", string displayFormat = "{0}", string hintDescription = null)
[Obsolete("Will be removed in Exiled 10 in favour of ctor with more params.")]
public SliderSetting(int id, string label, float minValue, float maxValue, float defaultValue, bool isInteger, string stringFormat, string displayFormat, string hintDescription)
: this(new SSSliderSetting(id, label, minValue, maxValue, defaultValue, isInteger, stringFormat, displayFormat, hintDescription))
{
Base = (SSSliderSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="SliderSetting"/> class.
/// </summary>
/// <param name="id"><inheritdoc cref="SettingBase.Id"/></param>
/// <param name="label"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="minValue"><inheritdoc cref="MinimumValue"/></param>
/// <param name="maxValue"><inheritdoc cref="MaximumValue"/></param>
/// <param name="defaultValue"><inheritdoc cref="DefaultValue"/></param>
/// <param name="isInteger"><inheritdoc cref="IsInteger"/></param>
/// <param name="stringFormat"><inheritdoc cref="StringFormat"/></param>
/// <param name="displayFormat"><inheritdoc cref="DisplayFormat"/></param>
/// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
/// <param name="collectionId"><inheritdoc cref="SettingBase.CollectionId"/></param>
/// <param name="isServerOnly"><inheritdoc cref="SettingBase.IsServerOnly"/></param>
/// <param name="header"><inheritdoc cref="SettingBase.Header"/></param>
/// <param name="onChanged"><inheritdoc cref="SettingBase.OnChanged"/></param>
public SliderSetting(int id, string label, float minValue, float maxValue, float defaultValue, bool isInteger = false, string stringFormat = "0.##", string displayFormat = "{0}", string hintDescription = null, byte collectionId = byte.MaxValue, bool isServerOnly = false, HeaderSetting header = null, Action<Player, SettingBase> onChanged = null)
: base(new SSSliderSetting(id, label, minValue, maxValue, defaultValue, isInteger, stringFormat, displayFormat, hintDescription, collectionId, isServerOnly), header, onChanged)
{
Base = (SSSliderSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="SliderSetting"/> class.
/// </summary>
Expand Down Expand Up @@ -112,6 +135,34 @@ public string DisplayFormat
/// <inheritdoc/>
public new SSSliderSetting Base { get; }

/// <summary>
/// Sends updated values to clients.
/// </summary>
/// <param name="min"><inheritdoc cref="MinimumValue"/></param>
/// <param name="max"><inheritdoc cref="MaximumValue"/></param>
/// <param name="isInteger"><inheritdoc cref="IsInteger"/></param>
/// <param name="stringFormat"><inheritdoc cref="StringFormat"/></param>
/// <param name="displayFormat"><inheritdoc cref="DisplayFormat"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateSetting(float min, float max, bool isInteger, string stringFormat, string displayFormat, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendSliderUpdate(min, max, isInteger, stringFormat, displayFormat, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// If setting is server only, sends updated values to clients.
/// </summary>
/// <param name="value"><inheritdoc cref="SliderValue"/></param>
/// <param name="overrideValue">If false, sends fake values.</param>
/// <param name="filter">Who to send the update to.</param>
public void UpdateValue(float value, bool overrideValue = true, Predicate<Player> filter = null)
{
filter ??= _ => true;
Base.SendValueUpdate(value, overrideValue, hub => filter(Player.Get(hub)));
}

/// <summary>
/// Returns a representation of this <see cref="SliderSetting"/>.
/// </summary>
Expand Down
Loading
Loading