1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 05:22:54 +08:00

Merge remote-tracking branch 'origin/master' into sorcerer-diffcalc-changes

This commit is contained in:
smoogipoo 2019-03-19 17:29:19 +09:00
commit 94340608d4
54 changed files with 507 additions and 300 deletions

View File

@ -23,16 +23,9 @@ namespace osu.Game.Rulesets.Catch.Difficulty
protected override int SectionLength => 750;
private readonly float halfCatchWidth;
public CatchDifficultyCalculator(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap)
{
var catcher = new CatcherArea.Catcher(beatmap.BeatmapInfo.BaseDifficulty);
halfCatchWidth = catcher.CatchWidth * 0.5f;
// We're only using 80% of the catcher's width to simulate imperfect gameplay.
halfCatchWidth *= 0.8f;
}
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
@ -54,6 +47,14 @@ namespace osu.Game.Rulesets.Catch.Difficulty
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate)
{
float halfCatchWidth;
using (var catcher = new CatcherArea.Catcher(beatmap.BeatmapInfo.BaseDifficulty))
{
halfCatchWidth = catcher.CatchWidth * 0.5f;
halfCatchWidth *= 0.8f; // We're only using 80% of the catcher's width to simulate imperfect gameplay.
}
CatchHitObject lastObject = null;
foreach (var hitObject in beatmap.HitObjects.OfType<CatchHitObject>())

View File

@ -15,77 +15,100 @@ namespace osu.Game.Rulesets.Catch.Mods
public override double ScoreMultiplier => 1.12;
public override bool Ranked => true;
private float lastStartX;
private int lastStartTime;
private float? lastPosition;
private double lastStartTime;
public void ApplyToHitObject(HitObject hitObject)
{
if (!(hitObject is Fruit))
return;
var catchObject = (CatchHitObject)hitObject;
float position = catchObject.X;
int startTime = (int)hitObject.StartTime;
double startTime = hitObject.StartTime;
if (lastStartX == 0)
if (lastPosition == null)
{
lastStartX = position;
lastPosition = position;
lastStartTime = startTime;
return;
}
float diff = lastStartX - position;
int timeDiff = startTime - lastStartTime;
float positionDiff = position - lastPosition.Value;
double timeDiff = startTime - lastStartTime;
if (timeDiff > 1000)
{
lastStartX = position;
lastPosition = position;
lastStartTime = startTime;
return;
}
if (diff == 0)
if (positionDiff == 0)
{
bool right = RNG.NextBool();
float rand = Math.Min(20, (float)RNG.NextDouble(0, timeDiff / 4d)) / CatchPlayfield.BASE_WIDTH;
if (right)
{
if (position + rand <= 1)
position += rand;
else
position -= rand;
}
else
{
if (position - rand >= 0)
position -= rand;
else
position += rand;
}
applyRandomOffset(ref position, timeDiff / 4d);
catchObject.X = position;
return;
}
if (Math.Abs(diff) < timeDiff / 3d)
{
if (diff > 0)
{
if (position - diff > 0)
position -= diff;
}
else
{
if (position - diff < 1)
position -= diff;
}
}
if (Math.Abs(positionDiff * CatchPlayfield.BASE_WIDTH) < timeDiff / 3d)
applyOffset(ref position, positionDiff);
catchObject.X = position;
lastStartX = position;
lastPosition = position;
lastStartTime = startTime;
}
/// <summary>
/// Applies a random offset in a random direction to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="maxOffset">The maximum offset, cannot exceed 20px.</param>
private void applyRandomOffset(ref float position, double maxOffset)
{
bool right = RNG.NextBool();
float rand = Math.Min(20, (float)RNG.NextDouble(0, maxOffset)) / CatchPlayfield.BASE_WIDTH;
if (right)
{
// Clamp to the right bound
if (position + rand <= 1)
position += rand;
else
position -= rand;
}
else
{
// Clamp to the left bound
if (position - rand >= 0)
position -= rand;
else
position += rand;
}
}
/// <summary>
/// Applies an offset to a position, ensuring that the final position remains within the boundary of the playfield.
/// </summary>
/// <param name="position">The position which the offset should be applied to.</param>
/// <param name="amount">The amount to offset by.</param>
private void applyOffset(ref float position, float amount)
{
if (amount > 0)
{
// Clamp to the right bound
if (position + amount < 1)
position += amount;
}
else
{
// Clamp to the left bound
if (position + amount > 0)
position += amount;
}
}
}
}

View File

@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.Catch.UI
if (lastPlateableFruit.IsLoaded)
action();
else
lastPlateableFruit.OnLoadComplete = _ => action();
lastPlateableFruit.OnLoadComplete += _ => action();
}
if (result.IsHit && fruit.CanBePlated)

View File

