1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 21:42:55 +08:00

Merge branch 'menu-mvvm' into menu-bar

This commit is contained in:
smoogipooo 2017-08-28 12:52:49 +09:00
commit 41b162d9e3
5 changed files with 99 additions and 63 deletions

@ -1 +1 @@
Subproject commit 8fe24d449fdcb975f5a799a40d92377116dd7d4f Subproject commit 2958d6fda1be252a0f479609090e72814b177c91

View File

@ -8,6 +8,7 @@ using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -54,8 +55,7 @@ namespace osu.Game.Graphics.UserInterface
private SampleChannel sampleClick; private SampleChannel sampleClick;
private SampleChannel sampleHover; private SampleChannel sampleHover;
private OsuSpriteText text; private TextContainer text;
private OsuSpriteText textBold;
public DrawableOsuContextMenuItem(Menu<TItem> menu, TItem item) public DrawableOsuContextMenuItem(Menu<TItem> menu, TItem item)
: base(item) : base(item)
@ -79,13 +79,13 @@ namespace osu.Game.Graphics.UserInterface
switch (Item.Type) switch (Item.Type)
{ {
case MenuItemType.Standard: case MenuItemType.Standard:
textBold.Colour = text.Colour = Color4.White; text.Colour = Color4.White;
break; break;
case MenuItemType.Destructive: case MenuItemType.Destructive:
textBold.Colour = text.Colour = Color4.Red; text.Colour = Color4.Red;
break; break;
case MenuItemType.Highlighted: case MenuItemType.Highlighted:
textBold.Colour = text.Colour = OsuColour.FromHex(@"ffcc22"); text.Colour = OsuColour.FromHex(@"ffcc22");
break; break;
} }
} }
@ -93,15 +93,15 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)
{ {
sampleHover.Play(); sampleHover.Play();
textBold.FadeIn(transition_length, Easing.OutQuint); text.BoldText.FadeIn(transition_length, Easing.OutQuint);
text.FadeOut(transition_length, Easing.OutQuint); text.NormalText.FadeOut(transition_length, Easing.OutQuint);
return base.OnHover(state); return base.OnHover(state);
} }
protected override void OnHoverLost(InputState state) protected override void OnHoverLost(InputState state)
{ {
textBold.FadeOut(transition_length, Easing.OutQuint); text.BoldText.FadeOut(transition_length, Easing.OutQuint);
text.FadeIn(transition_length, Easing.OutQuint); text.NormalText.FadeIn(transition_length, Easing.OutQuint);
base.OnHoverLost(state); base.OnHoverLost(state);
} }
@ -111,35 +111,53 @@ namespace osu.Game.Graphics.UserInterface
return base.OnClick(state); return base.OnClick(state);
} }
protected override Drawable CreateContent() => new Container protected override Drawable CreateContent() => text = new TextContainer();
private class TextContainer : Container, IHasText
{ {
AutoSizeAxes = Axes.Both, public string Text
Anchor = Anchor.CentreLeft, {
Origin = Anchor.CentreLeft, get { return NormalText.Text; }
set
{
NormalText.Text = value;
BoldText.Text = value;
}
}
public readonly SpriteText NormalText;
public readonly SpriteText BoldText;
public TextContainer()
{
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
AutoSizeAxes = Axes.Both;
Children = new Drawable[] Children = new Drawable[]
{ {
text = new OsuSpriteText NormalText = new OsuSpriteText
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
TextSize = text_size, TextSize = text_size,
Text = Item.Text,
Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL },
}, },
textBold = new OsuSpriteText BoldText = new OsuSpriteText
{ {
AlwaysPresent = true, AlwaysPresent = true,
Alpha = 0, Alpha = 0,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
TextSize = text_size, TextSize = text_size,
Text = Item.Text,
Font = @"Exo2.0-Bold", Font = @"Exo2.0-Bold",
Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL }, Margin = new MarginPadding { Horizontal = margin_horizontal, Vertical = MARGIN_VERTICAL },
} }
}
}; };
} }
}
}
#endregion #endregion
} }
} }

View File

@ -81,8 +81,7 @@ namespace osu.Game.Graphics.UserInterface
{ {
public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>(); public readonly Bindable<Color4?> AccentColour = new Bindable<Color4?>();
private SpriteIcon chevron; private TextContainer textContainer;
protected OsuSpriteText Label;
private Color4 nonAccentHoverColour; private Color4 nonAccentHoverColour;
private Color4 nonAccentSelectedColour; private Color4 nonAccentSelectedColour;
@ -117,17 +116,32 @@ namespace osu.Game.Graphics.UserInterface
protected override void UpdateForegroundColour() protected override void UpdateForegroundColour()
{ {
base.UpdateForegroundColour(); base.UpdateForegroundColour();
chevron.Alpha = IsHovered ? 1 : 0;
textContainer.Chevron.Alpha = IsHovered ? 1 : 0;
} }
protected override Drawable CreateContent() => new FillFlowContainer protected override Drawable CreateContent() => textContainer = new TextContainer();
protected class TextContainer : FillFlowContainer, IHasText
{ {
Direction = FillDirection.Horizontal, public string Text
RelativeSizeAxes = Axes.X, {
AutoSizeAxes = Axes.Y, get { return Label.Text; }
set { Label.Text = value; }
}
public readonly OsuSpriteText Label;
public readonly SpriteIcon Chevron;
public TextContainer()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Direction = FillDirection.Horizontal;
Children = new Drawable[] Children = new Drawable[]
{ {
chevron = new SpriteIcon Chevron = new SpriteIcon
{ {
AlwaysPresent = true, AlwaysPresent = true,
Icon = FontAwesome.fa_chevron_right, Icon = FontAwesome.fa_chevron_right,
@ -140,13 +154,13 @@ namespace osu.Game.Graphics.UserInterface
}, },
Label = new OsuSpriteText Label = new OsuSpriteText
{ {
Text = Item.Text,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
} }
}
}; };
} }
}
}
#endregion #endregion
} }
#endregion #endregion

View File

@ -181,9 +181,9 @@ namespace osu.Game.Graphics.UserInterface
protected override DrawableMenuItem CreateDrawableMenuItem(DropdownMenuItem<T> item) protected override DrawableMenuItem CreateDrawableMenuItem(DropdownMenuItem<T> item)
{ {
var poop = new DrawableOsuTabDropdownMenuItem(this, item); var result = new DrawableOsuTabDropdownMenuItem(this, item);
poop.AccentColour.BindTo(AccentColour); result.AccentColour.BindTo(AccentColour);
return poop; return result;
} }
private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem private class DrawableOsuTabDropdownMenuItem : DrawableOsuDropdownMenuItem

View File

@ -316,9 +316,13 @@ namespace osu.Game.Overlays.Settings.Sections.General
: base(item) : base(item)
{ {
Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 10, Right = 5 }; Foreground.Padding = new MarginPadding { Top = 5, Bottom = 5, Left = 10, Right = 5 };
Label.Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 };
CornerRadius = 5; CornerRadius = 5;
} }
protected override Drawable CreateContent() => new TextContainer
{
Label = { Margin = new MarginPadding { Left = UserDropdownHeader.LABEL_LEFT_MARGIN - 11 } }
};
} }
} }