1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Add OsuClickableContainer with generic sounds

This commit is contained in:
Dean Herbert 2017-06-27 21:05:49 +09:00
parent e6818a45be
commit 480cdba023
18 changed files with 68 additions and 56 deletions

View File

@ -0,0 +1,35 @@
// 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.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
namespace osu.Game.Graphics.Containers
{
public class OsuClickableContainer : ClickableContainer
{
public SampleChannel SampleClick, SampleHover;
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
SampleHover = audio.Sample.Get(@"UI/generic-hover");
SampleClick = audio.Sample.Get(@"UI/generic-click");
}
protected override bool OnHover(InputState state)
{
SampleHover?.Play();
return base.OnHover(state);
}
protected override bool OnClick(InputState state)
{
SampleClick?.Play();
return base.OnClick(state);
}
}
}

View File

@ -20,7 +20,6 @@ namespace osu.Game.Graphics.UserInterface
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
{
ActivationSound = audio.Sample.Get(@"Menu/menuback");
BackgroundColour = colours.Pink;
HoverColour = colours.PinkDark;
}

View File

@ -8,14 +8,14 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Containers;
using osu.Framework.Audio.Sample;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Graphics.Containers;
namespace osu.Game.Graphics.UserInterface
{
public class DialogButton : ClickableContainer
public class DialogButton : OsuClickableContainer
{
private const float hover_width = 0.9f;
private const float hover_duration = 500;
@ -79,8 +79,6 @@ namespace osu.Game.Graphics.UserInterface
}
}
public SampleChannel SampleClick, SampleHover;
private readonly Container backgroundContainer;
private readonly Container colourContainer;
private readonly Container glowContainer;
@ -100,8 +98,6 @@ namespace osu.Game.Graphics.UserInterface
didClick = true;
colourContainer.ResizeTo(new Vector2(1.5f, 1f), click_duration, EasingTypes.In);
flash();
SampleClick?.Play();
Action?.Invoke();
Delay(click_duration);
Schedule(delegate {
@ -110,7 +106,7 @@ namespace osu.Game.Graphics.UserInterface
glowContainer.FadeOut();
});
return true;
return base.OnClick(state);
}
protected override bool OnHover(Framework.Input.InputState state)
@ -119,7 +115,7 @@ namespace osu.Game.Graphics.UserInterface
colourContainer.ResizeTo(new Vector2(hover_width, 1f), hover_duration, EasingTypes.OutElastic);
glowContainer.FadeIn(glow_fade_duration, EasingTypes.Out);
SampleHover?.Play();
base.OnHover(state);
return true;
}

View File

