mirror of
https://github.com/ppy/osu.git
synced 2026-05-20 00:20:21 +08:00
Use enum for background states
This commit is contained in:
@@ -169,8 +169,12 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
text.Colour = Enabled.Value ? colourProvider.Content1 : colourProvider.Background1;
|
||||
|
||||
background.StyleHovered = IsHovered;
|
||||
background.StyleDisabled = !Enabled.Value;
|
||||
if (!Enabled.Value)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
|
||||
// TODO: Support BackgroundColour?
|
||||
}
|
||||
|
||||
@@ -141,8 +141,13 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
private void updateState()
|
||||
{
|
||||
caption.Colour = Current.Disabled ? colourProvider.Background1 : colourProvider.Content2;
|
||||
background.StyleHovered = IsHovered;
|
||||
background.StyleDisabled = IsDisabled;
|
||||
|
||||
if (IsDisabled)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
public IEnumerable<LocalisableString> FilterTerms => Caption.Yield();
|
||||
|
||||
@@ -135,7 +135,10 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
caption.Colour = colourProvider.Content2;
|
||||
|
||||
background.StyleHovered = IsHovered;
|
||||
if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
private void updateColours()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
@@ -18,36 +19,15 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
public const float CORNER_EXPONENT = 2.5f;
|
||||
public const float BORDER_THICKNESS = 2.5f;
|
||||
|
||||
private bool styleDisabled;
|
||||
private VisualStyle visualStyle;
|
||||
|
||||
public bool StyleDisabled
|
||||
public VisualStyle VisualStyle
|
||||
{
|
||||
get => visualStyle;
|
||||
set
|
||||
{
|
||||
styleDisabled = value;
|
||||
updateStyling();
|
||||
}
|
||||
}
|
||||
|
||||
private bool styleFocused;
|
||||
|
||||
public bool StyleFocused
|
||||
{
|
||||
set
|
||||
{
|
||||
styleFocused = value;
|
||||
updateStyling();
|
||||
}
|
||||
}
|
||||
|
||||
private bool styleHovered;
|
||||
|
||||
public bool StyleHovered
|
||||
{
|
||||
set
|
||||
{
|
||||
styleHovered = value;
|
||||
updateStyling();
|
||||
visualStyle = value;
|
||||
updateStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +63,7 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
updateStyling();
|
||||
updateStyle();
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
@@ -92,30 +72,41 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
box.FlashColour(ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark2), 800, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private void updateStyling()
|
||||
private void updateStyle()
|
||||
{
|
||||
sounds.Enabled.Value = !styleDisabled;
|
||||
sounds.Enabled.Value = visualStyle != VisualStyle.Disabled;
|
||||
|
||||
ColourInfo colour = colourProvider.Background4.Darken(0.1f);
|
||||
ColourInfo borderColour = colourProvider.Light4;
|
||||
ColourInfo colour;
|
||||
ColourInfo borderColour;
|
||||
|
||||
bool border = false;
|
||||
|
||||
if (styleDisabled)
|
||||
switch (visualStyle)
|
||||
{
|
||||
colour = colourProvider.Background4;
|
||||
borderColour = colourProvider.Dark1;
|
||||
}
|
||||
else if (styleFocused)
|
||||
{
|
||||
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark3);
|
||||
border = true;
|
||||
borderColour = colourProvider.Highlight1;
|
||||
}
|
||||
else if (styleHovered)
|
||||
{
|
||||
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark4);
|
||||
border = true;
|
||||
case VisualStyle.Normal:
|
||||
colour = colourProvider.Background4.Darken(0.1f);
|
||||
borderColour = colourProvider.Light4;
|
||||
break;
|
||||
|
||||
case VisualStyle.Disabled:
|
||||
colour = colourProvider.Background4;
|
||||
borderColour = colourProvider.Dark1;
|
||||
break;
|
||||
|
||||
case VisualStyle.Hovered:
|
||||
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark4);
|
||||
borderColour = colourProvider.Light4;
|
||||
border = true;
|
||||
break;
|
||||
|
||||
case VisualStyle.Focused:
|
||||
colour = ColourInfo.GradientVertical(colourProvider.Background5, colourProvider.Dark3);
|
||||
border = true;
|
||||
borderColour = colourProvider.Highlight1;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
this.TransformTo(nameof(BorderColour), border ? borderColour : colour, 250, Easing.OutQuint);
|
||||
@@ -123,4 +114,12 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
box.FadeColour(colour, 250, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
|
||||
public enum VisualStyle
|
||||
{
|
||||
Normal,
|
||||
Disabled,
|
||||
Hovered,
|
||||
Focused
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,9 +246,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
else
|
||||
label.Alpha = 1;
|
||||
|
||||
background.StyleDisabled = Dropdown.Current.Disabled;
|
||||
background.StyleHovered = IsHovered;
|
||||
background.StyleFocused = dropdownOpen;
|
||||
if (Dropdown.Current.Disabled)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (dropdownOpen)
|
||||
background.VisualStyle = VisualStyle.Focused;
|
||||
else if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
private void updateChevron()
|
||||
|
||||
@@ -212,9 +212,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
caption.Colour = Current.Disabled ? colourProvider.Foreground1 : colourProvider.Content2;
|
||||
filenameText.Colour = Current.Disabled || Current.Value == null ? colourProvider.Foreground1 : colourProvider.Content1;
|
||||
|
||||
background.StyleDisabled = Current.Disabled;
|
||||
background.StyleFocused = popoverState.Value == Visibility.Visible;
|
||||
background.StyleHovered = IsHovered;
|
||||
if (Current.Disabled)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (popoverState.Value == Visibility.Visible)
|
||||
background.VisualStyle = VisualStyle.Focused;
|
||||
else if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
||||
@@ -395,9 +395,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
textBox.Colour = currentNumberInstantaneous.Disabled ? colourProvider.Background1 : colourProvider.Content1;
|
||||
valueLabel.Colour = currentNumberInstantaneous.Disabled ? colourProvider.Background1 : colourProvider.Content1;
|
||||
|
||||
background.StyleDisabled = Current.Disabled;
|
||||
background.StyleFocused = childHasFocus;
|
||||
background.StyleHovered = IsHovered || slider.IsDragging.Value;
|
||||
if (Current.Disabled)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (childHasFocus)
|
||||
background.VisualStyle = VisualStyle.Focused;
|
||||
else if (IsHovered || slider.IsDragging.Value)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
private void updateValueDisplay()
|
||||
|
||||
@@ -185,9 +185,14 @@ namespace osu.Game.Graphics.UserInterfaceV2
|
||||
caption.Colour = disabled ? colourProvider.Background1 : colourProvider.Content2;
|
||||
textBox.Colour = disabled ? colourProvider.Foreground1 : colourProvider.Content1;
|
||||
|
||||
background.StyleDisabled = Current.Disabled;
|
||||
background.StyleFocused = textBox.Focused.Value;
|
||||
background.StyleHovered = IsHovered;
|
||||
if (Current.Disabled)
|
||||
background.VisualStyle = VisualStyle.Disabled;
|
||||
else if (textBox.Focused.Value)
|
||||
background.VisualStyle = VisualStyle.Focused;
|
||||
else if (IsHovered)
|
||||
background.VisualStyle = VisualStyle.Hovered;
|
||||
else
|
||||
background.VisualStyle = VisualStyle.Normal;
|
||||
}
|
||||
|
||||
internal partial class InnerTextBox : OsuTextBox
|
||||
|
||||
Reference in New Issue
Block a user