1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 06:32:55 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/TimeInfoContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

176 lines
5.7 KiB
C#
Raw Normal View History

// 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
2017-11-18 13:24:09 +08:00
using osu.Framework.Graphics;
using osu.Game.Graphics.Sprites;
2018-03-19 15:27:52 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
2022-05-25 22:30:53 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Edit.Components
{
public partial class TimeInfoContainer : BottomBarContainer
{
private OsuSpriteText bpm = null!;
2022-05-25 22:30:53 +08:00
[Resolved]
private EditorBeatmap editorBeatmap { get; set; } = null!;
2018-04-13 17:19:50 +08:00
2020-02-14 21:14:00 +08:00
[Resolved]
private EditorClock editorClock { get; set; } = null!;
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours, OverlayColourProvider colourProvider)
2017-11-18 13:24:09 +08:00
{
Background.Colour = colourProvider.Background5;
2017-11-18 13:24:09 +08:00
Children = new Drawable[]
{
new TimestampControl(),
bpm = new OsuSpriteText
{
Colour = colours.Orange1,
Anchor = Anchor.CentreLeft,
Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold),
Position = new Vector2(2, 4),
}
2017-11-18 13:24:09 +08:00
};
}
2018-04-13 17:19:50 +08:00
private double? lastBPM;
protected override void Update()
{
base.Update();
double newBPM = editorBeatmap.ControlPointInfo.TimingPointAt(editorClock.CurrentTime).BPM;
if (lastBPM != newBPM)
{
lastBPM = newBPM;
bpm.Text = @$"{newBPM:0} BPM";
}
}
private partial class TimestampControl : OsuClickableContainer
{
private Container hoverLayer = null!;
private OsuSpriteText trackTimer = null!;
private OsuTextBox inputTextBox = null!;
2024-06-18 18:33:12 +08:00
[Resolved]
private Editor? editor { get; set; }
[Resolved]
private EditorClock editorClock { get; set; } = null!;
public TimestampControl()
: base(HoverSampleSet.Button)
{
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
AddRangeInternal(new Drawable[]
{
hoverLayer = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Top = 4,
Bottom = 1,
Horizontal = -2
},
Child = new Container
{
RelativeSizeAxes = Axes.Both,
CornerRadius = 5,
Masking = true,
Children = new Drawable[]
{
new Box { RelativeSizeAxes = Axes.Both, },
}
},
Alpha = 0,
},
trackTimer = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Spacing = new Vector2(-2, 0),
Font = OsuFont.Torus.With(size: 32, fixedWidth: true, weight: FontWeight.Light),
},
inputTextBox = new TimestampTextBox
{
Position = new Vector2(-2, 4),
Width = 128,
Height = 26,
Alpha = 0,
CommitOnFocusLost = true,
},
});
Action = () =>
{
trackTimer.Alpha = 0;
inputTextBox.Alpha = 1;
inputTextBox.Text = editorClock.CurrentTime.ToEditorFormattedString();
Schedule(() =>
{
GetContainingFocusManager()!.ChangeFocus(inputTextBox);
inputTextBox.SelectAll();
});
};
2024-06-18 18:33:12 +08:00
inputTextBox.Current.BindValueChanged(val => editor?.HandleTimestamp(val.NewValue));
inputTextBox.OnCommit += (_, __) =>
{
trackTimer.Alpha = 1;
inputTextBox.Alpha = 0;
};
}
private double? lastTime;
private bool showingHoverLayer;
protected override void Update()
{
base.Update();
if (lastTime != editorClock.CurrentTime)
{
lastTime = editorClock.CurrentTime;
trackTimer.Text = editorClock.CurrentTime.ToEditorFormattedString();
}
bool shouldShowHoverLayer = IsHovered && inputTextBox.Alpha == 0;
if (shouldShowHoverLayer != showingHoverLayer)
{
hoverLayer.FadeTo(shouldShowHoverLayer ? 0.2f : 0, 400, Easing.OutQuint);
showingHoverLayer = shouldShowHoverLayer;
}
}
private partial class TimestampTextBox : OsuTextBox
{
public TimestampTextBox()
{
TextContainer.Height = 0.8f;
}
}
}
}
}