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:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Scripting;
|
using OpenRA.Mods.Common.Scripting;
|
||||||
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -32,14 +33,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||||
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
|
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
|
||||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
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++;
|
numTabs++;
|
||||||
var objectivesTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
var objectivesTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
||||||
objectivesTabButton.GetText = () => "Objectives";
|
objectivesTabButton.GetText = () => "Objectives";
|
||||||
objectivesTabButton.IsVisible = () => lp != null && numTabs > 1 && !hasError;
|
objectivesTabButton.IsVisible = () => numTabs > 1 && !hasError;
|
||||||
objectivesTabButton.OnClick = () => activePanel = IngameInfoPanel.Objectives;
|
objectivesTabButton.OnClick = () => activePanel = IngameInfoPanel.Objectives;
|
||||||
objectivesTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Objectives;
|
objectivesTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Objectives;
|
||||||
|
|
||||||
@@ -54,7 +55,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Briefing tab
|
// Briefing tab
|
||||||
if (world.Map.Exists("map.png"))
|
var missionData = world.WorldActor.Info.TraitInfoOrDefault<MissionDataInfo>();
|
||||||
|
if (missionData != null && !string.IsNullOrEmpty(missionData.Briefing))
|
||||||
{
|
{
|
||||||
numTabs++;
|
numTabs++;
|
||||||
var mapTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
var mapTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
||||||
|
|||||||
@@ -24,26 +24,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public GameInfoObjectivesLogic(Widget widget, World world)
|
public GameInfoObjectivesLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
var lp = world.LocalPlayer;
|
var player = world.RenderPlayer ?? 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 objectivesPanel = widget.Get<ScrollPanelWidget>("OBJECTIVES_PANEL");
|
var objectivesPanel = widget.Get<ScrollPanelWidget>("OBJECTIVES_PANEL");
|
||||||
template = objectivesPanel.Get<ContainerWidget>("OBJECTIVE_TEMPLATE");
|
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);
|
PopulateObjectivesList(mo, objectivesPanel, template);
|
||||||
|
|
||||||
Action<Player, bool> redrawObjectives = (player, _) =>
|
Action<Player, bool> redrawObjectives = (p, _) =>
|
||||||
{
|
{
|
||||||
if (player == lp)
|
if (p == player)
|
||||||
PopulateObjectivesList(mo, objectivesPanel, template);
|
PopulateObjectivesList(mo, objectivesPanel, template);
|
||||||
};
|
};
|
||||||
mo.ObjectiveAdded += redrawObjectives;
|
mo.ObjectiveAdded += redrawObjectives;
|
||||||
|
|||||||
@@ -24,24 +24,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public GameInfoStatsLogic(Widget widget, World world, OrderManager orderManager)
|
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");
|
var checkbox = widget.Get<CheckboxWidget>("STATS_CHECKBOX");
|
||||||
checkbox.IsChecked = () => lp.WinState != WinState.Undefined;
|
var missionLabel = widget.Get<LabelWidget>("MISSION");
|
||||||
checkbox.GetCheckType = () => lp.WinState == WinState.Won ?
|
|
||||||
"checked" : "crossed";
|
|
||||||
if (lp.HasObjectives)
|
|
||||||
{
|
|
||||||
var mo = lp.PlayerActor.Trait<MissionObjectives>();
|
|
||||||
checkbox.GetText = () => mo.Objectives.First().Description;
|
|
||||||
}
|
|
||||||
|
|
||||||
var statusLabel = widget.Get<LabelWidget>("STATS_STATUS");
|
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" :
|
if (player != null && !player.NonCombatant)
|
||||||
lp.WinState == WinState.Lost ? "Failed" : "In progress";
|
{
|
||||||
statusLabel.GetColor = () => lp.WinState == WinState.Won ? Color.LimeGreen :
|
checkbox.IsChecked = () => player.WinState != WinState.Undefined;
|
||||||
lp.WinState == WinState.Lost ? Color.Red : Color.White;
|
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 playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST");
|
||||||
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
|
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
|
||||||
@@ -73,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
||||||
flag.GetImageCollection = () => "flags";
|
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;
|
flag.GetImageName = () => pp.Faction.InternalName;
|
||||||
item.Get<LabelWidget>("FACTION").GetText = () => pp.Faction.Name;
|
item.Get<LabelWidget>("FACTION").GetText = () => pp.Faction.Name;
|
||||||
|
|||||||
Reference in New Issue
Block a user