Refactor OsuColour into injected instance class

Which should allow you to change the color palette in the future for
skinning purposes.
This commit is contained in:
Drew DeVault 2017-01-12 23:49:05 -05:00
parent fa007e632d
commit f5f545df62
12 changed files with 248 additions and 210 deletions

View File

@ -4,54 +4,58 @@ using osu.Framework.Graphics.Colour;
namespace osu.Game.Graphics
{
public static class OsuColour
public static class OsuColourExtensions
{
public static Color4 Opacity(this Color4 color, float a) => new Color4(color.R, color.G, color.B, a);
public static Color4 Opacity(this Color4 color, byte a) => new Color4(color.R, color.G, color.B, a / 255f);
}
public class OsuColour
{
public static Color4 Gray(float amt) => new Color4(amt, amt, amt, 1f);
public static Color4 Gray(byte amt) => new Color4(amt, amt, amt, 255);
private static Color4 FromHex(string hex)
{
return new Color4(
Convert.ToByte(hex.Substring(1, 2), 16),
Convert.ToByte(hex.Substring(3, 2), 16),
Convert.ToByte(hex.Substring(5, 2), 16),
Convert.ToByte(hex.Substring(0, 2), 16),
Convert.ToByte(hex.Substring(2, 2), 16),
Convert.ToByte(hex.Substring(4, 2), 16),
255);
}
// See https://github.com/ppy/osu-web/blob/master/resources/assets/less/colors.less
public static readonly Color4 PurpleLighter = FromHex(@"eeeeff");
public static readonly Color4 PurpleLight = FromHex(@"aa88ff");
public static readonly Color4 Purple = FromHex(@"8866ee");
public static readonly Color4 PurpleDark = FromHex(@"6644cc");
public static readonly Color4 PurpleDarker = FromHex(@"441188");
public Color4 PurpleLighter = FromHex(@"eeeeff");
public Color4 PurpleLight = FromHex(@"aa88ff");
public Color4 Purple = FromHex(@"8866ee");
public Color4 PurpleDark = FromHex(@"6644cc");
public Color4 PurpleDarker = FromHex(@"441188");
public static readonly Color4 PinkLighter = FromHex(@"ffddee");
public static readonly Color4 PinkLight = FromHex(@"ff99cc");
public static readonly Color4 Pink = FromHex(@"ff66aa");
public static readonly Color4 PinkDark = FromHex(@"cc5288");
public static readonly Color4 PinkDarker = FromHex(@"bb1177");
public Color4 PinkLighter = FromHex(@"ffddee");
public Color4 PinkLight = FromHex(@"ff99cc");
public Color4 Pink = FromHex(@"ff66aa");
public Color4 PinkDark = FromHex(@"cc5288");
public Color4 PinkDarker = FromHex(@"bb1177");
public static readonly Color4 BlueLighter = FromHex(@"ddffff");
public static readonly Color4 BlueLight = FromHex(@"99eeff");
public static readonly Color4 Blue = FromHex(@"66ccff");
public static readonly Color4 BlueDark = FromHex(@"44aadd");
public static readonly Color4 BlueDarker = FromHex(@"2299bb");
public Color4 BlueLighter = FromHex(@"ddffff");
public Color4 BlueLight = FromHex(@"99eeff");
public Color4 Blue = FromHex(@"66ccff");
public Color4 BlueDark = FromHex(@"44aadd");
public Color4 BlueDarker = FromHex(@"2299bb");
public static readonly Color4 YellowLighter = FromHex(@"ffffdd");
public static readonly Color4 YellowLight = FromHex(@"ffdd55");
public static readonly Color4 Yellow = FromHex(@"ffcc22");
public static readonly Color4 YellowDark = FromHex(@"eeaa00");
public static readonly Color4 YellowDarker = FromHex(@"cc6600");
public Color4 YellowLighter = FromHex(@"ffffdd");
public Color4 YellowLight = FromHex(@"ffdd55");
public Color4 Yellow = FromHex(@"ffcc22");
public Color4 YellowDark = FromHex(@"eeaa00");
public Color4 YellowDarker = FromHex(@"cc6600");
public static readonly Color4 GreenLighter = FromHex(@"eeffcc");
public static readonly Color4 GreenLight = FromHex(@"b3d944");
public static readonly Color4 Green = FromHex(@"88b300");
public static readonly Color4 GreenDark = FromHex(@"668800");
public static readonly Color4 GreenDarker = FromHex(@"445500");
public Color4 GreenLighter = FromHex(@"eeffcc");
public Color4 GreenLight = FromHex(@"b3d944");
public Color4 Green = FromHex(@"88b300");
public Color4 GreenDark = FromHex(@"668800");
public Color4 GreenDarker = FromHex(@"445500");
public static readonly Color4 Red = FromHex(@"fc4549");
public Color4 Red = FromHex(@"fc4549");
}
}

