mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Remove overcomplicated stuff
This commit is contained in:
@ -55,13 +55,13 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestButtonVisibility()
|
public void TestButtonVisibility()
|
||||||
{
|
{
|
||||||
AddAssert("button is hidden", () => scroll.Button.State.Value == Visibility.Hidden);
|
AddAssert("button is hidden", () => scroll.Button.Current.Value == Visibility.Hidden);
|
||||||
|
|
||||||
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
|
AddStep("scroll to end", () => scroll.ScrollToEnd(false));
|
||||||
AddAssert("button is visible", () => scroll.Button.State.Value == Visibility.Visible);
|
AddAssert("button is visible", () => scroll.Button.Current.Value == Visibility.Visible);
|
||||||
|
|
||||||
AddStep("scroll to start", () => scroll.ScrollToStart(false));
|
AddStep("scroll to start", () => scroll.ScrollToStart(false));
|
||||||
AddAssert("button is hidden", () => scroll.Button.State.Value == Visibility.Hidden);
|
AddAssert("button is hidden", () => scroll.Button.Current.Value == Visibility.Hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -11,6 +10,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Effects;
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -43,7 +43,7 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
ScrollToStart();
|
ScrollToStart();
|
||||||
currentTarget = Target;
|
currentTarget = Target;
|
||||||
Button.State.Value = Visibility.Hidden;
|
Button.Current.Value = Visibility.Hidden;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
if (ScrollContent.DrawHeight + button_scroll_position < DrawHeight)
|
if (ScrollContent.DrawHeight + button_scroll_position < DrawHeight)
|
||||||
{
|
{
|
||||||
Button.State.Value = Visibility.Hidden;
|
Button.Current.Value = Visibility.Hidden;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,46 +62,21 @@ namespace osu.Game.Overlays
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
currentTarget = Target;
|
currentTarget = Target;
|
||||||
Button.State.Value = Current > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
|
Button.Current.Value = Current > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ScrollToTopButton : VisibilityContainer
|
public class ScrollToTopButton : OsuHoverContainer, IHasCurrentValue<Visibility>
|
||||||
{
|
{
|
||||||
private const int fade_duration = 500;
|
private const int fade_duration = 500;
|
||||||
|
|
||||||
public Action Action
|
private readonly BindableWithCurrent<Visibility> current = new BindableWithCurrent<Visibility>();
|
||||||
|
|
||||||
|
public Bindable<Visibility> Current
|
||||||
{
|
{
|
||||||
get => button.Action;
|
get => current.Current;
|
||||||
set => button.Action = value;
|
set => current.Current = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool PropagatePositionalInputSubTree => true;
|
|
||||||
|
|
||||||
protected override bool StartHidden => true;
|
|
||||||
|
|
||||||
private readonly Button button;
|
|
||||||
|
|
||||||
public ScrollToTopButton()
|
|
||||||
{
|
|
||||||
Size = new Vector2(50);
|
|
||||||
Child = button = new Button
|
|
||||||
{
|
|
||||||
AreaState = { BindTarget = State }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
|
||||||
|
|
||||||
protected override void PopIn() => button.FadeIn(fade_duration, Easing.OutQuint);
|
|
||||||
|
|
||||||
protected override void PopOut() => button.FadeOut(fade_duration, Easing.OutQuint);
|
|
||||||
|
|
||||||
private class Button : OsuHoverContainer
|
|
||||||
{
|
|
||||||
public readonly Bindable<Visibility> AreaState = new Bindable<Visibility>();
|
|
||||||
|
|
||||||
public override bool HandlePositionalInput => AreaState.Value == Visibility.Visible;
|
|
||||||
|
|
||||||
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
|
||||||
|
|
||||||
private Color4 flashColour;
|
private Color4 flashColour;
|
||||||
@ -109,9 +84,10 @@ namespace osu.Game.Overlays
|
|||||||
private readonly Container content;
|
private readonly Container content;
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
|
|
||||||
public Button()
|
public ScrollToTopButton()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
Size = new Vector2(50);
|
||||||
|
Alpha = 0;
|
||||||
Add(content = new CircularContainer
|
Add(content = new CircularContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -152,6 +128,16 @@ namespace osu.Game.Overlays
|
|||||||
flashColour = colourProvider.Light1;
|
flashColour = colourProvider.Light1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
Current.BindValueChanged(visibility =>
|
||||||
|
{
|
||||||
|
Enabled.Value = visibility.NewValue == Visibility.Visible;
|
||||||
|
this.FadeTo(visibility.NewValue == Visibility.Visible ? 1 : 0, fade_duration, Easing.OutQuint);
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
background.FlashColour(flashColour, 800, Easing.OutQuint);
|
background.FlashColour(flashColour, 800, Easing.OutQuint);
|
||||||
@ -171,5 +157,4 @@ namespace osu.Game.Overlays
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user