-
Notifications
You must be signed in to change notification settings - Fork 95
Change toolbar buttons tooltips to be more visible #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
210 changes: 205 additions & 5 deletions
210
PerformanceCalculatorGUI/Components/ScreenSelectionButton.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,221 @@ | ||
| // 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. | ||
|
|
||
| using osu.Framework.Extensions.Color4Extensions; | ||
| using osu.Framework.Graphics; | ||
| using osu.Framework.Graphics.Containers; | ||
| using osu.Framework.Graphics.Cursor; | ||
| using osu.Framework.Graphics.Effects; | ||
| using osu.Framework.Graphics.Shapes; | ||
| using osu.Framework.Graphics.Sprites; | ||
| using osu.Framework.Input.Bindings; | ||
| using osu.Framework.Input.Events; | ||
| using osu.Game.Graphics; | ||
| using osu.Game.Graphics.Containers; | ||
| using osu.Game.Graphics.Sprites; | ||
| using osu.Game.Graphics.UserInterface; | ||
| using osu.Game.Input.Bindings; | ||
| using osu.Game.Overlays.Toolbar; | ||
| using osuTK; | ||
| using osuTK.Graphics; | ||
|
|
||
| namespace PerformanceCalculatorGUI.Components | ||
| { | ||
| public partial class ScreenSelectionButton : ToolbarButton | ||
| public partial class ScreenSelectionButton : OsuClickableContainer, IKeyBindingHandler<GlobalAction>, IHasCustomTooltip<(string, GlobalAction?)> | ||
| { | ||
| private readonly string title; | ||
| private readonly GlobalAction? hotkey; | ||
|
|
||
| private const float padding = 3; | ||
|
|
||
| private readonly Box hoverBackground; | ||
| private readonly Box flashBackground; | ||
|
|
||
| public ScreenSelectionButton(string title, IconUsage? icon = null, GlobalAction? hotkey = null) | ||
| { | ||
| Hotkey = hotkey; | ||
| TooltipMain = title; | ||
| this.title = title; | ||
| this.hotkey = hotkey; | ||
|
|
||
| AutoSizeAxes = Axes.X; | ||
| RelativeSizeAxes = Axes.Y; | ||
|
|
||
| Children = new Drawable[] | ||
| { | ||
| new Container | ||
| { | ||
| Width = PerformanceCalculatorSceneManager.CONTROL_AREA_HEIGHT, | ||
| RelativeSizeAxes = Axes.Y, | ||
| Padding = new MarginPadding(padding), | ||
| Children = new Drawable[] | ||
| { | ||
| new Container | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Masking = true, | ||
| CornerRadius = 6, | ||
| CornerExponent = 3f, | ||
| Children = new Drawable[] | ||
| { | ||
| hoverBackground = new Box | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Colour = OsuColour.Gray(80).Opacity(180), | ||
| Blending = BlendingParameters.Additive, | ||
| Alpha = 0 | ||
| }, | ||
| flashBackground = new Box | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Alpha = 0, | ||
| Colour = Color4.White.Opacity(100), | ||
| Blending = BlendingParameters.Additive | ||
| } | ||
| } | ||
| }, | ||
| new FillFlowContainer | ||
| { | ||
| Direction = FillDirection.Horizontal, | ||
| Anchor = Anchor.TopCentre, | ||
| Origin = Anchor.TopCentre, | ||
| Padding = new MarginPadding { Horizontal = PerformanceCalculatorSceneManager.CONTROL_AREA_HEIGHT / 2 }, | ||
| RelativeSizeAxes = Axes.Y, | ||
| AutoSizeAxes = Axes.X, | ||
| Children = new Drawable[] | ||
| { | ||
| new ConstrainedIconContainer | ||
| { | ||
| Anchor = Anchor.CentreLeft, | ||
| Origin = Anchor.CentreLeft, | ||
| Size = new Vector2(25), | ||
| Icon = new ScreenSelectionButtonIcon(icon) { IconSize = new Vector2(20) } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| protected override bool OnMouseDown(MouseDownEvent e) => false; | ||
|
|
||
| protected override bool OnClick(ClickEvent e) | ||
| { | ||
| flashBackground.FadeIn(50).Then().FadeOutFromOne(800, Easing.OutQuint); | ||
| return base.OnClick(e); | ||
| } | ||
|
|
||
| protected override bool OnHover(HoverEvent e) | ||
| { | ||
| hoverBackground.FadeIn(300, Easing.OutQuint); | ||
| return true; | ||
| } | ||
|
|
||
| protected override void OnHoverLost(HoverLostEvent e) | ||
| { | ||
| hoverBackground.FadeOut(200, Easing.Out); | ||
| } | ||
|
|
||
| public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) | ||
| { | ||
| if (e.Action == hotkey && !e.Repeat) | ||
| { | ||
| TriggerClick(); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) | ||
| { | ||
| } | ||
|
|
||
| public ITooltip<(string, GlobalAction?)> GetCustomTooltip() | ||
| { | ||
| return new ScreenSelectionButtonTooltip(); | ||
| } | ||
|
|
||
| public (string, GlobalAction?) TooltipContent => (title, hotkey); | ||
|
|
||
| public partial class ScreenSelectionButtonTooltip : VisibilityContainer, ITooltip<(string, GlobalAction?)> | ||
| { | ||
| private (string, GlobalAction?)? currentData; | ||
|
|
||
| private readonly FillFlowContainer subTooltipFlow; | ||
| private readonly OsuSpriteText text; | ||
|
|
||
| public ScreenSelectionButtonTooltip() | ||
| { | ||
| AutoSizeAxes = Axes.Both; | ||
| Masking = true; | ||
| CornerRadius = 5; | ||
|
|
||
| EdgeEffect = new EdgeEffectParameters | ||
| { | ||
| Type = EdgeEffectType.Shadow, | ||
| Colour = Color4.Black.Opacity(0.2f), | ||
| Radius = 10f | ||
| }; | ||
|
|
||
| Children = new Drawable[] | ||
| { | ||
| new Box | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Colour = OsuColour.Gray(0.1f) | ||
| }, | ||
| new FillFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Padding = new MarginPadding(8f), | ||
| Direction = FillDirection.Vertical, | ||
| Spacing = new Vector2(5), | ||
| Children = new Drawable[] | ||
| { | ||
| text = new OsuSpriteText | ||
| { | ||
| Anchor = Anchor.TopLeft, | ||
| Origin = Anchor.TopLeft, | ||
| Shadow = true, | ||
| Font = OsuFont.GetFont(size: 18, weight: FontWeight.Bold) | ||
| }, | ||
| subTooltipFlow = new FillFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Anchor = Anchor.TopLeft, | ||
| Origin = Anchor.TopLeft, | ||
| Direction = FillDirection.Horizontal | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| protected override void PopIn() => this.FadeIn(300, Easing.OutQuint); | ||
| protected override void PopOut() => this.FadeOut(200, Easing.Out); | ||
|
|
||
| public void SetContent((string, GlobalAction?) data) | ||
| { | ||
| if (currentData == data) | ||
| return; | ||
|
|
||
| currentData = data; | ||
| subTooltipFlow.Clear(); | ||
|
|
||
| text.Text = data.Item1; | ||
|
|
||
| if (data.Item2 != null) | ||
| { | ||
| subTooltipFlow.Add(new HotkeyDisplay | ||
| { | ||
| Anchor = Anchor.BottomLeft, | ||
| Origin = Anchor.BottomLeft, | ||
| Hotkey = new Hotkey(data.Item2.Value), | ||
| Margin = new MarginPadding { Left = 3 } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| SetIcon(new ScreenSelectionButtonIcon(icon) { IconSize = new Vector2(25) }); | ||
| public void Move(Vector2 pos) => Position = pos; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this hotkey stuff actually used in this project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Settings can be opened using ctrl+o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like a lot of faff to be inlining for one usage most people already know, dunno.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but I do want to add screen switching hotkeys at some point too and those definitely will need a tooltip