View File

@ -34,55 +34,6 @@ namespace osu.Game.Graphics.UserInterface
public BackButton()
{
Size = size_retracted;
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
Children = new Drawable[]
{
leftBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.PinkDark,
Shear = new Vector2(shear, 0),
},
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 25,
Icon = FontAwesome.fa_osu_left_o
},
}
},
new Container
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
Children = new Drawable[]
{
rightBox = new Box
{
Colour = OsuColour.Pink,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
EdgeSmoothness = new Vector2(1.5f, 0),
},
new SpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = @"Back",
}
}
}
};
}
public override bool Contains(Vector2 screenSpacePos) => leftBox.Contains(screenSpacePos) || rightBox.Contains(screenSpacePos);
@ -140,9 +91,57 @@ namespace osu.Game.Graphics.UserInterface
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
private void load(AudioManager audio, OsuColour colours)
{
sampleClick = audio.Sample.Get(@"Menu/menuback");
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Width = 0.4f,
Children = new Drawable[]
{
leftBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.PinkDark,
Shear = new Vector2(shear, 0),
},
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 25,
Icon = FontAwesome.fa_osu_left_o
},
}
},
new Container
{
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Width = 0.6f,
Children = new Drawable[]
{
rightBox = new Box
{
Colour = colours.Pink,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(shear, 0),
EdgeSmoothness = new Vector2(1.5f, 0),
},
new SpriteText
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Text = @"Back",
}
}
}
};
}
protected override bool OnClick(InputState state)

View File

@ -3,6 +3,7 @@
using System;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Graphics.UserInterface
@ -12,7 +13,12 @@ namespace osu.Game.Graphics.UserInterface
public OsuButton()
{
Height = 25;
Colour = OsuColour.BlueDark;
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = colours.BlueDark;
}
}
}

View File

@ -13,6 +13,7 @@ using osu.Game.Beatmaps;
using osu.Game.Beatmaps.IO;
using osu.Game.Configuration;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.Processing;
using osu.Game.Online.API;
@ -41,6 +42,7 @@ namespace osu.Game
Dependencies.Cache(this);
Dependencies.Cache(Config);
Dependencies.Cache(new BeatmapDatabase(Host.Storage, Host));
Dependencies.Cache(new OsuColour());
//this completely overrides the framework default. will need to change once we make a proper FontStore.
Dependencies.Cache(Fonts = new FontStore { ScaleAdjust = 0.01f }, true);

View File

