Skip to content

Commit

Permalink
Merge branch 'gameplay-component'
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloYeew committed Aug 14, 2024
2 parents c626cd1 + 9ba0dbb commit afefbbb
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Renako.Game.Tests/Renako.Game.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ProjectReference Include="..\Renako.Game\Renako.Game.csproj" />
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions Renako.Game.Tests/Visual/Drawables/TestSceneGameplayProgressBar.cs
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);
}
}
}
5 changes: 5 additions & 0 deletions Renako.Game.Tests/Visual/GameDrawableTestScene.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using osu.Framework.Allocation;
using Renako.Game.Audio;
using Renako.Game.Graphics.ScreenStacks;

namespace Renako.Game.Tests.Visual;
Expand All @@ -20,12 +21,16 @@ public partial class GameDrawableTestScene : RenakoTestScene
[Cached]
public readonly SettingsScreenStack SettingsScreenStack = new SettingsScreenStack();

[Cached]
public readonly RenakoAudioManager AudioManager = new RenakoAudioManager();

[BackgroundDependencyLoader]
private void load()
{
Add(BackgroundScreenStack);
Add(MainScreenStack);
Add(LogoScreenStack);
Add(SettingsScreenStack);
Add(AudioManager);
}
}
8 changes: 8 additions & 0 deletions Renako.Game/Beatmaps/BeatmapsCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public void GenerateTestCollection()
Beatmaps = beatmapTestUtility.Beatmaps;
}

/// <summary>
/// Sort all <see cref="BeatmapSets"/> by ID.
/// </summary>
public void SortBeatmapSetsByID()
{
BeatmapSets = BeatmapSets.OrderBy(e => e.ID).ToList();
}

private void addThemeSongBeatmapSet()
{
// TODO: Get proper Title, Artist and Source translated from source
Expand Down
1 change: 1 addition & 0 deletions Renako.Game/Configurations/RenakoConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected override void InitialiseDefaults()
SetDefault(RenakoSetting.DisableVideoPreview, false);

SetDefault(RenakoSetting.ShowFPSCounter, false);
SetDefault(RenakoSetting.HardwareAcceleration, true);

// Game state
SetDefault(RenakoSetting.LatestBeatmapSetID, 0);
Expand Down
1 change: 1 addition & 0 deletions Renako.Game/Configurations/RenakoSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum RenakoSetting
DisableVideoPreview,

ShowFPSCounter,
HardwareAcceleration,

LatestBeatmapSetID,
LatestBeatmapID,
Expand Down
14 changes: 14 additions & 0 deletions Renako.Game/Graphics/Containers/PlayfieldContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public partial class PlayfieldContainer : Container
private RenakoSpriteText breakText;
private RenakoSpriteText hitText;
private RenakoSpriteText missText;
private RenakoSpriteText comboText;
private RenakoSpriteText clockText;

private const int fade_in_time = move_time / 2;
Expand Down Expand Up @@ -147,6 +148,12 @@ private void load(TextureStore textureStore, WorkingBeatmap workingBeatmap)
Origin = Anchor.TopRight,
Text = "Miss: 0"
},
comboText = new RenakoSpriteText()
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Text = "Combo: 0"
},
clockText = new RenakoSpriteText()
{
Anchor = Anchor.TopRight,
Expand All @@ -171,6 +178,7 @@ protected override void Update()
Logger.Log($"Missed note at {note.EndTime}", LoggingTarget.Runtime, LogLevel.Debug);
note.IsHit = true;
stats.Miss++;
stats.Combo = 0;
addHitResultAnimation(HitResult.Miss);
updateScoreText();
}
Expand Down Expand Up @@ -354,21 +362,25 @@ private void processHit(NoteLane lane)
if (diff < 50)
{
stats.Critical++;
stats.Combo++;
addHitResultAnimation(HitResult.Critical);
}
else if (diff < 100)
{
stats.Break++;
stats.Combo++;
addHitResultAnimation(HitResult.Break);
}
else if (diff < 200)
{
stats.Hit++;
stats.Combo++;
addHitResultAnimation(HitResult.Hit);
}
else
{
stats.Miss++;
stats.Combo = 0;
addHitResultAnimation(HitResult.Miss);
playHitAnimation = false;
}
Expand All @@ -391,6 +403,7 @@ private void updateScoreText()
breakText.Text = $"Break: {stats.Break}";
hitText.Text = $"Hit: {stats.Hit}";
missText.Text = $"Miss: {stats.Miss}";
comboText.Text = $"Combo: {stats.Combo}";
}

