Switch to observer ui on victory/defeat (Feature #1002).

This commit is contained in:
Paul Chote
2011-07-16 21:02:15 +12:00
parent 8f62ce9b25
commit b8ba48ee67
5 changed files with 116 additions and 106 deletions

View File

@@ -105,6 +105,7 @@
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
<Compile Include="Widgets\ToggleButtonWidget.cs" />
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -78,7 +78,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
ingameRoot = widget.GetWidget("INGAME_ROOT");
var playerRoot = ingameRoot.GetWidget("PLAYER_ROOT");
Action onOptionsClick = () =>
// Observer
if (world.LocalPlayer == null)
InitObserverWidgets(world, playerRoot);
else
InitPlayerWidgets(world, playerRoot);
}
public void OptionsClicked()
{
if (menu != MenuType.None)
{
@@ -91,15 +98,15 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{
{ "onExit", () => ingameRoot.IsVisible = () => true }
});
};
}
// Observer
if (world.LocalPlayer == null)
public void InitObserverWidgets(World world, Widget playerRoot)
{
var observerWidgets = Game.LoadWidget(world, "OBSERVER_WIDGETS", playerRoot, new WidgetArgs());
observerWidgets.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = onOptionsClick;
observerWidgets.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
}
else
public void InitPlayerWidgets(World world, Widget playerRoot)
{
// Real player
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
@@ -136,7 +143,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("VEHICLE"), "Vehicle");
SetupProductionGroupButton(queueTypes.GetWidget<ToggleButtonWidget>("AIRCRAFT"), "Aircraft");
playerWidgets.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = onOptionsClick;
playerWidgets.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = OptionsClicked;
var cheatsButton = playerWidgets.GetWidget<ButtonWidget>("CHEATS_BUTTON");
cheatsButton.OnClick = () =>
@@ -149,19 +156,16 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
};
cheatsButton.IsVisible = () => world.LocalPlayer != null && world.LobbyInfo.GlobalSettings.AllowCheats;
var postgameBG = ingameRoot.GetWidget("POSTGAME_BG");
postgameBG.IsVisible = () =>
var winLossWatcher = playerWidgets.GetWidget<LogicTickerWidget>("WIN_LOSS_WATCHER");
winLossWatcher.OnTick = () =>
{
return world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined;
};
postgameBG.GetWidget<LabelWidget>("TEXT").GetText = () =>
if (world.LocalPlayer.WinState != WinState.Undefined)
Game.RunAfterTick(() =>
{
var state = world.LocalPlayer.WinState;
return (state == WinState.Undefined)? "" :
((state == WinState.Lost)? "YOU ARE DEFEATED" : "YOU ARE VICTORIOUS");
playerRoot.RemoveChildren();
InitObserverWidgets(world, playerRoot);
});
};
}
}
}
}

View File

@@ -0,0 +1,21 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets
{
public class LogicTickerWidget : Widget
{
public Action OnTick = () => {};
public override void Tick() { OnTick(); }
}
}

View File

@@ -149,9 +149,8 @@ namespace OpenRA.Mods.RA.Widgets
int updateTicks = 0;
public override void Tick()
{
var hasRadarNew = world.LocalPlayer == null || world
.ActorsWithTrait<ProvidesRadar>()
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
var hasRadarNew = world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined ||
world.ActorsWithTrait<ProvidesRadar>().Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (hasRadarNew != hasRadar)
{

View File

@@ -88,6 +88,8 @@ Container@OBSERVER_WIDGETS:
Container@PLAYER_WIDGETS:
Id:PLAYER_WIDGETS
Children:
LogicTicker:
Id:WIN_LOSS_WATCHER
Button@CHEATS_BUTTON:
Id:CHEATS_BUTTON
X:WINDOW_RIGHT-400
@@ -98,23 +100,6 @@ Container@PLAYER_WIDGETS:
WorldCommand:
Width:WINDOW_RIGHT
Height:WINDOW_BOTTOM
Background@POSTGAME_BG:
Id:POSTGAME_BG
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:400
Height:100
Background:panel-black
Visible:false
Children:
Label@TEXT:
Id:TEXT
X:(PARENT_RIGHT - WIDTH)/2
Y:(PARENT_BOTTOM - HEIGHT)/2
Width:200
Height:40
Align:Center
Font:Bold
SupportPowers:
TooltipContainer:TOOLTIP_CONTAINER
X:10