mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Make a base OsuButton class to handle default samples
This commit is contained in:
parent
ae48b85827
commit
af499df6dd
@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
Add(container = new ExampleContainer());
|
Add(container = new ExampleContainer());
|
||||||
|
|
||||||
AddStep(@"Add button", () => container.Add(new OsuButton
|
AddStep(@"Add button", () => container.Add(new TriangleButton
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Text = @"Button",
|
Text = @"Button",
|
||||||
|
@ -1,87 +1,22 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenTK.Graphics;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
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.Backgrounds;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
public class OsuButton : Button, IFilterable
|
/// <summary>
|
||||||
|
/// A button with added default sound effects.
|
||||||
|
/// </summary>
|
||||||
|
public class OsuButton : Button
|
||||||
{
|
{
|
||||||
private Box hover;
|
|
||||||
|
|
||||||
private SampleChannel sampleClick;
|
private SampleChannel sampleClick;
|
||||||
private SampleChannel sampleHover;
|
private SampleChannel sampleHover;
|
||||||
|
|
||||||
protected Triangles Triangles;
|
|
||||||
|
|
||||||
public OsuButton()
|
|
||||||
{
|
|
||||||
Height = 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override SpriteText CreateText() => new OsuSpriteText
|
|
||||||
{
|
|
||||||
Depth = -1,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Font = @"Exo2.0-Bold",
|
|
||||||
};
|
|
||||||
|
|
||||||
public override bool HandleInput => Action != null;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colours, AudioManager audio)
|
|
||||||
{
|
|
||||||
if (Action == null)
|
|
||||||
Colour = OsuColour.Gray(0.5f);
|
|
||||||
|
|
||||||
BackgroundColour = colours.BlueDark;
|
|
||||||
|
|
||||||
Content.Masking = true;
|
|
||||||
Content.CornerRadius = 5;
|
|
||||||
|
|
||||||
AddRange(new Drawable[]
|
|
||||||
{
|
|
||||||
Triangles = new Triangles
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
ColourDark = colours.BlueDarker,
|
|
||||||
ColourLight = colours.Blue,
|
|
||||||
},
|
|
||||||
hover = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Blending = BlendingMode.Additive,
|
|
||||||
Colour = Color4.White.Opacity(0.1f),
|
|
||||||
Alpha = 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
sampleClick = audio.Sample.Get(@"UI/generic-select");
|
|
||||||
sampleHover = audio.Sample.Get(@"UI/generic-hover");
|
|
||||||
|
|
||||||
Enabled.ValueChanged += enabled_ValueChanged;
|
|
||||||
Enabled.TriggerChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void enabled_ValueChanged(bool enabled)
|
|
||||||
{
|
|
||||||
this.FadeColour(enabled ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
sampleClick?.Play();
|
sampleClick?.Play();
|
||||||
@ -91,36 +26,14 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
sampleHover?.Play();
|
sampleHover?.Play();
|
||||||
hover.FadeIn(200);
|
|
||||||
return base.OnHover(state);
|
return base.OnHover(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours, AudioManager audio)
|
||||||
{
|
{
|
||||||
hover.FadeOut(200);
|
sampleClick = audio.Sample.Get(@"UI/generic-select");
|
||||||
base.OnHoverLost(state);
|
sampleHover = audio.Sample.Get(@"UI/generic-hover");
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
||||||
{
|
|
||||||
Content.ScaleTo(0.9f, 4000, Easing.OutQuint);
|
|
||||||
return base.OnMouseDown(state, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
||||||
{
|
|
||||||
Content.ScaleTo(1, 1000, Easing.OutElastic);
|
|
||||||
return base.OnMouseUp(state, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> FilterTerms => new[] { Text };
|
|
||||||
|
|
||||||
public bool MatchingFilter
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
this.FadeTo(value ? 1 : 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
111
osu.Game/Graphics/UserInterface/TriangleButton.cs
Normal file
111
osu.Game/Graphics/UserInterface/TriangleButton.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// 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.Collections.Generic;
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
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.Backgrounds;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics.UserInterface
|
||||||
|
{
|
||||||
|
public class TriangleButton : OsuButton, IFilterable
|
||||||
|
{
|
||||||
|
private Box hover;
|
||||||
|
|
||||||
|
protected Triangles Triangles;
|
||||||
|
|
||||||
|
public TriangleButton()
|
||||||
|
{
|
||||||
|
Height = 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override SpriteText CreateText() => new OsuSpriteText
|
||||||
|
{
|
||||||
|
Depth = -1,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Font = @"Exo2.0-Bold",
|
||||||
|
};
|
||||||
|
|
||||||
|
public override bool HandleInput => Action != null;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuColour colours, AudioManager audio)
|
||||||
|
{
|
||||||
|
if (Action == null)
|
||||||
|
Colour = OsuColour.Gray(0.5f);
|
||||||
|
|
||||||
|
BackgroundColour = colours.BlueDark;
|
||||||
|
|
||||||
|
Content.Masking = true;
|
||||||
|
Content.CornerRadius = 5;
|
||||||
|
|
||||||
|
AddRange(new Drawable[]
|
||||||
|
{
|
||||||
|
Triangles = new Triangles
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
ColourDark = colours.BlueDarker,
|
||||||
|
ColourLight = colours.Blue,
|
||||||
|
},
|
||||||
|
hover = new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Blending = BlendingMode.Additive,
|
||||||
|
Colour = Color4.White.Opacity(0.1f),
|
||||||
|
Alpha = 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Enabled.ValueChanged += enabled_ValueChanged;
|
||||||
|
Enabled.TriggerChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enabled_ValueChanged(bool enabled)
|
||||||
|
{
|
||||||
|
this.FadeColour(enabled ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(InputState state)
|
||||||
|
{
|
||||||
|
hover.FadeIn(200);
|
||||||
|
return base.OnHover(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(InputState state)
|
||||||
|
{
|
||||||
|
hover.FadeOut(200);
|
||||||
|
base.OnHoverLost(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
|
{
|
||||||
|
Content.ScaleTo(0.9f, 4000, Easing.OutQuint);
|
||||||
|
return base.OnMouseDown(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||||
|
{
|
||||||
|
Content.ScaleTo(1, 1000, Easing.OutElastic);
|
||||||
|
return base.OnMouseUp(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> FilterTerms => new[] { Text };
|
||||||
|
|
||||||
|
public bool MatchingFilter
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.FadeTo(value ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -55,7 +55,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ResetButton : OsuButton
|
public class ResetButton : TriangleButton
|
||||||
{
|
{
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
|
@ -12,9 +12,9 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
{
|
{
|
||||||
public class GeneralSettings : SettingsSubsection
|
public class GeneralSettings : SettingsSubsection
|
||||||
{
|
{
|
||||||
private OsuButton importButton;
|
private TriangleButton importButton;
|
||||||
private OsuButton deleteButton;
|
private TriangleButton deleteButton;
|
||||||
private OsuButton restoreButton;
|
private TriangleButton restoreButton;
|
||||||
|
|
||||||
protected override string Header => "General";
|
protected override string Header => "General";
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ using osu.Game.Graphics.UserInterface;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Settings
|
namespace osu.Game.Overlays.Settings
|
||||||
{
|
{
|
||||||
public class SettingsButton : OsuButton
|
public class SettingsButton : TriangleButton
|
||||||
{
|
{
|
||||||
public SettingsButton()
|
public SettingsButton()
|
||||||
{
|
{
|
||||||
|
@ -193,21 +193,21 @@ namespace osu.Game.Screens.Tournament
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuButton
|
new TriangleButton
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
|
||||||
Text = "Begin random",
|
Text = "Begin random",
|
||||||
Action = teamsContainer.StartScrolling,
|
Action = teamsContainer.StartScrolling,
|
||||||
},
|
},
|
||||||
new OsuButton
|
new TriangleButton
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
|
||||||
Text = "Stop random",
|
Text = "Stop random",
|
||||||
Action = teamsContainer.StopScrolling,
|
Action = teamsContainer.StopScrolling,
|
||||||
},
|
},
|
||||||
new OsuButton
|
new TriangleButton
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ namespace osu.Game.Screens.Tournament
|
|||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new OsuButton
|
new TriangleButton
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
|
||||||
|
@ -271,6 +271,7 @@
|
|||||||
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
|
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
|
||||||
<Compile Include="Database\DatabaseContextFactory.cs" />
|
<Compile Include="Database\DatabaseContextFactory.cs" />
|
||||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||||
|
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
||||||
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
|
<Compile Include="Migrations\20171019041408_InitialCreate.cs" />
|
||||||
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
|
<Compile Include="Migrations\20171019041408_InitialCreate.Designer.cs">
|
||||||
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>
|
<DependentUpon>20171019041408_InitialCreate.cs</DependentUpon>
|
||||||
@ -366,7 +367,7 @@
|
|||||||
<Compile Include="Graphics\UserInterface\LoadingAnimation.cs" />
|
<Compile Include="Graphics\UserInterface\LoadingAnimation.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
|
<Compile Include="Graphics\UserInterface\MenuItemType.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\Nub.cs" />
|
<Compile Include="Graphics\UserInterface\Nub.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuButton.cs" />
|
<Compile Include="Graphics\UserInterface\TriangleButton.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuCheckbox.cs" />
|
<Compile Include="Graphics\UserInterface\OsuCheckbox.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
|
<Compile Include="Graphics\UserInterface\OsuContextMenu.cs" />
|
||||||
<Compile Include="Graphics\UserInterface\OsuDropdown.cs" />
|
<Compile Include="Graphics\UserInterface\OsuDropdown.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user