@ -2,16 +2,31 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Game.Online.API;
using osu.Game.Screens.Menu;
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
public class TestCaseDisclaimer : ScreenTestCase
{
[Cached(typeof(IAPIProvider))]
private readonly DummyAPIAccess api = new DummyAPIAccess();
[BackgroundDependencyLoader]
private void load()
{
LoadScreen(new Disclaimer());
AddStep("load disclaimer", () => LoadScreen(new Disclaimer()));
AddStep("toggle support", () =>
{
api.LocalUser.Value = new User
{
Username = api.LocalUser.Value.Username,
Id = api.LocalUser.Value.Id,
IsSupporter = !api.LocalUser.Value.IsSupporter,
};
});
}
}
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual
}
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[BackgroundDependencyLoader]
private void load()

View File

@ -22,7 +22,7 @@ namespace osu.Game.Tests.Visual
private BeatmapManager beatmaps { get; set; }
[BackgroundDependencyLoader]
private void load(OsuGameBase osu, APIAccess api, RulesetStore rulesets)
private void load(OsuGameBase osu, IAPIProvider api, RulesetStore rulesets)
{
Bindable<BeatmapInfo> beatmapBindable = new Bindable<BeatmapInfo>();

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual
public class TestCaseUserProfile : OsuTestCase
{
private readonly TestUserProfileOverlay profile;
private APIAccess api;
private IAPIProvider api;
public override IReadOnlyList<Type> RequiredTypes => new[]
{
@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
}

View File

@ -64,7 +64,7 @@ namespace osu.Game.Beatmaps
private readonly BeatmapStore beatmaps;
private readonly APIAccess api;
private readonly IAPIProvider api;
private readonly AudioManager audioManager;
@ -72,7 +72,7 @@ namespace osu.Game.Beatmaps
private readonly List<DownloadBeatmapSetRequest> currentDownloads = new List<DownloadBeatmapSetRequest>();
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, APIAccess api, AudioManager audioManager, GameHost host = null,
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, AudioManager audioManager, GameHost host = null,
WorkingBeatmap defaultBeatmap = null)
: base(storage, contextFactory, new BeatmapStore(contextFactory), host)
{

View File

@ -51,7 +51,7 @@ namespace osu.Game.Beatmaps.Drawables
drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill;
drawable.OnLoadComplete = d => d.FadeInFromZero(400);
drawable.OnLoadComplete += d => d.FadeInFromZero(400);
return drawable;
}

View File

@ -67,16 +67,19 @@ namespace osu.Game.Beatmaps.Drawables
if (beatmapSet != null)
{
BeatmapSetCover cover;
Add(displayedCover = new DelayedLoadWrapper(
new BeatmapSetCover(beatmapSet, coverType)
cover = new BeatmapSetCover(beatmapSet, coverType)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out),
})
);
cover.OnLoadComplete += d => d.FadeInFromZero(400, Easing.Out);
}
}
}

View File

@ -22,7 +22,7 @@ namespace osu.Game.Online.API
private readonly OsuConfigManager config;
private readonly OAuth authentication;
public string Endpoint = @"https://osu.ppy.sh";
public string Endpoint => @"https://osu.ppy.sh";
private const string client_id = @"5";
private const string client_secret = @"FGc9GAtyHzeQDshWP5Ah7dega8hJACAJpQtw6OXk";

View File

@ -61,9 +61,12 @@ namespace osu.Game.Online.API
private Action pendingFailure;
public void Perform(APIAccess api)
public void Perform(IAPIProvider api)
{
API = api;
if (!(api is APIAccess apiAccess))
throw new NotSupportedException($"A {nameof(APIAccess)} is required to perform requests.");
API = apiAccess;
if (checkAndScheduleFailure())
return;
@ -71,7 +74,7 @@ namespace osu.Game.Online.API
WebRequest = CreateWebRequest();
WebRequest.Failed += Fail;
WebRequest.AllowRetryOnTimeout = false;
WebRequest.AddHeader("Authorization", $"Bearer {api.AccessToken}");
WebRequest.AddHeader("Authorization", $"Bearer {API.AccessToken}");
if (checkAndScheduleFailure())
return;
@ -85,7 +88,7 @@ namespace osu.Game.Online.API
if (checkAndScheduleFailure())
return;
api.Schedule(delegate { Success?.Invoke(); });
API.Schedule(delegate { Success?.Invoke(); });
}
public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled"));

View File

@ -11,14 +11,16 @@ namespace osu.Game.Online.API
public Bindable<User> LocalUser { get; } = new Bindable<User>(new User
{
Username = @"Dummy",
Id = 1,
Id = 1001,
});
public bool IsLoggedIn => true;
public void Update()
{
}
public string ProvidedUsername => LocalUser.Value.Username;
public string Endpoint => "http://localhost";
public APIState State => LocalUser.Value.Id == 1 ? APIState.Offline : APIState.Online;
public virtual void Queue(APIRequest request)
{
@ -26,6 +28,28 @@ namespace osu.Game.Online.API
public void Register(IOnlineComponent component)
{
// todo: add support
}
public void Unregister(IOnlineComponent component)
{
// todo: add support
}
public void Login(string username, string password)
{
LocalUser.Value = new User
{
Username = @"Dummy",
Id = 1001,
};
}
public void Logout()
{
LocalUser.Value = new GuestUser();
}
public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) => null;
}
}

