-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
229 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
45 changes: 45 additions & 0 deletions
45
Renako.Game.Tests/Visual/Drawables/TestSceneGameplayProgressBar.cs
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using NUnit.Framework; | ||
using osu.Framework.Allocation; | ||
using Renako.Game.Beatmaps; | ||
using Renako.Game.Graphics.Drawables; | ||
|
||
namespace Renako.Game.Tests.Visual.Drawables; | ||
|
||
public partial class TestSceneGameplayProgressBar : GameDrawableTestScene | ||
{ | ||
[Cached] | ||
private BeatmapsCollection beatmapsCollection = new BeatmapsCollection(); | ||
|
||
[Cached] | ||
private WorkingBeatmap workingBeatmap = new WorkingBeatmap(); | ||
|
||
private GameplayProgressBar gameplayProgressBar; | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
beatmapsCollection.GenerateTestCollection(); | ||
workingBeatmap.BeatmapSet = beatmapsCollection.BeatmapSets.Find(set => set.ID == 1); | ||
workingBeatmap.Beatmap = beatmapsCollection.Beatmaps.Find(beatmap => beatmap.ID == 1); | ||
} | ||
|
||
[Test] | ||
public void TestGameplayProgressBar() | ||
{ | ||
AddStep("add gameplay progress bar", () => Add(gameplayProgressBar = new GameplayProgressBar())); | ||
AddStep("set total time", () => gameplayProgressBar.SetTotalTime(workingBeatmap.BeatmapSet.TotalLength)); | ||
AddStep("start track", () => AudioManager.Track.Start()); | ||
AddStep("set current time", () => gameplayProgressBar.SetCurrentTime(AudioManager.Track.CurrentTime)); | ||
AddStep("seek to 100s", () => AudioManager.Track.Seek(100000)); | ||
} | ||
|
||
protected override void Update() | ||
{ | ||
base.Update(); | ||
|
||
if (AudioManager.Track.IsRunning) | ||
{ | ||
gameplayProgressBar.SetCurrentTime(AudioManager.Track.CurrentTime); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
|
||
namespace Renako.Game.Graphics.Drawables; | ||
|
||
public partial class GameplayProgressBar : CompositeDrawable | ||
{ | ||
private RenakoSpriteText currentTime; | ||
private RenakoSpriteText totalTime; | ||
private double totalTimeValue; | ||
private Container progressBar; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
Anchor = Anchor.BottomCentre; | ||
Origin = Anchor.BottomCentre; | ||
RelativeSizeAxes = Axes.X; | ||
Width = 0.85f; | ||
Height = 15; | ||
Y = -20; | ||
InternalChildren = new Drawable[] | ||
{ | ||
new Container() | ||
{ | ||
Anchor = Anchor.BottomCentre, | ||
Origin = Anchor.BottomCentre, | ||
RelativeSizeAxes = Axes.Both, | ||
Width = 0.9f, | ||
Children = new Drawable[] | ||
{ | ||
new Container() | ||
{ | ||
Masking = true, | ||
CornerRadius = 10, | ||
RelativeSizeAxes = Axes.Both, | ||
Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = Colour4.Gray | ||
} | ||
} | ||
}, | ||
progressBar = new Container() | ||
{ | ||
Masking = true, | ||
CornerRadius = 10, | ||
RelativeSizeAxes = Axes.Both, | ||
Width = 0f, | ||
Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = Colour4.White | ||
} | ||
} | ||
}, | ||
} | ||
}, | ||
currentTime = new RenakoSpriteText() | ||
{ | ||
Anchor = Anchor.CentreLeft, | ||
Origin = Anchor.CentreLeft, | ||
Font = RenakoFont.GetFont(RenakoFont.Typeface.JosefinSans, 25), | ||
Text = "0:00" | ||
}, | ||
totalTime = new RenakoSpriteText() | ||
{ | ||
Anchor = Anchor.CentreRight, | ||
Origin = Anchor.CentreRight, | ||
Font = RenakoFont.GetFont(RenakoFont.Typeface.JosefinSans, 25), | ||
Text = "0:00" | ||
} | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Set the total time of the progress bar in milliseconds. | ||
/// </summary> | ||
/// <param name="time">The total time in milliseconds.</param> | ||
public void SetTotalTime(double time) | ||
{ | ||
totalTime.Text = TimeSpan.FromMilliseconds(time).ToString(@"m\:ss"); | ||
totalTimeValue = time; | ||
} | ||
|
||
/// <summary> | ||
/// Set the current time of the progress bar in milliseconds. | ||
/// </summary> | ||
/// <param name="time">The current time in milliseconds.</param> | ||
public void SetCurrentTime(double time) | ||
{ | ||
currentTime.Text = TimeSpan.FromMilliseconds(time).ToString(@"m\:ss"); | ||
if (totalTimeValue == 0) | ||
return; | ||
|
||
progressBar.ResizeWidthTo((float)(time / totalTimeValue), 500, Easing.OutQuint); | ||
} | ||
} |
This file contains 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 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.