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.
This commit is contained in:
Oliver Brakmann
2016-03-16 23:04:42 +01:00
parent 85c20e7adf
commit 2490e4d67e
3 changed files with 50 additions and 32 deletions

View File

@@ -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<LuaScript>();
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().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<ButtonWidget>(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<MissionDataInfo>();
if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing))
{
numTabs++;
var mapTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));

View File

@@ -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<LabelWidget>("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<MissionObjectives>();
if (mo == null)
return;
var player = world.RenderPlayer ?? world.LocalPlayer;
var objectivesPanel = widget.Get<ScrollPanelWidget>("OBJECTIVES_PANEL");
template = objectivesPanel.Get<ContainerWidget>("OBJECTIVE_TEMPLATE");
if (player == null)
{
objectivesPanel.RemoveChildren();
return;
}
var mo = player.PlayerActor.TraitOrDefault<MissionObjectives>();
if (mo == null)
{
objectivesPanel.RemoveChildren();
return;
}
var missionStatus = widget.Get<LabelWidget>("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<Player, bool> redrawObjectives = (player, _) =>
Action<Player, bool> redrawObjectives = (p, _) =>
{
if (player == lp)
if (p == player)
PopulateObjectivesList(mo, objectivesPanel, template);
};
mo.ObjectiveAdded += redrawObjectives;

View File

@@ -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<CheckboxWidget>("STATS_CHECKBOX");
checkbox.IsChecked = () => lp.WinState != WinState.Undefined;
checkbox.GetCheckType = () => lp.WinState == WinState.Won ?
"checked" : "crossed";
if (lp.HasObjectives)
{
var mo = lp.PlayerActor.Trait<MissionObjectives>();
checkbox.GetText = () => mo.Objectives.First().Description;
}
var missionLabel = widget.Get<LabelWidget>("MISSION");
var statusLabel = widget.Get<LabelWidget>("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<MissionObjectives>();
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<ScrollPanelWidget>("PLAYER_LIST");
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
@@ -73,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var flag = item.Get<ImageWidget>("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<LabelWidget>("FACTION").GetText = () => pp.Faction.Name;