Merge pull request #10934 from obrakmann/spec-objectives-panel

Make objectives panel visible to spectators/observers
This commit is contained in:
Paul Chote
2016-03-27 13:58:53 +01:00
6 changed files with 135 additions and 100 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,26 +24,41 @@ 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 playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST");
var checkbox = widget.Get<CheckboxWidget>("STATS_CHECKBOX");
checkbox.IsChecked = () => lp.WinState != WinState.Undefined;
checkbox.GetCheckType = () => lp.WinState == WinState.Won ?
"checked" : "crossed";
if (lp.HasObjectives)
if (player != null && !player.NonCombatant)
{
var mo = lp.PlayerActor.Trait<MissionObjectives>();
checkbox.GetText = () => mo.Objectives.First().Description;
var checkbox = widget.Get<CheckboxWidget>("STATS_CHECKBOX");
var statusLabel = widget.Get<LabelWidget>("STATS_STATUS");
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;
}
else
{
// 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;
playerPanel.Bounds.Y -= objectiveGroup.Bounds.Height;
playerPanel.Bounds.Height += objectiveGroup.Bounds.Height;
}
var statusLabel = widget.Get<LabelWidget>("STATS_STATUS");
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;
var playerPanel = widget.Get<ScrollPanelWidget>("PLAYER_LIST");
var playerTemplate = playerPanel.Get("PLAYER_TEMPLATE");
playerPanel.RemoveChildren();
@@ -73,7 +88,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;

View File

@@ -3,28 +3,31 @@ Container@SKIRMISH_STATS:
Width: PARENT_RIGHT
Logic: GameInfoStatsLogic
Children:
Label@STATS_OBJECTIVE:
X: 15
Y: 10
Width: 85
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 10
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 15
Y: 45
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@OBJECTIVE:
Height: 75
Children:
Label@MISSION:
X: 15
Y: 10
Width: 85
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 10
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 15
Y: 45
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@STATS_HEADERS:
X: 17
Y: 80

View File

@@ -3,28 +3,31 @@ Container@SKIRMISH_STATS:
Width: PARENT_RIGHT
Logic: GameInfoStatsLogic
Children:
Label@MISSION:
X: 20
Y: 20
Width: 482
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 20
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 20
Y: 55
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@OBJECTIVE:
Height: 75
Children:
Label@MISSION:
X: 20
Y: 20
Width: 482
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 20
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 20
Y: 55
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@STATS_HEADERS:
X: 22
Y: 80

View File

@@ -3,28 +3,31 @@ Container@SKIRMISH_STATS:
Width: PARENT_RIGHT
Logic: GameInfoStatsLogic
Children:
Label@MISSION:
X: 20
Y: 20
Width: 482
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 20
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 20
Y: 55
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@OBJECTIVE:
Height: 75
Children:
Label@MISSION:
X: 20
Y: 20
Width: 482
Height: 25
Font: MediumBold
Text: Mission:
Label@STATS_STATUS:
X: 100
Y: 20
Width: PARENT_RIGHT - 10
Height: 25
Font: MediumBold
Checkbox@STATS_CHECKBOX:
X: 20
Y: 55
Width: 482
Height: 20
Font: Bold
Text: Destroy all opposition!
Disabled: yes
TextColorDisabled: FFFFFF
Container@STATS_HEADERS:
X: 22
Y: 80