mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 11:42:56 +08:00
---changing---
This commit is contained in:
parent
eda0e99179
commit
d04893a43a
@ -32,8 +32,8 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
Spacing = new Vector2(0,10),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TooltipContainer("Text with some tooltip"),
|
||||
new TooltipContainer("and another one with a custom delay")
|
||||
new TooltipTextContainer("Text with some tooltip"),
|
||||
new TooltipTextContainer("and another one with a custom delay")
|
||||
{
|
||||
TooltipDelay = 1000,
|
||||
},
|
||||
@ -57,15 +57,15 @@ namespace osu.Desktop.VisualTests.Tests
|
||||
});
|
||||
}
|
||||
|
||||
private class TooltipContainer : Container, IHasTooltipWithCustomDelay
|
||||
private class TooltipTextContainer : Container, IHasTooltipWithCustomDelay
|
||||
{
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public string TooltipText => text.Text;
|
||||
|
||||
public int TooltipDelay { get; set; } = Tooltip.DEFAULT_APPEAR_DELAY;
|
||||
public int TooltipDelay { get; set; } = TooltipContainer.DEFAULT_APPEAR_DELAY;
|
||||
|
||||
public TooltipContainer(string tooltipText)
|
||||
public TooltipTextContainer(string tooltipText)
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Children = new[]
|
||||
|
@ -20,12 +20,6 @@ namespace osu.Game.Graphics.Cursor
|
||||
protected override Drawable CreateCursor() => new Cursor();
|
||||
|
||||
private bool dragging;
|
||||
private readonly Tooltip tooltip;
|
||||
|
||||
public MenuCursor()
|
||||
{
|
||||
Add(tooltip = new Tooltip());
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(InputState state)
|
||||
{
|
||||
@ -43,9 +37,6 @@ namespace osu.Game.Graphics.Cursor
|
||||
ActiveCursor.RotateTo(degrees, 600, EasingTypes.OutQuint);
|
||||
}
|
||||
|
||||
tooltip.Position = new Vector2(state.Mouse.Position.X,Math.Min(ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + ActiveCursor.DrawHeight));
|
||||
tooltip.MouseState = state.Mouse;
|
||||
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
@ -107,7 +98,7 @@ namespace osu.Game.Graphics.Cursor
|
||||
|
||||
public Cursor()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
Size = new Vector2(42);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -1,113 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public class Tooltip : Container
|
||||
{
|
||||
private readonly Box tooltipBackground;
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
private ScheduledDelegate show;
|
||||
private UserInputManager input;
|
||||
private IHasDisappearingTooltip disappearingTooltip;
|
||||
|
||||
public const int DEFAULT_APPEAR_DELAY = 250;
|
||||
|
||||
public string TooltipText {
|
||||
get
|
||||
{
|
||||
return text.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
text.Text = value;
|
||||
if (string.IsNullOrEmpty(value))
|
||||
Hide();
|
||||
else
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
public IMouseState MouseState
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false)
|
||||
{
|
||||
show?.Cancel();
|
||||
TooltipText = string.Empty;
|
||||
IHasTooltip hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||
if (hasTooltip != null)
|
||||
{
|
||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
||||
show = Scheduler.AddDelayed(() => TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Tooltip()
|
||||
{
|
||||
AlwaysPresent = true;
|
||||
Children = new[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
CornerRadius = 5,
|
||||
Masking = true,
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(40),
|
||||
Radius = 5,
|
||||
},
|
||||
Children = new Drawable[]
|
||||
{
|
||||
tooltipBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Padding = new MarginPadding(3),
|
||||
Font = @"Exo2.0-Regular",
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour, UserInputManager input)
|
||||
{
|
||||
this.input = input;
|
||||
tooltipBackground.Colour = colour.Gray3;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (disappearingTooltip?.Disappear == false)
|
||||
TooltipText = disappearingTooltip.TooltipText;
|
||||
else if (disappearingTooltip != null)
|
||||
{
|
||||
disappearingTooltip = null;
|
||||
TooltipText = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
130
osu.Game/Graphics/Cursor/TooltipContainer.cs
Normal file
130
osu.Game/Graphics/Cursor/TooltipContainer.cs
Normal file
@ -0,0 +1,130 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Graphics.Cursor
|
||||
{
|
||||
public class TooltipContainer : Container
|
||||
{
|
||||
private readonly CursorContainer cursor;
|
||||
private readonly Tooltip tooltip;
|
||||
|
||||
private ScheduledDelegate show;
|
||||
private UserInputManager input;
|
||||
private IHasDisappearingTooltip disappearingTooltip;
|
||||
|
||||
public const int DEFAULT_APPEAR_DELAY = 250;
|
||||
|
||||
public IMouseState MouseState
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value.Position != value.LastPosition && disappearingTooltip?.Disappear != false)
|
||||
{
|
||||
show?.Cancel();
|
||||
tooltip.TooltipText = string.Empty;
|
||||
IHasTooltip hasTooltip = input.HoveredDrawables.OfType<IHasTooltip>().FirstOrDefault();
|
||||
if (hasTooltip != null)
|
||||
{
|
||||
IHasTooltipWithCustomDelay delayedTooltip = hasTooltip as IHasTooltipWithCustomDelay;
|
||||
disappearingTooltip = hasTooltip as IHasDisappearingTooltip;
|
||||
show = Scheduler.AddDelayed(() => tooltip.TooltipText = hasTooltip.TooltipText, delayedTooltip?.TooltipDelay ?? DEFAULT_APPEAR_DELAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TooltipContainer(CursorContainer cursor)
|
||||
{
|
||||
this.cursor = cursor;
|
||||
AlwaysPresent = true;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour, UserInputManager input)
|
||||
{
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
if (disappearingTooltip?.Disappear == false)
|
||||
tooltip.TooltipText = disappearingTooltip.TooltipText;
|
||||
else if (disappearingTooltip != null)
|
||||
{
|
||||
disappearingTooltip = null;
|
||||
tooltip.TooltipText = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(InputState state)
|
||||
{
|
||||
Position = new Vector2(state.Mouse.Position.X, Math.Min(cursor.ActiveCursor.BoundingBox.Bottom, state.Mouse.Position.Y + cursor.ActiveCursor.DrawHeight));
|
||||
return base.OnMouseMove(state);
|
||||
}
|
||||
|
||||
public class Tooltip : Container
|
||||
{
|
||||
private readonly Box tooltipBackground;
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
public string TooltipText
|
||||
{
|
||||
set
|
||||
{
|
||||
text.Text = value;
|
||||
if (string.IsNullOrEmpty(value))
|
||||
Hide();
|
||||
else
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
public Tooltip()
|
||||
{
|
||||
|
||||
AutoSizeAxes = Axes.Both;
|
||||
CornerRadius = 5;
|
||||
Masking = true;
|
||||
EdgeEffect = new EdgeEffect
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Colour = Color4.Black.Opacity(40),
|
||||
Radius = 5,
|
||||
};
|
||||
Children = new Drawable[]
|
||||
{
|
||||
tooltipBackground = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
text = new OsuSpriteText
|
||||
{
|
||||
Padding = new MarginPadding(3),
|
||||
Font = @"Exo2.0-Regular",
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
{
|
||||
tooltipBackground.Colour = colour.Gray3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -98,7 +98,7 @@
|
||||
<Compile Include="Graphics\UserInterface\OsuTextBox.cs" />
|
||||
<Compile Include="Graphics\UserInterface\SimpleComboCounter.cs" />
|
||||
<Compile Include="Graphics\UserInterface\TwoLayerButton.cs" />
|
||||
<Compile Include="Graphics\Cursor\Tooltip.cs" />
|
||||
<Compile Include="Graphics\Cursor\TooltipContainer.cs" />
|
||||
<Compile Include="Input\Handlers\ReplayInputHandler.cs" />
|
||||
<Compile Include="IO\Legacy\ILegacySerializable.cs" />
|
||||
<Compile Include="IO\Legacy\SerializationReader.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user