Skip to content

Commit

Permalink
Merge pull request #409 from DrabWeb/popup-dialog
Browse files Browse the repository at this point in the history
Popup dialog
  • Loading branch information
peppy authored Mar 2, 2017
2 parents 66cea49 + 963117f commit ffd6560
Show file tree
Hide file tree
Showing 17 changed files with 607 additions and 43 deletions.
80 changes: 80 additions & 0 deletions osu.Desktop.VisualTests/Tests/TestCaseDialogOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using osu.Framework.Graphics;
using osu.Framework.Screens.Testing;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;

namespace osu.Desktop.VisualTests.Tests
{
class TestCaseDialogOverlay : TestCase
{
public override string Name => @"Dialog Overlay";
public override string Description => @"Display dialogs";

DialogOverlay overlay;

public override void Reset()
{
base.Reset();

Add(overlay = new DialogOverlay());

AddButton("dialog #1", () => overlay.Push(new PopupDialog
{
Icon = FontAwesome.fa_trash_o,
HeaderText = @"Confirm deletion of",
BodyText = @"Ayase Rie - Yuima-ru*World TVver.",
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"I never want to see this again.",
Action = () => System.Console.WriteLine(@"OK"),
},
new PopupDialogCancelButton
{
Text = @"Firetruck, I still want quick ranks!",
Action = () => System.Console.WriteLine(@"Cancel"),
},
},
}));

AddButton("dialog #2", () => overlay.Push(new PopupDialog
{
Icon = FontAwesome.fa_gear,
HeaderText = @"What do you want to do with",
BodyText = "Camellia as \"Bang Riot\" - Blastix Riotz",
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Manage collections",
},
new PopupDialogOkButton
{
Text = @"Delete...",
},
new PopupDialogOkButton
{
Text = @"Remove from unplayed",
},
new PopupDialogOkButton
{
Text = @"Clear local scores",
},
new PopupDialogOkButton
{
Text = @"Edit",
},
new PopupDialogCancelButton
{
Text = @"Cancel",
},
},
}));
}
}
}
1 change: 1 addition & 0 deletions osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<Compile Include="Platform\TestStorage.cs" />
<Compile Include="Tests\TestCaseOptions.cs" />
<Compile Include="Tests\TestCasePauseOverlay.cs" />
<Compile Include="Tests\TestCaseDialogOverlay.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;

namespace osu.Game.Overlays.Pause
namespace osu.Game.Graphics.UserInterface
{
public class PauseButton : ClickableContainer
public class DialogButton : ClickableContainer
{
private const float hover_width = 0.9f;
private const float hover_duration = 500;
private const float glow_fade_duration = 250;
private const float click_duration = 200;

private Color4 backgroundColour = OsuColour.Gray(34);

private Color4 buttonColour;
public Color4 ButtonColour
{
Expand All @@ -35,8 +33,21 @@ public Color4 ButtonColour
{
buttonColour = value;
updateGlow();
if (colourContainer == null) return;
colourContainer.Colour = ButtonColour;
colourContainer.Colour = value;
}
}

private Color4 backgroundColour = OsuColour.Gray(34);
public Color4 BackgroundColour
{
get
{
return backgroundColour;
}
set
{
backgroundColour = value;
background.Colour = value;
}
}

Expand All @@ -50,16 +61,30 @@ public string Text
set
{
text = value;
if (spriteText == null) return;
spriteText.Text = Text;
}
}

private float textSize = 28;
internal float TextSize
{
get
{
return textSize;
}
set
{
textSize = value;
spriteText.TextSize = value;
}
}

public SampleChannel SampleClick, SampleHover;

private Container backgroundContainer, colourContainer, glowContainer;
private Box leftGlow, centerGlow, rightGlow;
private Box leftGlow, centerGlow, rightGlow, background;
private SpriteText spriteText;
private Vector2 hoverSpacing => new Vector2(3f, 0f);

private bool didClick; // Used for making sure that the OnMouseDown animation can call instead of OnHoverLost's when clicking

Expand All @@ -85,8 +110,9 @@ protected override bool OnClick(Framework.Input.InputState state)

protected override bool OnHover(Framework.Input.InputState state)
{
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, EasingTypes.OutElastic);

colourContainer.ResizeTo(new Vector2(hover_width, 1f), hover_duration, EasingTypes.OutElastic);
spriteText.TransformSpacingTo(new Vector2(3f, 0f), hover_duration, EasingTypes.OutElastic);
glowContainer.FadeIn(glow_fade_duration, EasingTypes.Out);
SampleHover?.Play();
return true;
Expand Down Expand Up @@ -127,8 +153,10 @@ private void updateGlow()
rightGlow.ColourInfo = ColourInfo.GradientHorizontal(ButtonColour, new Color4(ButtonColour.R, ButtonColour.G, ButtonColour.B, 0f));
}

public PauseButton()
public DialogButton()
{
RelativeSizeAxes = Axes.X;

Children = new Drawable[]
{
backgroundContainer = new Container
Expand All @@ -137,12 +165,12 @@ public PauseButton()
Width = 1f,
Children = new Drawable[]
{
new Box
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = backgroundColour
}
}
Colour = backgroundColour,
},
},
},
glowContainer = new Container
{
Expand All @@ -156,23 +184,23 @@ public PauseButton()
RelativeSizeAxes = Axes.Both,
Origin = Anchor.TopLeft,
Anchor = Anchor.TopLeft,
Width = 0.125f
Width = 0.125f,
},
centerGlow = new Box
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Width = 0.75f
Width = 0.75f,
},
rightGlow = new Box
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Width = 0.125f
}
}
Width = 0.125f,
},
},
},
new Container
{
Expand All @@ -194,7 +222,7 @@ public PauseButton()
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.2f),
Radius = 5
Radius = 5,
},
Colour = ButtonColour,
Shear = new Vector2(0.2f, 0),
Expand All @@ -203,7 +231,7 @@ public PauseButton()
new Box
{
EdgeSmoothness = new Vector2(2, 0),
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
},
new Container
{
Expand All @@ -217,13 +245,13 @@ public PauseButton()
RelativeSizeAxes = Axes.Both,
TriangleScale = 4,
ColourDark = OsuColour.Gray(0.88f),
Shear = new Vector2(-0.2f, 0)
}
}
Shear = new Vector2(-0.2f, 0),
},
},
},
}
}
}
},
},
},
},
spriteText = new OsuSpriteText
{
Expand All @@ -234,8 +262,8 @@ public PauseButton()
Font = "Exo2.0-Bold",
Shadow = true,
ShadowColour = new Color4(0, 0, 0, 0.1f),
Colour = Color4.White
}
Colour = Color4.White,
},
};

updateGlow();
Expand Down
8 changes: 8 additions & 0 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class OsuGame : OsuGameBase

private NotificationManager notificationManager;

private DialogOverlay dialogOverlay;

private Intro intro
{
get
Expand Down Expand Up @@ -142,6 +144,11 @@ protected override void LoadComplete()
Origin = Anchor.TopRight,
}).LoadAsync(this, overlayContent.Add);

(dialogOverlay = new DialogOverlay
{
Depth = -4,
}).LoadAsync(this, overlayContent.Add);

Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Important) return;
Expand All @@ -155,6 +162,7 @@ protected override void LoadComplete()
Dependencies.Cache(options);
Dependencies.Cache(musicController);
Dependencies.Cache(notificationManager);
Dependencies.Cache(dialogOverlay);

(Toolbar = new Toolbar
{
Expand Down
Loading

0 comments on commit ffd6560

Please sign in to comment.