Content update for UI prediction (#27214)
* Content update for UI refactor * Big update * Sharing * Remaining content updates * First big update * Prototype updates * AUGH * Fix UI comp ref * Cleanup - Fix predicted message, fix item slots, fix interaction range check. * Fix regressions * Make this predictive idk why it wasn't. * Fix slime merge * Merge conflict * Fix merge
This commit is contained in:
@@ -157,39 +157,37 @@ public sealed partial class BlockGame
|
||||
/// <param name="message">The message to broadcase to all players/spectators.</param>
|
||||
private void SendMessage(BoundUserInterfaceMessage message)
|
||||
{
|
||||
if (_uiSystem.TryGetUi(_owner, BlockGameUiKey.Key, out var bui))
|
||||
_uiSystem.SendUiMessage(bui, message);
|
||||
_uiSystem.ServerSendUiMessage(_entityManager.GetEntity(message.Entity), BlockGameUiKey.Key, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles sending a message to a specific player/spectator.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to send to a specific player/spectator.</param>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendMessage(BoundUserInterfaceMessage message, ICommonSession session)
|
||||
/// <param name="actor">The target recipient.</param>
|
||||
private void SendMessage(BoundUserInterfaceMessage message, EntityUid actor)
|
||||
{
|
||||
if (_uiSystem.TryGetUi(_owner, BlockGameUiKey.Key, out var bui))
|
||||
_uiSystem.TrySendUiMessage(bui, message, session);
|
||||
_uiSystem.ServerSendUiMessage(_entityManager.GetEntity(message.Entity), BlockGameUiKey.Key, message, actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles sending the current state of the game to a player that has just opened the UI.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
public void UpdateNewPlayerUI(ICommonSession session)
|
||||
/// <param name="actor">The target recipient.</param>
|
||||
public void UpdateNewPlayerUI(EntityUid actor)
|
||||
{
|
||||
if (_gameOver)
|
||||
{
|
||||
SendMessage(new BlockGameMessages.BlockGameGameOverScreenMessage(Points, _highScorePlacement?.LocalPlacement, _highScorePlacement?.GlobalPlacement), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameGameOverScreenMessage(Points, _highScorePlacement?.LocalPlacement, _highScorePlacement?.GlobalPlacement), actor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Paused)
|
||||
SendMessage(new BlockGameMessages.BlockGameSetScreenMessage(BlockGameMessages.BlockGameScreen.Pause, Started), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameSetScreenMessage(BlockGameMessages.BlockGameScreen.Pause, Started), actor);
|
||||
else
|
||||
SendMessage(new BlockGameMessages.BlockGameSetScreenMessage(BlockGameMessages.BlockGameScreen.Game, Started), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameSetScreenMessage(BlockGameMessages.BlockGameScreen.Game, Started), actor);
|
||||
|
||||
FullUpdate(session);
|
||||
FullUpdate(actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -209,14 +207,14 @@ public sealed partial class BlockGame
|
||||
/// Handles broadcasting the full player-visible game state to a specific player/spectator.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void FullUpdate(ICommonSession session)
|
||||
private void FullUpdate(EntityUid actor)
|
||||
{
|
||||
UpdateFieldUI(session);
|
||||
SendNextPieceUpdate(session);
|
||||
SendHoldPieceUpdate(session);
|
||||
SendLevelUpdate(session);
|
||||
SendPointsUpdate(session);
|
||||
SendHighscoreUpdate(session);
|
||||
UpdateFieldUI(actor);
|
||||
SendNextPieceUpdate(actor);
|
||||
SendHoldPieceUpdate(actor);
|
||||
SendLevelUpdate(actor);
|
||||
SendPointsUpdate(actor);
|
||||
SendHighscoreUpdate(actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -234,14 +232,13 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Handles broadcasting the current location of all of the blocks in the playfield + the active piece to a specific player/spectator.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
public void UpdateFieldUI(ICommonSession session)
|
||||
public void UpdateFieldUI(EntityUid actor)
|
||||
{
|
||||
if (!Started)
|
||||
return;
|
||||
|
||||
var computedField = ComputeField();
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(computedField.ToArray(), BlockGameMessages.BlockGameVisualType.GameField), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(computedField.ToArray(), BlockGameMessages.BlockGameVisualType.GameField), actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -282,10 +279,9 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Broadcasts the state of the next queued piece to a specific viewer.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendNextPieceUpdate(ICommonSession session)
|
||||
private void SendNextPieceUpdate(EntityUid actor)
|
||||
{
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(NextPiece.BlocksForPreview(), BlockGameMessages.BlockGameVisualType.NextBlock), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(NextPiece.BlocksForPreview(), BlockGameMessages.BlockGameVisualType.NextBlock), actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -302,13 +298,12 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Broadcasts the state of the currently held piece to a specific viewer.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendHoldPieceUpdate(ICommonSession session)
|
||||
private void SendHoldPieceUpdate(EntityUid actor)
|
||||
{
|
||||
if (HeldPiece.HasValue)
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(HeldPiece.Value.BlocksForPreview(), BlockGameMessages.BlockGameVisualType.HoldBlock), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(HeldPiece.Value.BlocksForPreview(), BlockGameMessages.BlockGameVisualType.HoldBlock), actor);
|
||||
else
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(Array.Empty<BlockGameBlock>(), BlockGameMessages.BlockGameVisualType.HoldBlock), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameVisualUpdateMessage(Array.Empty<BlockGameBlock>(), BlockGameMessages.BlockGameVisualType.HoldBlock), actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -322,10 +317,9 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Broadcasts the current game level to a specific viewer.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendLevelUpdate(ICommonSession session)
|
||||
private void SendLevelUpdate(EntityUid actor)
|
||||
{
|
||||
SendMessage(new BlockGameMessages.BlockGameLevelUpdateMessage(Level), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameLevelUpdateMessage(Level), actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -339,10 +333,9 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Broadcasts the current game score to a specific viewer.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendPointsUpdate(ICommonSession session)
|
||||
private void SendPointsUpdate(EntityUid actor)
|
||||
{
|
||||
SendMessage(new BlockGameMessages.BlockGameScoreUpdateMessage(Points), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameScoreUpdateMessage(Points), actor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -356,9 +349,8 @@ public sealed partial class BlockGame
|
||||
/// <summary>
|
||||
/// Broadcasts the current game high score positions to a specific viewer.
|
||||
/// </summary>
|
||||
/// <param name="session">The target recipient.</param>
|
||||
private void SendHighscoreUpdate(ICommonSession session)
|
||||
private void SendHighscoreUpdate(EntityUid actor)
|
||||
{
|
||||
SendMessage(new BlockGameMessages.BlockGameHighScoreUpdateMessage(_arcadeSystem.GetLocalHighscores(), _arcadeSystem.GetGlobalHighscores()), session);
|
||||
SendMessage(new BlockGameMessages.BlockGameHighScoreUpdateMessage(_arcadeSystem.GetLocalHighscores(), _arcadeSystem.GetGlobalHighscores()), actor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ public sealed partial class BlockGame
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
private readonly ArcadeSystem _arcadeSystem = default!;
|
||||
private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
private readonly ArcadeSystem _arcadeSystem;
|
||||
private readonly UserInterfaceSystem _uiSystem;
|
||||
|
||||
/// <summary>
|
||||
/// What entity is currently hosting this game of NT-BG.
|
||||
@@ -78,7 +78,7 @@ public sealed partial class BlockGame
|
||||
_gameOver = true;
|
||||
|
||||
if (_entityManager.TryGetComponent<BlockGameArcadeComponent>(_owner, out var cabinet)
|
||||
&& _entityManager.TryGetComponent<MetaDataComponent>(cabinet.Player?.AttachedEntity, out var meta))
|
||||
&& _entityManager.TryGetComponent<MetaDataComponent>(cabinet.Player, out var meta))
|
||||
{
|
||||
_highScorePlacement = _arcadeSystem.RegisterHighScore(meta.EntityName, Points);
|
||||
SendHighscoreUpdate();
|
||||
|
||||
@@ -13,10 +13,10 @@ public sealed partial class BlockGameArcadeComponent : Component
|
||||
/// <summary>
|
||||
/// The player currently playing the active session of NT-BG.
|
||||
/// </summary>
|
||||
public ICommonSession? Player = null;
|
||||
public EntityUid? Player = null;
|
||||
|
||||
/// <summary>
|
||||
/// The players currently viewing (but not playing) the active session of NT-BG.
|
||||
/// </summary>
|
||||
public readonly List<ICommonSession> Spectators = new();
|
||||
public readonly List<EntityUid> Spectators = new();
|
||||
}
|
||||
|
||||
@@ -37,14 +37,12 @@ public sealed class BlockGameArcadeSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePlayerStatus(EntityUid uid, ICommonSession session, PlayerBoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null)
|
||||
private void UpdatePlayerStatus(EntityUid uid, EntityUid actor, BlockGameArcadeComponent? blockGame = null)
|
||||
{
|
||||
if (!Resolve(uid, ref blockGame))
|
||||
return;
|
||||
if (bui == null && !_uiSystem.TryGetUi(uid, BlockGameUiKey.Key, out bui))
|
||||
return;
|
||||
|
||||
_uiSystem.TrySendUiMessage(bui, new BlockGameMessages.BlockGameUserStatusMessage(blockGame.Player == session), session);
|
||||
_uiSystem.ServerSendUiMessage(uid, BlockGameUiKey.Key, new BlockGameMessages.BlockGameUserStatusMessage(blockGame.Player == actor), actor);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, BlockGameArcadeComponent component, ComponentInit args)
|
||||
@@ -54,33 +52,21 @@ public sealed class BlockGameArcadeSystem : EntitySystem
|
||||
|
||||
private void OnAfterUIOpen(EntityUid uid, BlockGameArcadeComponent component, AfterActivatableUIOpenEvent args)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(args.User, out var actor))
|
||||
return;
|
||||
if (!_uiSystem.TryGetUi(uid, BlockGameUiKey.Key, out var bui))
|
||||
return;
|
||||
|
||||
var session = actor.PlayerSession;
|
||||
if (!bui.SubscribedSessions.Contains(session))
|
||||
return;
|
||||
|
||||
if (component.Player == null)
|
||||
component.Player = session;
|
||||
component.Player = args.Actor;
|
||||
else
|
||||
component.Spectators.Add(session);
|
||||
component.Spectators.Add(args.Actor);
|
||||
|
||||
UpdatePlayerStatus(uid, session, bui, component);
|
||||
component.Game?.UpdateNewPlayerUI(session);
|
||||
UpdatePlayerStatus(uid, args.Actor, component);
|
||||
component.Game?.UpdateNewPlayerUI(args.Actor);
|
||||
}
|
||||
|
||||
private void OnAfterUiClose(EntityUid uid, BlockGameArcadeComponent component, BoundUIClosedEvent args)
|
||||
{
|
||||
if (args.Session is not { } session)
|
||||
return;
|
||||
|
||||
if (component.Player != session)
|
||||
if (component.Player != args.Actor)
|
||||
{
|
||||
component.Spectators.Remove(session);
|
||||
UpdatePlayerStatus(uid, session, blockGame: component);
|
||||
component.Spectators.Remove(args.Actor);
|
||||
UpdatePlayerStatus(uid, args.Actor, blockGame: component);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,11 +74,11 @@ public sealed class BlockGameArcadeSystem : EntitySystem
|
||||
if (component.Spectators.Count > 0)
|
||||
{
|
||||
component.Player = component.Spectators[0];
|
||||
component.Spectators.Remove(component.Player);
|
||||
UpdatePlayerStatus(uid, component.Player, blockGame: component);
|
||||
component.Spectators.Remove(component.Player.Value);
|
||||
UpdatePlayerStatus(uid, component.Player.Value, blockGame: component);
|
||||
}
|
||||
|
||||
UpdatePlayerStatus(uid, temp, blockGame: component);
|
||||
UpdatePlayerStatus(uid, temp.Value, blockGame: component);
|
||||
}
|
||||
|
||||
private void OnBlockPowerChanged(EntityUid uid, BlockGameArcadeComponent component, ref PowerChangedEvent args)
|
||||
@@ -100,8 +86,7 @@ public sealed class BlockGameArcadeSystem : EntitySystem
|
||||
if (args.Powered)
|
||||
return;
|
||||
|
||||
if (_uiSystem.TryGetUi(uid, BlockGameUiKey.Key, out var bui))
|
||||
_uiSystem.CloseAll(bui);
|
||||
_uiSystem.CloseUi(uid, BlockGameUiKey.Key);
|
||||
component.Player = null;
|
||||
component.Spectators.Clear();
|
||||
}
|
||||
@@ -112,7 +97,7 @@ public sealed class BlockGameArcadeSystem : EntitySystem
|
||||
return;
|
||||
if (!BlockGameUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
if (msg.Session != component.Player)
|
||||
if (msg.Actor != component.Player)
|
||||
return;
|
||||
|
||||
if (msg.PlayerAction == BlockGamePlayerAction.NewGame)
|
||||
|
||||
Reference in New Issue
Block a user