View File

@ -18,6 +18,19 @@ namespace osu.Game.Online.API
/// </summary>
bool IsLoggedIn { get; }
/// <summary>
/// The last username provided by the end-user.
/// May not be authenticated.
/// </summary>
string ProvidedUsername { get; }
/// <summary>
/// The URL endpoint for this API. Does not include a trailing slash.
/// </summary>
string Endpoint { get; }
APIState State { get; }
/// <summary>
/// Queue a new request.
/// </summary>
@ -29,5 +42,32 @@ namespace osu.Game.Online.API
/// </summary>
/// <param name="component">The component to register.</param>
void Register(IOnlineComponent component);
/// <summary>
/// Unregisters a component to receive state changes.
/// </summary>
/// <param name="component">The component to unregister.</param>
void Unregister(IOnlineComponent component);
/// <summary>
/// Attempt to login using the provided credentials. This is a non-blocking operation.
/// </summary>
/// <param name="username">The user's username.</param>
/// <param name="password">The user's password.</param>
void Login(string username, string password);
/// <summary>
/// Log out the current user.
/// </summary>
void Logout();
/// <summary>
/// Create a new user account. This is a blocking operation.
/// </summary>
/// <param name="email">The email to create the account with.</param>
/// <param name="username">The username to create the account with.</param>
/// <param name="password">The password to create the account with.</param>
/// <returns>Any errors encoutnered during account creation.</returns>
RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password);
}
}

View File

@ -5,6 +5,6 @@ namespace osu.Game.Online.API
{
public interface IOnlineComponent
{
void APIStateChanged(APIAccess api, APIState state);
void APIStateChanged(IAPIProvider api, APIState state);
}
}

View File

@ -174,12 +174,12 @@ namespace osu.Game.Online.Leaderboards
};
}
private APIAccess api;
private IAPIProvider api;
private ScheduledDelegate pendingUpdateScores;
[BackgroundDependencyLoader(true)]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
api?.Register(this);
@ -195,7 +195,7 @@ namespace osu.Game.Online.Leaderboards
private APIRequest getScoresRequest;
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
if (state == APIState.Online)
UpdateScores();

View File

@ -64,6 +64,8 @@ namespace osu.Game.Online.Leaderboards
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
Avatar innerAvatar;
Children = new Drawable[]
{
new Container
@ -109,12 +111,11 @@ namespace osu.Game.Online.Leaderboards
Children = new[]
{
avatar = new DelayedLoadWrapper(
new Avatar(user)
innerAvatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
CornerRadius = corner_radius,
Masking = true,
OnLoadComplete = d => d.FadeInFromZero(200),
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
@ -214,6 +215,8 @@ namespace osu.Game.Online.Leaderboards
},
},
};
innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200);
}
public override void Show()

View File

@ -152,7 +152,6 @@ namespace osu.Game
API = new APIAccess(LocalConfig);
dependencies.Cache(API);
dependencies.CacheAs<IAPIProvider>(API);
var defaultBeatmap = new DummyWorkingBeatmap(this);

View File

