mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 07:06:35 +09:00
Merge https://github.com/ppy/osu into playlist
This commit is contained in:
@ -13,6 +13,7 @@ using osu.Framework.Graphics.OpenGL.Buffers;
|
||||
using OpenTK.Graphics.ES30;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Colour;
|
||||
using osu.Framework.Timing;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
@ -58,6 +59,9 @@ namespace osu.Game.Graphics.Cursor
|
||||
|
||||
public CursorTrail()
|
||||
{
|
||||
// as we are currently very dependent on having a running clock, let's make our own clock for the time being.
|
||||
Clock = new FramedClock();
|
||||
|
||||
AlwaysReceiveInput = true;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -231,4 +235,4 @@ namespace osu.Game.Graphics.Cursor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -80,14 +80,12 @@ namespace osu.Game.Graphics.Cursor
|
||||
protected override void PopIn()
|
||||
{
|
||||
ActiveCursor.FadeTo(1, 250, EasingTypes.OutQuint);
|
||||
ActiveCursor.ScaleTo(1, 1000, EasingTypes.OutElastic);
|
||||
ActiveCursor.ScaleTo(1, 400, EasingTypes.OutQuint);
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
ActiveCursor.FadeTo(0, 1400, EasingTypes.OutQuint);
|
||||
ActiveCursor.ScaleTo(1.1f, 100, EasingTypes.Out);
|
||||
ActiveCursor.Delay(100);
|
||||
ActiveCursor.FadeTo(0, 900, EasingTypes.OutQuint);
|
||||
ActiveCursor.ScaleTo(0, 500, EasingTypes.In);
|
||||
}
|
||||
|
||||
@ -100,7 +98,7 @@ namespace osu.Game.Graphics.Cursor
|
||||
|
||||
public Cursor()
|
||||
{
|
||||
Size = new Vector2(42);
|
||||
AutoSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
158
osu.Game/Graphics/Cursor/TooltipContainer.cs
Normal file
158
osu.Game/Graphics/Cursor/TooltipContainer.cs
Normal file
@ -0,0 +1,158 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public class TooltipContainer : Container
|
||||
{
|
||||
private readonly CursorContainer cursor;
|
||||
private readonly Tooltip tooltip;
|
||||
|
||||
private ScheduledDelegate findTooltipTask;
|
||||
private UserInputManager inputManager;
|
||||
|
||||
private const int default_appear_delay = 220;
|
||||
|
||||
private IHasTooltip currentlyDisplayed;
|
||||
|
||||
public TooltipContainer(CursorContainer cursor)
|
||||
{
|
||||
this.cursor = cursor;
|
||||
AlwaysPresent = true;
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Add(tooltip = new Tooltip { Alpha = 0 });
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(UserInputManager input)
|
||||
{
|
||||
inputManager = input;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (tooltip.IsPresent)
|
||||
{
|
||||
if (currentlyDisplayed != null)
|
||||
tooltip.TooltipText = currentlyDisplayed.TooltipText;
|
||||
|
||||
//update the position of the displayed tooltip.
|
||||
tooltip.Position = ToLocalSpace(cursor.ActiveCursor.ScreenSpaceDrawQuad.Centre) + new Vector2(10);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||
{
|
||||
updateTooltipState(state);
|
||||
return base.OnMouseUp(state, args);
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(InputState state)
|
||||
{
|
||||
updateTooltipState(state);
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
private void updateTooltipState(InputState state)
|
||||
{
|
||||
if (currentlyDisplayed?.Hovering != true)
|
||||
{
|
||||
if (currentlyDisplayed != null && !state.Mouse.HasMainButtonPressed)
|
||||
{
|
||||
tooltip.Delay(150);
|
||||
tooltip.FadeOut(500, EasingTypes.OutQuint);
|
||||
currentlyDisplayed = null;
|
||||
}
|
||||
|
||||
findTooltipTask?.Cancel();
|
||||
findTooltipTask = Scheduler.AddDelayed(delegate
|
||||
{
|
||||
var tooltipTarget = inputManager.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||
|
||||
if (tooltipTarget == null) return;
|
||||
|
||||
tooltip.TooltipText = tooltipTarget.TooltipText;
|
||||
tooltip.FadeIn(500, EasingTypes.OutQuint);
|
||||
|
||||
currentlyDisplayed = tooltipTarget;
|
||||
}, (1 - tooltip.Alpha) * default_appear_delay);
|
||||
}
|
||||
}
|
||||
|
||||
public class Tooltip : Container
|
||||
{
|
||||
private readonly Box background;
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public string TooltipText
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == text.Text) return;
|
||||
|
||||
text.Text = value;
|
||||
if (Alpha > 0)
|
||||
{
|
||||
AutoSizeDuration = 250;
|
||||
background.FlashColour(OsuColour.Gray(0.4f), 1000, EasingTypes.OutQuint);
|
||||
}
|
||||
else
|
||||
AutoSizeDuration = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandleInput => false;
|
||||
|
||||
private const float text_size = 16;
|
||||
|
||||
public Tooltip()
|
||||
{
|
||||
AutoSizeEasing = EasingTypes.OutQuint;
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
CornerRadius = 5;
|
||||
Masking = true;
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(40),
|
||||
Radius = 5,
|
||||
};
|
||||
Children = new Drawable[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Alpha = 0.9f,
|
||||
},
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
TextSize = text_size,
|
||||
Padding = new MarginPadding(5),
|
||||
Font = @"Exo2.0-Regular",
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
{
|
||||
background.Colour = colour.Gray3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ namespace osu.Game.Graphics
|
||||
/// <param name="easing">The tween easing.</param>
|
||||
public static void FadeAccent(this IHasAccentColour accentedDrawable, Color4 newColour, double duration = 0, EasingTypes easing = EasingTypes.None)
|
||||
{
|
||||
accentedDrawable.TransformTo(accentedDrawable.AccentColour, newColour, duration, easing, new TransformAccent());
|
||||
accentedDrawable.TransformTo(() => accentedDrawable.AccentColour, newColour, duration, easing, new TransformAccent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
osu.Game/Graphics/IHasTooltip.cs
Normal file
15
osu.Game/Graphics/IHasTooltip.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics
|
||||
{
|
||||
public interface IHasTooltip : IDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// Tooltip that shows when hovering the drawable
|
||||
/// </summary>
|
||||
string TooltipText { get; }
|
||||
}
|
||||
}
|
@ -80,6 +80,10 @@ namespace osu.Game.Graphics
|
||||
public Color4 GrayE = FromHex(@"eee");
|
||||
public Color4 GrayF = FromHex(@"fff");
|
||||
|
||||
public Color4 Red = FromHex(@"fc4549");
|
||||
public Color4 RedLighter = FromHex(@"ffeded");
|
||||
public Color4 RedLight = FromHex(@"ed7787");
|
||||
public Color4 Red = FromHex(@"ed1121");
|
||||
public Color4 RedDark = FromHex(@"ba0011");
|
||||
public Color4 RedDarker = FromHex(@"870000");
|
||||
}
|
||||
}
|
||||
|
@ -817,13 +817,13 @@ namespace osu.Game.Graphics
|
||||
fa_youtube_play = 0xf16a,
|
||||
fa_youtube_square = 0xf166,
|
||||
|
||||
// gamemode icons in circles
|
||||
// ruleset icons in circles
|
||||
fa_osu_osu_o = 0xe000,
|
||||
fa_osu_mania_o = 0xe001,
|
||||
fa_osu_fruits_o = 0xe002,
|
||||
fa_osu_taiko_o = 0xe003,
|
||||
|
||||
// gamemode icons without circles
|
||||
// ruleset icons without circles
|
||||
fa_osu_filled_circle = 0xe004,
|
||||
fa_osu_cross_o = 0xe005,
|
||||
fa_osu_logo = 0xe006,
|
||||
|
137
osu.Game/Graphics/UserInterface/Bar.cs
Normal file
137
osu.Game/Graphics/UserInterface/Bar.cs
Normal file
@ -0,0 +1,137 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class Bar : Container, IHasAccentColour
|
||||
{
|
||||
private readonly Box background;
|
||||
private readonly Box bar;
|
||||
|
||||
private const int resize_duration = 250;
|
||||
|
||||
private const EasingTypes easing = EasingTypes.InOutCubic;
|
||||
|
||||
private float length;
|
||||
/// <summary>
|
||||
/// Length of the bar, ranges from 0 to 1
|
||||
/// </summary>
|
||||
public float Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return length;
|
||||
}
|
||||
set
|
||||
{
|
||||
length = MathHelper.Clamp(value, 0, 1);
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public Color4 BackgroundColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return background.Colour;
|
||||
}
|
||||
set
|
||||
{
|
||||
background.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return bar.Colour;
|
||||
}
|
||||
set
|
||||
{
|
||||
bar.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
private BarDirection direction = BarDirection.LeftToRight;
|
||||
public BarDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
set
|
||||
{
|
||||
direction = value;
|
||||
updateBarLength();
|
||||
}
|
||||
}
|
||||
|
||||
public Bar()
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(0,0,0,0)
|
||||
},
|
||||
bar = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private void updateBarLength()
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.RightToLeft:
|
||||
bar.ResizeTo(new Vector2(length, 1), resize_duration, easing);
|
||||
break;
|
||||
|
||||
case BarDirection.TopToBottom:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.ResizeTo(new Vector2(1, length), resize_duration, easing);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case BarDirection.LeftToRight:
|
||||
case BarDirection.TopToBottom:
|
||||
bar.Anchor = Anchor.TopLeft;
|
||||
bar.Origin = Anchor.TopLeft;
|
||||
break;
|
||||
|
||||
case BarDirection.RightToLeft:
|
||||
case BarDirection.BottomToTop:
|
||||
bar.Anchor = Anchor.BottomRight;
|
||||
bar.Origin = Anchor.BottomRight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BarDirection
|
||||
{
|
||||
LeftToRight = 1 << 0,
|
||||
RightToLeft = 1 << 1,
|
||||
TopToBottom = 1 << 2,
|
||||
BottomToTop = 1 << 3,
|
||||
|
||||
Vertical = TopToBottom | BottomToTop,
|
||||
Horizontal = LeftToRight | RightToLeft,
|
||||
}
|
||||
}
|
65
osu.Game/Graphics/UserInterface/BarGraph.cs
Normal file
65
osu.Game/Graphics/UserInterface/BarGraph.cs
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class BarGraph : FillFlowContainer<Bar>
|
||||
{
|
||||
/// <summary>
|
||||
/// Manually sets the max value, if null <see cref="Enumerable.Max(IEnumerable{float})"/> is instead used
|
||||
/// </summary>
|
||||
public float? MaxValue { get; set; }
|
||||
|
||||
private BarDirection direction = BarDirection.BottomToTop;
|
||||
public new BarDirection Direction
|
||||
{
|
||||
get
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
set
|
||||
{
|
||||
direction = value;
|
||||
base.Direction = (direction & BarDirection.Horizontal) > 0 ? FillDirection.Vertical : FillDirection.Horizontal;
|
||||
foreach (var bar in Children)
|
||||
{
|
||||
bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / Children.Count()) : new Vector2(1.0f / Children.Count(), 1);
|
||||
bar.Direction = direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list of floats that defines the length of each <see cref="Bar"/>
|
||||
/// </summary>
|
||||
public IEnumerable<float> Values
|
||||
{
|
||||
set
|
||||
{
|
||||
List<Bar> bars = Children.ToList();
|
||||
foreach (var bar in value.Select((length, index) => new { Value = length, Bar = bars.Count > index ? bars[index] : null }))
|
||||
if (bar.Bar != null)
|
||||
{
|
||||
bar.Bar.Length = bar.Value / (MaxValue ?? value.Max());
|
||||
bar.Bar.Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1);
|
||||
}
|
||||
else
|
||||
Add(new Bar
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = (direction & BarDirection.Horizontal) > 0 ? new Vector2(1, 1.0f / value.Count()) : new Vector2(1.0f / value.Count(), 1),
|
||||
Length = bar.Value / (MaxValue ?? value.Max()),
|
||||
Direction = Direction,
|
||||
});
|
||||
//I'm using ToList() here because Where() returns an Enumerable which can change it's elements afterwards
|
||||
Remove(Children.Where((bar, index) => index >= value.Count()).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 @@ using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
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 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
private CheckboxState state;
|
||||
|
||||
public CheckboxState State
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
public Bindable<bool> Current { get; } = new Bindable<bool>();
|
||||
}
|
||||
}
|
||||
|
@ -23,19 +23,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if (bindable?.Disabled ?? true)
|
||||
Alpha = 0.3f;
|
||||
Current.BindTo(bindable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,18 +72,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Margin = new MarginPadding { Right = 5 },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void bindableValueChanged(bool isChecked)
|
||||
{
|
||||
State = isChecked ? CheckboxState.Checked : CheckboxState.Unchecked;
|
||||
}
|
||||
nub.Current.BindTo(Current);
|
||||
|
||||
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();
|
||||
};
|
||||
|
||||
Current.DisabledChanged += disabled =>
|
||||
{
|
||||
Alpha = disabled ? 0.3f : 1;
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
@ -117,23 +109,5 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
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);
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
@ -13,15 +13,36 @@ using osu.Framework.Input;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuSliderBar<U> : SliderBar<U> where U : struct
|
||||
public class OsuSliderBar<T> : SliderBar<T>, IHasTooltip where T : struct
|
||||
{
|
||||
private SampleChannel sample;
|
||||
private double lastSampleTime;
|
||||
private T lastSampleValue;
|
||||
|
||||
private readonly Nub nub;
|
||||
private readonly Box leftBox;
|
||||
private readonly Box rightBox;
|
||||
|
||||
public virtual string TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
var bindableDouble = CurrentNumber as BindableNumber<double>;
|
||||
if (bindableDouble != null)
|
||||
{
|
||||
if (bindableDouble.MaxValue == 1 && (bindableDouble.MinValue == 0 || bindableDouble.MinValue == -1))
|
||||
return bindableDouble.Value.ToString(@"P0");
|
||||
return bindableDouble.Value.ToString(@"n1");
|
||||
}
|
||||
|
||||
var bindableInt = CurrentNumber as BindableNumber<int>;
|
||||
if (bindableInt != null)
|
||||
return bindableInt.Value.ToString(@"n0");
|
||||
|
||||
return Current.Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public OsuSliderBar()
|
||||
{
|
||||
Height = 12;
|
||||
@ -50,10 +71,14 @@ namespace osu.Game.Graphics.UserInterface
|
||||
nub = new Nub
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
State = CheckboxState.Unchecked,
|
||||
Expanded = true,
|
||||
}
|
||||
};
|
||||
|
||||
Current.DisabledChanged += disabled =>
|
||||
{
|
||||
Alpha = disabled ? 0.3f : 1;
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -64,15 +89,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
rightBox.Colour = colours.Pink;
|
||||
}
|
||||
|
||||
private void playSample()
|
||||
{
|
||||
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
||||
return;
|
||||
lastSampleTime = Clock.CurrentTime;
|
||||
sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
||||
sample.Play();
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
nub.Glowing = true;
|
||||
@ -85,37 +101,45 @@ namespace osu.Game.Graphics.UserInterface
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
protected override void OnUserChange()
|
||||
{
|
||||
if (args.Key == Key.Left || args.Key == Key.Right)
|
||||
playSample();
|
||||
return base.OnKeyDown(state, args);
|
||||
base.OnUserChange();
|
||||
playSample();
|
||||
}
|
||||
|
||||
private void playSample()
|
||||
{
|
||||
if (Clock == null || Clock.CurrentTime - lastSampleTime <= 50)
|
||||
return;
|
||||
|
||||
if (Current.Value.Equals(lastSampleValue))
|
||||
return;
|
||||
|
||||
lastSampleValue = Current.Value;
|
||||
|
||||
lastSampleTime = Clock.CurrentTime;
|
||||
sample.Frequency.Value = 1 + NormalizedValue * 0.2f;
|
||||
|
||||
if (NormalizedValue == 0)
|
||||
sample.Frequency.Value -= 0.4f;
|
||||
else if (NormalizedValue == 1)
|
||||
sample.Frequency.Value += 0.4f;
|
||||
|
||||
sample.Play();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
playSample();
|
||||
return base.OnClick(state);
|
||||
}
|
||||
|
||||
protected override bool OnDrag(InputState state)
|
||||
{
|
||||
playSample();
|
||||
return base.OnDrag(state);
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildren()
|
||||
{
|
||||
base.UpdateAfterChildren();
|
||||
|
@ -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 @@ namespace osu.Game.Graphics.UserInterface
|
||||
private readonly SpriteText text;
|
||||
private readonly TextAwesome icon;
|
||||
|
||||
public event EventHandler<CheckboxState> Action;
|
||||
|
||||
private Color4? accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
@ -34,7 +31,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
accentColour = value;
|
||||
|
||||
if (State != CheckboxState.Checked)
|
||||
if (Current)
|
||||
{
|
||||
text.Colour = AccentColour;
|
||||
icon.Colour = AccentColour;
|
||||
@ -48,20 +45,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
if (State == CheckboxState.Unchecked)
|
||||
if (!Current)
|
||||
fadeOut();
|
||||
|
||||
base.OnHoverLost(state);
|
||||
@ -134,6 +117,20 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Anchor = Anchor.BottomLeft,
|
||||
}
|
||||
};
|
||||
|
||||
Current.ValueChanged += v =>
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
fadeIn();
|
||||
icon.Icon = FontAwesome.fa_check_circle_o;
|
||||
}
|
||||
else
|
||||
{
|
||||
fadeOut();
|
||||
icon.Icon = FontAwesome.fa_circle_o;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Height = 40;
|
||||
TextContainer.Height = 0.5f;
|
||||
CornerRadius = 5;
|
||||
|
||||
Current.DisabledChanged += disabled =>
|
||||
{
|
||||
Alpha = disabled ? 0.3f : 1;
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -10,10 +10,11 @@ using osu.Game.Graphics.Sprites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public abstract class RollingCounter<T> : Container
|
||||
public abstract class RollingCounter<T> : Container, IHasAccentColour
|
||||
{
|
||||
/// <summary>
|
||||
/// The current value.
|
||||
@ -80,6 +81,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get { return DisplayedCountSpriteText.Colour; }
|
||||
set { DisplayedCountSpriteText.Colour = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Skeleton of a numeric counter which value rolls over time.
|
||||
/// </summary>
|
||||
@ -108,11 +115,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Flush(false, TransformType);
|
||||
|
||||
DisplayedCountSpriteText.Text = FormatCount(Current);
|
||||
DisplayedCountSpriteText.Anchor = Anchor;
|
||||
DisplayedCountSpriteText.Origin = Origin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -205,8 +208,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
? GetProportionalDuration(currentValue, newValue)
|
||||
: RollingDuration;
|
||||
|
||||
transform.StartTime = Time.Current;
|
||||
transform.EndTime = Time.Current + rollingTotalDuration;
|
||||
transform.StartTime = TransformStartTime;
|
||||
transform.EndTime = TransformStartTime + rollingTotalDuration;
|
||||
transform.StartValue = currentValue;
|
||||
transform.EndValue = newValue;
|
||||
transform.Easing = RollingEasing;
|
||||
|
@ -15,6 +15,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
protected override double RollingDuration => 1000;
|
||||
protected override EasingTypes RollingEasing => EasingTypes.Out;
|
||||
|
||||
public bool UseCommaSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// How many leading zeroes the counter has.
|
||||
/// </summary>
|
||||
@ -41,7 +43,12 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected override string FormatCount(double count)
|
||||
{
|
||||
return ((long)count).ToString("D" + LeadingZeroes);
|
||||
string format = new string('0', (int)LeadingZeroes);
|
||||
if (UseCommaSeparator)
|
||||
for (int i = format.Length - 3; i > 0; i -= 3)
|
||||
format = format.Insert(i, @",");
|
||||
|
||||
return ((long)count).ToString(format);
|
||||
}
|
||||
|
||||
public override void Increment(double amount)
|
||||
|
61
osu.Game/Graphics/UserInterface/SimpleComboCounter.cs
Normal file
61
osu.Game/Graphics/UserInterface/SimpleComboCounter.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// 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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Transforms;
|
||||
using osu.Framework.MathUtils;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as an accuracy counter. Represented visually as a percentage.
|
||||
/// </summary>
|
||||
public class SimpleComboCounter : RollingCounter<int>
|
||||
{
|
||||
protected override Type TransformType => typeof(TransformCounterCount);
|
||||
|
||||
protected override double RollingDuration => 750;
|
||||
|
||||
public SimpleComboCounter()
|
||||
{
|
||||
Current.Value = DisplayedCount = 0;
|
||||
}
|
||||
|
||||
protected override string FormatCount(int count)
|
||||
{
|
||||
return $@"{count}x";
|
||||
}
|
||||
|
||||
protected override double GetProportionalDuration(int currentValue, int newValue)
|
||||
{
|
||||
return Math.Abs(currentValue - newValue) * RollingDuration * 100.0f;
|
||||
}
|
||||
|
||||
public override void Increment(int amount)
|
||||
{
|
||||
Current.Value = Current + amount;
|
||||
}
|
||||
|
||||
private class TransformCounterCount : Transform<int>
|
||||
{
|
||||
public override int CurrentValue
|
||||
{
|
||||
get
|
||||
{
|
||||
double time = Time?.Current ?? 0;
|
||||
if (time < StartTime) return StartValue;
|
||||
if (time >= EndTime) return EndValue;
|
||||
|
||||
return (int)Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Apply(Drawable d)
|
||||
{
|
||||
base.Apply(d);
|
||||
((SimpleComboCounter)d).DisplayedCount = CurrentValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -131,14 +131,14 @@ namespace osu.Game.Graphics.UserInterface
|
||||
foreach (var star in stars.Children)
|
||||
{
|
||||
star.ClearTransforms(true);
|
||||
if (count <= newValue)
|
||||
star.Delay(Math.Max(i - count, 0) * animationDelay, true);
|
||||
else
|
||||
star.Delay(Math.Max(count - 1 - i, 0) * animationDelay, true);
|
||||
|
||||
star.FadeTo(i < newValue ? 1.0f : minStarAlpha, fadingDuration);
|
||||
star.Icon.ScaleTo(getStarScale(i, newValue), scalingDuration, scalingEasing);
|
||||
star.DelayReset();
|
||||
var delay = (count <= newValue ? Math.Max(i - count, 0) : Math.Max(count - 1 - i, 0)) * animationDelay;
|
||||
|
||||
using (BeginDelayedSequence(delay, true))
|
||||
{
|
||||
star.FadeTo(i < newValue ? 1.0f : minStarAlpha, fadingDuration);
|
||||
star.Icon.ScaleTo(getStarScale(i, newValue), scalingDuration, scalingEasing);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user