Update UI control access in line with framework changes.

This commit is contained in:
Dean Herbert 2017-04-10 14:31:08 +09:00
parent d2a889d2bb
commit bb4a909de5
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
11 changed files with 58 additions and 127 deletions

@ -1 +1 @@
Subproject commit 7ac3dbff3615fb410da1e330e6379b53a41292b6
Subproject commit bbfd0fc7a8f5293a0f853f51040b40808abbb459

View File

@ -36,7 +36,7 @@ public override void Reset()
filter.PinItem(GroupMode.All);
filter.PinItem(GroupMode.RecentlyPlayed);
filter.SelectedItem.ValueChanged += newFilter =>
filter.Current.ValueChanged += newFilter =>
{
text.Text = "Currently Selected: " + newFilter.ToString();
};

View File

@ -3,8 +3,8 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -12,18 +12,18 @@
namespace osu.Game.Graphics.UserInterface
{
public class Nub : CircularContainer, IStateful<CheckboxState>
public class Nub : CircularContainer, IHasCurrentValue<bool>
{
public const float COLLAPSED_SIZE = 20;
public const float EXPANDED_SIZE = 40;
private readonly Box fill;
private const float border_width = 3;
private Color4 glowingColour, idleColour;
public Nub()
{
Box fill;
Size = new Vector2(COLLAPSED_SIZE, 12);
BorderColour = Color4.White;
@ -40,6 +40,14 @@ public Nub()
AlwaysPresent = true,
},
};
Current.ValueChanged += newValue =>
{
if (newValue)
fill.FadeIn(200, EasingTypes.OutQuint);
else
fill.FadeTo(0.01f, 200, EasingTypes.OutQuint); //todo: remove once we figure why containers aren't drawing at all times
};
}
[BackgroundDependencyLoader]
@ -84,28 +92,12 @@ public bool Expanded
}
}
private CheckboxState state;
private readonly Bindable<bool> current = new Bindable<bool>();
public CheckboxState State
public Bindable<bool> Current
{
get
{
return state;
}
set
{
state = value;
switch (state)
{
case CheckboxState.Checked:
fill.FadeIn(200, EasingTypes.OutQuint);
break;
case CheckboxState.Unchecked:
fill.FadeTo(0.01f, 200, EasingTypes.OutQuint); //todo: remove once we figure why containers aren't drawing at all times
break;
}
}
get { return current; }
set { current.BindTo(value); }
}
}
}

View File

@ -23,16 +23,10 @@ public Bindable<bool> Bindable
{
set
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
bindable = value;
if (bindable != null)
{
bool state = State == CheckboxState.Checked;
if (state != bindable.Value)
State = bindable.Value ? CheckboxState.Checked : CheckboxState.Unchecked;
bindable.ValueChanged += bindableValueChanged;
}
Current = bindable;
if (bindable?.Disabled ?? true)
Alpha = 0.3f;
@ -78,23 +72,20 @@ public OsuCheckbox()
labelSpriteText = new OsuSpriteText(),
nub = new Nub
{
Current = Current,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 5 },
}
};
}
private void bindableValueChanged(bool isChecked)
{
State = isChecked ? CheckboxState.Checked : CheckboxState.Unchecked;
}
protected override void Dispose(bool isDisposing)
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
base.Dispose(isDisposing);
Current.ValueChanged += newValue =>
{
if (newValue)
sampleChecked?.Play();
else
sampleUnchecked?.Play();
};
}
protected override bool OnHover(InputState state)
@ -117,23 +108,5 @@ private void load(AudioManager audio)
sampleChecked = audio.Sample.Get(@"Checkbox/check-on");
sampleUnchecked = audio.Sample.Get(@"Checkbox/check-off");
}
protected override void OnChecked()
{
sampleChecked?.Play();
nub.State = CheckboxState.Checked;
if (bindable != null)
bindable.Value = true;
}
protected override void OnUnchecked()
{
sampleUnchecked?.Play();
nub.State = CheckboxState.Unchecked;
if (bindable != null)
bindable.Value = false;
}
}
}

View File

@ -45,7 +45,7 @@ private void load(OsuColour colours)
private class OsuDropdownMenuItem : DropdownMenuItem<T>
{
public OsuDropdownMenuItem(string text, T value) : base(text, value)
public OsuDropdownMenuItem(string text, T current) : base(text, current)
{
Foreground.Padding = new MarginPadding(2);

View File

@ -50,7 +50,6 @@ public OsuSliderBar()
nub = new Nub
{
Origin = Anchor.TopCentre,
State = CheckboxState.Unchecked,
Expanded = true,
}
};
@ -94,13 +93,13 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
nub.State = CheckboxState.Checked;
nub.Current.Value = true;
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
nub.State = CheckboxState.Unchecked;
nub.Current.Value = false;
return base.OnMouseUp(state, args);
}

