// Copyright (c) ppy Pty Ltd . 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 { /// /// A cell of the grid. Contains the content and tracks to the linked facade. /// private class Cell : CompositeDrawable { /// /// The index of the original facade of this cell. /// public readonly int FacadeIndex; /// /// The contained content. /// public readonly Drawable Content; /// /// An action that toggles the maximisation state of this cell. /// public Action ToggleMaximisationState; /// /// Whether this cell is currently maximised. /// public bool IsMaximised; private Facade facade; private bool isTracking = true; public Cell(int facadeIndex, Drawable content) { FacadeIndex = facadeIndex; Origin = Anchor.Centre; InternalChild = Content = content; } protected override void Update() { base.Update(); if (isTracking) { Position = getFinalPosition(); Size = getFinalSize(); } } /// /// Makes this cell track a new facade. /// public void SetFacade([NotNull] Facade newFacade) { Facade lastFacade = facade; 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; } } } }