From 8cf6aa267c7be3d9bf734883dcdfda3acb83c456 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Fri, 16 Aug 2019 21:38:05 +0200 Subject: [PATCH] Allow single observers to use spectator team chat in mp --- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index adea6e196d..140ea4c9a4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -49,10 +49,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var players = world.Players.Where(p => p != world.LocalPlayer && !p.NonCombatant && !p.IsBot); var isObserver = orderManager.LocalClient != null && orderManager.LocalClient.IsObserver; - var isOnlyObserver = isObserver && orderManager.LobbyInfo.Clients.All(c => c == orderManager.LocalClient || !c.IsObserver); - var observersExist = orderManager.LobbyInfo.Clients.Any(c => c.IsObserver); var alwaysDisabled = world.IsReplay || world.LobbyInfo.NonBotClients.Count() == 1; - var disableTeamChat = alwaysDisabled || isOnlyObserver || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer))); + var disableTeamChat = alwaysDisabled || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer))); var teamChat = !disableTeamChat; tabCompletion.Commands = chatTraits.OfType().SelectMany(x => x.Commands.Keys).ToList(); @@ -73,47 +71,26 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatMode.GetText = () => teamChat && !disableTeamChat ? "Team" : "All"; chatMode.OnClick = () => teamChat ^= true; - // Team chat is disabled if we are the only spectator - // This changes as soon as a defeated player can talk in the spectator chat - if (!alwaysDisabled && isOnlyObserver) + // Enable teamchat if we are a player and die, + // or disable it when we are the only one left in the team + if (!alwaysDisabled && world.LocalPlayer != null) { chatMode.IsDisabled = () => { if (world.IsGameOver) return true; - disableTeamChat = players.All(p => p.WinState == WinState.Undefined); - return disableTeamChat; - }; - } - else if (!alwaysDisabled && world.LocalPlayer != null) - { - chatMode.IsDisabled = () => - { - if (world.IsGameOver) - return true; - - // Check if we are the only living team member - if (players.All(p => p.WinState != WinState.Undefined || !p.IsAlliedWith(world.LocalPlayer))) - { - disableTeamChat = true; - return disableTeamChat; - } - - // Still alive and nothing changed since the start - if (world.LocalPlayer.WinState == WinState.Undefined) - return disableTeamChat; - - // At this point our player is dead - // Allow to chat with existing spectators - if (observersExist) + // The game is over for us, join spectator team chat + if (world.LocalPlayer.WinState != WinState.Undefined) { disableTeamChat = false; return disableTeamChat; } - // Or wait until another player died - disableTeamChat = players.All(p => p.WinState == WinState.Undefined); + // If team chat isn't already disabled, check if we are the only living team member + if (!disableTeamChat) + disableTeamChat = players.All(p => p.WinState != WinState.Undefined || !p.IsAlliedWith(world.LocalPlayer)); + return disableTeamChat; }; }