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

Merge branch 'master' into fix-overlays-drag-closing

This commit is contained in:
Dan Balasescu 2019-12-02 14:12:37 +09:00 committed by GitHub
commit 700fe5162d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 68 additions and 38 deletions

View File

@ -18,6 +18,7 @@ using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
@ -30,6 +31,8 @@ namespace osu.Game.Rulesets.Osu.UI
{ {
} }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; // always show the gameplay cursor
public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this); public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this);
protected override Playfield CreatePlayfield() => new OsuPlayfield(); protected override Playfield CreatePlayfield() => new OsuPlayfield();

View File

@ -228,7 +228,7 @@ namespace osu.Game.Tournament
if (b.BeatmapInfo == null && b.ID > 0) if (b.BeatmapInfo == null && b.ID > 0)
{ {
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID }); var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = b.ID });
req.Perform(API); API.Perform(req);
b.BeatmapInfo = req.Result?.ToBeatmap(RulesetStore); b.BeatmapInfo = req.Result?.ToBeatmap(RulesetStore);
addedInfo = true; addedInfo = true;

View File

@ -398,7 +398,7 @@ namespace osu.Game.Beatmaps
try try
{ {
// intentionally blocking to limit web request concurrency // intentionally blocking to limit web request concurrency
req.Perform(api); api.Perform(req);
var res = req.Result; var res = req.Result;

View File

@ -99,17 +99,7 @@ namespace osu.Game.Database
currentDownloads.Add(request); currentDownloads.Add(request);
PostNotification?.Invoke(notification); PostNotification?.Invoke(notification);
Task.Factory.StartNew(() => api.PerformAsync(request);
{
try
{
request.Perform(api);
}
catch (Exception error)
{
triggerFailure(error);
}
}, TaskCreationOptions.LongRunning);
DownloadBegan?.Invoke(request); DownloadBegan?.Invoke(request);
return true; return true;

View File

@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -198,6 +199,22 @@ namespace osu.Game.Online.API
} }
} }
public void Perform(APIRequest request)
{
try
{
request.Perform(this);
}
catch (Exception e)
{
// todo: fix exception handling
request.Fail(e);
}
}
public Task PerformAsync(APIRequest request) =>
Task.Factory.StartNew(() => Perform(request), TaskCreationOptions.LongRunning);
public void Login(string username, string password) public void Login(string username, string password)
{ {
Debug.Assert(State == APIState.Offline); Debug.Assert(State == APIState.Offline);

View File

@ -3,6 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Users; using osu.Game.Users;
@ -56,6 +57,10 @@ namespace osu.Game.Online.API
{ {
} }
public void Perform(APIRequest request) { }
public Task PerformAsync(APIRequest request) => Task.CompletedTask;
public void Register(IOnlineComponent component) public void Register(IOnlineComponent component)
{ {
Scheduler.Add(delegate { components.Add(component); }); Scheduler.Add(delegate { components.Add(component); });

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading.Tasks;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Users; using osu.Game.Users;
@ -42,6 +43,24 @@ namespace osu.Game.Online.API
/// <param name="request">The request to perform.</param> /// <param name="request">The request to perform.</param>
void Queue(APIRequest request); void Queue(APIRequest request);
/// <summary>
/// Perform a request immediately, bypassing any API state checks.
/// </summary>
/// <remarks>
/// Can be used to run requests as a guest user.
/// </remarks>
/// <param name="request">The request to perform.</param>
void Perform(APIRequest request);
/// <summary>
/// Perform a request immediately, bypassing any API state checks.
/// </summary>
/// <remarks>
/// Can be used to run requests as a guest user.
/// </remarks>
/// <param name="request">The request to perform.</param>
Task PerformAsync(APIRequest request);
/// <summary> /// <summary>
/// Register a component to receive state changes. /// Register a component to receive state changes.
/// </summary> /// </summary>

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -43,18 +42,7 @@ namespace osu.Game.Overlays.Changelog
}; };
req.Failure += _ => complete = true; req.Failure += _ => complete = true;
// This is done on a separate thread to support cancellation below api.PerformAsync(req);
Task.Run(() =>
{
try
{
req.Perform(api);
}
catch
{
complete = true;
}
});
while (!complete) while (!complete)
{ {

View File

@ -191,15 +191,7 @@ namespace osu.Game.Overlays
tcs.SetResult(false); tcs.SetResult(false);
}; };
try await API.PerformAsync(req);
{
req.Perform(API);
}
catch
{
initialFetchTask = null;
tcs.SetResult(false);
}
await tcs.Task; await tcs.Task;
}); });

View File

@ -34,6 +34,7 @@ using osu.Game.Rulesets.Configuration;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -331,6 +332,9 @@ namespace osu.Game.Rulesets.UI
protected override bool OnHover(HoverEvent e) => true; // required for IProvideCursor protected override bool OnHover(HoverEvent e) => true; // required for IProvideCursor
// only show the cursor when within the playfield, by default.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Playfield.ReceivePositionalInputAt(screenSpacePos);
CursorContainer IProvideCursor.Cursor => Playfield.Cursor; CursorContainer IProvideCursor.Cursor => Playfield.Cursor;
public override GameplayCursorContainer Cursor => Playfield.Cursor; public override GameplayCursorContainer Cursor => Playfield.Cursor;

View File

@ -100,10 +100,13 @@ namespace osu.Game.Rulesets.UI
public GameplayCursorContainer Cursor { get; private set; } public GameplayCursorContainer Cursor { get; private set; }
/// <summary> /// <summary>
/// Provide an optional cursor which is to be used for gameplay. /// Provide a cursor which is to be used for gameplay.
/// </summary> /// </summary>
/// <returns>The cursor, or null if a cursor is not rqeuired.</returns> /// <remarks>
protected virtual GameplayCursorContainer CreateCursor() => null; /// The default provided cursor is invisible when inside the bounds of the <see cref="Playfield"/>.
/// </remarks>
/// <returns>The cursor, or null to show the menu cursor.</returns>
protected virtual GameplayCursorContainer CreateCursor() => new InvisibleCursorContainer();
/// <summary> /// <summary>
/// Registers a <see cref="Playfield"/> as a nested <see cref="Playfield"/>. /// Registers a <see cref="Playfield"/> as a nested <see cref="Playfield"/>.
@ -143,5 +146,14 @@ namespace osu.Game.Rulesets.UI
/// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s. /// Creates the container that will be used to contain the <see cref="DrawableHitObject"/>s.
/// </summary> /// </summary>
protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer(); protected virtual HitObjectContainer CreateHitObjectContainer() => new HitObjectContainer();
public class InvisibleCursorContainer : GameplayCursorContainer
{
protected override Drawable CreateCursor() => new InvisibleCursor();
private class InvisibleCursor : Drawable
{
}
}
} }
} }