Refactor color handling

colour*
This commit is contained in:
Drew DeVault
2017-03-15 20:52:31 -04:00
parent db5a1e241a
commit 01cca1a4d2
5 changed files with 81 additions and 39 deletions

View File

@ -2,6 +2,8 @@
// 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 System;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.UserInterface.Tab; using osu.Framework.Graphics.UserInterface.Tab;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
@ -20,5 +22,25 @@ namespace osu.Game.Graphics.UserInterface
foreach (var val in (T[])Enum.GetValues(typeof(T))) foreach (var val in (T[])Enum.GetValues(typeof(T)))
AddTab(val); AddTab(val);
} }
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
if (accentColour == null)
AccentColour = colours.Blue;
}
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
(DropDown as OsuTabDropDownMenu<T>).AccentColour = value;
foreach (OsuTabItem<T> item in TabContainer.Children)
item.AccentColour = value;
}
}
} }
} }

View File

@ -9,8 +9,6 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Transforms; using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Graphics.UserInterface.Tab; using osu.Framework.Graphics.UserInterface.Tab;
using osu.Game.Graphics;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -19,9 +17,26 @@ namespace osu.Game.Graphics.UserInterface
public override float HeaderWidth => 14; public override float HeaderWidth => 14;
public override float HeaderHeight => 24; public override float HeaderHeight => 24;
protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader(); private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
Header.Colour = value;
foreach (OsuTabDropDownMenuItem<T> item in ItemList)
item.AccentColour = value;
}
}
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) => new OsuTabDropDownMenuItem<T>(key, value); protected override DropDownHeader CreateHeader() => new OsuTabDropDownHeader
{
Colour = AccentColour
};
protected override DropDownMenuItem<T> CreateDropDownItem(string key, T value) =>
new OsuTabDropDownMenuItem<T>(key, value) { AccentColour = AccentColour };
public OsuTabDropDownMenu() public OsuTabDropDownMenu()
{ {
@ -50,7 +65,8 @@ namespace osu.Game.Graphics.UserInterface
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
Header.Colour = typeof(T) == typeof(SortMode) ? colours.GreenLight : colours.Blue; if (accentColour == null)
AccentColour = colours.Blue;
} }
} }
} }

View File

@ -6,10 +6,8 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -30,23 +28,27 @@ namespace osu.Game.Graphics.UserInterface
}); });
} }
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.Value; }
set
{
accentColour = value;
BackgroundColourHover = BackgroundColourSelected = value;
FormatBackground();
FormatForeground();
}
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
BackgroundColour = Color4.Black.Opacity(0f); BackgroundColour = Color4.Black.Opacity(0f);
ForegroundColourHover = Color4.Black; ForegroundColourHover = Color4.Black;
ForegroundColourSelected = Color4.Black; ForegroundColourSelected = Color4.Black;
if (accentColour == null)
if (typeof(T) == typeof(SortMode)) AccentColour = colours.Blue;
{
BackgroundColourHover = colours.GreenLight;
BackgroundColourSelected = colours.GreenLight;
}
else
{
BackgroundColourHover = colours.Blue;
BackgroundColourSelected = colours.Blue;
}
} }
} }
} }

View File

@ -10,9 +10,7 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface.Tab; using osu.Framework.Graphics.UserInterface.Tab;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -20,7 +18,18 @@ namespace osu.Game.Graphics.UserInterface
{ {
private SpriteText text; private SpriteText text;
private Box box; private Box box;
private Color4 fadeColour;
private Color4? accentColour;
public Color4 AccentColour
{
get { return accentColour.GetValueOrDefault(); }
set
{
accentColour = value;
if (!Active)
text.Colour = value;
}
}
public new T Value public new T Value
{ {
@ -54,16 +63,18 @@ namespace osu.Game.Graphics.UserInterface
private void fadeInactive() private void fadeInactive()
{ {
box.FadeOut(300); box.FadeOut(300);
text.FadeColour(fadeColour, 300); text.FadeColour(AccentColour, 300);
} }
protected override bool OnHover(InputState state) { protected override bool OnHover(InputState state)
{
if (!Active) if (!Active)
fadeActive(); fadeActive();
return true; return true;
} }
protected override void OnHoverLost(InputState state) { protected override void OnHoverLost(InputState state)
{
if (!Active) if (!Active)
fadeInactive(); fadeInactive();
} }
@ -94,18 +105,8 @@ namespace osu.Game.Graphics.UserInterface
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
if (typeof(T) == typeof(SortMode)) if (accentColour == null)
{ AccentColour = colours.Blue;
fadeColour = colours.GreenLight;
if (!Active)
text.Colour = colours.GreenLight;
}
else
{
fadeColour = colours.Blue;
if (!Active)
text.Colour = colours.Blue;
}
} }
} }
} }

View File

@ -24,6 +24,8 @@ namespace osu.Game.Screens.Select
public string Search => searchTextBox.Text; public string Search => searchTextBox.Text;
private OsuTabControl<SortMode> sortTabs;
private SortMode sort = SortMode.Title; private SortMode sort = SortMode.Title;
public SortMode Sort public SortMode Sort
{ {
@ -60,7 +62,6 @@ namespace osu.Game.Screens.Select
public FilterControl(float height) public FilterControl(float height)
{ {
TabControl<SortMode> sortTabs;
TabControl<GroupMode> groupTabs; TabControl<GroupMode> groupTabs;
Children = new Drawable[] Children = new Drawable[]
@ -134,7 +135,7 @@ namespace osu.Game.Screens.Select
sortTabs = new OsuTabControl<SortMode>(87) sortTabs = new OsuTabControl<SortMode>(87)
{ {
Width = 191, Width = 191,
AutoSort = true AutoSort = true,
} }
} }
} }
@ -164,7 +165,7 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
spriteText.Colour = colours.GreenLight; sortTabs.AccentColour = spriteText.Colour = colours.GreenLight;
} }
} }
} }