1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 12:43:06 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerGrid_Cell.cs

100 lines
2.9 KiB
C#
Raw Normal View History

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 JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
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 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>
2021-04-07 22:15:09 +08:00
public Action<Cell> ToggleMaximisationState;
2021-04-07 23:06:32 +08:00
/// <summary>
/// Whether this cell is currently maximised.
/// </summary>
2021-04-07 22:15:09 +08:00
public bool IsMaximised;
2021-04-07 23:06:14 +08:00
private Facade facade;
2021-04-07 22:15:09 +08:00
private bool isTracking = true;
2021-04-07 23:06:14 +08:00
public Cell(int facadeIndex, Drawable content)
2021-04-07 22:15:09 +08:00
{
2021-04-07 23:06:14 +08:00
FacadeIndex = facadeIndex;
2021-04-07 22:15:09 +08:00
2021-04-07 23:06:14 +08:00
Origin = Anchor.Centre;
InternalChild = Content = content;
2021-04-07 22:15:09 +08:00
}
protected override void Update()
{
base.Update();
if (isTracking)
{
Position = getFinalPosition();
Size = getFinalSize();
}
}
2021-04-07 23:06:14 +08:00
/// <summary>
/// Makes this cell track a new facade.
/// </summary>
public void SetFacade([NotNull] Facade newFacade)
2021-04-07 22:15:09 +08:00
{
2021-04-07 23:06:14 +08:00
Facade lastFacade = facade;
2021-04-07 22:15:09 +08:00
facade = newFacade;
if (lastFacade == null || lastFacade == newFacade)
return;
isTracking = false;
this.MoveTo(getFinalPosition(), 400, Easing.OutQuint).ResizeTo(getFinalSize(), 400, Easing.OutQuint)
.Then()
.OnComplete(_ =>
{
if (facade == newFacade)
isTracking = true;
});
}
private Vector2 getFinalPosition()
{
var topLeft = Parent.ToLocalSpace(facade.ToScreenSpace(Vector2.Zero));
return topLeft + facade.DrawSize / 2;
}
private Vector2 getFinalSize() => facade.DrawSize;
protected override bool OnClick(ClickEvent e)
{
ToggleMaximisationState(this);
return true;
}
}
}
}