1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 15:12:57 +08:00

Merge pull request #320 from default0/audio-device-selection

Audio device selection
This commit is contained in:
Dean Herbert 2017-02-09 16:45:29 +09:00 committed by GitHub
commit d73093867d
11 changed files with 93 additions and 24 deletions

@ -1 +1 @@
Subproject commit 9da998211a81db471c7b9c649702f877b1246aff
Subproject commit 21fd81a84860cf6854026458ac82905b6248f41d

View File

@ -17,16 +17,8 @@ namespace osu.Game.Graphics.UserInterface
{
protected override DropDownHeader CreateHeader() => new OsuDropDownHeader();
protected override IEnumerable<DropDownMenuItem<U>> GetDropDownItems(IEnumerable<U> values)
{
return values.Select(v =>
{
var field = typeof(U).GetField(Enum.GetName(typeof(U), v));
return new OsuDropDownMenuItem<U>(
field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name, v);
});
}
protected override IEnumerable<DropDownMenuItem<U>> GetDropDownItems(IEnumerable<KeyValuePair<string, U>> values)
=> values.Select(v => new OsuDropDownMenuItem<U>(v.Key, v.Value));
public OsuDropDownMenu()
{

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using System.Collections.Generic;
namespace osu.Game.Overlays.Options
{
@ -59,10 +60,25 @@ namespace osu.Game.Overlays.Options
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()
{
if (!typeof(T).IsEnum)
throw new InvalidOperationException("OptionsDropdown only supports enums as the generic type argument");
Items = new KeyValuePair<string, T>[0];
Direction = FlowDirection.VerticalOnly;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -75,7 +91,7 @@ namespace osu.Game.Overlays.Options
{
Margin = new MarginPadding { Top = 5 },
RelativeSizeAxes = Axes.X,
Items = (T[])Enum.GetValues(typeof(T)),
Items = this.Items,
}
};
dropdown.ValueChanged += Dropdown_ValueChanged;

View 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;
}
}
}

View File

@ -1,17 +1,40 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Overlays.Options.Sections.Audio
{
public class AudioDevicesOptions : OptionsSubsection
{
protected override string Header => "Devices";
public AudioDevicesOptions()
private AudioManager audio;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
Children = new[]
this.audio = audio;
}
protected override void LoadComplete()
{
new OptionLabel { Text = "Output device: TODO dropdown" }
base.LoadComplete();
var deviceItems = new List<KeyValuePair<string, string>>();
deviceItems.Add(new KeyValuePair<string, string>("Default", string.Empty));
deviceItems.AddRange(audio.GetDeviceNames().Select(d => new KeyValuePair<string, string>(d, d)));
Children = new Drawable[]
{
new OptionDropDown<string>()
{
Items = deviceItems,
Bindable = audio.AudioDevice
},
};
}
}

View File

@ -23,12 +23,12 @@ namespace osu.Game.Overlays.Options.Sections.Gameplay
LabelText = "Background dim",
Bindable = (BindableInt)config.GetBindable<int>(OsuConfig.DimLevel)
},
new OptionDropDown<ProgressBarType>
new OptionEnumDropDown<ProgressBarType>
{
LabelText = "Progress display",
Bindable = config.GetBindable<ProgressBarType>(OsuConfig.ProgressBarType)
},
new OptionDropDown<ScoreMeterType>
new OptionEnumDropDown<ScoreMeterType>
{
LabelText = "Score meter type",
Bindable = config.GetBindable<ScoreMeterType>(OsuConfig.ScoreMeter)

View File

@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Options.Sections.General
{
Children = new Drawable[]
{
new OptionDropDown<ReleaseStream>
new OptionEnumDropDown<ReleaseStream>
{
LabelText = "Release stream",
Bindable = config.GetBindable<ReleaseStream>(OsuConfig.ReleaseStream),

View File

@ -57,7 +57,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
LabelText = "Softening filter",
Bindable = config.GetBindable<bool>(OsuConfig.BloomSoftening)
},
new OptionDropDown<ScreenshotFormat>
new OptionEnumDropDown<ScreenshotFormat>
{
LabelText = "Screenshot",
Bindable = config.GetBindable<ScreenshotFormat>(OsuConfig.ScreenshotFormat)

View File

@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Options.Sections.Graphics
Children = new Drawable[]
{
// TODO: this needs to be a custom dropdown at some point
new OptionDropDown<FrameSync>
new OptionEnumDropDown<FrameSync>
{
LabelText = "Frame limiter",
Bindable = config.GetBindable<FrameSync>(FrameworkConfig.FrameSync)

View File

@ -33,7 +33,7 @@ namespace osu.Game.Overlays.Options.Sections.Input
LabelText = "Map absolute raw input to the osu! window",
Bindable = config.GetBindable<bool>(OsuConfig.AbsoluteToOsuWindow)
},
new OptionDropDown<ConfineMouseMode>
new OptionEnumDropDown<ConfineMouseMode>
{
LabelText = "Confine mouse cursor",
Bindable = config.GetBindable<ConfineMouseMode>(OsuConfig.ConfineMouse),

View File

@ -100,6 +100,7 @@
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
<Compile Include="Configuration\OsuConfigManager.cs" />
<Compile Include="Overlays\Options\OptionDropDown.cs" />
<Compile Include="Overlays\Options\OptionLabel.cs" />
<Compile Include="Graphics\UserInterface\OsuDropDownHeader.cs" />
<Compile Include="Graphics\UserInterface\OsuDropDownMenu.cs" />
@ -241,7 +242,7 @@
<Compile Include="Overlays\Options\OptionTextBox.cs" />
<Compile Include="Overlays\Options\OptionSlider.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\ScoreMeterType.cs" />
<Compile Include="Configuration\ReleaseStream.cs" />