@ -33,7 +33,7 @@ namespace osu.Game.Overlays.AccountCreation
private OsuTextBox emailTextBox;
private OsuPasswordTextBox passwordTextBox;
private APIAccess api;
private IAPIProvider api;
private ShakeContainer registerShake;
private IEnumerable<Drawable> characterCheckText;
@ -42,7 +42,7 @@ namespace osu.Game.Overlays.AccountCreation
private GameHost host;
[BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api, GameHost host)
private void load(OsuColour colours, IAPIProvider api, GameHost host)
{
this.api = api;
this.host = host;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.AccountCreation
{
private OsuTextFlowContainer multiAccountExplanationText;
private LinkFlowContainer furtherAssistance;
private APIAccess api;
private IAPIProvider api;
private const string help_centre_url = "/help/wiki/Help_Centre#login";
@ -39,7 +39,7 @@ namespace osu.Game.Overlays.AccountCreation
}
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, APIAccess api, OsuGame game, TextureStore textures)
private void load(OsuColour colours, IAPIProvider api, OsuGame game, TextureStore textures)
{
this.api = api;

View File

@ -30,7 +30,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api)
private void load(OsuColour colours, IAPIProvider api)
{
api.Register(this);
@ -96,7 +96,7 @@ namespace osu.Game.Overlays
this.FadeOut(100);
}
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{

View File

@ -39,7 +39,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
}
[BackgroundDependencyLoader]
private void load(APIAccess api, BeatmapManager beatmaps)
private void load(IAPIProvider api, BeatmapManager beatmaps)
{
FillFlowContainer textSprites;

View File

@ -45,7 +45,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}
private GetScoresRequest getScoresRequest;
private APIAccess api;
private IAPIProvider api;
public BeatmapInfo Beatmap
{
@ -129,7 +129,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
updateDisplay();

View File

@ -31,7 +31,7 @@ namespace osu.Game.Overlays
private readonly Header header;
private APIAccess api;
private IAPIProvider api;
private RulesetStore rulesets;
private readonly ScrollContainer scroll;
@ -101,7 +101,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
private void load(IAPIProvider api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;

View File

@ -28,6 +28,8 @@ namespace osu.Game.Overlays.Chat.Tabs
if (value.Type != ChannelType.PM)
throw new ArgumentException("Argument value needs to have the targettype user!");
Avatar avatar;
AddRange(new Drawable[]
{
new Container
@ -49,11 +51,10 @@ namespace osu.Game.Overlays.Chat.Tabs
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Masking = true,
Child = new DelayedLoadWrapper(new Avatar(value.Users.First())
Child = new DelayedLoadWrapper(avatar = new Avatar(value.Users.First())
{
RelativeSizeAxes = Axes.Both,
OpenOnClick = { Value = false },
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
})
{
RelativeSizeAxes = Axes.Both,
@ -63,6 +64,8 @@ namespace osu.Game.Overlays.Chat.Tabs
},
});
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
Text.X = ChatOverlay.TAB_AREA_HEIGHT;
TextBold.X = ChatOverlay.TAB_AREA_HEIGHT;
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays
{
private const float panel_padding = 10f;
private APIAccess api;
private IAPIProvider api;
private RulesetStore rulesets;
private readonly FillFlowContainer resultCountsContainer;
@ -164,7 +164,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
private void load(OsuColour colours, IAPIProvider api, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
{
this.api = api;
this.rulesets = rulesets;

View File

@ -109,7 +109,7 @@ namespace osu.Game.Overlays.MedalSplash
s.Font = s.Font.With(size: 16);
});
medalContainer.OnLoadComplete = d =>
medalContainer.OnLoadComplete += d =>
{
unlocked.Position = new Vector2(0f, medalContainer.DrawSize.Y / 2 + 10);
infoFlow.Position = new Vector2(0f, unlocked.Position.Y + 90);

View File

@ -335,9 +335,12 @@ namespace osu.Game.Overlays.Profile
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(200),
Depth = float.MaxValue,
}, coverContainer.Add);
}, background =>
{
coverContainer.Add(background);
background.FadeInFromZero(200);
});
if (user.IsSupporter)
SupporterTag.Show();

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections
protected readonly Bindable<User> User = new Bindable<User>();
protected APIAccess Api;
protected IAPIProvider Api;
protected APIRequest RetrievalRequest;
protected RulesetStore Rulesets;
@ -84,7 +84,7 @@ namespace osu.Game.Overlays.Profile.Sections
}
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets)
private void load(IAPIProvider api, RulesetStore rulesets)
{
Api = api;
Rulesets = rulesets;

View File

@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
{
public class DrawableRecentActivity : DrawableProfileRow
{
private APIAccess api;
private IAPIProvider api;
private readonly APIRecentActivity activity;
@ -28,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;

View File

@ -58,14 +58,14 @@ namespace osu.Game.Overlays.Settings.Sections.General
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, APIAccess api)
private void load(OsuColour colours, IAPIProvider api)
{
this.colours = colours;
api?.Register(this);
}
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
form = null;
@ -194,7 +194,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
{
private TextBox username;
private TextBox password;
private APIAccess api;
private IAPIProvider api;
public Action RequestHide;
@ -205,7 +205,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api, OsuConfigManager config, AccountCreationOverlay accountCreation)
private void load(IAPIProvider api, OsuConfigManager config, AccountCreationOverlay accountCreation)
{
this.api = api;
Direction = FillDirection.Vertical;

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays
{
public class SocialOverlay : SearchableListOverlay<SocialTab, SocialSortCriteria, SortDirection>, IOnlineComponent
{
private APIAccess api;
private IAPIProvider api;
private readonly LoadingAnimation loading;
private FillFlowContainer<SocialPanel> panels;
@ -89,7 +89,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
api.Register(this);
@ -193,7 +193,7 @@ namespace osu.Game.Overlays
}
}
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{

View File

@ -43,12 +43,12 @@ namespace osu.Game.Overlays.Toolbar
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
api.Register(this);
}
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
switch (state)
{

View File

@ -26,7 +26,7 @@ namespace osu.Game.Overlays
private ProfileSection lastSection;
private ProfileSection[] sections;
private GetUserRequest userReq;
private APIAccess api;
private IAPIProvider api;
protected ProfileHeader Header;
private SectionsContainer<ProfileSection> sectionsContainer;
private ProfileTabControl tabs;
@ -56,7 +56,7 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
}

View File

@ -0,0 +1,153 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Input.Handlers;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.UI
{
/// <summary>
/// A container which consumes a parent gameplay clock and standardises frame counts for children.
/// Will ensure a minimum of 40 frames per clock second is maintained, regardless of any system lag or seeks.
/// </summary>
public class FrameStabilityContainer : Container, IHasReplayHandler
{
public FrameStabilityContainer()
{
RelativeSizeAxes = Axes.Both;
gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock()));
}
private readonly ManualClock manualClock;
private readonly FramedClock framedClock;
[Cached]
private GameplayClock gameplayClock;
private IFrameBasedClock parentGameplayClock;
[BackgroundDependencyLoader(true)]
private void load(GameplayClock clock)
{
if (clock != null)
parentGameplayClock = clock;
}
protected override void LoadComplete()
{
base.LoadComplete();
setClock();
}
/// <summary>
/// Whether we are running up-to-date with our parent clock.
/// If not, we will need to keep processing children until we catch up.
/// </summary>
private bool requireMoreUpdateLoops;
/// <summary>
/// Whether we are in a valid state (ie. should we keep processing children frames).
/// This should be set to false when the replay is, for instance, waiting for future frames to arrive.
/// </summary>
private bool validState;
protected override bool RequiresChildrenUpdate => base.RequiresChildrenUpdate && validState;
private bool isAttached => ReplayInputHandler != null;
private const int max_catch_up_updates_per_frame = 50;
private const double sixty_frame_time = 1000.0 / 60;
public override bool UpdateSubTree()
{
requireMoreUpdateLoops = true;
validState = true;
int loops = 0;
while (validState && requireMoreUpdateLoops && loops++ < max_catch_up_updates_per_frame)
{
updateClock();
if (validState)
{
base.UpdateSubTree();
UpdateSubTreeMasking(this, ScreenSpaceDrawQuad.AABBFloat);
}
}
return true;
}
private void updateClock()
{
if (parentGameplayClock == null)
setClock(); // LoadComplete may not be run yet, but we still want the clock.
validState = true;
manualClock.Rate = parentGameplayClock.Rate;
manualClock.IsRunning = parentGameplayClock.IsRunning;
var newProposedTime = parentGameplayClock.CurrentTime;
try
{
if (Math.Abs(manualClock.CurrentTime - newProposedTime) > sixty_frame_time * 1.2f)
{
newProposedTime = manualClock.Rate > 0
? Math.Min(newProposedTime, manualClock.CurrentTime + sixty_frame_time)
: Math.Max(newProposedTime, manualClock.CurrentTime - sixty_frame_time);
}
if (!isAttached)
{
manualClock.CurrentTime = newProposedTime;
}
else
{
double? newTime = ReplayInputHandler.SetFrameFromTime(newProposedTime);
if (newTime == null)
{
// we shouldn't execute for this time value. probably waiting on more replay data.
validState = false;
requireMoreUpdateLoops = true;
manualClock.CurrentTime = newProposedTime;
return;
}
manualClock.CurrentTime = newTime.Value;
}
requireMoreUpdateLoops = manualClock.CurrentTime != parentGameplayClock.CurrentTime;
}
finally
{
// The manual clock time has changed in the above code. The framed clock now needs to be updated
// to ensure that the its time is valid for our children before input is processed
framedClock.ProcessFrame();
}
}
private void setClock()
{
// in case a parent gameplay clock isn't available, just use the parent clock.
if (parentGameplayClock == null)
parentGameplayClock = Clock;
Clock = gameplayClock;
ProcessCustomClock = false;
}
public ReplayInputHandler ReplayInputHandler { get; set; }
}
}

View File

@ -132,6 +132,8 @@ namespace osu.Game.Rulesets.UI
protected virtual ReplayInputHandler CreateReplayInputHandler(Replay replay) => null;
protected FrameStabilityContainer FrameStabilityContainer;
public Score ReplayScore { get; private set; }
/// <summary>
@ -149,7 +151,11 @@ namespace osu.Game.Rulesets.UI
throw new InvalidOperationException($"A {nameof(KeyBindingInputManager)} which supports replay loading is not available");
ReplayScore = replayScore;
ReplayInputManager.ReplayInputHandler = replayScore != null ? CreateReplayInputHandler(replayScore.Replay) : null;
var handler = replayScore != null ? CreateReplayInputHandler(replayScore.Replay) : null;
ReplayInputManager.ReplayInputHandler = handler;
FrameStabilityContainer.ReplayInputHandler = handler;
HasReplayLoaded.Value = ReplayInputManager.ReplayInputHandler != null;
}
@ -243,7 +249,6 @@ namespace osu.Game.Rulesets.UI
Beatmap = (Beatmap<TObject>)workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo);
KeyBindingInputManager = CreateInputManager();
KeyBindingInputManager.RelativeSizeAxes = Axes.Both;
applyBeatmapMods(Mods);
}
@ -262,7 +267,10 @@ namespace osu.Game.Rulesets.UI
InternalChildren = new Drawable[]
{
KeyBindingInputManager,
FrameStabilityContainer = new FrameStabilityContainer
{
Child = KeyBindingInputManager,
},
Overlays = new Container { RelativeSizeAxes = Axes.Both }
};

