mirror of
https://github.com/ppy/osu
synced 2025-01-05 05:39:49 +00:00
Allow Nub/OsuCheckbox/OsuSliderBar colours to be overridden.
This commit is contained in:
parent
08219ccb42
commit
c8066cfde9
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -12,13 +13,12 @@ using osu.Framework.Graphics.UserInterface;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class Nub : CircularContainer, IHasCurrentValue<bool>
|
public class Nub : CircularContainer, IHasCurrentValue<bool>, IHasAccentColour
|
||||||
{
|
{
|
||||||
public const float COLLAPSED_SIZE = 20;
|
public const float COLLAPSED_SIZE = 20;
|
||||||
public const float EXPANDED_SIZE = 40;
|
public const float EXPANDED_SIZE = 40;
|
||||||
|
|
||||||
private const float border_width = 3;
|
private const float border_width = 3;
|
||||||
private Color4 glowingColour, idleColour;
|
|
||||||
|
|
||||||
public Nub()
|
public Nub()
|
||||||
{
|
{
|
||||||
@ -53,33 +53,41 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
Colour = idleColour = colours.Pink;
|
AccentColour = colours.Pink;
|
||||||
glowingColour = colours.PinkLighter;
|
GlowingAccentColour = colours.PinkLighter;
|
||||||
|
GlowColour = colours.PinkDarker;
|
||||||
|
|
||||||
EdgeEffect = new EdgeEffect
|
EdgeEffect = new EdgeEffect
|
||||||
{
|
{
|
||||||
Colour = colours.PinkDarker,
|
Colour = GlowColour,
|
||||||
Type = EdgeEffectType.Glow,
|
Type = EdgeEffectType.Glow,
|
||||||
Radius = 10,
|
Radius = 10,
|
||||||
Roundness = 8,
|
Roundness = 8,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
FadeEdgeEffectTo(0);
|
FadeEdgeEffectTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool glowing;
|
||||||
public bool Glowing
|
public bool Glowing
|
||||||
{
|
{
|
||||||
|
get { return glowing; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
glowing = value;
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
FadeColour(glowingColour, 500, EasingTypes.OutQuint);
|
FadeColour(GlowingAccentColour, 500, EasingTypes.OutQuint);
|
||||||
FadeEdgeEffectTo(1, 500, EasingTypes.OutQuint);
|
FadeEdgeEffectTo(1, 500, EasingTypes.OutQuint);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FadeEdgeEffectTo(0, 500);
|
FadeEdgeEffectTo(0, 500);
|
||||||
FadeColour(idleColour, 500);
|
FadeColour(AccentColour, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,5 +101,43 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Bindable<bool> Current { get; } = new Bindable<bool>();
|
public Bindable<bool> Current { get; } = new Bindable<bool>();
|
||||||
|
|
||||||
|
private Color4 accentColour;
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get { return accentColour; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
accentColour = value;
|
||||||
|
if (!Glowing)
|
||||||
|
Colour = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color4 glowingAccentColour;
|
||||||
|
public Color4 GlowingAccentColour
|
||||||
|
{
|
||||||
|
get { return glowingAccentColour; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
glowingAccentColour = value;
|
||||||
|
if (Glowing)
|
||||||
|
Colour = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color4 glowColour;
|
||||||
|
public Color4 GlowColour
|
||||||
|
{
|
||||||
|
get { return glowColour; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
glowColour = value;
|
||||||
|
|
||||||
|
var effect = EdgeEffect;
|
||||||
|
effect.Colour = value;
|
||||||
|
EdgeEffect = effect;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,8 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Nub nub;
|
protected readonly Nub Nub;
|
||||||
|
|
||||||
private readonly SpriteText labelSpriteText;
|
private readonly SpriteText labelSpriteText;
|
||||||
private SampleChannel sampleChecked;
|
private SampleChannel sampleChecked;
|
||||||
private SampleChannel sampleUnchecked;
|
private SampleChannel sampleUnchecked;
|
||||||
@ -64,7 +65,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
labelSpriteText = new OsuSpriteText(),
|
labelSpriteText = new OsuSpriteText(),
|
||||||
nub = new Nub
|
Nub = new Nub
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
@ -72,7 +73,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
nub.Current.BindTo(Current);
|
Nub.Current.BindTo(Current);
|
||||||
|
|
||||||
Current.ValueChanged += newValue =>
|
Current.ValueChanged += newValue =>
|
||||||
{
|
{
|
||||||
@ -90,15 +91,15 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
nub.Glowing = true;
|
Nub.Glowing = true;
|
||||||
nub.Expanded = true;
|
Nub.Expanded = true;
|
||||||
return base.OnHover(state);
|
return base.OnHover(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
nub.Glowing = false;
|
Nub.Glowing = false;
|
||||||
nub.Expanded = false;
|
Nub.Expanded = false;
|
||||||
base.OnHoverLost(state);
|
base.OnHoverLost(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
@ -14,14 +15,14 @@ using osu.Framework.Input;
|
|||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class OsuSliderBar<T> : SliderBar<T>, IHasTooltip
|
public class OsuSliderBar<T> : SliderBar<T>, IHasTooltip, IHasAccentColour
|
||||||
where T : struct, IEquatable<T>
|
where T : struct, IEquatable<T>
|
||||||
{
|
{
|
||||||
private SampleChannel sample;
|
private SampleChannel sample;
|
||||||
private double lastSampleTime;
|
private double lastSampleTime;
|
||||||
private T lastSampleValue;
|
private T lastSampleValue;
|
||||||
|
|
||||||
private readonly Nub nub;
|
protected readonly Nub Nub;
|
||||||
private readonly Box leftBox;
|
private readonly Box leftBox;
|
||||||
private readonly Box rightBox;
|
private readonly Box rightBox;
|
||||||
|
|
||||||
@ -45,6 +46,18 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Color4 accentColour;
|
||||||
|
public Color4 AccentColour
|
||||||
|
{
|
||||||
|
get { return accentColour; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
accentColour = value;
|
||||||
|
leftBox.Colour = value;
|
||||||
|
rightBox.Colour = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public OsuSliderBar()
|
public OsuSliderBar()
|
||||||
{
|
{
|
||||||
Height = 12;
|
Height = 12;
|
||||||
@ -70,7 +83,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Alpha = 0.5f,
|
Alpha = 0.5f,
|
||||||
},
|
},
|
||||||
nub = new Nub
|
Nub = new Nub
|
||||||
{
|
{
|
||||||
Origin = Anchor.TopCentre,
|
Origin = Anchor.TopCentre,
|
||||||
Expanded = true,
|
Expanded = true,
|
||||||
@ -87,19 +100,18 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
private void load(AudioManager audio, OsuColour colours)
|
private void load(AudioManager audio, OsuColour colours)
|
||||||
{
|
{
|
||||||
sample = audio.Sample.Get(@"Sliderbar/sliderbar");
|
sample = audio.Sample.Get(@"Sliderbar/sliderbar");
|
||||||
leftBox.Colour = colours.Pink;
|
AccentColour = colours.Pink;
|
||||||
rightBox.Colour = colours.Pink;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
nub.Glowing = true;
|
Nub.Glowing = true;
|
||||||
return base.OnHover(state);
|
return base.OnHover(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
nub.Glowing = false;
|
Nub.Glowing = false;
|
||||||
base.OnHoverLost(state);
|
base.OnHoverLost(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,13 +144,13 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
{
|
{
|
||||||
nub.Current.Value = true;
|
Nub.Current.Value = true;
|
||||||
return base.OnMouseDown(state, args);
|
return base.OnMouseDown(state, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||||
{
|
{
|
||||||
nub.Current.Value = false;
|
Nub.Current.Value = false;
|
||||||
return base.OnMouseUp(state, args);
|
return base.OnMouseUp(state, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,14 +158,14 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
leftBox.Scale = new Vector2(MathHelper.Clamp(
|
leftBox.Scale = new Vector2(MathHelper.Clamp(
|
||||||
nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1);
|
Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, DrawWidth), 1);
|
||||||
rightBox.Scale = new Vector2(MathHelper.Clamp(
|
rightBox.Scale = new Vector2(MathHelper.Clamp(
|
||||||
DrawWidth - nub.DrawPosition.X - nub.DrawWidth / 2, 0, DrawWidth), 1);
|
DrawWidth - Nub.DrawPosition.X - Nub.DrawWidth / 2, 0, DrawWidth), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateValue(float value)
|
protected override void UpdateValue(float value)
|
||||||
{
|
{
|
||||||
nub.MoveToX(RangePadding + UsableWidth * value, 250, EasingTypes.OutQuint);
|
Nub.MoveToX(RangePadding + UsableWidth * value, 250, EasingTypes.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user