@ -65,7 +65,31 @@ namespace osu.Game.Overlays
Origin = Anchor.TopRight;
Position = start_position;
Margin = new MarginPadding(10);
}
protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state)
{
Vector2 change = (state.Mouse.Position - state.Mouse.PositionMouseDown.Value);
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
change *= (float)Math.Pow(change.Length, 0.7f) / change.Length;
MoveTo(start_position + change);
return base.OnDrag(state);
}
protected override bool OnDragEnd(InputState state)
{
MoveTo(start_position, 800, EasingTypes.OutElastic);
return base.OnDragEnd(state);
}
[BackgroundDependencyLoader]
private void load(OsuGameBase osuGame, BeatmapDatabase beatmaps, AudioManager audio,
TextureStore textures, OsuColour colours)
{
Children = new Drawable[]
{
title = new SpriteText
@ -171,34 +195,11 @@ namespace osu.Game.Overlays
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
Height = 10,
Colour = OsuColour.Yellow,
Colour = colours.Yellow,
SeekRequested = seek
}
};
}
protected override bool OnDragStart(InputState state) => true;
protected override bool OnDrag(InputState state)
{
Vector2 change = (state.Mouse.Position - state.Mouse.PositionMouseDown.Value);
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
change *= (float)Math.Pow(change.Length, 0.7f) / change.Length;
MoveTo(start_position + change);
return base.OnDrag(state);
}
protected override bool OnDragEnd(InputState state)
{
MoveTo(start_position, 800, EasingTypes.OutElastic);
return base.OnDragEnd(state);
}
[BackgroundDependencyLoader]
private void load(OsuGameBase osuGame, BeatmapDatabase beatmaps, AudioManager audio, TextureStore textures)
{
this.beatmaps = beatmaps;
trackManager = osuGame.Audio.Track;
config = osuGame.Config;

View File

@ -141,22 +141,13 @@ namespace osu.Game.Overlays.Options
private Box fill;
const float border_width = 3;
private Color4 glowingColour, idleColour;
public Light()
{
Size = new Vector2(40, 12);
Masking = true;
Colour = OsuColour.Pink;
EdgeEffect = new EdgeEffect
{
Colour = OsuColour.PinkDarker,
Type = EdgeEffectType.Glow,
Radius = 10,
Roundness = 8,
};
Masking = true;
CornerRadius = Height / 2;
Masking = true;
@ -173,19 +164,33 @@ namespace osu.Game.Overlays.Options
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Colour = idleColour = colours.Pink;
EdgeEffect = new EdgeEffect
{
Colour = glowingColour = colours.PinkDarker,
Type = EdgeEffectType.Glow,
Radius = 10,
Roundness = 8,
};
}
public bool Glowing
{
set
{
if (value)
{
FadeColour(OsuColour.PinkLighter, 500, EasingTypes.OutQuint);
FadeColour(glowingColour, 500, EasingTypes.OutQuint);
FadeGlowTo(1, 500, EasingTypes.OutQuint);
}
else
{
FadeGlowTo(0, 500);
FadeColour(OsuColour.Pink, 500);
FadeColour(idleColour, 500);
}
}
}

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -131,9 +132,6 @@ namespace osu.Game.Overlays.Options
private class StyledDropDownComboBox : DropDownComboBox
{
protected override Color4 BackgroundColour => Color4.Black.Opacity(0.5f);
protected override Color4 BackgroundColourHover => OsuColour.PinkDarker;
private SpriteText label;
protected override string Label
{
@ -157,14 +155,17 @@ namespace osu.Game.Overlays.Options
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = Color4.Black.Opacity(0.5f);
BackgroundColourHover = colours.PinkDarker;
}
}
private class StyledDropDownMenuItem<U> : DropDownMenuItem<U>
{
protected override Color4 BackgroundColour => Color4.Black.Opacity(0.5f);
protected override Color4 BackgroundColourSelected => Color4.Black.Opacity(0.5f);
protected override Color4 BackgroundColourHover => OsuColour.PinkDarker;
public StyledDropDownMenuItem(string text, U value) : base(text, value)
{
AutoSizeAxes = Axes.None;
@ -193,6 +194,14 @@ namespace osu.Game.Overlays.Options
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = Color4.Black.Opacity(0.5f);
BackgroundColourHover = colours.PinkDarker;
BackgroundColourSelected = Color4.Black.Opacity(0.5f);
}
}
}
}

View File

@ -3,6 +3,7 @@
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
@ -19,14 +20,16 @@ namespace osu.Game.Overlays.Options
public abstract FontAwesome Icon { get; }
public abstract string Header { get; }
private SpriteText headerLabel;
public OptionsSection()
{
Margin = new MarginPadding { Top = 20 };
const int headerSize = 26, headerMargin = 25;
const int borderSize = 2;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
const int headerSize = 26, headerMargin = 25;
const int borderSize = 2;
AddInternal(new Drawable[]
{
new Box
@ -48,10 +51,9 @@ namespace osu.Game.Overlays.Options
AutoSizeAxes = Axes.Y,
Children = new[]
{
new SpriteText
headerLabel = new SpriteText
{
TextSize = headerSize,
Colour = OsuColour.Pink,
Text = Header,
},
content = new FlowContainer
@ -66,5 +68,11 @@ namespace osu.Game.Overlays.Options
},
});
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
headerLabel.Colour = colours.Pink;
}
}
}

View File

