1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:02:57 +08:00

Merge branch 'master' into player-completion-refactoring

This commit is contained in:
Dean Herbert 2021-06-17 23:51:42 +09:00 committed by GitHub
commit e0a3696145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 132 additions and 135 deletions

View File

@ -174,8 +174,8 @@ namespace osu.Game.Rulesets.Catch.Tests
private void addToPlayfield(DrawableCatchHitObject drawable) private void addToPlayfield(DrawableCatchHitObject drawable)
{ {
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObjects>()) foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObjects(new[] { drawable }); mod.ApplyToDrawableHitObject(drawable);
drawableRuleset.Playfield.Add(drawable); drawableRuleset.Playfield.Add(drawable);
} }

View File

@ -92,8 +92,8 @@ namespace osu.Game.Rulesets.Osu.Tests
var drawable = CreateDrawableHitCircle(circle, auto, hitOffset); var drawable = CreateDrawableHitCircle(circle, auto, hitOffset);
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObjects>()) foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObjects(new[] { drawable }); mod.ApplyToDrawableHitObject(drawable);
return drawable; return drawable;
} }

View File

@ -335,8 +335,8 @@ namespace osu.Game.Rulesets.Osu.Tests
var drawable = CreateDrawableSlider(slider); var drawable = CreateDrawableSlider(slider);
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObjects>()) foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObjects(new[] { drawable }); mod.ApplyToDrawableHitObject(drawable);
drawable.OnNewResult += onNewResult; drawable.OnNewResult += onNewResult;

View File

@ -85,8 +85,8 @@ namespace osu.Game.Rulesets.Osu.Tests
Scale = new Vector2(0.75f) Scale = new Vector2(0.75f)
}; };
foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObjects>()) foreach (var mod in SelectedMods.Value.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObjects(new[] { drawableSpinner }); mod.ApplyToDrawableHitObject(drawableSpinner);
return drawableSpinner; return drawableSpinner;
} }

View File

@ -1,9 +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.Collections.Generic;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -13,7 +11,7 @@ using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModApproachDifferent : Mod, IApplicableToDrawableHitObjects public class OsuModApproachDifferent : Mod, IApplicableToDrawableHitObject
{ {
public override string Name => "Approach Different"; public override string Name => "Approach Different";
public override string Acronym => "AD"; public override string Acronym => "AD";
@ -32,22 +30,19 @@ namespace osu.Game.Rulesets.Osu.Mods
[SettingSource("Style", "Change the animation style of the approach circles.", 1)] [SettingSource("Style", "Change the animation style of the approach circles.", 1)]
public Bindable<AnimationStyle> Style { get; } = new Bindable<AnimationStyle>(); public Bindable<AnimationStyle> Style { get; } = new Bindable<AnimationStyle>();
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{ {
drawables.ForEach(drawable => drawable.ApplyCustomUpdateState += (drawableObject, state) =>
{ {
drawable.ApplyCustomUpdateState += (drawableObject, state) => if (!(drawableObject is DrawableHitCircle drawableHitCircle)) return;
{
if (!(drawableObject is DrawableHitCircle drawableHitCircle)) return;
var hitCircle = drawableHitCircle.HitObject; var hitCircle = drawableHitCircle.HitObject;
drawableHitCircle.ApproachCircle.ClearTransforms(targetMember: nameof(Scale)); drawableHitCircle.ApproachCircle.ClearTransforms(targetMember: nameof(Scale));
using (drawableHitCircle.BeginAbsoluteSequence(hitCircle.StartTime - hitCircle.TimePreempt)) using (drawableHitCircle.BeginAbsoluteSequence(hitCircle.StartTime - hitCircle.TimePreempt))
drawableHitCircle.ApproachCircle.ScaleTo(Scale.Value).ScaleTo(1f, hitCircle.TimePreempt, getEasing(Style.Value)); drawableHitCircle.ApproachCircle.ScaleTo(Scale.Value).ScaleTo(1f, hitCircle.TimePreempt, getEasing(Style.Value));
}; };
});
} }
private Easing getEasing(AnimationStyle style) private Easing getEasing(AnimationStyle style)

View File

@ -1,7 +1,6 @@
// 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.Collections.Generic;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
@ -9,22 +8,19 @@ using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModBarrelRoll : ModBarrelRoll<OsuHitObject>, IApplicableToDrawableHitObjects public class OsuModBarrelRoll : ModBarrelRoll<OsuHitObject>, IApplicableToDrawableHitObject
{ {
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObject(DrawableHitObject d)
{ {
foreach (var d in drawables) d.OnUpdate += _ =>
{ {
d.OnUpdate += _ => switch (d)
{ {
switch (d) case DrawableHitCircle circle:
{ circle.CirclePiece.Rotation = -CurrentRotation;
case DrawableHitCircle circle: break;
circle.CirclePiece.Rotation = -CurrentRotation; }
break; };
}
};
}
} }
} }
} }

