mirror of
https://github.com/ppy/osu.git
synced 2025-03-05 15:03:16 +08:00
Simplify counter visibility changes in PaginatedContainerHeader
This commit is contained in:
parent
931e567c7e
commit
e5f70d8eae
@ -16,21 +16,14 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
public class PaginatedContainerHeader : CompositeDrawable, IHasCurrentValue<int>
|
public class PaginatedContainerHeader : CompositeDrawable, IHasCurrentValue<int>
|
||||||
{
|
{
|
||||||
|
private readonly BindableWithCurrent<int> current = new BindableWithCurrent<int>();
|
||||||
|
|
||||||
public Bindable<int> Current
|
public Bindable<int> Current
|
||||||
{
|
{
|
||||||
get => current;
|
get => current.Current;
|
||||||
set
|
set => current.Current = value;
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
|
|
||||||
current.UnbindBindings();
|
|
||||||
current.BindTo(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Bindable<int> current = new Bindable<int>();
|
|
||||||
|
|
||||||
private readonly string text;
|
private readonly string text;
|
||||||
private readonly CounterVisibilityState counterState;
|
private readonly CounterVisibilityState counterState;
|
||||||
|
|
||||||
@ -82,7 +75,6 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
{
|
{
|
||||||
Anchor = Anchor.CentreLeft,
|
Anchor = Anchor.CentreLeft,
|
||||||
Origin = Anchor.CentreLeft,
|
Origin = Anchor.CentreLeft,
|
||||||
Alpha = getInitialCounterAlpha(),
|
|
||||||
Current = { BindTarget = current }
|
Current = { BindTarget = current }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,33 +85,32 @@ namespace osu.Game.Overlays.Profile.Sections
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
current.BindValueChanged(onCurrentChanged);
|
current.BindValueChanged(onCurrentChanged, true);
|
||||||
}
|
|
||||||
|
|
||||||
private float getInitialCounterAlpha()
|
|
||||||
{
|
|
||||||
switch (counterState)
|
|
||||||
{
|
|
||||||
case CounterVisibilityState.AlwaysHidden:
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case CounterVisibilityState.AlwaysVisible:
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
case CounterVisibilityState.VisibleWhenZero:
|
|
||||||
return current.Value == 0 ? 1 : 0;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new NotImplementedException($"{counterState} has an incorrect value.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCurrentChanged(ValueChangedEvent<int> countValue)
|
private void onCurrentChanged(ValueChangedEvent<int> countValue)
|
||||||
{
|
{
|
||||||
if (counterState == CounterVisibilityState.VisibleWhenZero)
|
float alpha;
|
||||||
|
|
||||||
|
switch (counterState)
|
||||||
{
|
{
|
||||||
counterPill.Alpha = countValue.NewValue == 0 ? 1 : 0;
|
case CounterVisibilityState.AlwaysHidden:
|
||||||
|
alpha = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CounterVisibilityState.AlwaysVisible:
|
||||||
|
alpha = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CounterVisibilityState.VisibleWhenZero:
|
||||||
|
alpha = current.Value == 0 ? 1 : 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new NotImplementedException($"{counterState} has an incorrect value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counterPill.Alpha = alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user