mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Rework OptionDropdowns to be more versatile
The existing OptionDropdown only supported enums and was thus renamed to OptionEnumDropDown. A new OptionDropdown has been created in its place to allow binding to arbitrary values, with a set of user-provided items.
This commit is contained in:
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Sprites;
|
|||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Options
|
namespace osu.Game.Overlays.Options
|
||||||
{
|
{
|
||||||
@ -56,10 +57,25 @@ namespace osu.Game.Overlays.Options
|
|||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<KeyValuePair<string, T>> items;
|
||||||
|
public IEnumerable<KeyValuePair<string, T>> Items
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
items = value;
|
||||||
|
if(dropdown != null)
|
||||||
|
dropdown.Items = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public OptionDropDown()
|
public OptionDropDown()
|
||||||
{
|
{
|
||||||
if (!typeof(T).IsEnum)
|
Items = new KeyValuePair<string, T>[0];
|
||||||
throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument");
|
|
||||||
Direction = FlowDirection.VerticalOnly;
|
Direction = FlowDirection.VerticalOnly;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
@ -72,7 +88,7 @@ namespace osu.Game.Overlays.Options
|
|||||||
{
|
{
|
||||||
Margin = new MarginPadding { Top = 5 },
|
Margin = new MarginPadding { Top = 5 },
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Items = (T[])Enum.GetValues(typeof(T)),
|
Items = this.Items,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dropdown.ValueChanged += Dropdown_ValueChanged;
|
dropdown.ValueChanged += Dropdown_ValueChanged;
|
||||||
|
37
osu.Game/Overlays/Options/OptionEnumDropDown.cs
Normal file
37
osu.Game/Overlays/Options/OptionEnumDropDown.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Options
|
||||||
|
{
|
||||||
|
public class OptionEnumDropDown<T> : OptionDropDown<T>
|
||||||
|
{
|
||||||
|
public OptionEnumDropDown()
|
||||||
|
{
|
||||||
|
if (!typeof(T).IsEnum)
|
||||||
|
throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument");
|
||||||
|
|
||||||
|
List<KeyValuePair<string, T>> items = new List<KeyValuePair<string, T>>();
|
||||||
|
foreach(var val in (T[])Enum.GetValues(typeof(T)))
|
||||||
|
{
|
||||||
|
var field = typeof(T).GetField(Enum.GetName(typeof(T), val));
|
||||||
|
items.Add(
|
||||||
|
new KeyValuePair<string, T>(
|
||||||
|
field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? Enum.GetName(typeof(T), val),
|
||||||
|
val
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Items = items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,12 +23,12 @@ namespace osu.Game.Overlays.Options.Sections.Gameplay
|
|||||||
LabelText = "Background dim",
|
LabelText = "Background dim",
|
||||||
Bindable = (BindableInt)config.GetBindable<int>(OsuConfig.DimLevel)
|
Bindable = (BindableInt)config.GetBindable<int>(OsuConfig.DimLevel)
|
||||||
},
|
},
|
||||||
new OptionDropDown<ProgressBarType>
|
new OptionEnumDropDown<ProgressBarType>
|
||||||
{
|
{
|
||||||
LabelText = "Progress display",
|
LabelText = "Progress display",
|
||||||
Bindable = config.GetBindable<ProgressBarType>(OsuConfig.ProgressBarType)
|
Bindable = config.GetBindable<ProgressBarType>(OsuConfig.ProgressBarType)
|
||||||
},
|
},
|
||||||
new OptionDropDown<ScoreMeterType>
|
new OptionEnumDropDown<ScoreMeterType>
|
||||||
{
|
{
|
||||||
LabelText = "Score meter type",
|
LabelText = "Score meter type",
|
||||||
Bindable = config.GetBindable<ScoreMeterType>(OsuConfig.ScoreMeter)
|
Bindable = config.GetBindable<ScoreMeterType>(OsuConfig.ScoreMeter)
|
||||||
|
@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Options.Sections.General
|
|||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OptionDropDown<ReleaseStream>
|
new OptionEnumDropDown<ReleaseStream>
|
||||||
{
|
{
|
||||||
LabelText = "Release stream",
|
LabelText = "Release stream",
|
||||||
Bindable = config.GetBindable<ReleaseStream>(OsuConfig.ReleaseStream),
|
Bindable = config.GetBindable<ReleaseStream>(OsuConfig.ReleaseStream),
|
||||||
|
@ -57,7 +57,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
|||||||
LabelText = "Softening filter",
|
LabelText = "Softening filter",
|
||||||
Bindable = config.GetBindable<bool>(OsuConfig.BloomSoftening)
|
Bindable = config.GetBindable<bool>(OsuConfig.BloomSoftening)
|
||||||
},
|
},
|
||||||
new OptionDropDown<ScreenshotFormat>
|
new OptionEnumDropDown<ScreenshotFormat>
|
||||||
{
|
{
|
||||||
LabelText = "Screenshot",
|
LabelText = "Screenshot",
|
||||||
Bindable = config.GetBindable<ScreenshotFormat>(OsuConfig.ScreenshotFormat)
|
Bindable = config.GetBindable<ScreenshotFormat>(OsuConfig.ScreenshotFormat)
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
// TODO: this needs to be a custom dropdown at some point
|
// TODO: this needs to be a custom dropdown at some point
|
||||||
new OptionDropDown<FrameSync>
|
new OptionEnumDropDown<FrameSync>
|
||||||
{
|
{
|
||||||
LabelText = "Frame limiter",
|
LabelText = "Frame limiter",
|
||||||
Bindable = config.GetBindable<FrameSync>(FrameworkConfig.FrameSync)
|
Bindable = config.GetBindable<FrameSync>(FrameworkConfig.FrameSync)
|
||||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Options.Sections.Input
|
|||||||
LabelText = "Map absolute raw input to the osu! window",
|
LabelText = "Map absolute raw input to the osu! window",
|
||||||
Bindable = config.GetBindable<bool>(OsuConfig.AbsoluteToOsuWindow)
|
Bindable = config.GetBindable<bool>(OsuConfig.AbsoluteToOsuWindow)
|
||||||
},
|
},
|
||||||
new OptionDropDown<ConfineMouseMode>
|
new OptionEnumDropDown<ConfineMouseMode>
|
||||||
{
|
{
|
||||||
LabelText = "Confine mouse cursor",
|
LabelText = "Confine mouse cursor",
|
||||||
Bindable = config.GetBindable<ConfineMouseMode>(OsuConfig.ConfineMouse),
|
Bindable = config.GetBindable<ConfineMouseMode>(OsuConfig.ConfineMouse),
|
||||||
|
@ -99,6 +99,7 @@
|
|||||||
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
|
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
|
||||||
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
|
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
|
||||||
<Compile Include="Configuration\OsuConfigManager.cs" />
|
<Compile Include="Configuration\OsuConfigManager.cs" />
|
||||||
|
<Compile Include="Overlays\Options\OptionDropDown.cs" />
|
||||||
<Compile Include="Overlays\Options\OptionLabel.cs" />
|
<Compile Include="Overlays\Options\OptionLabel.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuDropDownHeader.cs" />
|
<Compile Include="Graphics\UserInterface\OsuDropDownHeader.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuDropDownMenu.cs" />
|
<Compile Include="Graphics\UserInterface\OsuDropDownMenu.cs" />
|
||||||
@ -239,7 +240,7 @@
|
|||||||
<Compile Include="Overlays\Options\OptionTextBox.cs" />
|
<Compile Include="Overlays\Options\OptionTextBox.cs" />
|
||||||
<Compile Include="Overlays\Options\OptionSlider.cs" />
|
<Compile Include="Overlays\Options\OptionSlider.cs" />
|
||||||
<Compile Include="Configuration\ProgressBarType.cs" />
|
<Compile Include="Configuration\ProgressBarType.cs" />
|
||||||
<Compile Include="Overlays\Options\OptionDropDown.cs" />
|
<Compile Include="Overlays\Options\OptionEnumDropDown.cs" />
|
||||||
<Compile Include="Configuration\RankingType.cs" />
|
<Compile Include="Configuration\RankingType.cs" />
|
||||||
<Compile Include="Configuration\ScoreMeterType.cs" />
|
<Compile Include="Configuration\ScoreMeterType.cs" />
|
||||||
<Compile Include="Configuration\ReleaseStream.cs" />
|
<Compile Include="Configuration\ReleaseStream.cs" />
|
||||||
|
Reference in New Issue
Block a user