2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-01-07 15:38:49 +08:00
|
|
|
|
using System.Linq;
|
2020-08-06 16:18:45 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2021-02-25 14:38:56 +08:00
|
|
|
|
using osu.Framework.Extensions.EnumExtensions;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-09-03 15:29:15 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-11-08 13:55:26 +08:00
|
|
|
|
using osu.Framework.Input;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2021-01-13 15:53:04 +08:00
|
|
|
|
using osu.Game.Database;
|
2021-02-22 16:14:00 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-01 13:22:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-08-06 16:17:24 +08:00
|
|
|
|
public abstract class ToolbarButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-08-06 16:17:24 +08:00
|
|
|
|
protected GlobalAction? Hotkey { get; set; }
|
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
public void SetIcon(Drawable icon)
|
|
|
|
|
{
|
|
|
|
|
IconContainer.Icon = icon;
|
|
|
|
|
IconContainer.Show();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-09-03 15:28:53 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private TextureStore textures { get; set; }
|
|
|
|
|
|
2021-11-08 13:55:26 +08:00
|
|
|
|
[Resolved]
|
2021-11-08 17:24:37 +08:00
|
|
|
|
private ReadableKeyCombinationProvider keyCombinationProvider { get; set; }
|
2021-11-08 13:55:26 +08:00
|
|
|
|
|
2020-09-03 15:28:53 +08:00
|
|
|
|
public void SetIcon(string texture) =>
|
|
|
|
|
SetIcon(new Sprite
|
|
|
|
|
{
|
|
|
|
|
Texture = textures.Get(texture),
|
|
|
|
|
});
|
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString Text
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => DrawableText.Text;
|
|
|
|
|
set => DrawableText.Text = value;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString TooltipMain
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => tooltip1.Text;
|
|
|
|
|
set => tooltip1.Text = value;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString TooltipSub
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => tooltip2.Text;
|
|
|
|
|
set => tooltip2.Text = value;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-10 15:26:43 +08:00
|
|
|
|
protected virtual Anchor TooltipAnchor => Anchor.TopLeft;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-08-03 13:36:21 +08:00
|
|
|
|
protected ConstrainedIconContainer IconContainer;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
protected SpriteText DrawableText;
|
|
|
|
|
protected Box HoverBackground;
|
2020-06-15 13:16:17 +08:00
|
|
|
|
private readonly Box flashBackground;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly FillFlowContainer tooltipContainer;
|
|
|
|
|
private readonly SpriteText tooltip1;
|
|
|
|
|
private readonly SpriteText tooltip2;
|
2020-08-06 16:18:45 +08:00
|
|
|
|
private readonly SpriteText keyBindingTooltip;
|
2017-03-02 02:33:01 +08:00
|
|
|
|
protected FillFlowContainer Flow;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-08-06 16:18:45 +08:00
|
|
|
|
[Resolved]
|
2022-01-24 18:59:58 +08:00
|
|
|
|
private RealmAccess realm { get; set; }
|
2020-08-06 16:18:45 +08:00
|
|
|
|
|
2020-08-06 16:06:51 +08:00
|
|
|
|
protected ToolbarButton()
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-09-03 15:29:15 +08:00
|
|
|
|
Width = Toolbar.HEIGHT;
|
2017-02-08 19:14:17 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
HoverBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-06-15 13:02:21 +08:00
|
|
|
|
Colour = OsuColour.Gray(80).Opacity(180),
|
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2020-06-15 13:16:17 +08:00
|
|
|
|
flashBackground = new Box
|
2020-06-15 13:02:21 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-06-15 15:14:35 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Colour = Color4.White.Opacity(100),
|
2019-08-21 12:29:50 +08:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Flow = new FillFlowContainer
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Spacing = new Vector2(5),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-02-08 19:14:17 +08:00
|
|
|
|
Padding = new MarginPadding { Left = Toolbar.HEIGHT / 2, Right = Toolbar.HEIGHT / 2 },
|
2016-10-12 11:22:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
IconContainer = new ConstrainedIconContainer
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2020-09-03 15:29:15 +08:00
|
|
|
|
Size = new Vector2(26),
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Alpha = 0,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
|
DrawableText = new OsuSpriteText
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
2016-10-04 18:41:18 +08:00
|
|
|
|
},
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
2017-03-02 02:33:01 +08:00
|
|
|
|
tooltipContainer = new FillFlowContainer
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2020-05-05 09:31:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both, // stops us being considered in parent's autosize
|
2021-02-25 14:38:56 +08:00
|
|
|
|
Anchor = TooltipAnchor.HasFlagFast(Anchor.x0) ? Anchor.BottomLeft : Anchor.BottomRight,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Origin = TooltipAnchor,
|
2021-02-25 14:38:56 +08:00
|
|
|
|
Position = new Vector2(TooltipAnchor.HasFlagFast(Anchor.x0) ? 5 : -5, 5),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Alpha = 0,
|
2020-08-06 16:18:45 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2017-01-31 17:53:52 +08:00
|
|
|
|
tooltip1 = new OsuSpriteText
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Anchor = TooltipAnchor,
|
|
|
|
|
Origin = TooltipAnchor,
|
2016-11-23 10:35:31 +08:00
|
|
|
|
Shadow = true,
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 22, weight: FontWeight.Bold),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
2020-08-06 16:18:45 +08:00
|
|
|
|
new FillFlowContainer
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2020-08-06 16:18:45 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-02-10 15:26:43 +08:00
|
|
|
|
Anchor = TooltipAnchor,
|
|
|
|
|
Origin = TooltipAnchor,
|
2020-08-06 16:18:45 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
tooltip2 = new OsuSpriteText { Shadow = true },
|
|
|
|
|
keyBindingTooltip = new OsuSpriteText { Shadow = true }
|
|
|
|
|
}
|
2016-10-12 11:22:19 +08:00
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-06-15 15:14:35 +08:00
|
|
|
|
flashBackground.FadeOutFromOne(800, Easing.OutQuint);
|
2019-03-01 07:43:04 +08:00
|
|
|
|
tooltipContainer.FadeOut(100);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnClick(e);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-08-06 17:22:17 +08:00
|
|
|
|
updateKeyBindingTooltip();
|
|
|
|
|
|
2020-06-15 13:02:21 +08:00
|
|
|
|
HoverBackground.FadeIn(200);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
tooltipContainer.FadeIn(100);
|
2021-06-22 17:26:42 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnHover(e);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2020-06-15 13:02:21 +08:00
|
|
|
|
HoverBackground.FadeOut(200);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
tooltipContainer.FadeOut(100);
|
|
|
|
|
}
|
2020-08-06 16:17:24 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2020-08-06 16:17:24 +08:00
|
|
|
|
{
|
2022-04-03 21:24:00 +08:00
|
|
|
|
if (e.Action == Hotkey && !e.Repeat)
|
2020-08-06 16:17:24 +08:00
|
|
|
|
{
|
2021-08-04 16:27:44 +08:00
|
|
|
|
TriggerClick();
|
2020-08-06 16:17:24 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2020-08-06 16:17:24 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2021-01-13 15:53:04 +08:00
|
|
|
|
|
|
|
|
|
private void updateKeyBindingTooltip()
|
|
|
|
|
{
|
2021-06-22 17:26:42 +08:00
|
|
|
|
if (Hotkey == null) return;
|
|
|
|
|
|
2022-01-24 18:59:58 +08:00
|
|
|
|
var realmKeyBinding = realm.Realm.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value);
|
2021-06-22 17:26:42 +08:00
|
|
|
|
|
2021-01-13 15:53:04 +08:00
|
|
|
|
if (realmKeyBinding != null)
|
|
|
|
|
{
|
2021-11-08 17:24:37 +08:00
|
|
|
|
string keyBindingString = keyCombinationProvider.GetReadableString(realmKeyBinding.KeyCombination);
|
2021-01-13 15:53:04 +08:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(keyBindingString))
|
|
|
|
|
keyBindingTooltip.Text = $" ({keyBindingString})";
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-01 17:53:13 +08:00
|
|
|
|
public class OpaqueBackground : Container
|
|
|
|
|
{
|
|
|
|
|
public OpaqueBackground()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-12-01 20:12:37 +08:00
|
|
|
|
Masking = true;
|
2017-02-04 21:09:44 +08:00
|
|
|
|
MaskingSmoothness = 0;
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-01-30 21:16:17 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
|
Radius = 5,
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-01 17:53:13 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-01-13 05:38:27 +08:00
|
|
|
|
Colour = OsuColour.Gray(30)
|
2016-12-01 17:53:13 +08:00
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-04 21:09:44 +08:00
|
|
|
|
ColourLight = OsuColour.Gray(40),
|
|
|
|
|
ColourDark = OsuColour.Gray(20),
|
2016-12-01 17:53:13 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-26 01:41:18 +08:00
|
|
|
|
}
|