View File

@ -1,7 +1,6 @@
// 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.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -12,7 +11,6 @@ using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges.Events;
using osu.Framework.Input.States;
using osu.Framework.Timing;
using osu.Game.Configuration;
using osu.Game.Input.Bindings;
using osu.Game.Input.Handlers;
@ -41,7 +39,12 @@ namespace osu.Game.Rulesets.UI
protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique)
{
InternalChild = KeyBindingContainer = CreateKeyBindingContainer(ruleset, variant, unique);
gameplayClock = new GameplayClock(framedClock = new FramedClock(manualClock = new ManualClock()));
}
[BackgroundDependencyLoader(true)]
private void load(OsuConfigManager config)
{
mouseDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableButtons);
}
#region Action mapping (for replays)
@ -85,137 +88,6 @@ namespace osu.Game.Rulesets.UI
#endregion
#region Clock control
private readonly ManualClock manualClock;
private readonly FramedClock framedClock;
[Cached]
private GameplayClock gameplayClock;
private IFrameBasedClock parentGameplayClock;
[BackgroundDependencyLoader(true)]
private void load(OsuConfigManager config, GameplayClock clock)
{
mouseDisabled = config.GetBindable<bool>(OsuSetting.MouseDisableButtons);
if (clock != null)
parentGameplayClock = clock;
}
protected override void LoadComplete()
{
base.LoadComplete();
setClock();
}
/// <summary>
/// Whether we are running up-to-date with our parent clock.
/// If not, we will need to keep processing children until we catch up.
/// </summary>
private bool requireMoreUpdateLoops;
/// <summary>
/// Whether we are in a valid state (ie. should we keep processing children frames).
/// This should be set to false when the replay is, for instance, waiting for future frames to arrive.
/// </summary>
private bool validState;
protected override bool RequiresChildrenUpdate => base.RequiresChildrenUpdate && validState;
private bool isAttached => replayInputHandler != null && !UseParentInput;
private const int max_catch_up_updates_per_frame = 50;
private const double sixty_frame_time = 1000.0 / 60;
public override bool UpdateSubTree()
{
requireMoreUpdateLoops = true;
validState = true;
int loops = 0;
while (validState && requireMoreUpdateLoops && loops++ < max_catch_up_updates_per_frame)
{
updateClock();
if (validState)
{
base.UpdateSubTree();
UpdateSubTreeMasking(this, ScreenSpaceDrawQuad.AABBFloat);
}
}
return true;
}
private void updateClock()
{
if (parentGameplayClock == null)
setClock(); // LoadComplete may not be run yet, but we still want the clock.
validState = true;
manualClock.Rate = parentGameplayClock.Rate;
manualClock.IsRunning = parentGameplayClock.IsRunning;
var newProposedTime = parentGameplayClock.CurrentTime;
try
{
if (Math.Abs(manualClock.CurrentTime - newProposedTime) > sixty_frame_time * 1.2f)
{
newProposedTime = manualClock.Rate > 0
? Math.Min(newProposedTime, manualClock.CurrentTime + sixty_frame_time)
: Math.Max(newProposedTime, manualClock.CurrentTime - sixty_frame_time);
}
if (!isAttached)
{
manualClock.CurrentTime = newProposedTime;
}
else
{
double? newTime = replayInputHandler.SetFrameFromTime(newProposedTime);
if (newTime == null)
{
// we shouldn't execute for this time value. probably waiting on more replay data.
validState = false;
requireMoreUpdateLoops = true;
manualClock.CurrentTime = newProposedTime;
return;
}
manualClock.CurrentTime = newTime.Value;
}
requireMoreUpdateLoops = manualClock.CurrentTime != parentGameplayClock.CurrentTime;
}
finally
{
// The manual clock time has changed in the above code. The framed clock now needs to be updated
// to ensure that the its time is valid for our children before input is processed
framedClock.ProcessFrame();
}
}
private void setClock()
{
// in case a parent gameplay clock isn't available, just use the parent clock.
if (parentGameplayClock == null)
parentGameplayClock = Clock;
Clock = gameplayClock;
ProcessCustomClock = false;
}
#endregion
#region Setting application (disables etc.)
private Bindable<bool> mouseDisabled;

