Add per player mutes

This commit is contained in:
Gustas
2022-08-10 12:58:59 +03:00
committed by teinarss
parent 81da717f19
commit ce254f8b46
12 changed files with 193 additions and 3 deletions

View File

@@ -27,6 +27,8 @@ namespace OpenRA.Network
readonly Dictionary<int, (int SyncHash, ulong DefeatState)> syncForFrame = new Dictionary<int, (int, ulong)>(); readonly Dictionary<int, (int SyncHash, ulong DefeatState)> syncForFrame = new Dictionary<int, (int, ulong)>();
public Session LobbyInfo = new Session(); public Session LobbyInfo = new Session();
/// <summary> Null when watching a replay </summary>
public Session.Client LocalClient => LobbyInfo.ClientWithIndex(Connection.LocalClientId); public Session.Client LocalClient => LobbyInfo.ClientWithIndex(Connection.LocalClientId);
public World World; public World World;
public int OrderQueueLength => pendingOrders.Count > 0 ? pendingOrders.Min(q => q.Value.Count) : 0; public int OrderQueueLength => pendingOrders.Count > 0 ? pendingOrders.Min(q => q.Value.Count) : 0;

View File

@@ -21,6 +21,8 @@ namespace OpenRA
static readonly string SystemMessageLabel; static readonly string SystemMessageLabel;
public static long ChatDisabledUntil { get; internal set; } public static long ChatDisabledUntil { get; internal set; }
public static readonly Dictionary<int, bool> MutedPlayers = new Dictionary<int, bool>();
static readonly List<TextNotification> NotificationsCache = new List<TextNotification>(); static readonly List<TextNotification> NotificationsCache = new List<TextNotification>();
public static IReadOnlyList<TextNotification> Notifications => NotificationsCache; public static IReadOnlyList<TextNotification> Notifications => NotificationsCache;
@@ -94,6 +96,7 @@ namespace OpenRA
public static void Clear() public static void Clear()
{ {
NotificationsCache.Clear(); NotificationsCache.Clear();
MutedPlayers.Clear();
} }
} }
} }

View File

@@ -22,11 +22,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
class GameInfoStatsLogic : ChromeLogic class GameInfoStatsLogic : ChromeLogic
{ {
[TranslationReference]
static readonly string Unmute = "unmute";
[TranslationReference]
static readonly string Mute = "mute";
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager, WorldRenderer worldRenderer, Action<bool> hideMenu) public GameInfoStatsLogic(Widget widget, ModData modData, World world, OrderManager orderManager, WorldRenderer worldRenderer, Action<bool> hideMenu)
{ {
var player = world.LocalPlayer; var player = world.LocalPlayer;
var playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST"); var playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST");
var statsHeader = widget.Get("STATS_HEADERS");
if (player != null && !player.NonCombatant) if (player != null && !player.NonCombatant)
{ {
@@ -51,7 +58,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
// Expand the stats window to cover the hidden objectives // Expand the stats window to cover the hidden objectives
var objectiveGroup = widget.Get("OBJECTIVE"); var objectiveGroup = widget.Get("OBJECTIVE");
var statsHeader = widget.Get("STATS_HEADERS");
objectiveGroup.Visible = false; objectiveGroup.Visible = false;
statsHeader.Bounds.Y -= objectiveGroup.Bounds.Height; statsHeader.Bounds.Y -= objectiveGroup.Bounds.Height;
@@ -59,9 +65,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
playerPanel.Bounds.Height += objectiveGroup.Bounds.Height; playerPanel.Bounds.Height += objectiveGroup.Bounds.Height;
} }
if (!orderManager.LobbyInfo.Clients.Any(c => !c.IsBot && c.Index != orderManager.LocalClient?.Index && c.State != Session.ClientState.Disconnected))
statsHeader.Get<LabelWidget>("ACTIONS").Visible = false;
var teamTemplate = playerPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE"); var teamTemplate = playerPanel.Get<ScrollItemWidget>("TEAM_TEMPLATE");
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE"); var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE"); var spectatorTemplate = playerPanel.Get("SPECTATOR_TEMPLATE");
var unmuteTooltip = modData.Translation.GetString(Unmute);
var muteTooltip = modData.Translation.GetString(Mute);
playerPanel.RemoveChildren(); playerPanel.RemoveChildren();
var teams = world.Players.Where(p => !p.NonCombatant && p.Playable) var teams = world.Players.Where(p => !p.NonCombatant && p.Playable)
@@ -112,6 +123,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var scoreCache = new CachedTransform<int, string>(s => s.ToString()); var scoreCache = new CachedTransform<int, string>(s => s.ToString());
item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0); item.Get<LabelWidget>("SCORE").GetText = () => scoreCache.Update(p.PlayerStatistics?.Experience ?? 0);
var muteCheckbox = item.Get<CheckboxWidget>("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() ? unmuteTooltip : muteTooltip;
playerPanel.AddChild(item); playerPanel.AddChild(item);
} }
} }
@@ -143,7 +160,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}; };
var kickButton = item.Get<ButtonWidget>("KICK"); var kickButton = item.Get<ButtonWidget>("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 = () => kickButton.OnClick = () =>
{ {
hideMenu(true); hideMenu(true);
@@ -159,6 +176,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
confirmText: "Kick"); confirmText: "Kick");
}; };
var muteCheckbox = item.Get<CheckboxWidget>("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() ? unmuteTooltip : muteTooltip;
playerPanel.AddChild(item); playerPanel.AddChild(item);
} }
} }

