mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:20:04 +08:00
Add OptionsDropdown<T> and wire up one example
This commit is contained in:
parent
ff7ec88e66
commit
9daf524120
@ -110,7 +110,7 @@ namespace osu.Game.Configuration
|
||||
Set(OsuConfig.NotifyFriends, true);
|
||||
Set(OsuConfig.NotifySubmittedThread, true);
|
||||
Set(OsuConfig.PopupDuringGameplay, true);
|
||||
//Set(OsuConfig.ProgressBarType, ProgressBarTypes.Pie);
|
||||
Set(OsuConfig.ProgressBarType, ProgressBarType.Pie);
|
||||
//Set(OsuConfig.RankType, RankingType.Top);
|
||||
Set(OsuConfig.RefreshRate, 60);
|
||||
Set(OsuConfig.OverrideRefreshRate, Get<int>(OsuConfig.RefreshRate) != 60);
|
||||
|
12
osu.Game/Configuration/ProgressBarType.cs
Normal file
12
osu.Game/Configuration/ProgressBarType.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
namespace osu.Game.Configuration
|
||||
{
|
||||
public enum ProgressBarType
|
||||
{
|
||||
Off,
|
||||
Pie,
|
||||
TopRight,
|
||||
BottomRight,
|
||||
Bottom
|
||||
}
|
||||
}
|
@ -25,7 +25,11 @@ namespace osu.Game.Overlays.Options.Gameplay
|
||||
LabelText = "Background dim",
|
||||
Bindable = (BindableInt)config.GetBindable<int>(OsuConfig.DimLevel)
|
||||
},
|
||||
new SpriteText { Text = "Progress display: TODO dropdown" },
|
||||
new OptionsDropdown<ProgressBarType>
|
||||
{
|
||||
Label = "Progress display",
|
||||
Bindable = config.GetBindable<ProgressBarType>(OsuConfig.ProgressBarType)
|
||||
},
|
||||
new SpriteText { Text = "Score meter type: TODO dropdown" },
|
||||
new SliderOption<double>
|
||||
{
|
||||
|
70
osu.Game/Overlays/Options/OptionsDropdown.cs
Normal file
70
osu.Game/Overlays/Options/OptionsDropdown.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenTK.Graphics;
|
||||
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;
|
||||
|
||||
namespace osu.Game.Overlays.Options
|
||||
{
|
||||
public class OptionsDropdown<T> : FlowContainer
|
||||
{
|
||||
private DropDownMenu<T> dropdown;
|
||||
private SpriteText text;
|
||||
|
||||
public string Label
|
||||
{
|
||||
get { return text.Text; }
|
||||
set
|
||||
{
|
||||
text.Text = value;
|
||||
text.Alpha = string.IsNullOrEmpty(value) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
public Bindable<T> Bindable
|
||||
{
|
||||
get { return bindable; }
|
||||
set
|
||||
{
|
||||
if (bindable != null)
|
||||
bindable.ValueChanged -= Bindable_ValueChanged;
|
||||
bindable = value;
|
||||
bindable.ValueChanged += Bindable_ValueChanged;
|
||||
Bindable_ValueChanged(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Bindable<T> bindable;
|
||||
|
||||
void Bindable_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
dropdown.SelectedValue = bindable.Value;
|
||||
}
|
||||
|
||||
public OptionsDropdown()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument");
|
||||
Direction = FlowDirection.VerticalOnly;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
var items = Enum.GetNames(typeof(T)).Zip(
|
||||
(T[])Enum.GetValues(typeof(T)), (a, b) => new Tuple<string, T>(a, b));
|
||||
Children = new Drawable[]
|
||||
{
|
||||
text = new SpriteText { Alpha = 0 },
|
||||
dropdown = new DropDownMenu<T>
|
||||
{
|
||||
Margin = new MarginPadding { Top = 5 },
|
||||
Height = 10,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Items = items.Select(item => new DropDownMenuItem<T>(item.Item1, item.Item2))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -223,6 +223,8 @@
|
||||
<Compile Include="Overlays\Options\SidebarButton.cs" />
|
||||
<Compile Include="Overlays\Options\TextBoxOption.cs" />
|
||||
<Compile Include="Overlays\Options\SliderOption.cs" />
|
||||
<Compile Include="Configuration\ProgressBarType.cs" />
|
||||
<Compile Include="Overlays\Options\OptionsDropdown.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||
@ -251,4 +253,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user