1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Further refactorings along with shadow implementation

This commit is contained in:
Dean Herbert 2023-07-26 19:08:46 +09:00
parent 84bc14c1dd
commit 38244c081f
3 changed files with 26 additions and 21 deletions

View File

@ -67,8 +67,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
SpectatorPlayerClock = clock;
RelativeSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 5;
AudioContainer audioContainer;
InternalChildren = new Drawable[]

View File

@ -83,8 +83,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
var facade = new Facade();
facadeContainer.Add(facade);
var cell = new Cell(index, content) { ToggleMaximisationState = toggleMaximisationState };
cell.SetFacade(facade);
var cell = new Cell(index, content, facade) { ToggleMaximisationState = toggleMaximisationState };
cellContainer.Add(cell);
}
@ -99,30 +98,28 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
private void toggleMaximisationState(Cell target)
{
bool anyMaximised = target.IsMaximised = !target.IsMaximised;
// in the case the target is the already maximised cell, no cell should be maximised.
bool hasMaximised = !target.IsMaximised;
// Iterate through all cells to ensure only one is maximised at any time.
foreach (var cell in cellContainer.ToList())
{
if (cell != target)
cell.IsMaximised = false;
if (cell.IsMaximised)
if (hasMaximised && cell == target)
{
// Transfer cell to the maximised facade.
cell.SetFacade(MaximisedFacade);
cell.SetFacade(MaximisedFacade, true);
cellContainer.ChangeChildDepth(cell, maximisedInstanceDepth -= 0.001f);
}
else
{
// Transfer cell back to its original facade.
cell.SetFacade(facadeContainer[cell.FacadeIndex]);
cell.SetFacade(facadeContainer[cell.FacadeIndex], false);
}
cell.FadeColour(anyMaximised && cell != target ? Color4.Gray : Color4.White, ANIMATION_DELAY, Easing.Out);
cell.FadeColour(hasMaximised && cell != target ? Color4.Gray : Color4.White, ANIMATION_DELAY, Easing.OutQuint);
}
facadeContainer.ScaleTo(anyMaximised ? 0.95f : 1, ANIMATION_DELAY, Easing.OutQuint);
facadeContainer.ScaleTo(hasMaximised ? 0.95f : 1, ANIMATION_DELAY, Easing.OutQuint);
}
protected override void Update()

View File

@ -1,12 +1,10 @@
// 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.
#nullable disable
using System;
using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osuTK;
@ -33,23 +31,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// <summary>
/// An action that toggles the maximisation state of this cell.
/// </summary>
public Action<Cell> ToggleMaximisationState;
public Action<Cell>? ToggleMaximisationState;
/// <summary>
/// Whether this cell is currently maximised.
/// </summary>
public bool IsMaximised;
public bool IsMaximised { get; private set; }
private Facade facade;
private bool isAnimating;
public Cell(int facadeIndex, Drawable content)
public Cell(int facadeIndex, Drawable content, Facade facade)
{
FacadeIndex = facadeIndex;
this.facade = facade;
Origin = Anchor.Centre;
InternalChild = Content = content;
Masking = true;
CornerRadius = 5;
}
protected override void Update()
@ -78,10 +80,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
/// <summary>
/// Makes this cell track a new facade.
/// </summary>
public void SetFacade([NotNull] Facade newFacade)
public void SetFacade(Facade newFacade, bool isMaximised)
{
facade = newFacade;
IsMaximised = isMaximised;
isAnimating = true;
TweenEdgeEffectTo(new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Radius = isMaximised ? 30 : 10,
Colour = Colour4.Black.Opacity(isMaximised ? 0.5f : 0.2f),
}, ANIMATION_DELAY, Easing.OutQuint);
}
private Vector2 getFinalPosition() =>
@ -93,7 +103,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
protected override bool OnClick(ClickEvent e)
{
ToggleMaximisationState(this);
ToggleMaximisationState?.Invoke(this);
return true;
}
}