1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-29 00:32: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 DropDownHeader CreateHeader() => new OsuDropDownHeader();
protected override IEnumerable<DropDownMenuItem<U>> GetDropDownItems(IEnumerable<U> values) protected override IEnumerable<DropDownMenuItem<U>> GetDropDownItems(IEnumerable<KeyValuePair<string, U>> values)
{ => values.Select(v => new OsuDropDownMenuItem<U>(v.Key, v.Value));
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);
});
}
public OsuDropDownMenu() public OsuDropDownMenu()
{ {

View File

@ -10,6 +10,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
{ {
@ -59,10 +60,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;
@ -75,7 +91,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;

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>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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 namespace osu.Game.Overlays.Options.Sections.Audio
{ {
public class AudioDevicesOptions : OptionsSubsection public class AudioDevicesOptions : OptionsSubsection
{ {
protected override string Header => "Devices"; 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", 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)

View File

@ -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),

View File

@ -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)

View File

@ -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)

View File

@ -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),

View File

@ -100,6 +100,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" />
@ -241,7 +242,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" />