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
2 changes: 2 additions & 0 deletions EXILED/Exiled.API/Features/Core/UserSettings/SettingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ public static bool TryGetSetting<T>(Player player, int id, out T setting)
SSGroupHeader header => new HeaderSetting(header),
SSKeybindSetting keybindSetting => new KeybindSetting(keybindSetting),
SSTwoButtonsSetting twoButtonsSetting => new TwoButtonsSetting(twoButtonsSetting),
SSPlaintextSetting plainTextSetting => new UserTextInputSetting(plainTextSetting),
SSSliderSetting sliderSetting => new SliderSetting(sliderSetting),
_ => new SettingBase(settingBase)
};

Expand Down
124 changes: 124 additions & 0 deletions EXILED/Exiled.API/Features/Core/UserSettings/SliderSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// -----------------------------------------------------------------------
// <copyright file="SliderSetting.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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

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

/// <summary>
/// Represents a slider setting.
/// </summary>
public class SliderSetting : SettingBase, IWrapper<SSSliderSetting>
{
/// <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>
public SliderSetting(int id, string label, float minValue, float maxValue, float defaultValue, bool isInteger = false, string stringFormat = "0.##", string displayFormat = "{0}", string hintDescription = null)
: 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="settingBase">A <see cref="SSSliderSetting"/> instance.</param>
internal SliderSetting(SSSliderSetting settingBase)
: base(settingBase)
{
Base = settingBase;
}

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

/// <summary>
/// Gets or sets the maximum value of the slider.
/// </summary>
public float MaximumValue
{
get => Base.MaxValue;
set => Base.MaxValue = value;
}

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

/// <summary>
/// Gets or sets a value indicating whether the slider displays integers.
/// </summary>
public bool IsInteger
{
get => Base.Integer;
set => Base.Integer = value;
}

/// <summary>
/// Gets a value indicating whether the slider is currently being dragged.
/// </summary>
public bool IsBeingDragged => Base.SyncDragging;

/// <summary>
/// Gets a float that represents the current value of the slider.
/// </summary>
public float SliderValue => Base.Integer ? Base.SyncIntValue : Base.SyncFloatValue;

/// <summary>
/// Gets or sets the formatting used for the number in the slider.
/// </summary>
public string StringFormat
{
get => Base.ValueToStringFormat;
set => Base.ValueToStringFormat = value;
}

/// <summary>
/// Gets or sets the formatting used for the final display of the value of the slider.
/// </summary>
public string DisplayFormat
{
get => Base.FinalDisplayFormat;
set => Base.FinalDisplayFormat = value;
}

/// <inheritdoc/>
public new SSSliderSetting Base { get; }

/// <summary>
/// Returns a representation of this <see cref="SliderSetting"/>.
/// </summary>
/// <returns>A string in human-readable format.</returns>
public override string ToString()
{
return base.ToString() + $" /{MinimumValue}/ *{MaximumValue}* +{DefaultValue}+ '{SliderValue}'";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// -----------------------------------------------------------------------
// <copyright file="UserTextInputSetting.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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

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

/// <summary>
/// Represents a user text input setting.
/// </summary>
public class UserTextInputSetting : SettingBase, IWrapper<SSPlaintextSetting>
{
/// <summary>
/// Initializes a new instance of the <see cref="UserTextInputSetting"/> class.
/// </summary>
/// <param name="id"><inheritdoc cref="SettingBase.Id"/></param>
/// <param name="label"><inheritdoc cref="SettingBase.Label"/></param>
/// <param name="placeHolder"><inheritdoc cref="PlaceHolder"/></param>
/// <param name="characterLimit"><inheritdoc cref="CharacterLimit"/></param>
/// <param name="contentType"><inheritdoc cref="ContentType"/></param>
/// /// <param name="hintDescription"><inheritdoc cref="SettingBase.HintDescription"/></param>
public UserTextInputSetting(int id, string label, string placeHolder = "", int characterLimit = 64, TMP_InputField.ContentType contentType = TMP_InputField.ContentType.Standard, string hintDescription = null)
: this(new SSPlaintextSetting(id, label, placeHolder, characterLimit, contentType, hintDescription))
{
Base = (SSPlaintextSetting)base.Base;
}

/// <summary>
/// Initializes a new instance of the <see cref="UserTextInputSetting"/> class.
/// </summary>
/// <param name="settingBase">A <see cref="SSPlaintextSetting"/> instance.</param>
internal UserTextInputSetting(SSPlaintextSetting settingBase)
: base(settingBase)
{
Base = settingBase;
}

/// <inheritdoc/>
public new SSPlaintextSetting Base { get; }

/// <summary>
/// Gets the value of the text entered by a client.
/// </summary>
public string Text => Base.SyncInputText;

/// <summary>
/// Gets or sets a value indicating the placeholder shown within the PlainTextSetting.
/// </summary>
public string PlaceHolder
{
get => Base.Placeholder;
set => Base.Placeholder = value;
}

/// <summary>
/// Gets or sets a value indicating the type of content within the PlainTextSetting.
/// </summary>
public TMP_InputField.ContentType ContentType
{
get => Base.ContentType;
set => Base.ContentType = value;
}

/// <summary>
/// Gets or sets a value indicating the max number of characters in the PlainTextSetting.
/// </summary>
public int CharacterLimit
{
get => Base.CharacterLimit;
set => Base.CharacterLimit = value;
}

/// <summary>
/// Returns a representation of this <see cref="UserTextInputSetting"/>.
/// </summary>
/// <returns>A string in human-readable format.</returns>
public override string ToString()
{
return base.ToString() + $" /{Text}/ *{ContentType}* +{CharacterLimit}+";
}
}
}