private enum HitResult
Expand Down Expand Up @@ -421,6 +434,7 @@ private class Statistics
public int Break { get; set; } // More than 50ms but less than 100ms
public int Hit { get; set; } // More than 100ms but less than 200ms
public int Miss { get; set; } // More than 200ms
public int Combo { get; set; } // Count of critical, break, and hit
}

private class PlayfieldNote
Expand Down
8 changes: 8 additions & 0 deletions Renako.Game/Graphics/Containers/SettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ private void load(RenakoConfigManager renakoConfigManager, FrameworkConfigManage
Current = renakoConfigManager.GetBindable<bool>(RenakoSetting.ShowFPSCounter)
},
new SpriteText()
{
Text = "Enable Hardware Acceleration"
},
new BasicCheckbox()
{
Current = renakoConfigManager.GetBindable<bool>(RenakoSetting.HardwareAcceleration)
},
new SpriteText()
{
Text = "FPS Limit"
},
Expand Down
105 changes: 105 additions & 0 deletions Renako.Game/Graphics/Drawables/GameplayProgressBar.cs
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);
}
}
28 changes: 23 additions & 5 deletions Renako.Game/Graphics/Screens/PlayablePlayfieldScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Renako.Game.Beatmaps;
using Renako.Game.Configurations;
using Renako.Game.Graphics.Containers;
using Renako.Game.Graphics.Drawables;
using Renako.Game.Graphics.ScreenStacks;

namespace Renako.Game.Graphics.Screens;
Expand All @@ -22,19 +23,23 @@ namespace Renako.Game.Graphics.Screens;
public partial class PlayablePlayfieldScreen : PlayfieldScreen
{
private PlayfieldContainer playfieldContainer;
private GameplayProgressBar progressBar;

private readonly StopwatchClock stopwatchClock = new StopwatchClock();
private readonly StopwatchClock playfieldClock = new StopwatchClock();

[Resolved]
private RenakoAudioManager audioManager { get; set; }

[Resolved]
private RenakoBackgroundScreenStack backgroundScreenStack { get; set; }

[Resolved]
private WorkingBeatmap workingBeatmap { get; set; }

[BackgroundDependencyLoader]
private void load(RenakoConfigManager configManager, RenakoBackgroundScreenStack backgroundScreenStack)
{
AddInternal(playfieldContainer = new PlayfieldContainer(stopwatchClock)
AddInternal(playfieldContainer = new PlayfieldContainer(playfieldClock)
{
RelativeSizeAxes = Axes.Both
});
Expand Down Expand Up @@ -106,6 +111,9 @@ private void load(RenakoConfigManager configManager, RenakoBackgroundScreenStack
Margin = new MarginPadding(20)
});

AddInternal(progressBar = new GameplayProgressBar());
progressBar.SetTotalTime(workingBeatmap.BeatmapSet.TotalLength);

backgroundScreenStack.AdjustMaskAlpha(configManager.Get<int>(RenakoSetting.PlayfieldBackgroundDim) / 100f);
}

Expand All @@ -117,9 +125,13 @@ protected override void LoadComplete()
audioManager.Track?.Restart();
audioManager.Track?.Seek(0);
audioManager.Track?.Start();
stopwatchClock.Start();
backgroundScreenStack.SeekBackgroundVideo(0f);
backgroundScreenStack.ShowBackgroundVideo();
playfieldClock.Start();
if (workingBeatmap.BeatmapSet.HasVideo)
{
backgroundScreenStack.SeekBackgroundVideo(0f);
backgroundScreenStack.ShowBackgroundVideo();
}
}, 2000);

if (audioManager.Track != null)
Expand All @@ -132,6 +144,12 @@ protected override void LoadComplete()
base.LoadComplete();
}

protected override void Update()
{
base.Update();
progressBar.SetCurrentTime(playfieldClock.CurrentTime);
}

protected override bool OnKeyDown(KeyDownEvent e)
{
switch (e.Key)
Expand Down
2 changes: 1 addition & 1 deletion Renako.Game/Renako.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<ProjectReference Include="..\Renako.Resources\Renako.Resources.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework" Version="2024.528.1" />
<PackageReference Include="ppy.osu.Framework" Version="2024.716.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit afefbbb

Please sign in to comment.