View File

@ -97,7 +97,7 @@ namespace osu.Game.Screens.Menu
private OsuGame game { get; set; }
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[Resolved(CanBeNull = true)]
private NotificationOverlay notifications { get; set; }

View File

@ -2,11 +2,12 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Screens;
using osu.Game.Graphics;
@ -25,16 +26,17 @@ namespace osu.Game.Screens.Menu
private SpriteIcon icon;
private Color4 iconColour;
private LinkFlowContainer textFlow;
private LinkFlowContainer supportFlow;
public override bool HideOverlaysOnEnter => true;
public override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
public override bool CursorVisible => false;
private readonly List<Drawable> supporterDrawables = new List<Drawable>();
private Drawable heart;
private const float icon_y = -85;
private const float icon_size = 30;
private readonly Bindable<User> currentUser = new Bindable<User>();
@ -44,7 +46,7 @@ namespace osu.Game.Screens.Menu
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, APIAccess api)
private void load(OsuColour colours, IAPIProvider api)
{
InternalChildren = new Drawable[]
{
@ -53,19 +55,39 @@ namespace osu.Game.Screens.Menu
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.fa_warning,
Size = new Vector2(30),
Size = new Vector2(icon_size),
Y = icon_y,
},
textFlow = new LinkFlowContainer
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding(50),
TextAnchor = Anchor.TopCentre,
Y = -110,
Direction = FillDirection.Vertical,
Y = icon_y + icon_size,
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Spacing = new Vector2(0, 2),
Children = new Drawable[]
{
textFlow = new LinkFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
TextAnchor = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Spacing = new Vector2(0, 2),
},
supportFlow = new LinkFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
TextAnchor = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Alpha = 0,
Spacing = new Vector2(0, 2),
},
}
}
};
@ -88,28 +110,45 @@ namespace osu.Game.Screens.Menu
textFlow.NewParagraph();
textFlow.NewParagraph();
supporterDrawables.AddRange(textFlow.AddText("Consider becoming an ", format));
supporterDrawables.AddRange(textFlow.AddLink("osu!supporter", "https://osu.ppy.sh/home/support", creationParameters: format));
supporterDrawables.AddRange(textFlow.AddText(" to help support the game", format));
supporterDrawables.Add(heart = textFlow.AddIcon(FontAwesome.fa_heart, t =>
{
t.Padding = new MarginPadding { Left = 5 };
t.Font = t.Font.With(size: 12);
t.Colour = colours.Pink;
t.Origin = Anchor.Centre;
}).First());
iconColour = colours.Yellow;
currentUser.BindTo(api.LocalUser);
currentUser.BindValueChanged(e =>
{
supportFlow.Children.ForEach(d => d.FadeOut().Expire());
if (e.NewValue.IsSupporter)
supporterDrawables.ForEach(d => d.FadeOut(500, Easing.OutQuint).Expire());
{
supportFlow.AddText("Thank you for supporting osu!", format);
}
else
{
supportFlow.AddText("Consider becoming an ", format);
supportFlow.AddLink("osu!supporter", "https://osu.ppy.sh/home/support", creationParameters: format);
supportFlow.AddText(" to help support the game", format);
}
heart = supportFlow.AddIcon(FontAwesome.fa_heart, t =>
{
t.Padding = new MarginPadding { Left = 5 };
t.Font = t.Font.With(size: 12);
t.Origin = Anchor.Centre;
t.Colour = colours.Pink;
}).First();
if (IsLoaded)
animateHeart();
if (supportFlow.IsPresent)
supportFlow.FadeInFromZero(500);
}, true);
}
private void animateHeart()
{
heart.FlashColour(Color4.White, 750, Easing.OutQuint).Loop();
}
protected override void LoadComplete()
{
base.LoadComplete();
@ -128,7 +167,9 @@ namespace osu.Game.Screens.Menu
.MoveToY(icon_y, 160, Easing.InCirc)
.RotateTo(0, 160, Easing.InCirc);
supporterDrawables.ForEach(d => d.FadeOut().Delay(2000).FadeIn(500));
supportFlow.FadeOut().Delay(2000).FadeIn(500);
animateHeart();
this
.FadeInFromZero(500)
@ -136,8 +177,6 @@ namespace osu.Game.Screens.Menu
.FadeOut(250)
.ScaleTo(0.9f, 250, Easing.InQuint)
.Finally(d => this.Push(intro));
heart.FlashColour(Color4.White, 750, Easing.OutQuint).Loop();
}
}
}

