From 2490e4d67e0d515987016bf89f3182d0598ea8e8 Mon Sep 17 00:00:00 2001 From: Oliver Brakmann Date: Wed, 16 Mar 2016 23:04:42 +0100 Subject: [PATCH] Make objectives panel visible to spectators/observers It also allows switching the context of the panel by selecting a certain player's view in the player view spectator drop down. --- .../Widgets/Logic/Ingame/GameInfoLogic.cs | 10 +++-- .../Logic/Ingame/GameInfoObjectivesLogic.cs | 35 +++++++++++------- .../Logic/Ingame/GameInfoStatsLogic.cs | 37 +++++++++++-------- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs index c2aea8c6e5..2f54dceba3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoLogic.cs @@ -11,6 +11,7 @@ using System.Linq; using OpenRA.Mods.Common.Scripting; +using OpenRA.Mods.Common.Traits; using OpenRA.Traits; using OpenRA.Widgets; @@ -32,14 +33,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic var scriptContext = world.WorldActor.TraitOrDefault(); var hasError = scriptContext != null && scriptContext.FatalErrorOccurred; var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); - var hasObjectives = hasError || (lp != null && iop != null && iop.PanelName != null); + var hasObjectivesPanel = hasError || (iop != null && iop.PanelName != null); - if (hasObjectives) + if (hasObjectivesPanel) { numTabs++; var objectivesTabButton = widget.Get(string.Concat("BUTTON", numTabs.ToString())); objectivesTabButton.GetText = () => "Objectives"; - objectivesTabButton.IsVisible = () => lp != null && numTabs > 1 && !hasError; + objectivesTabButton.IsVisible = () => numTabs > 1 && !hasError; objectivesTabButton.OnClick = () => activePanel = IngameInfoPanel.Objectives; objectivesTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Objectives; @@ -54,7 +55,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } // Briefing tab - if (world.Map.Exists("map.png")) + var missionData = world.WorldActor.Info.TraitInfoOrDefault(); + if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing)) { numTabs++; var mapTabButton = widget.Get(string.Concat("BUTTON", numTabs.ToString())); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs index 45723c6d5b..cf211c4398 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoObjectivesLogic.cs @@ -24,26 +24,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public GameInfoObjectivesLogic(Widget widget, World world) { - var lp = world.LocalPlayer; - - var missionStatus = widget.Get("MISSION_STATUS"); - missionStatus.GetText = () => lp.WinState == WinState.Undefined ? "In progress" : - lp.WinState == WinState.Won ? "Accomplished" : "Failed"; - missionStatus.GetColor = () => lp.WinState == WinState.Undefined ? Color.White : - lp.WinState == WinState.Won ? Color.LimeGreen : Color.Red; - - var mo = lp.PlayerActor.TraitOrDefault(); - if (mo == null) - return; + var player = world.RenderPlayer ?? world.LocalPlayer; var objectivesPanel = widget.Get("OBJECTIVES_PANEL"); template = objectivesPanel.Get("OBJECTIVE_TEMPLATE"); + if (player == null) + { + objectivesPanel.RemoveChildren(); + return; + } + + var mo = player.PlayerActor.TraitOrDefault(); + if (mo == null) + { + objectivesPanel.RemoveChildren(); + return; + } + + var missionStatus = widget.Get("MISSION_STATUS"); + missionStatus.GetText = () => player.WinState == WinState.Undefined ? "In progress" : + player.WinState == WinState.Won ? "Accomplished" : "Failed"; + missionStatus.GetColor = () => player.WinState == WinState.Undefined ? Color.White : + player.WinState == WinState.Won ? Color.LimeGreen : Color.Red; + PopulateObjectivesList(mo, objectivesPanel, template); - Action redrawObjectives = (player, _) => + Action redrawObjectives = (p, _) => { - if (player == lp) + if (p == player) PopulateObjectivesList(mo, objectivesPanel, template); }; mo.ObjectiveAdded += redrawObjectives; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 673bcc6ab9..e2b75f947b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -24,24 +24,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager) { - var lp = world.LocalPlayer; + var player = world.RenderPlayer ?? world.LocalPlayer; var checkbox = widget.Get("STATS_CHECKBOX"); - checkbox.IsChecked = () => lp.WinState != WinState.Undefined; - checkbox.GetCheckType = () => lp.WinState == WinState.Won ? - "checked" : "crossed"; - if (lp.HasObjectives) - { - var mo = lp.PlayerActor.Trait(); - checkbox.GetText = () => mo.Objectives.First().Description; - } - + var missionLabel = widget.Get("MISSION"); var statusLabel = widget.Get("STATS_STATUS"); + checkbox.IsVisible = () => player != null && !player.NonCombatant; + missionLabel.IsVisible = () => player != null && !player.NonCombatant; + statusLabel.IsVisible = () => player != null && !player.NonCombatant; - statusLabel.GetText = () => lp.WinState == WinState.Won ? "Accomplished" : - lp.WinState == WinState.Lost ? "Failed" : "In progress"; - statusLabel.GetColor = () => lp.WinState == WinState.Won ? Color.LimeGreen : - lp.WinState == WinState.Lost ? Color.Red : Color.White; + if (player != null && !player.NonCombatant) + { + checkbox.IsChecked = () => player.WinState != WinState.Undefined; + checkbox.GetCheckType = () => player.WinState == WinState.Won ? + "checked" : "crossed"; + if (player.HasObjectives) + { + var mo = player.PlayerActor.Trait(); + checkbox.GetText = () => mo.Objectives.First().Description; + } + + statusLabel.GetText = () => player.WinState == WinState.Won ? "Accomplished" : + player.WinState == WinState.Lost ? "Failed" : "In progress"; + statusLabel.GetColor = () => player.WinState == WinState.Won ? Color.LimeGreen : + player.WinState == WinState.Lost ? Color.Red : Color.White; + } var playerPanel = widget.Get("PLAYER_LIST"); var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE"); @@ -73,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var flag = item.Get("FACTIONFLAG"); flag.GetImageCollection = () => "flags"; - if (lp.Stances[pp] == Stance.Ally || lp.WinState != WinState.Undefined) + if (player == null || player.Stances[pp] == Stance.Ally || player.WinState != WinState.Undefined) { flag.GetImageName = () => pp.Faction.InternalName; item.Get("FACTION").GetText = () => pp.Faction.Name;