@ -4,6 +4,7 @@
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -55,44 +56,49 @@ namespace osu.Game.Overlays.Options
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
backgroundBox = new Box
backgroundBox = new Box
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = OsuColour.Gray(60),
Alpha = 0,
},
new Container
{
Width = OptionsSidebar.default_width,
RelativeSizeAxes = Axes.Y,
Children = new[]
{
RelativeSizeAxes = Axes.Both,
BlendingMode = BlendingMode.Additive,
Colour = OsuColour.Gray(60),
Alpha = 0,
},
new Container
{
Width = OptionsSidebar.default_width,
RelativeSizeAxes = Axes.Y,
Children = new[]
drawableIcon = new TextAwesome
{
drawableIcon = new TextAwesome
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
},
headerText = new SpriteText
{
Position = new Vector2(OptionsSidebar.default_width + 10, 0),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
selectionIndicator = new Box
{
Alpha = 0,
RelativeSizeAxes = Axes.Y,
Width = 5,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Colour = OsuColour.Pink
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
}
},
headerText = new SpriteText
{
Position = new Vector2(OptionsSidebar.default_width + 10, 0),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
selectionIndicator = new Box
{
Alpha = 0,
RelativeSizeAxes = Axes.Y,
Width = 5,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
selectionIndicator.Colour = colours.Pink;
}
protected override bool OnClick(InputState state)
{
Action?.Invoke();

View File

@ -17,6 +17,7 @@ using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Graphics;
using System.Linq;
namespace osu.Game.Overlays.Options
{
@ -85,7 +86,6 @@ namespace osu.Game.Overlays.Options
RelativeSizeAxes = Axes.None,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = OsuColour.Pink,
},
rightBox = new Box
{
@ -93,7 +93,6 @@ namespace osu.Game.Overlays.Options
RelativeSizeAxes = Axes.None,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Colour = OsuColour.Pink,
Alpha = 0.5f,
},
nub = new Container
@ -105,13 +104,11 @@ namespace osu.Game.Overlays.Options
AutoSizeAxes = Axes.None,
RelativeSizeAxes = Axes.None,
Masking = true,
BorderColour = OsuColour.Pink,
BorderThickness = 3,
Children = new[]
{
new Box
{
Colour = OsuColour.Pink.Opacity(0),
RelativeSizeAxes = Axes.Both
}
}
@ -120,9 +117,13 @@ namespace osu.Game.Overlays.Options
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
private void load(AudioManager audio, OsuColour colours)
{
sample = audio.Sample.Get(@"Sliderbar/sliderbar");
leftBox.Colour = colours.Pink;
rightBox.Colour = colours.Pink;
nub.BorderColour = colours.Pink;
(nub.Children.First() as Box).Colour = colours.Pink.Opacity(0);
}
private void playSample()

View File

@ -46,6 +46,13 @@ namespace osu.Game.Overlays
private float lastKnownScroll;
public OptionsOverlay()
{
RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X;
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game, OsuColour colours)
{
sections = new OptionsSection[]
{
@ -59,10 +66,6 @@ namespace osu.Game.Overlays
new OnlineSection(),
new MaintenanceSection(),
};
RelativeSizeAxes = Axes.Y;
AutoSizeAxes = Axes.X;
Children = new Drawable[]
{
new Box
@ -95,7 +98,7 @@ namespace osu.Game.Overlays
},
new SpriteText
{
Colour = OsuColour.Pink,
Colour = colours.Pink,
Text = "Change the way osu! behaves",
TextSize = 18,
Margin = new MarginPadding { Left = CONTENT_MARGINS, Bottom = 30 },
@ -124,11 +127,7 @@ namespace osu.Game.Overlays
).ToArray()
}
};
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGame game)
{
scrollContainer.Padding = new MarginPadding { Top = game?.Toolbar.DrawHeight ?? 0 };
}

View File

@ -81,7 +81,34 @@ namespace osu.Game.Screens.Select
}
}
public PlaySongSelect()
Player player;
private void start()
{
if (player != null)
return;
//in the future we may want to move this logic to a PlayerLoader gamemode or similar, so we can rely on the SongSelect transition
//and provide a better loading experience (at the moment song select is still accepting input during preload).
player = new Player
{
BeatmapInfo = carousel.SelectedGroup.SelectedPanel.Beatmap,
PreferredPlayMode = playMode.Value
};
player.Preload(Game, delegate
{
if (!Push(player))
{
player = null;
//error occured?
}
});
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapDatabase beatmaps, AudioManager audio, BaseGame game,
OsuGame osuGame, OsuColour colours)
{
const float carouselWidth = 640;
const float bottomToolHeight = 50;
@ -143,42 +170,13 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.Y,
Width = 100,
Text = "Play",
Colour = OsuColour.Pink,
Colour = colours.Pink,
Action = start
},
}
}
};
}
Player player;
private void start()
{
if (player != null)
return;
//in the future we may want to move this logic to a PlayerLoader gamemode or similar, so we can rely on the SongSelect transition
//and provide a better loading experience (at the moment song select is still accepting input during preload).
player = new Player
{
BeatmapInfo = carousel.SelectedGroup.SelectedPanel.Beatmap,
PreferredPlayMode = playMode.Value
};
player.Preload(Game, delegate
{
if (!Push(player))
{
player = null;
//error occured?
}
});
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapDatabase beatmaps, AudioManager audio, BaseGame game, OsuGame osuGame)
{
if (osuGame != null)
{
playMode = osuGame.PlayMode;