mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 01:33:21 +08:00
Use Bindable for DropDown.
This commit is contained in:
parent
f0edf5d3d3
commit
b46ded7794
@ -1,7 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -10,7 +10,6 @@ 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
|
||||
{
|
||||
@ -33,12 +32,8 @@ namespace osu.Game.Overlays.Options
|
||||
get { return bindable; }
|
||||
set
|
||||
{
|
||||
if (bindable != null)
|
||||
bindable.ValueChanged -= bindable_ValueChanged;
|
||||
bindable = value;
|
||||
bindable.ValueChanged += bindable_ValueChanged;
|
||||
bindable_ValueChanged(null, null);
|
||||
|
||||
dropdown.SelectedValue.BindTo(bindable);
|
||||
if (bindable.Disabled)
|
||||
Alpha = 0.3f;
|
||||
}
|
||||
@ -46,23 +41,6 @@ namespace osu.Game.Overlays.Options
|
||||
|
||||
private Bindable<T> bindable;
|
||||
|
||||
private void bindable_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
dropdown.SelectedValue = bindable.Value;
|
||||
}
|
||||
|
||||
private void dropdown_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
bindable.Value = dropdown.SelectedValue;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
bindable.ValueChanged -= bindable_ValueChanged;
|
||||
dropdown.ValueChanged -= dropdown_ValueChanged;
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
private IEnumerable<KeyValuePair<string, T>> items;
|
||||
public IEnumerable<KeyValuePair<string, T>> Items
|
||||
{
|
||||
@ -73,15 +51,8 @@ namespace osu.Game.Overlays.Options
|
||||
set
|
||||
{
|
||||
items = value;
|
||||
if(dropdown != null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,7 +75,6 @@ namespace osu.Game.Overlays.Options
|
||||
Items = Items,
|
||||
}
|
||||
};
|
||||
dropdown.ValueChanged += dropdown_ValueChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user