View File

@ -1,7 +1,6 @@
// 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 OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
@ -24,8 +23,6 @@ public class OsuTabControlCheckbox : Checkbox
private readonly SpriteText text;
private readonly TextAwesome icon;
public event EventHandler<CheckboxState> Action;
private Color4? accentColour;
public Color4 AccentColour
{
@ -34,7 +31,7 @@ public Color4 AccentColour
{
accentColour = value;
if (State != CheckboxState.Checked)
if (Current)
{
text.Colour = AccentColour;
icon.Colour = AccentColour;
@ -48,20 +45,6 @@ public string Text
set { text.Text = value; }
}
protected override void OnChecked()
{
fadeIn();
icon.Icon = FontAwesome.fa_check_circle_o;
Action?.Invoke(this, State);
}
protected override void OnUnchecked()
{
fadeOut();
icon.Icon = FontAwesome.fa_circle_o;
Action?.Invoke(this, State);
}
private const float transition_length = 500;
private void fadeIn()
@ -84,7 +67,7 @@ protected override bool OnHover(InputState state)
protected override void OnHoverLost(InputState state)
{
if (State == CheckboxState.Unchecked)
if (!Current)
fadeOut();
base.OnHoverLost(state);
@ -134,6 +117,20 @@ public OsuTabControlCheckbox()
Anchor = Anchor.BottomLeft,
}
};
Current.ValueChanged += v =>
{
if (v)
{
fadeIn();
icon.Icon = FontAwesome.fa_check_circle_o;
}
else
{
fadeOut();
icon.Icon = FontAwesome.fa_circle_o;
}
};
}
}
}

View File

@ -33,7 +33,7 @@ public Bindable<T> Bindable
set
{
bindable = value;
dropdown.SelectedValue.BindTo(bindable);
dropdown.Current = bindable;
if (bindable.Disabled)
Alpha = 0.3f;
}

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Configuration;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Overlays.Options
@ -15,38 +14,13 @@ public Bindable<string> Bindable
{
set
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
bindable = value;
if (bindable != null)
{
Text = bindable.Value;
bindable.ValueChanged += bindableValueChanged;
}
Current = bindable;
if (bindable?.Disabled ?? true)
Alpha = 0.3f;
}
}
public OptionTextBox()
{
OnChange += onChange;
}
private void onChange(TextBox sender, bool newText)
{
if (bindable != null)
bindable.Value = Text;
}
private void bindableValueChanged(string newValue) => Text = newValue;
protected override void Dispose(bool isDisposing)
{
if (bindable != null)
bindable.ValueChanged -= bindableValueChanged;
base.Dispose(isDisposing);
}
}
}

View File

@ -8,7 +8,6 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
@ -24,7 +23,7 @@ public class BeatmapDetailAreaTabControl : Container
private void invokeOnFilter()
{
OnFilter?.Invoke(tabs.SelectedItem, modsCheckbox.State == CheckboxState.Checked);
OnFilter?.Invoke(tabs.Current, modsCheckbox.Current);
}
[BackgroundDependencyLoader]
@ -61,10 +60,10 @@ public BeatmapDetailAreaTabControl()
},
};
tabs.SelectedItem.ValueChanged += item => invokeOnFilter();
modsCheckbox.Action += (sender, e) => invokeOnFilter();
tabs.Current.ValueChanged += item => invokeOnFilter();
modsCheckbox.Current.ValueChanged += item => invokeOnFilter();
tabs.SelectedItem.Value = BeatmapDetailTab.Global;
tabs.Current.Value = BeatmapDetailTab.Global;
}
}

View File

@ -93,11 +93,6 @@ public FilterControl()
searchTextBox = new SearchTextBox
{
RelativeSizeAxes = Axes.X,
OnChange = (sender, newText) =>
{
if (newText)
FilterChanged?.Invoke(CreateCriteria());
},
Exit = () => Exit?.Invoke(),
},
new Box
@ -149,10 +144,12 @@ public FilterControl()
}
};
searchTextBox.Current.ValueChanged += t => FilterChanged?.Invoke(CreateCriteria());
groupTabs.PinItem(GroupMode.All);
groupTabs.PinItem(GroupMode.RecentlyPlayed);
groupTabs.SelectedItem.ValueChanged += val => Group = val;
sortTabs.SelectedItem.ValueChanged += val => Sort = val;
groupTabs.Current.ValueChanged += val => Group = val;
sortTabs.Current.ValueChanged += val => Sort = val;
}
public void Deactivate()