View File

@@ -69,6 +69,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var teamMessage = modData.Translation.GetString(Team); var teamMessage = modData.Translation.GetString(Team);
var allMessage = modData.Translation.GetString(All); var allMessage = modData.Translation.GetString(All);
// Only execute this once, the first time this widget is loaded
if (TextNotificationsManager.MutedPlayers.Count == 0)
foreach (var c in orderManager.LobbyInfo.Clients)
TextNotificationsManager.MutedPlayers.Add(c.Index, false);
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().ToArray().SelectMany(x => x.Commands.Keys); tabCompletion.Commands = chatTraits.OfType<ChatCommands>().ToArray().SelectMany(x => x.Commands.Keys);
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList(); tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();
@@ -273,6 +278,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (!IsNotificationEligible(notification)) if (!IsNotificationEligible(notification))
return; return;
if (notification.ClientId != TextNotificationsManager.SystemClientId && TextNotificationsManager.MutedPlayers[notification.ClientId])
return;
if (!IsNotificationMuted(notification)) if (!IsNotificationMuted(notification))
chatOverlayDisplay?.AddNotification(notification); chatOverlayDisplay?.AddNotification(notification);

View File

@@ -265,6 +265,22 @@ checkbox-highlighted-disabled:
checkbox-highlighted-pressed: checkbox-highlighted-pressed:
Inherits: button-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 # Panels
# === # ===
@@ -418,6 +434,17 @@ checkmark-cross:
checkmark-highlighted-cross: checkmark-highlighted-cross:
Inherits: checkmark-cross Inherits: checkmark-cross
checkmark-mute:
Inherits: ^Chrome
Regions:
unchecked: 989, 34, 16, 16
unchecked-pressed: 1006, 34, 16, 16
checked: 1006, 34, 16, 16
checked-pressed: 989, 34, 16, 16
checkmark-highlighted-mute:
Inherits: checkmark-mute
flags: flags:
Inherits: ^Chrome Inherits: ^Chrome
Regions: Regions:

View File

@@ -125,6 +125,13 @@ Container@SKIRMISH_STATS:
Width: 60 Width: 60
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Container@SPECTATOR_TEMPLATE: Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27 Width: PARENT_RIGHT - 27
Height: 25 Height: 25
@@ -148,6 +155,13 @@ Container@SKIRMISH_STATS:
Width: 191 Width: 191
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Button@KICK: Button@KICK:
X: 485 X: 485
Width: 25 Width: 25

View File

