1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-23 05:08:34 +01:00
MLEM/MLEM.Ui/Elements/Slider.cs

43 lines
1.8 KiB
C#
Raw Normal View History

2019-08-16 19:08:36 +02:00
using Microsoft.Xna.Framework;
2019-09-09 17:12:36 +02:00
using MLEM.Misc;
2019-08-16 19:08:36 +02:00
namespace MLEM.Ui.Elements {
2020-05-22 17:02:24 +02:00
/// <summary>
/// A slider element for use inside of a <see cref="UiSystem"/>.
/// A slider is a horizontal <see cref="ScrollBar"/> whose value can additionally be controlled using the <see cref="UiControls.LeftButtons"/> and <see cref="UiControls.RightButtons"/>.
/// </summary>
2019-08-16 19:08:36 +02:00
public class Slider : ScrollBar {
2020-05-22 17:02:24 +02:00
/// <summary>
/// Creates a new slider with the given settings
/// </summary>
/// <param name="anchor">The slider's anchor</param>
/// <param name="size">The slider's size</param>
/// <param name="scrollerSize">The size of the slider's scroller indicator</param>
/// <param name="maxValue">The slider's maximum value</param>
2019-08-16 19:08:36 +02:00
public Slider(Anchor anchor, Vector2 size, int scrollerSize, float maxValue) :
base(anchor, size, scrollerSize, maxValue, true) {
2019-09-09 17:12:36 +02:00
this.CanBeSelected = true;
this.GetGamepadNextElement = (dir, next) => {
if (dir == Direction2.Left || dir == Direction2.Right)
return null;
return next;
};
2019-09-09 17:12:36 +02:00
}
2020-05-22 17:02:24 +02:00
/// <inheritdoc />
2019-09-09 17:12:36 +02:00
public override void Update(GameTime time) {
base.Update(time);
if (this.IsSelected) {
2022-04-30 12:26:40 +02:00
if (this.CurrentValue > 0 && this.Controls.LeftButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) {
2019-09-09 17:12:36 +02:00
this.CurrentValue -= this.StepPerScroll;
2022-04-30 12:26:40 +02:00
} else if (this.CurrentValue < this.MaxValue && this.Controls.RightButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) {
2019-09-09 17:12:36 +02:00
this.CurrentValue += this.StepPerScroll;
}
}
}
2019-08-16 19:08:36 +02:00
}
2022-06-17 18:23:47 +02:00
}