mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Merge branch 'master' into menu-bar
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
// 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.Linq;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -14,35 +14,43 @@ using OpenTK;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
public class OsuDropdown<T> : Dropdown<T>
|
||||
public class OsuDropdown<T> : Dropdown<T>, IHasAccentColour
|
||||
{
|
||||
public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>();
|
||||
private Color4 accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get { return accentColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
updateAccentColour();
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
if (AccentColour.Value == null)
|
||||
AccentColour.Value = colours.PinkDarker;
|
||||
if (accentColour == default(Color4))
|
||||
accentColour = colours.PinkDarker;
|
||||
updateAccentColour();
|
||||
|
||||
}
|
||||
|
||||
protected override DropdownHeader CreateHeader()
|
||||
private void updateAccentColour()
|
||||
{
|
||||
var newHeader = new OsuDropdownHeader();
|
||||
newHeader.AccentColour.BindTo(AccentColour);
|
||||
var header = Header as IHasAccentColour;
|
||||
if (header != null) header.AccentColour = accentColour;
|
||||
|
||||
return newHeader;
|
||||
var menu = Menu as IHasAccentColour;
|
||||
if (menu != null) menu.AccentColour = accentColour;
|
||||
}
|
||||
|
||||
protected override DropdownMenu CreateMenu()
|
||||
{
|
||||
var newMenu = new OsuDropdownMenu();
|
||||
newMenu.AccentColour.BindTo(AccentColour);
|
||||
protected override DropdownHeader CreateHeader() => new OsuDropdownHeader();
|
||||
|
||||
return newMenu;
|
||||
}
|
||||
protected override DropdownMenu CreateMenu() => new OsuDropdownMenu();
|
||||
|
||||
#region OsuDropdownMenu
|
||||
protected class OsuDropdownMenu : DropdownMenu
|
||||
protected class OsuDropdownMenu : DropdownMenu, IHasAccentColour
|
||||
{
|
||||
// todo: this uses the same styling as OsuMenu. hopefully we can just use OsuMenu in the future with some refactoring
|
||||
public OsuDropdownMenu()
|
||||
@ -65,23 +73,41 @@ namespace osu.Game.Graphics.UserInterface
|
||||
this.ResizeHeightTo(State == MenuState.Opened ? actualHeight : 0, 300, Easing.OutQuint);
|
||||
}
|
||||
|
||||
public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>();
|
||||
|
||||
|
||||
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item)
|
||||
private Color4 accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
var newItem = new DrawableOsuDropdownMenuItem(item);
|
||||
newItem.AccentColour.BindTo(AccentColour);
|
||||
|
||||
return newItem;
|
||||
get { return accentColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
foreach (var c in Children.OfType<IHasAccentColour>())
|
||||
c.AccentColour = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region DrawableOsuDropdownMenuItem
|
||||
protected class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem
|
||||
{
|
||||
public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>();
|
||||
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuDropdownMenuItem(item) { AccentColour = accentColour };
|
||||
|
||||
private TextContainer textContainer;
|
||||
#region DrawableOsuDropdownMenuItem
|
||||
protected class DrawableOsuDropdownMenuItem : DrawableDropdownMenuItem, IHasAccentColour
|
||||
{
|
||||
private Color4? accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get { return accentColour ?? nonAccentSelectedColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
updateColours();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateColours()
|
||||
{
|
||||
BackgroundColourHover = accentColour ?? nonAccentHoverColour;
|
||||
BackgroundColourSelected = accentColour ?? nonAccentSelectedColour;
|
||||
UpdateBackgroundColour();
|
||||
UpdateForegroundColour();
|
||||
}
|
||||
|
||||
private Color4 nonAccentHoverColour;
|
||||
private Color4 nonAccentSelectedColour;
|
||||
@ -93,36 +119,29 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
Masking = true;
|
||||
CornerRadius = 6;
|
||||
|
||||
AccentColour.ValueChanged += updateAccent;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = Color4.Transparent;
|
||||
|
||||
nonAccentHoverColour = colours.PinkDarker;
|
||||
nonAccentSelectedColour = Color4.Black.Opacity(0.5f);
|
||||
}
|
||||
|
||||
private void updateAccent(Color4? newValue)
|
||||
{
|
||||
BackgroundColourHover = newValue ?? nonAccentHoverColour;
|
||||
BackgroundColourSelected = newValue ?? nonAccentSelectedColour;
|
||||
UpdateBackgroundColour();
|
||||
UpdateForegroundColour();
|
||||
updateColours();
|
||||
}
|
||||
|
||||
protected override void UpdateForegroundColour()
|
||||
{
|
||||
base.UpdateForegroundColour();
|
||||
|
||||
textContainer.Chevron.Alpha = IsHovered ? 1 : 0;
|
||||
var content = Foreground.Children.FirstOrDefault() as Content;
|
||||
if (content != null) content.Chevron.Alpha = IsHovered ? 1 : 0;
|
||||
}
|
||||
|
||||
protected override Drawable CreateContent() => textContainer = new TextContainer();
|
||||
protected override Drawable CreateContent() => new Content();
|
||||
|
||||
protected class TextContainer : FillFlowContainer, IHasText
|
||||
protected class Content : FillFlowContainer, IHasText
|
||||
{
|
||||
public string Text
|
||||
{
|
||||
@ -133,7 +152,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
public readonly OsuSpriteText Label;
|
||||
public readonly SpriteIcon Chevron;
|
||||
|
||||
public TextContainer()
|
||||
public Content()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
@ -165,7 +184,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class OsuDropdownHeader : DropdownHeader
|
||||
public class OsuDropdownHeader : DropdownHeader, IHasAccentColour
|
||||
{
|
||||
protected readonly SpriteText Text;
|
||||
protected override string Label
|
||||
@ -176,7 +195,16 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected readonly SpriteIcon Icon;
|
||||
|
||||
public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>();
|
||||
private Color4 accentColour;
|
||||
public virtual Color4 AccentColour
|
||||
{
|
||||
get { return accentColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
BackgroundColourHover = accentColour;
|
||||
}
|
||||
}
|
||||
|
||||
public OsuDropdownHeader()
|
||||
{
|
||||
@ -203,20 +231,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Size = new Vector2(20),
|
||||
}
|
||||
};
|
||||
|
||||
AccentColour.ValueChanged += accentColourChanged;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundColour = Color4.Black.Opacity(0.5f);
|
||||
BackgroundColourHover = AccentColour?.Value ?? colours.PinkDarker;
|
||||
}
|
||||
|
||||
private void accentColourChanged(Color4? newValue)
|
||||
{
|
||||
BackgroundColourHover = newValue ?? Color4.White;
|
||||
BackgroundColourHover = colours.PinkDarker;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
|
@ -1,11 +1,16 @@
|
||||
// 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;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Input;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -15,6 +20,49 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
public override bool AllowClipboardExport => false;
|
||||
|
||||
private readonly CapsWarning warning;
|
||||
|
||||
private GameHost host;
|
||||
|
||||
public OsuPasswordTextBox()
|
||||
{
|
||||
Add(warning = new CapsWarning
|
||||
{
|
||||
Size = new Vector2(20),
|
||||
Origin = Anchor.CentreRight,
|
||||
Anchor = Anchor.CentreRight,
|
||||
Margin = new MarginPadding { Right = 10 },
|
||||
Alpha = 0,
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host)
|
||||
{
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (args.Key == Key.CapsLock)
|
||||
updateCapsWarning(host.CapsLockEnabled);
|
||||
return base.OnKeyDown(state, args);
|
||||
}
|
||||
|
||||
protected override void OnFocus(InputState state)
|
||||
{
|
||||
updateCapsWarning(host.CapsLockEnabled);
|
||||
base.OnFocus(state);
|
||||
}
|
||||
|
||||
protected override void OnFocusLost(InputState state)
|
||||
{
|
||||
updateCapsWarning(false);
|
||||
base.OnFocusLost(state);
|
||||
}
|
||||
|
||||
private void updateCapsWarning(bool visible) => warning.FadeTo(visible ? 1 : 0, 250, Easing.OutQuint);
|
||||
|
||||
public class PasswordMaskChar : Container
|
||||
{
|
||||
private readonly CircularContainer circle;
|
||||
@ -51,5 +99,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
circle.ResizeTo(new Vector2(0.8f), 500, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
private class CapsWarning : SpriteIcon, IHasTooltip
|
||||
{
|
||||
public string TooltipText => @"Caps lock is active";
|
||||
|
||||
public CapsWarning()
|
||||
{
|
||||
Icon = FontAwesome.fa_warning;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
{
|
||||
Colour = colour.YellowLight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,34 +37,34 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
if (accentColour == null)
|
||||
if (accentColour == default(Color4))
|
||||
AccentColour = colours.Blue;
|
||||
}
|
||||
|
||||
private Color4? accentColour;
|
||||
private Color4 accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get { return accentColour.GetValueOrDefault(); }
|
||||
get { return accentColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
var dropdown = Dropdown as OsuTabDropdown;
|
||||
var dropdown = Dropdown as IHasAccentColour;
|
||||
if (dropdown != null)
|
||||
dropdown.AccentColour.Value = value;
|
||||
foreach (var item in TabContainer.Children.OfType<OsuTabItem>())
|
||||
item.AccentColour = value;
|
||||
dropdown.AccentColour = value;
|
||||
foreach (var i in TabContainer.Children.OfType<IHasAccentColour>())
|
||||
i.AccentColour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class OsuTabItem : TabItem<T>
|
||||
public class OsuTabItem : TabItem<T>, IHasAccentColour
|
||||
{
|
||||
protected readonly SpriteText Text;
|
||||
private readonly Box box;
|
||||
|
||||
private Color4? accentColour;
|
||||
private Color4 accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
get { return accentColour.GetValueOrDefault(); }
|
||||
get { return accentColour; }
|
||||
set
|
||||
{
|
||||
accentColour = value;
|
||||
@ -103,7 +103,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
if (accentColour == null)
|
||||
if (accentColour == default(Color4))
|
||||
AccentColour = colours.Blue;
|
||||
}
|
||||
|
||||
@ -148,25 +148,13 @@ namespace osu.Game.Graphics.UserInterface
|
||||
RelativeSizeAxes = Axes.X;
|
||||
}
|
||||
|
||||
protected override DropdownMenu CreateMenu()
|
||||
protected override DropdownMenu CreateMenu() => new OsuTabDropdownMenu();
|
||||
|
||||
protected override DropdownHeader CreateHeader() => new OsuTabDropdownHeader
|
||||
{
|
||||
var menu = new OsuTabDropdownMenu();
|
||||
menu.AccentColour.BindTo(AccentColour);
|
||||
return menu;
|
||||
}
|
||||
|
||||
protected override DropdownHeader CreateHeader()
|
||||
{
|
||||
var newHeader = new OsuTabDropdownHeader
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight
|
||||
};
|
||||
|
||||
newHeader.AccentColour.BindTo(AccentColour);
|
||||
|
||||
return newHeader;
|
||||
}
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight
|
||||
};
|
||||
|
||||
private class OsuTabDropdownMenu : OsuDropdownMenu
|
||||
{
|
||||
@ -179,12 +167,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
MaxHeight = 400;
|
||||
}
|
||||
|
||||
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item)
|
||||
{
|
||||
var result = new DrawableOsuTabDropdownMenuItem(item);
|
||||
result.AccentColour.BindTo(AccentColour);
|
||||
return result;
|
||||
}
|
||||
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableOsuTabDropdownMenuItem(item) { AccentColour = AccentColour };
|
||||
|
||||
private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem
|
||||
{
|
||||
@ -199,6 +182,20 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected class OsuTabDropdownHeader : OsuDropdownHeader
|
||||
{
|
||||
public override Color4 AccentColour
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.AccentColour;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.AccentColour = value;
|
||||
Foreground.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
public OsuTabDropdownHeader()
|
||||
{
|
||||
RelativeSizeAxes = Axes.None;
|
||||
@ -227,13 +224,6 @@ namespace osu.Game.Graphics.UserInterface
|
||||
};
|
||||
|
||||
Padding = new MarginPadding { Left = 5, Right = 5 };
|
||||
|
||||
AccentColour.ValueChanged += accentColourChanged;
|
||||
}
|
||||
|
||||
private void accentColourChanged(Color4? newValue)
|
||||
{
|
||||
Foreground.Colour = newValue ?? Color4.White;
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
|
Reference in New Issue
Block a user