From 7f8aa97fb637626c9df6bcda0d81694e679b26b5 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Wed, 10 Aug 2022 12:58:59 +0300 Subject: [PATCH] Add per player mutes --- OpenRA.Game/TextNotificationsManager.cs | 3 +++ .../Logic/Ingame/GameInfoStatsLogic.cs | 20 ++++++++++++-- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 6 +++++ mods/cnc/chrome.yaml | 27 +++++++++++++++++++ mods/cnc/chrome/ingame-infostats.yaml | 14 ++++++++++ mods/common/chrome/ingame-infostats.yaml | 14 ++++++++++ mods/d2k/chrome.yaml | 27 +++++++++++++++++++ mods/d2k/chrome/ingame-infostats.yaml | 14 ++++++++++ mods/ra/chrome.yaml | 27 +++++++++++++++++++ mods/ts/chrome.yaml | 27 +++++++++++++++++++ 10 files changed, 177 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/TextNotificationsManager.cs b/OpenRA.Game/TextNotificationsManager.cs index e709f76329d8..63f320f6b8df 100644 --- a/OpenRA.Game/TextNotificationsManager.cs +++ b/OpenRA.Game/TextNotificationsManager.cs @@ -21,6 +21,8 @@ public static class TextNotificationsManager static readonly string SystemMessageLabel; public static long ChatDisabledUntil { get; internal set; } + public static readonly Dictionary MutedPlayers = new Dictionary(); + static readonly List NotificationsCache = new List(); public static IReadOnlyList Notifications => NotificationsCache; @@ -94,6 +96,7 @@ static bool IsPoolEnabled(TextNotificationPool pool) public static void Clear() { NotificationsCache.Clear(); + MutedPlayers.Clear(); } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 88ade69eb74f..043ce473a980 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -27,6 +27,7 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, { var player = world.LocalPlayer; var playerPanel = widget.Get("PLAYER_LIST"); + var statsHeader = widget.Get("STATS_HEADERS"); if (player != null && !player.NonCombatant) { @@ -51,7 +52,6 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, { // Expand the stats window to cover the hidden objectives var objectiveGroup = widget.Get("OBJECTIVE"); - var statsHeader = widget.Get("STATS_HEADERS"); objectiveGroup.Visible = false; statsHeader.Bounds.Y -= objectiveGroup.Bounds.Height; @@ -59,6 +59,10 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, playerPanel.Bounds.Height += objectiveGroup.Bounds.Height; } + // orderManager.LocalClient is null when watching a replay + if (!orderManager.LobbyInfo.Clients.Any(c => !c.IsBot && c.Index != orderManager.LocalClient?.Index && c.State != Session.ClientState.Disconnected)) + statsHeader.Get("ACTIONS").Visible = false; + var teamTemplate = playerPanel.Get("TEAM_TEMPLATE"); var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE"); var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE"); @@ -112,6 +116,12 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, var scoreCache = new CachedTransform(s => s.ToString()); item.Get("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0); + var muteCheckbox = item.Get("MUTE"); + muteCheckbox.IsChecked = () => TextNotificationsManager.MutedPlayers[pp.ClientIndex]; + muteCheckbox.OnClick = () => TextNotificationsManager.MutedPlayers[pp.ClientIndex] ^= true; + muteCheckbox.IsVisible = () => !pp.IsBot && client.State != Session.ClientState.Disconnected && pp.ClientIndex != orderManager.LocalClient?.Index; + muteCheckbox.GetTooltipText = () => muteCheckbox.IsChecked() ? "Unmute this player" : "Mute this player"; + playerPanel.AddChild(item); } } @@ -143,7 +153,7 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, }; var kickButton = item.Get("KICK"); - kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient.Index && client.State != Session.ClientState.Disconnected; + kickButton.IsVisible = () => Game.IsHost && client.Index != orderManager.LocalClient?.Index && client.State != Session.ClientState.Disconnected; kickButton.OnClick = () => { hideMenu(true); @@ -159,6 +169,12 @@ public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, confirmText: "Kick"); }; + var muteCheckbox = item.Get("MUTE"); + muteCheckbox.IsChecked = () => TextNotificationsManager.MutedPlayers[client.Index]; + muteCheckbox.OnClick = () => TextNotificationsManager.MutedPlayers[client.Index] ^= true; + muteCheckbox.IsVisible = () => !client.IsBot && client.State != Session.ClientState.Disconnected && client.Index != orderManager.LocalClient?.Index; + muteCheckbox.GetTooltipText = () => muteCheckbox.IsChecked() ? "Unmute this player" : "Mute this player"; + playerPanel.AddChild(item); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 8e94ed5a1df2..e00bbf4fc7d1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -57,6 +57,9 @@ public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Mo var disableTeamChat = alwaysDisabled || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer))); var teamChat = !disableTeamChat; + if (TextNotificationsManager.MutedPlayers.Count == 0) + orderManager.LobbyInfo.Clients.Do((c) => TextNotificationsManager.MutedPlayers.Add(c.Index, false)); + tabCompletion.Commands = chatTraits.OfType().ToArray().SelectMany(x => x.Commands.Keys); tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList(); @@ -261,6 +264,9 @@ void INotificationHandler.Handle(TextNotification notification if (!IsNotificationEligible(notification)) return; + if (notification.ClientId != TextNotificationsManager.SystemClientId && TextNotificationsManager.MutedPlayers[notification.ClientId]) + return; + if (!IsNotificationMuted(notification)) chatOverlayDisplay?.AddNotification(notification); diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index f9ede3236a6c..82fa145ff819 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -265,6 +265,22 @@ checkbox-highlighted-disabled: checkbox-highlighted-pressed: Inherits: button-highlighted-pressed +checkbox-toggle: + +checkbox-toggle-hover: + Inherits: checkbox + +checkbox-toggle-pressed: + Inherits: checkbox-pressed + +checkbox-toggle-highlighted: + +checkbox-toggle-highlighted-hover: + Inherits: checkbox-highlighted + +checkbox-toggle-highlighted-pressed: + Inherits: checkbox-highlighted-pressed + # # Panels # === @@ -418,6 +434,17 @@ checkmark-cross: checkmark-highlighted-cross: Inherits: checkmark-cross +checkmark-mute: + Inherits: ^Chrome + Regions: + unchecked: 768, 209, 16, 13 + unchecked-pressed: 785, 209, 16, 13 + checked: 785, 209, 16, 13 + checked-pressed: 768, 209, 16, 13 + +checkmark-highlighted-mute: + Inherits: checkmark-mute + flags: Inherits: ^Chrome Regions: diff --git a/mods/cnc/chrome/ingame-infostats.yaml b/mods/cnc/chrome/ingame-infostats.yaml index e6c689cd25a0..9be389dc762e 100644 --- a/mods/cnc/chrome/ingame-infostats.yaml +++ b/mods/cnc/chrome/ingame-infostats.yaml @@ -123,6 +123,13 @@ Container@SKIRMISH_STATS: Width: 60 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Container@SPECTATOR_TEMPLATE: Width: PARENT_RIGHT - 27 Height: 25 @@ -146,6 +153,13 @@ Container@SKIRMISH_STATS: Width: 191 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Button@KICK: X: 485 Width: 25 diff --git a/mods/common/chrome/ingame-infostats.yaml b/mods/common/chrome/ingame-infostats.yaml index 7c47234e3584..ded123bcd484 100644 --- a/mods/common/chrome/ingame-infostats.yaml +++ b/mods/common/chrome/ingame-infostats.yaml @@ -121,6 +121,13 @@ Container@SKIRMISH_STATS: Width: 60 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Container@SPECTATOR_TEMPLATE: Width: PARENT_RIGHT - 26 Height: 25 @@ -144,6 +151,13 @@ Container@SKIRMISH_STATS: Width: 191 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Button@KICK: X: 485 Width: 25 diff --git a/mods/d2k/chrome.yaml b/mods/d2k/chrome.yaml index 4c936e79b832..b041abb13908 100644 --- a/mods/d2k/chrome.yaml +++ b/mods/d2k/chrome.yaml @@ -395,6 +395,17 @@ checkmark-cross: checkmark-highlighted-cross: Inherits: checkmark-cross +checkmark-mute: + Inherits: ^Glyphs + Regions: + unchecked: 0, 144, 16, 13 + unchecked-pressed: 17, 144, 16, 13 + checked: 17, 144, 16, 13 + checked-pressed: 0, 144, 16, 13 + +checkmark-highlighted-mute: + Inherits: checkmark-mute + checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 @@ -419,6 +430,22 @@ checkbox-highlighted-pressed: checkbox-highlighted-disabled: Inherits: checkbox-disabled +checkbox-toggle: + +checkbox-toggle-hover: + Inherits: button + +checkbox-toggle-pressed: + Inherits: checkbox-pressed + +checkbox-toggle-highlighted: + +checkbox-toggle-highlighted-hover: + Inherits: button-highlighted + +checkbox-toggle-highlighted-pressed: + Inherits: checkbox-highlighted-pressed + scrollitem-selected: Inherits: button-pressed diff --git a/mods/d2k/chrome/ingame-infostats.yaml b/mods/d2k/chrome/ingame-infostats.yaml index 889ec3e3e137..0aebb2db214b 100644 --- a/mods/d2k/chrome/ingame-infostats.yaml +++ b/mods/d2k/chrome/ingame-infostats.yaml @@ -123,6 +123,13 @@ Container@SKIRMISH_STATS: Width: 60 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Container@SPECTATOR_TEMPLATE: Width: PARENT_RIGHT - 26 Height: 25 @@ -146,6 +153,13 @@ Container@SKIRMISH_STATS: Width: 191 Height: 25 Shadow: True + Checkbox@MUTE: + X: 457 + Width: 25 + Height: 25 + Checkmark: mute + Background: checkbox-toggle + TooltipContainer: TOOLTIP_CONTAINER Button@KICK: X: 485 Width: 25 diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index f023df0b4a45..fa57bfc981bf 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -524,6 +524,17 @@ checkmark-cross: checkmark-highlighted-cross: Inherits: checkmark-cross +checkmark-mute: + Inherits: ^Glyphs + Regions: + unchecked: 0, 170, 16, 13 + unchecked-pressed: 17, 170, 16, 13 + checked: 17, 170, 16, 13 + checked-pressed: 0, 170, 16, 13 + +checkmark-highlighted-mute: + Inherits: checkmark-mute + checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 @@ -548,6 +559,22 @@ checkbox-highlighted-pressed: checkbox-highlighted-disabled: Inherits: checkbox-disabled +checkbox-toggle: + +checkbox-toggle-hover: + Inherits: button + +checkbox-toggle-pressed: + Inherits: checkbox-pressed + +checkbox-toggle-highlighted: + +checkbox-toggle-highlighted-hover: + Inherits: button-highlighted + +checkbox-toggle-highlighted-pressed: + Inherits: checkbox-highlighted-pressed + scrollitem-selected: Inherits: button-pressed diff --git a/mods/ts/chrome.yaml b/mods/ts/chrome.yaml index 7d771a24adab..3894b92b5470 100644 --- a/mods/ts/chrome.yaml +++ b/mods/ts/chrome.yaml @@ -657,6 +657,17 @@ checkmark-cross: checkmark-highlighted-cross: Inherits: checkmark-cross +checkmark-mute: + Inherits: ^Glyphs + Regions: + unchecked: 0, 144, 16, 13 + unchecked-pressed: 17, 144, 16, 13 + checked: 17, 144, 16, 13 + checked-pressed: 0, 144, 16, 13 + +checkmark-highlighted-mute: + Inherits: checkmark-mute + checkbox-hover: Inherits: ^Dialog PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 @@ -681,6 +692,22 @@ checkbox-highlighted-pressed: checkbox-highlighted-disabled: Inherits: checkbox-disabled +checkbox-toggle: + +checkbox-toggle-hover: + Inherits: button + +checkbox-toggle-pressed: + Inherits: checkbox-pressed + +checkbox-toggle-highlighted: + +checkbox-toggle-highlighted-hover: + Inherits: button-highlighted + +checkbox-toggle-highlighted-pressed: + Inherits: checkbox-highlighted-pressed + scrollitem-selected: Inherits: button-pressed