mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Move replay button to score card
This commit is contained in:
@ -0,0 +1,49 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Users;
|
||||||
|
using osuTK;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestSceneReplayDownloadButton : OsuTestScene
|
||||||
|
{
|
||||||
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(ReplayDownloadButton)
|
||||||
|
};
|
||||||
|
|
||||||
|
private ReplayDownloadButton downloadButton;
|
||||||
|
|
||||||
|
public TestSceneReplayDownloadButton()
|
||||||
|
{
|
||||||
|
Add(new ReplayDownloadButton(getScoreInfo())
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoreInfo getScoreInfo()
|
||||||
|
{
|
||||||
|
return new APILegacyScoreInfo
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
OnlineScoreID = 2553163309,
|
||||||
|
Ruleset = new OsuRuleset().RulesetInfo,
|
||||||
|
Replay = true,
|
||||||
|
User = new User
|
||||||
|
{
|
||||||
|
Id = 39828,
|
||||||
|
Username = @"WubWoofWolf",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -54,6 +54,12 @@ namespace osu.Game.Online
|
|||||||
attachDownload(download);
|
attachDownload(download);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
manager.DownloadFailed += download =>
|
||||||
|
{
|
||||||
|
if (download.Model.Equals(Model.Value))
|
||||||
|
attachDownload(null);
|
||||||
|
};
|
||||||
|
|
||||||
manager.ItemAdded += itemAdded;
|
manager.ItemAdded += itemAdded;
|
||||||
manager.ItemRemoved += itemRemoved;
|
manager.ItemRemoved += itemRemoved;
|
||||||
}
|
}
|
||||||
@ -109,6 +115,9 @@ namespace osu.Game.Online
|
|||||||
if (!s.Equals(Model.Value))
|
if (!s.Equals(Model.Value))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// when model states are being updated from manager, update the model being held by us also so that it will
|
||||||
|
// be up do date when being consumed for reading files etc.
|
||||||
|
Model.Value = s;
|
||||||
State.Value = state;
|
State.Value = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,5 +64,7 @@ namespace osu.Game.Scoring
|
|||||||
public ScoreInfo Query(Expression<Func<ScoreInfo, bool>> query) => ModelStore.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
public ScoreInfo Query(Expression<Func<ScoreInfo, bool>> query) => ModelStore.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
||||||
|
|
||||||
protected override ArchiveDownloadRequest<ScoreInfo> CreateDownloadRequest(ScoreInfo score, bool minimiseDownload) => new DownloadReplayRequest(score);
|
protected override ArchiveDownloadRequest<ScoreInfo> CreateDownloadRequest(ScoreInfo score, bool minimiseDownload) => new DownloadReplayRequest(score);
|
||||||
|
|
||||||
|
protected override bool CheckLocalAvailability(ScoreInfo model, IQueryable<ScoreInfo> items) => items.Any(s => s.OnlineScoreID == model.OnlineScoreID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,55 +1,147 @@
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Cursor;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Online;
|
using osu.Game.Online;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
using osuTK;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Framework.Graphics.Effects;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
namespace osu.Game.Screens.Play
|
||||||
{
|
{
|
||||||
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
|
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>, IHasTooltip
|
||||||
{
|
{
|
||||||
[Resolved]
|
private const int size = 40;
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
private OsuGame game { get; set; }
|
private OsuGame game { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private ScoreManager scores { get; set; }
|
private ScoreManager scores { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
|
private OsuClickableContainer button;
|
||||||
|
private SpriteIcon downloadIcon;
|
||||||
|
private SpriteIcon playIcon;
|
||||||
|
private ShakeContainer shakeContainer;
|
||||||
|
|
||||||
|
public string TooltipText
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (scores.IsAvailableLocally(Model.Value))
|
||||||
|
return @"Watch replay";
|
||||||
|
|
||||||
|
if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay)
|
||||||
|
return @"Download replay";
|
||||||
|
|
||||||
|
return @"Replay unavailable";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ReplayDownloadButton(ScoreInfo score)
|
public ReplayDownloadButton(ScoreInfo score)
|
||||||
: base(score)
|
: base(score)
|
||||||
{
|
{
|
||||||
|
Size = new Vector2(size);
|
||||||
|
CornerRadius = size / 2;
|
||||||
|
Masking = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
private bool hasReplay => (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) || scores.IsAvailableLocally(Model.Value);
|
||||||
private void load(OsuColour colours)
|
|
||||||
{
|
|
||||||
AddInternal(new TwoLayerButton
|
|
||||||
{
|
|
||||||
BackgroundColour = colours.Yellow,
|
|
||||||
Icon = FontAwesome.Solid.PlayCircle,
|
|
||||||
Text = @"Replay",
|
|
||||||
HoverColour = colours.YellowDark,
|
|
||||||
Action = onReplay,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onReplay()
|
[BackgroundDependencyLoader(true)]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
if (scores.IsAvailableLocally(Model.Value))
|
EdgeEffect = new EdgeEffectParameters
|
||||||
{
|
{
|
||||||
game.PresentScore(Model.Value);
|
Colour = Color4.Black.Opacity(0.4f),
|
||||||
return;
|
Type = EdgeEffectType.Shadow,
|
||||||
}
|
Radius = 5,
|
||||||
|
|
||||||
scores.Download(Model.Value);
|
|
||||||
|
|
||||||
scores.ItemAdded += score =>
|
|
||||||
{
|
|
||||||
if (score.Equals(Model.Value))
|
|
||||||
// use the newly added score instead of ModelInfo.Score because that won't have the Files property populated
|
|
||||||
game.PresentScore(score);
|
|
||||||
//ReplayLoaded?.Invoke(scores.GetScore(score));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
InternalChild = shakeContainer = new ShakeContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = button = new OsuClickableContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = colours.GrayF,
|
||||||
|
},
|
||||||
|
playIcon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.Solid.Play,
|
||||||
|
Size = Vector2.Zero,
|
||||||
|
Colour = colours.Gray3,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
downloadIcon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Icon = FontAwesome.Solid.FileDownload,
|
||||||
|
Size = Vector2.Zero,
|
||||||
|
Colour = colours.Gray3,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
button.Action = () =>
|
||||||
|
{
|
||||||
|
switch (State.Value)
|
||||||
|
{
|
||||||
|
case DownloadState.LocallyAvailable:
|
||||||
|
game.PresentScore(Model.Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DownloadState.NotDownloaded:
|
||||||
|
scores.Download(Model.Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DownloadState.Downloading:
|
||||||
|
shakeContainer.Shake();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
State.BindValueChanged(state =>
|
||||||
|
{
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case DownloadState.Downloading:
|
||||||
|
FadeEdgeEffectTo(colours.Yellow, 400, Easing.OutQuint);
|
||||||
|
button.Enabled.Value = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DownloadState.LocallyAvailable:
|
||||||
|
playIcon.ResizeTo(13, 300, Easing.OutQuint);
|
||||||
|
downloadIcon.ResizeTo(Vector2.Zero, 300, Easing.OutExpo);
|
||||||
|
FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
|
||||||
|
button.Enabled.Value = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DownloadState.NotDownloaded:
|
||||||
|
playIcon.ResizeTo(Vector2.Zero, 300, Easing.OutQuint);
|
||||||
|
downloadIcon.ResizeTo(13, 300, Easing.OutExpo);
|
||||||
|
FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
|
||||||
|
button.Enabled.Value = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,23 +20,6 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
if (scores.IsAvailableLocally(Score) || hasOnlineReplay)
|
|
||||||
{
|
|
||||||
AddInternal(new ReplayDownloadButton(Score)
|
|
||||||
{
|
|
||||||
Anchor = Framework.Graphics.Anchor.BottomRight,
|
|
||||||
Origin = Framework.Graphics.Anchor.BottomRight,
|
|
||||||
Height = 80,
|
|
||||||
Width = 100,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool hasOnlineReplay => Score is APILegacyScoreInfo apiScore && apiScore.OnlineScoreID != null && apiScore.Replay;
|
|
||||||
|
|
||||||
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new IResultPageInfo[]
|
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new IResultPageInfo[]
|
||||||
{
|
{
|
||||||
new ScoreOverviewPageInfo(Score, Beatmap.Value),
|
new ScoreOverviewPageInfo(Score, Beatmap.Value),
|
||||||
|
@ -33,9 +33,12 @@ namespace osu.Game.Screens.Ranking.Pages
|
|||||||
private Container scoreContainer;
|
private Container scoreContainer;
|
||||||
private ScoreCounter scoreCounter;
|
private ScoreCounter scoreCounter;
|
||||||
|
|
||||||
|
private readonly ScoreInfo score;
|
||||||
|
|
||||||
public ScoreResultsPage(ScoreInfo score, WorkingBeatmap beatmap)
|
public ScoreResultsPage(ScoreInfo score, WorkingBeatmap beatmap)
|
||||||
: base(score, beatmap)
|
: base(score, beatmap)
|
||||||
{
|
{
|
||||||
|
this.score = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FillFlowContainer<DrawableScoreStatistic> statisticsContainer;
|
private FillFlowContainer<DrawableScoreStatistic> statisticsContainer;
|
||||||
@ -163,9 +166,15 @@ namespace osu.Game.Screens.Ranking.Pages
|
|||||||
Direction = FillDirection.Horizontal,
|
Direction = FillDirection.Horizontal,
|
||||||
LayoutDuration = 200,
|
LayoutDuration = 200,
|
||||||
LayoutEasing = Easing.OutQuint
|
LayoutEasing = Easing.OutQuint
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
|
new ReplayDownloadButton(score)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.BottomCentre,
|
||||||
|
Origin = Anchor.BottomCentre,
|
||||||
|
Margin = new MarginPadding { Bottom = 10 },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
statisticsContainer.ChildrenEnumerable = Score.Statistics.OrderByDescending(p => p.Key).Select(s => new DrawableScoreStatistic(s));
|
statisticsContainer.ChildrenEnumerable = Score.Statistics.OrderByDescending(p => p.Key).Select(s => new DrawableScoreStatistic(s));
|
||||||
|
Reference in New Issue
Block a user