Skip to content

Commit

Permalink
Merge pull request #345 from Tom94/audio-options
Browse files Browse the repository at this point in the history
Audio options
  • Loading branch information
peppy authored Feb 11, 2017
2 parents 2da8e8f + 85d3337 commit b0b4c09
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
1 change: 0 additions & 1 deletion osu.Game/Overlays/MusicController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ protected override void Update()

if (current?.TrackLoaded ?? false)
{

progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length));
playButton.Icon = current.Track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;

Expand Down
7 changes: 7 additions & 0 deletions osu.Game/Overlays/Options/OptionDropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public IEnumerable<KeyValuePair<string, T>> Items
{
items = value;
if(dropdown != null)
{
dropdown.Items = value;

// We need to refresh the dropdown because our items changed,
// thus its selected value may be outdated.
if (bindable != null)
dropdown.SelectedValue = bindable.Value;
}
}
}

Expand Down
35 changes: 30 additions & 5 deletions osu.Game/Overlays/Options/Sections/Audio/AudioDevicesOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,53 @@ public class AudioDevicesOptions : OptionsSubsection
protected override string Header => "Devices";

private AudioManager audio;
private OptionDropDown<string> dropdown;

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
this.audio = audio;
}

protected override void LoadComplete()
protected override void Dispose(bool isDisposing)
{
base.LoadComplete();
base.Dispose(isDisposing);

audio.OnNewDevice -= onDeviceChanged;
audio.OnLostDevice -= onDeviceChanged;
}

private void updateItems()
{
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)));
deviceItems.AddRange(audio.AudioDeviceNames.Select(d => new KeyValuePair<string, string>(d, d)));

var preferredDeviceName = audio.AudioDevice.Value;
if (!deviceItems.Any(kv => kv.Value == preferredDeviceName))
deviceItems.Add(new KeyValuePair<string, string>(preferredDeviceName, preferredDeviceName));

dropdown.Items = deviceItems;
}

private void onDeviceChanged(string name) => updateItems();

protected override void LoadComplete()
{
base.LoadComplete();

Children = new Drawable[]
{
new OptionDropDown<string>()
dropdown = new OptionDropDown<string>()
{
Items = deviceItems,
Bindable = audio.AudioDevice
},
};

updateItems();

audio.OnNewDevice += onDeviceChanged;
audio.OnLostDevice += onDeviceChanged;
}
}
}

0 comments on commit b0b4c09

Please sign in to comment.