View File

@ -1,7 +1,6 @@
// 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.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -15,7 +14,7 @@ using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModClassic : ModClassic, IApplicableToHitObject, IApplicableToDrawableHitObjects, IApplicableToDrawableRuleset<OsuHitObject> public class OsuModClassic : ModClassic, IApplicableToHitObject, IApplicableToDrawableHitObject, IApplicableToDrawableRuleset<OsuHitObject>
{ {
[SettingSource("No slider head accuracy requirement", "Scores sliders proportionally to the number of ticks hit.")] [SettingSource("No slider head accuracy requirement", "Scores sliders proportionally to the number of ticks hit.")]
public Bindable<bool> NoSliderHeadAccuracy { get; } = new BindableBool(true); public Bindable<bool> NoSliderHeadAccuracy { get; } = new BindableBool(true);
@ -54,24 +53,21 @@ namespace osu.Game.Rulesets.Osu.Mods
osuRuleset.Playfield.HitPolicy = new ObjectOrderedHitPolicy(); osuRuleset.Playfield.HitPolicy = new ObjectOrderedHitPolicy();
} }
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObject(DrawableHitObject obj)
{ {
foreach (var obj in drawables) switch (obj)
{ {
switch (obj) case DrawableSlider slider:
{ slider.Ball.InputTracksVisualSize = !FixedFollowCircleHitArea.Value;
case DrawableSlider slider: break;
slider.Ball.InputTracksVisualSize = !FixedFollowCircleHitArea.Value;
break;
case DrawableSliderHead head: case DrawableSliderHead head:
head.TrackFollowCircle = !NoSliderHeadMovement.Value; head.TrackFollowCircle = !NoSliderHeadMovement.Value;
break; break;
case DrawableSliderTail tail: case DrawableSliderTail tail:
tail.SamplePlaysOnlyOnHit = !AlwaysPlayTailSample.Value; tail.SamplePlaysOnlyOnHit = !AlwaysPlayTailSample.Value;
break; break;
}
} }
} }
} }

View File

@ -2,8 +2,6 @@
// 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; using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
@ -19,7 +17,7 @@ using osuTK;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModFlashlight : ModFlashlight<OsuHitObject>, IApplicableToDrawableHitObjects public class OsuModFlashlight : ModFlashlight<OsuHitObject>, IApplicableToDrawableHitObject
{ {
public override double ScoreMultiplier => 1.12; public override double ScoreMultiplier => 1.12;
@ -31,12 +29,10 @@ namespace osu.Game.Rulesets.Osu.Mods
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(); public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight();
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObject(DrawableHitObject drawable)
{ {
foreach (var s in drawables.OfType<DrawableSlider>()) if (drawable is DrawableSlider s)
{
s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange;
}
} }
public override void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset) public override void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)

View File

