2021-04-07 22:15:09 +08:00
|
|
|
// 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.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-07-26 18:08:46 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2021-04-07 22:15:09 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2023-07-26 17:56:41 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-04-07 22:15:09 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
|
|
|
|
{
|
|
|
|
public partial class PlayerGrid
|
|
|
|
{
|
2021-04-07 23:06:32 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A cell of the grid. Contains the content and tracks to the linked facade.
|
|
|
|
/// </summary>
|
2021-04-07 22:15:09 +08:00
|
|
|
private partial class Cell : CompositeDrawable
|
|
|
|
{
|
2021-04-07 23:06:14 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The index of the original facade of this cell.
|
|
|
|
/// </summary>
|
|
|
|
public readonly int FacadeIndex;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The contained content.
|
|
|
|
/// </summary>
|
|
|
|
public readonly Drawable Content;
|
|
|
|
|
2021-04-07 23:06:32 +08:00
|
|
|
/// <summary>
|
|
|
|
/// An action that toggles the maximisation state of this cell.
|
|
|
|
/// </summary>
|
2023-07-26 18:08:46 +08:00
|
|
|
public Action<Cell>? ToggleMaximisationState;
|
2021-04-07 23:06:32 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether this cell is currently maximised.
|
|
|
|
/// </summary>
|
2023-07-26 18:08:46 +08:00
|
|
|
public bool IsMaximised { get; private set; }
|
2021-04-07 22:15:09 +08:00
|
|
|
|
2021-04-07 23:06:14 +08:00
|
|
|
private Facade facade;
|
2023-07-26 17:56:41 +08:00
|
|
|
|
|
|
|
private bool isAnimating;
|
2021-04-07 22:15:09 +08:00
|
|
|
|
2023-07-26 18:08:46 +08:00
|
|
|
public Cell(int facadeIndex, Drawable content, Facade facade)
|
2021-04-07 22:15:09 +08:00
|
|
|
{
|
2021-04-07 23:06:14 +08:00
|
|
|
FacadeIndex = facadeIndex;
|
2023-07-26 18:08:46 +08:00
|
|
|
this.facade = facade;
|
2021-04-07 22:15:09 +08:00
|
|
|
|
2021-04-07 23:06:14 +08:00
|
|
|
Origin = Anchor.Centre;
|
|
|
|
InternalChild = Content = content;
|
2023-07-26 18:08:46 +08:00
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 5;
|
2021-04-07 22:15:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2023-07-26 17:56:41 +08:00
|
|
|
var targetPos = getFinalPosition();
|
|
|
|
var targetSize = getFinalSize();
|
|
|
|
|
|
|
|
double duration = isAnimating ? 60 : 0;
|
|
|
|
|
|
|
|
Position = new Vector2(
|
|
|
|
(float)Interpolation.DampContinuously(Position.X, targetPos.X, duration, Time.Elapsed),
|
|
|
|
(float)Interpolation.DampContinuously(Position.Y, targetPos.Y, duration, Time.Elapsed)
|
|
|
|
);
|
|
|
|
|
|
|
|
Size = new Vector2(
|
|
|
|
(float)Interpolation.DampContinuously(Size.X, targetSize.X, duration, Time.Elapsed),
|
|
|
|
(float)Interpolation.DampContinuously(Size.Y, targetSize.Y, duration, Time.Elapsed)
|
|
|
|
);
|
|
|
|
|
|
|
|
// If we don't track the animating state, the animation will also occur when resizing the window.
|
2023-08-01 19:18:21 +08:00
|
|
|
isAnimating &= !Precision.AlmostEquals(Size, targetSize, 0.5f);
|
2021-04-07 22:15:09 +08:00
|
|
|
}
|
|
|
|
|
2021-04-07 23:06:14 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Makes this cell track a new facade.
|
|
|
|
/// </summary>
|
2023-07-26 18:08:46 +08:00
|
|
|
public void SetFacade(Facade newFacade, bool isMaximised)
|
2021-04-07 22:15:09 +08:00
|
|
|
{
|
|
|
|
facade = newFacade;
|
2023-07-26 18:08:46 +08:00
|
|
|
IsMaximised = isMaximised;
|
2023-07-26 17:56:41 +08:00
|
|
|
isAnimating = true;
|
2023-07-26 18:08:46 +08:00
|
|
|
|
|
|
|
TweenEdgeEffectTo(new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = isMaximised ? 30 : 10,
|
|
|
|
Colour = Colour4.Black.Opacity(isMaximised ? 0.5f : 0.2f),
|
|
|
|
}, ANIMATION_DELAY, Easing.OutQuint);
|
2021-04-07 22:15:09 +08:00
|
|
|
}
|
|
|
|
|
2023-07-26 17:56:41 +08:00
|
|
|
private Vector2 getFinalPosition() =>
|
2023-10-17 16:40:44 +08:00
|
|
|
Parent!.ToLocalSpace(facade.ScreenSpaceDrawQuad.Centre);
|
2021-04-07 22:15:09 +08:00
|
|
|
|
2023-07-26 17:56:41 +08:00
|
|
|
private Vector2 getFinalSize() =>
|
2023-10-17 16:40:44 +08:00
|
|
|
Parent!.ToLocalSpace(facade.ScreenSpaceDrawQuad.BottomRight)
|
|
|
|
- Parent!.ToLocalSpace(facade.ScreenSpaceDrawQuad.TopLeft);
|
2021-04-07 22:15:09 +08:00
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2023-07-26 18:08:46 +08:00
|
|
|
ToggleMaximisationState?.Invoke(this);
|
2021-04-07 22:15:09 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|