@ -9,10 +9,11 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Graphics.Containers;
namespace osu.Game.Graphics.UserInterface
{
public class IconButton : ClickableContainer
public class IconButton : OsuClickableContainer
{
private readonly TextAwesome icon;
private readonly Box hover;

View File

@ -18,7 +18,7 @@ using osu.Framework.Graphics.Shapes;
namespace osu.Game.Graphics.UserInterface
{
public class TwoLayerButton : ClickableContainer
public class TwoLayerButton : OsuClickableContainer
{
private readonly BouncingIcon bouncingIcon;
@ -32,7 +32,6 @@ namespace osu.Game.Graphics.UserInterface
public static readonly Vector2 SIZE_EXTENDED = new Vector2(140, 50);
public static readonly Vector2 SIZE_RETRACTED = new Vector2(100, 50);
public SampleChannel ActivationSound;
private readonly SpriteText text;
public Color4 HoverColour;
@ -210,8 +209,6 @@ namespace osu.Game.Graphics.UserInterface
flash.FadeOut(500, EasingTypes.OutQuint);
flash.Expire();
ActivationSound.Play();
return base.OnClick(state);
}

View File

@ -16,6 +16,7 @@ using osu.Framework.Graphics.Textures;
using System.Linq;
using osu.Framework.Input;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Direct
{
@ -151,7 +152,7 @@ namespace osu.Game.Overlays.Direct
};
}
private class DownloadButton : ClickableContainer
private class DownloadButton : OsuClickableContainer
{
private readonly TextAwesome icon;

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.SearchableList;
namespace osu.Game.Overlays.Direct
@ -42,7 +43,7 @@ namespace osu.Game.Overlays.Direct
}
}
private class RulesetToggleButton : ClickableContainer
private class RulesetToggleButton : OsuClickableContainer
{
private readonly TextAwesome icon;

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Notifications
{
@ -152,7 +153,7 @@ namespace osu.Game.Overlays.Notifications
Expire();
}
private class CloseButton : ClickableContainer
private class CloseButton : OsuClickableContainer
{
private Color4 hoverColour;

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Notifications
{
@ -131,7 +132,7 @@ namespace osu.Game.Overlays.Notifications
countText.Text = notifications.Children.Count(c => c.Alpha > 0.99f).ToString();
}
private class ClearAllButton : ClickableContainer
private class ClearAllButton : OsuClickableContainer
{
private readonly OsuSpriteText text;

View File

@ -6,6 +6,7 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.SearchableList
{
@ -52,7 +53,7 @@ namespace osu.Game.Overlays.SearchableList
DisplayStyle.Value = PanelDisplayStyle.Grid;
}
private class DisplayStyleToggleButton : ClickableContainer
private class DisplayStyleToggleButton : OsuClickableContainer
{
private readonly TextAwesome icon;
private readonly PanelDisplayStyle style;

View File

@ -1,10 +1,8 @@
// 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;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -16,10 +14,11 @@ using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarButton : Container
public class ToolbarButton : OsuClickableContainer
{
public const float WIDTH = Toolbar.HEIGHT * 1.4f;
@ -58,7 +57,6 @@ namespace osu.Game.Overlays.Toolbar
protected virtual Anchor TooltipAnchor => Anchor.TopLeft;
public Action Action;
protected TextAwesome DrawableIcon;
protected SpriteText DrawableText;
protected Box HoverBackground;
@ -66,7 +64,6 @@ namespace osu.Game.Overlays.Toolbar
private readonly SpriteText tooltip1;
private readonly SpriteText tooltip2;
protected FillFlowContainer Flow;
private SampleChannel sampleClick;
public ToolbarButton()
{
@ -136,27 +133,19 @@ namespace osu.Game.Overlays.Toolbar
};
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleClick = audio.Sample.Get(@"Menu/menuclick");
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
protected override bool OnClick(InputState state)
{
Action?.Invoke();
sampleClick.Play();
HoverBackground.FlashColour(Color4.White.Opacity(100), 500, EasingTypes.OutQuint);
return true;
return base.OnClick(state);
}
protected override bool OnHover(InputState state)
{
HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100);
return false;
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)

View File

@ -11,13 +11,14 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Multiplayer;
using osu.Game.Users;
namespace osu.Game.Screens.Multiplayer
{
public class DrawableRoom : ClickableContainer
public class DrawableRoom : OsuClickableContainer
{
private const float content_padding = 5;
private const float height = 90;

View File

@ -191,12 +191,6 @@ namespace osu.Game.Screens.Play
public class Button : DialogButton
{
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
SampleHover = audio.Sample.Get(@"Menu/menuclick");
SampleClick = audio.Sample.Get(@"Menu/menuback");
}
}
}
}

View File

@ -16,8 +16,8 @@ using osu.Game.Screens.Ranking;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Play
{
@ -175,16 +175,14 @@ namespace osu.Game.Screens.Play
}
}
private class Button : Container
private class Button : OsuClickableContainer
{
public Action Action;
private Color4 colourNormal;
private Color4 colourHover;
private Box box;
private FillFlowContainer flow;
private Box background;
private AspectContainer aspect;
private SampleChannel activationSound;
public Button()
{
@ -194,8 +192,6 @@ namespace osu.Game.Screens.Play
[BackgroundDependencyLoader]
private void load(OsuColour colours, AudioManager audio)
{
activationSound = audio.Sample.Get(@"Menu/menuhit");
colourNormal = colours.Yellow;
colourHover = colours.YellowDark;
@ -282,13 +278,9 @@ namespace osu.Game.Screens.Play
protected override bool OnClick(InputState state)
{
Action?.Invoke();
activationSound.Play();
box.FlashColour(Color4.White, 500, EasingTypes.OutQuint);
aspect.ScaleTo(1.2f, 2000, EasingTypes.OutQuint);
return true;
return base.OnClick(state);
}
}
}

View File

@ -6,15 +6,15 @@ using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select
{
public class FooterButton : ClickableContainer
public class FooterButton : OsuClickableContainer
{
private static readonly Vector2 shearing = new Vector2(0.15f, 0);

View File

@ -13,10 +13,11 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Users;
using osu.Framework;
using osu.Game.Rulesets.Scoring;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select.Leaderboards
{
public class LeaderboardScore : ClickableContainer, IStateful<Visibility>
public class LeaderboardScore : OsuClickableContainer, IStateful<Visibility>
{
public static readonly float HEIGHT = 60;

View File

@ -11,10 +11,11 @@ using osu.Game.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsButton : ClickableContainer
public class BeatmapOptionsButton : OsuClickableContainer
{
private const float width = 130;

View File

@ -76,6 +76,7 @@
<Compile Include="Audio\SampleInfoList.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
<Compile Include="Graphics\Containers\OsuClickableContainer.cs" />
<Compile Include="Graphics\Cursor\OsuContextMenuContainer.cs" />
<Compile Include="Graphics\UserInterface\IconButton.cs" />
<Compile Include="Configuration\SelectionRandomType.cs" />