@ -2,7 +2,6 @@
// 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; using System;
using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Utils; using osu.Framework.Utils;
@ -13,7 +12,7 @@ using osu.Game.Rulesets.Osu.Objects.Drawables;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModSpunOut : Mod, IApplicableToDrawableHitObjects public class OsuModSpunOut : Mod, IApplicableToDrawableHitObject
{ {
public override string Name => "Spun Out"; public override string Name => "Spun Out";
public override string Acronym => "SO"; public override string Acronym => "SO";
@ -23,15 +22,12 @@ namespace osu.Game.Rulesets.Osu.Mods
public override double ScoreMultiplier => 0.9; public override double ScoreMultiplier => 0.9;
public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) }; public override Type[] IncompatibleMods => new[] { typeof(ModAutoplay), typeof(OsuModAutopilot) };
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public void ApplyToDrawableHitObject(DrawableHitObject hitObject)
{ {
foreach (var hitObject in drawables) if (hitObject is DrawableSpinner spinner)
{ {
if (hitObject is DrawableSpinner spinner) spinner.HandleUserInput = false;
{ spinner.OnUpdate += onSpinnerUpdate;
spinner.HandleUserInput = false;
spinner.OnUpdate += onSpinnerUpdate;
}
} }
} }

View File

@ -53,9 +53,8 @@ namespace osu.Game.Overlays.BeatmapSet
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
CornerRadius = 4, CornerRadius = 4,
Masking = true, Masking = true,
Child = avatar = new UpdateableAvatar Child = avatar = new UpdateableAvatar(showGuestOnNull: false)
{ {
ShowGuestOnNull = false,
Size = new Vector2(height), Size = new Vector2(height),
}, },
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters

View File

@ -61,7 +61,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
}, },
} }
}, },
avatar = new UpdateableAvatar avatar = new UpdateableAvatar(showGuestOnNull: false)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -75,7 +75,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Offset = new Vector2(0, 2), Offset = new Vector2(0, 2),
Radius = 1, Radius = 1,
}, },
ShowGuestOnNull = false,
}, },
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -51,7 +51,7 @@ namespace osu.Game.Overlays.Chat.Tabs
Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First()) Child = new DelayedLoadWrapper(avatar = new ClickableAvatar(value.Users.First())
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OpenOnClick = { Value = false }, OpenOnClick = false,
}) })
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,

View File

@ -58,13 +58,11 @@ namespace osu.Game.Overlays.Profile.Header
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
Children = new Drawable[] Children = new Drawable[]
{ {
avatar = new UpdateableAvatar avatar = new UpdateableAvatar(openOnClick: false, showGuestOnNull: false)
{ {
Size = new Vector2(avatar_size), Size = new Vector2(avatar_size),
Masking = true, Masking = true,
CornerRadius = avatar_size * 0.25f, CornerRadius = avatar_size * 0.25f,
OpenOnClick = { Value = false },
ShowGuestOnNull = false,
}, },
new Container new Container
{ {

View File

@ -32,14 +32,13 @@ namespace osu.Game.Overlays.Toolbar
Add(new OpaqueBackground { Depth = 1 }); Add(new OpaqueBackground { Depth = 1 });
Flow.Add(avatar = new UpdateableAvatar Flow.Add(avatar = new UpdateableAvatar(openOnClick: false)
{ {
Masking = true, Masking = true,
Size = new Vector2(32), Size = new Vector2(32),
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
CornerRadius = 4, CornerRadius = 4,
OpenOnClick = { Value = false },
EdgeEffect = new EdgeEffectParameters EdgeEffect = new EdgeEffectParameters
{ {
Type = EdgeEffectType.Shadow, Type = EdgeEffectType.Shadow,

View File

@ -1,7 +1,9 @@
// 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;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Mods namespace osu.Game.Rulesets.Mods
@ -9,13 +11,20 @@ namespace osu.Game.Rulesets.Mods
/// <summary> /// <summary>
/// An interface for <see cref="Mod"/>s that can be applied to <see cref="DrawableHitObject"/>s. /// An interface for <see cref="Mod"/>s that can be applied to <see cref="DrawableHitObject"/>s.
/// </summary> /// </summary>
public interface IApplicableToDrawableHitObjects : IApplicableMod public interface IApplicableToDrawableHitObject : IApplicableMod
{ {
/// <summary> /// <summary>
/// Applies this <see cref="IApplicableToDrawableHitObjects"/> to a list of <see cref="DrawableHitObject"/>s. /// Applies this <see cref="IApplicableToDrawableHitObject"/> to a <see cref="DrawableHitObject"/>.
/// This will only be invoked with top-level <see cref="DrawableHitObject"/>s. Access <see cref="DrawableHitObject.NestedHitObjects"/> if adjusting nested objects is necessary. /// This will only be invoked with top-level <see cref="DrawableHitObject"/>s. Access <see cref="DrawableHitObject.NestedHitObjects"/> if adjusting nested objects is necessary.
/// </summary> /// </summary>
/// <param name="drawables">The list of <see cref="DrawableHitObject"/>s to apply to.</param> void ApplyToDrawableHitObject(DrawableHitObject drawable);
}
[Obsolete(@"Use the singular version IApplicableToDrawableHitObject instead.")] // Can be removed 20211216
public interface IApplicableToDrawableHitObjects : IApplicableToDrawableHitObject
{
void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables); void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables);
void IApplicableToDrawableHitObject.ApplyToDrawableHitObject(DrawableHitObject drawable) => ApplyToDrawableHitObjects(drawable.Yield());
} }
} }

View File

@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Mods
/// A <see cref="Mod"/> which applies visibility adjustments to <see cref="DrawableHitObject"/>s /// A <see cref="Mod"/> which applies visibility adjustments to <see cref="DrawableHitObject"/>s
/// with an optional increased visibility adjustment depending on the user's "increase first object visibility" setting. /// with an optional increased visibility adjustment depending on the user's "increase first object visibility" setting.
/// </summary> /// </summary>
public abstract class ModWithVisibilityAdjustment : Mod, IReadFromConfig, IApplicableToBeatmap, IApplicableToDrawableHitObjects public abstract class ModWithVisibilityAdjustment : Mod, IReadFromConfig, IApplicableToBeatmap, IApplicableToDrawableHitObject
{ {
/// <summary> /// <summary>
/// The first adjustable object. /// The first adjustable object.
@ -73,19 +73,16 @@ namespace osu.Game.Rulesets.Mods
} }
} }
public virtual void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables) public virtual void ApplyToDrawableHitObject(DrawableHitObject dho)
{ {
foreach (var dho in drawables) dho.ApplyCustomUpdateState += (o, state) =>
{ {
dho.ApplyCustomUpdateState += (o, state) => // Increased visibility is applied to the entire first object, including all of its nested hitobjects.
{ if (IncreaseFirstObjectVisibility.Value && isObjectEqualToOrNestedIn(o.HitObject, FirstObject))
// Increased visibility is applied to the entire first object, including all of its nested hitobjects. ApplyIncreasedVisibilityState(o, state);
if (IncreaseFirstObjectVisibility.Value && isObjectEqualToOrNestedIn(o.HitObject, FirstObject)) else
ApplyIncreasedVisibilityState(o, state); ApplyNormalVisibilityState(o, state);
else };
ApplyNormalVisibilityState(o, state);
};
}
} }
/// <summary> /// <summary>

View File

@ -199,8 +199,11 @@ namespace osu.Game.Rulesets.UI
Playfield.PostProcess(); Playfield.PostProcess();
foreach (var mod in Mods.OfType<IApplicableToDrawableHitObjects>()) foreach (var mod in Mods.OfType<IApplicableToDrawableHitObject>())
mod.ApplyToDrawableHitObjects(Playfield.AllHitObjects); {
foreach (var drawableHitObject in Playfield.AllHitObjects)
mod.ApplyToDrawableHitObject(drawableHitObject);
}
} }
public override void RequestResume(Action continueResume) public override void RequestResume(Action continueResume)

View File

@ -356,8 +356,8 @@ namespace osu.Game.Rulesets.UI
// This is done before Apply() so that the state is updated once when the hitobject is applied. // This is done before Apply() so that the state is updated once when the hitobject is applied.
if (mods != null) if (mods != null)
{ {
foreach (var m in mods.OfType<IApplicableToDrawableHitObjects>()) foreach (var m in mods.OfType<IApplicableToDrawableHitObject>())
m.ApplyToDrawableHitObjects(dho.Yield()); m.ApplyToDrawableHitObject(dho);
} }
} }

View File

@ -5,7 +5,6 @@ using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Users; using osu.Game.Users;
@ -91,7 +90,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
}); });
} }
private class UserTile : CompositeDrawable, IHasTooltip private class UserTile : CompositeDrawable
{ {
public User User public User User
{ {
@ -99,8 +98,6 @@ namespace osu.Game.Screens.OnlinePlay.Components
set => avatar.User = value; set => avatar.User = value;
} }
public string TooltipText => User?.Username ?? string.Empty;
private readonly UpdateableAvatar avatar; private readonly UpdateableAvatar avatar;
public UserTile() public UserTile()
@ -116,7 +113,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex(@"27252d"), Colour = Color4Extensions.FromHex(@"27252d"),
}, },
avatar = new UpdateableAvatar { RelativeSizeAxes = Axes.Both }, avatar = new UpdateableAvatar(showUsernameTooltip: true) { RelativeSizeAxes = Axes.Both },
}; };
} }
} }

View File

@ -509,16 +509,18 @@ namespace osu.Game.Screens.Play
/// Attempts to complete a user request to exit gameplay. /// Attempts to complete a user request to exit gameplay.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// - This should only be called in response to a user interaction. Exiting is not guaranteed. /// <list type="bullet">
/// - This will interrupt any pending progression to the results screen, even if the transition has begun. /// <item>This should only be called in response to a user interaction. Exiting is not guaranteed.</item>
/// <item>This will interrupt any pending progression to the results screen, even if the transition has begun.</item>
/// </list>
/// </remarks> /// </remarks>
/// <param name="showDialogFirst"> /// <param name="showDialogFirst">
/// Whether the pause or fail dialog should be shown before performing an exit. /// Whether the pause or fail dialog should be shown before performing an exit.
/// If <c>true</c> and a dialog is not yet displayed, the exit will be blocked the relevant dialog will display instead. /// If <see langword="true"/> and a dialog is not yet displayed, the exit will be blocked and the relevant dialog will display instead.
/// </param> /// </param>
protected void PerformExit(bool showDialogFirst) protected void PerformExit(bool showDialogFirst)
{ {
// if an exit has been requested, cancel any pending completion (the user has showing intention to exit). // if an exit has been requested, cancel any pending completion (the user has shown intention to exit).
resultsDisplayDelegate?.Cancel(); resultsDisplayDelegate?.Cancel();
// there is a chance that an exit request occurs after the transition to results has already started. // there is a chance that an exit request occurs after the transition to results has already started.

View File

@ -2,7 +2,6 @@
// 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 osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -13,16 +12,32 @@ namespace osu.Game.Users.Drawables
{ {
public class ClickableAvatar : Container public class ClickableAvatar : Container
{ {
private const string default_tooltip_text = "view profile";
/// <summary> /// <summary>
/// Whether to open the user's profile when clicked. /// Whether to open the user's profile when clicked.
/// </summary> /// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true); public bool OpenOnClick
{
set => clickableArea.Enabled.Value = value;
}
/// <summary>
/// By default, the tooltip will show "view profile" as avatars are usually displayed next to a username.
/// Setting this to <c>true</c> exposes the username via tooltip for special cases where this is not true.
/// </summary>
public bool ShowUsernameTooltip
{
set => clickableArea.TooltipText = value ? (user?.Username ?? string.Empty) : default_tooltip_text;
}
private readonly User user; private readonly User user;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private OsuGame game { get; set; } private OsuGame game { get; set; }
private readonly ClickableArea clickableArea;
/// <summary> /// <summary>
/// A clickable avatar for the specified user, with UI sounds included. /// A clickable avatar for the specified user, with UI sounds included.
/// If <see cref="OpenOnClick"/> is <c>true</c>, clicking will open the user's profile. /// If <see cref="OpenOnClick"/> is <c>true</c>, clicking will open the user's profile.
@ -31,35 +46,35 @@ namespace osu.Game.Users.Drawables
public ClickableAvatar(User user = null) public ClickableAvatar(User user = null)
{ {
this.user = user; this.user = user;
}
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
{
ClickableArea clickableArea;
Add(clickableArea = new ClickableArea Add(clickableArea = new ClickableArea
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Action = openProfile Action = openProfile
}); });
}
[BackgroundDependencyLoader]
private void load(LargeTextureStore textures)
{
LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add); LoadComponentAsync(new DrawableAvatar(user), clickableArea.Add);
clickableArea.Enabled.BindTo(OpenOnClick);
} }
private void openProfile() private void openProfile()
{ {
if (!OpenOnClick.Value)
return;
if (user?.Id > 1) if (user?.Id > 1)
game?.ShowUser(user.Id); game?.ShowUser(user.Id);
} }
private class ClickableArea : OsuClickableContainer private class ClickableArea : OsuClickableContainer
{ {
public override string TooltipText => Enabled.Value ? @"view profile" : null; private string tooltip = default_tooltip_text;
public override string TooltipText
{
get => Enabled.Value ? tooltip : null;
set => tooltip = value;
}
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {

View File

@ -1,7 +1,6 @@
// 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 osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
@ -45,33 +44,38 @@ namespace osu.Game.Users.Drawables
protected override double LoadDelay => 200; protected override double LoadDelay => 200;
/// <summary> private readonly bool openOnClick;
/// Whether to show a default guest representation on null user (as opposed to nothing). private readonly bool showUsernameTooltip;
/// </summary> private readonly bool showGuestOnNull;
public bool ShowGuestOnNull = true;
/// <summary> /// <summary>
/// Whether to open the user's profile when clicked. /// Construct a new UpdateableAvatar.
/// </summary> /// </summary>
public readonly BindableBool OpenOnClick = new BindableBool(true); /// <param name="user">The initial user to display.</param>
/// <param name="openOnClick">Whether to open the user's profile when clicked.</param>
public UpdateableAvatar(User user = null) /// <param name="showUsernameTooltip">Whether to show the username rather than "view profile" on the tooltip.</param>
/// <param name="showGuestOnNull">Whether to show a default guest representation on null user (as opposed to nothing).</param>
public UpdateableAvatar(User user = null, bool openOnClick = true, bool showUsernameTooltip = false, bool showGuestOnNull = true)
{ {
this.openOnClick = openOnClick;
this.showUsernameTooltip = showUsernameTooltip;
this.showGuestOnNull = showGuestOnNull;
User = user; User = user;
} }
protected override Drawable CreateDrawable(User user) protected override Drawable CreateDrawable(User user)
{ {
if (user == null && !ShowGuestOnNull) if (user == null && !showGuestOnNull)
return null; return null;
var avatar = new ClickableAvatar(user) var avatar = new ClickableAvatar(user)
{ {
OpenOnClick = openOnClick,
ShowUsernameTooltip = showUsernameTooltip,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}; };
avatar.OpenOnClick.BindTo(OpenOnClick);
return avatar; return avatar;
} }
} }

View File

@ -48,11 +48,7 @@ namespace osu.Game.Users
statusIcon.FinishTransforms(); statusIcon.FinishTransforms();
} }
protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar protected UpdateableAvatar CreateAvatar() => new UpdateableAvatar(User, false);
{
User = User,
OpenOnClick = { Value = false }
};
protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.Country) protected UpdateableFlag CreateFlag() => new UpdateableFlag(User.Country)
{ {