@@ -123,6 +123,13 @@ Container@SKIRMISH_STATS:
Width: 60 Width: 60
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Container@SPECTATOR_TEMPLATE: Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 26 Width: PARENT_RIGHT - 26
Height: 25 Height: 25
@@ -146,6 +153,13 @@ Container@SKIRMISH_STATS:
Width: 191 Width: 191
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Button@KICK: Button@KICK:
X: 485 X: 485
Width: 25 Width: 25

View File

@@ -117,6 +117,10 @@ in-progress = In progress
accomplished = Accomplished accomplished = Accomplished
failed = Failed failed = Failed
## GameInfoStatsLogic
mute = Mute this player
unmute = Unmute this player
## GameTimerLogic ## GameTimerLogic
paused = Paused paused = Paused
max-speed = Max Speed max-speed = Max Speed

View File

@@ -395,6 +395,17 @@ checkmark-cross:
checkmark-highlighted-cross: checkmark-highlighted-cross:
Inherits: checkmark-cross Inherits: checkmark-cross
checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 221, 34, 16, 16
unchecked-pressed: 238, 34, 16, 16
checked: 238, 34, 16, 16
checked-pressed: 221, 34, 16, 16
checkmark-highlighted-mute:
Inherits: checkmark-mute
checkbox-hover: checkbox-hover:
Inherits: ^Dialog Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
@@ -419,6 +430,22 @@ checkbox-highlighted-pressed:
checkbox-highlighted-disabled: checkbox-highlighted-disabled:
Inherits: checkbox-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: scrollitem-selected:
Inherits: button-pressed Inherits: button-pressed

View File

@@ -125,6 +125,13 @@ Container@SKIRMISH_STATS:
Width: 60 Width: 60
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Container@SPECTATOR_TEMPLATE: Container@SPECTATOR_TEMPLATE:
Width: PARENT_RIGHT - 27 Width: PARENT_RIGHT - 27
Height: 25 Height: 25
@@ -148,6 +155,13 @@ Container@SKIRMISH_STATS:
Width: 191 Width: 191
Height: 25 Height: 25
Shadow: True Shadow: True
Checkbox@MUTE:
X: 457
Width: 25
Height: 25
Checkmark: mute
Background: checkbox-toggle
TooltipContainer: TOOLTIP_CONTAINER
Button@KICK: Button@KICK:
X: 485 X: 485
Width: 25 Width: 25

View File

@@ -524,6 +524,17 @@ checkmark-cross:
checkmark-highlighted-cross: checkmark-highlighted-cross:
Inherits: checkmark-cross Inherits: checkmark-cross
checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 0, 170, 16, 16
unchecked-pressed: 17, 170, 16, 16
checked: 17, 170, 16, 16
checked-pressed: 0, 170, 16, 16
checkmark-highlighted-mute:
Inherits: checkmark-mute
checkbox-hover: checkbox-hover:
Inherits: ^Dialog Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
@@ -548,6 +559,22 @@ checkbox-highlighted-pressed:
checkbox-highlighted-disabled: checkbox-highlighted-disabled:
Inherits: checkbox-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: scrollitem-selected:
Inherits: button-pressed Inherits: button-pressed

View File

@@ -657,6 +657,17 @@ checkmark-cross:
checkmark-highlighted-cross: checkmark-highlighted-cross:
Inherits: checkmark-cross Inherits: checkmark-cross
checkmark-mute:
Inherits: ^Glyphs
Regions:
unchecked: 221, 34, 16, 16
unchecked-pressed: 238, 34, 16, 16
checked: 238, 34, 16, 16
checked-pressed: 221, 34, 16, 16
checkmark-highlighted-mute:
Inherits: checkmark-mute
checkbox-hover: checkbox-hover:
Inherits: ^Dialog Inherits: ^Dialog
PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2 PanelRegion: 641, 129, 2, 2, 122, 122, 2, 2
@@ -681,6 +692,22 @@ checkbox-highlighted-pressed:
checkbox-highlighted-disabled: checkbox-highlighted-disabled:
Inherits: checkbox-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: scrollitem-selected:
Inherits: button-pressed Inherits: button-pressed