View File

@ -246,7 +246,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
}
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
private GetRoomScoresRequest request;

View File

@ -52,12 +52,18 @@ namespace osu.Game.Screens.Multi.Match.Components
Participants.BindValueChanged(participants =>
{
usersFlow.Children = participants.NewValue.Select(u => new UserPanel(u)
usersFlow.Children = participants.NewValue.Select(u =>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 300,
OnLoadComplete = d => d.FadeInFromZero(60),
var panel = new UserPanel(u)
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Width = 300,
};
panel.OnLoadComplete += d => d.FadeInFromZero(60);
return panel;
}).ToList();
}, true);
}

View File

@ -54,7 +54,7 @@ namespace osu.Game.Screens.Multi
private OsuGameBase game { get; set; }
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[Resolved(CanBeNull = true)]
private OsuLogo logo { get; set; }
@ -163,7 +163,7 @@ namespace osu.Game.Screens.Multi
this.Push(new PlayerLoader(player));
}
public void APIStateChanged(APIAccess api, APIState state)
public void APIStateChanged(IAPIProvider api, APIState state)
{
if (state != APIState.Online)
forcefullyExit();

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Multi.Play
private readonly PlaylistItem playlistItem;
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }

View File

@ -30,7 +30,7 @@ namespace osu.Game.Screens.Multi
private Bindable<FilterCriteria> currentFilter { get; set; }
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }

View File

@ -60,7 +60,7 @@ namespace osu.Game.Screens.Play
private RulesetInfo ruleset;
private APIAccess api;
private IAPIProvider api;
private SampleChannel sampleRestart;
@ -85,7 +85,7 @@ namespace osu.Game.Screens.Play
private GameplayClockContainer gameplayClockContainer;
[BackgroundDependencyLoader]
private void load(AudioManager audio, APIAccess api, OsuConfigManager config)
private void load(AudioManager audio, IAPIProvider api, OsuConfigManager config)
{
this.api = api;

View File

@ -577,7 +577,7 @@ namespace osu.Game.Screens.Select
else
{
float y = currentY;
d.OnLoadComplete = _ => performMove(y, setY);
d.OnLoadComplete += _ => performMove(y, setY);
}
break;

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.Select
private readonly FailRetryGraph failRetryGraph;
private readonly DimmedLoadingAnimation loading;
private APIAccess api;
private IAPIProvider api;
private ScheduledDelegate pendingBeatmapSwitch;
@ -160,7 +160,7 @@ namespace osu.Game.Screens.Select
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
private void load(IAPIProvider api)
{
this.api = api;
}

View File

@ -49,11 +49,16 @@ namespace osu.Game.Screens.Select.Carousel
Children = new Drawable[]
{
new DelayedLoadUnloadWrapper(() =>
new PanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
{
var background = new PanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(1000, Easing.OutQuint),
}, 300, 5000
};
background.OnLoadComplete += d => d.FadeInFromZero(1000, Easing.OutQuint);
return background;
}, 300, 5000
),
new FillFlowContainer
{

View File

@ -43,7 +43,7 @@ namespace osu.Game.Screens.Select.Leaderboards
private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved]
private APIAccess api { get; set; }
private IAPIProvider api { get; set; }
[BackgroundDependencyLoader]
private void load()

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Game.IO;
using osu.Game.Screens.Play;
namespace osu.Game.Storyboards.Drawables
{
@ -55,9 +56,12 @@ namespace osu.Game.Storyboards.Drawables
});
}
[BackgroundDependencyLoader]
private void load(FileStore fileStore)
[BackgroundDependencyLoader(true)]
private void load(FileStore fileStore, GameplayClock clock)
{
if (clock != null)
Clock = clock;
dependencies.Cache(new TextureStore(new TextureLoaderStore(fileStore.Store), false, scaleAdjust: 1));
foreach (var layer in Storyboard.Layers)

View File

@ -57,9 +57,9 @@ namespace osu.Game.Users
var avatar = new Avatar(user)
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
};
avatar.OnLoadComplete += d => d.FadeInFromZero(300, Easing.OutQuint);
avatar.OpenOnClick.BindTo(OpenOnClick);
Add(displayedAvatar = new DelayedLoadWrapper(avatar));

View File

@ -59,6 +59,8 @@ namespace osu.Game.Users
FillFlowContainer infoContainer;
UserCoverBackground coverBackground;
AddInternal(content = new Container
{
RelativeSizeAxes = Axes.Both,
@ -73,13 +75,12 @@ namespace osu.Game.Users
Children = new Drawable[]
{
new DelayedLoadWrapper(new UserCoverBackground(user)
new DelayedLoadWrapper(coverBackground = new UserCoverBackground(user)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
OnLoadComplete = d => d.FadeInFromZero(400, Easing.Out)
}, 300) { RelativeSizeAxes = Axes.Both },
new Box
{
@ -181,6 +182,8 @@ namespace osu.Game.Users
}
});
coverBackground.OnLoadComplete += d => d.FadeInFromZero(400, Easing.Out);
if (user.IsSupporter)
{
infoContainer.Add(new SupporterIcon

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.315.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.313.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.315.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.315.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />