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\Logic\SupportPowerTooltipLogic.cs" />
<Compile Include="Widgets\ToggleButtonWidget.cs" /> <Compile Include="Widgets\ToggleButtonWidget.cs" />
<Compile Include="Widgets\Logic\CncColorPickerLogic.cs" /> <Compile Include="Widgets\Logic\CncColorPickerLogic.cs" />
<Compile Include="Widgets\LogicTickerWidget.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

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

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; int updateTicks = 0;
public override void Tick() public override void Tick()
{ {
var hasRadarNew = world.LocalPlayer == null || world var hasRadarNew = world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined ||
.ActorsWithTrait<ProvidesRadar>() world.ActorsWithTrait<ProvidesRadar>().Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
.Any(a => a.Actor.Owner == world.LocalPlayer && a.Trait.IsActive);
if (hasRadarNew != hasRadar) if (hasRadarNew != hasRadar)
{ {

View File

@@ -88,6 +88,8 @@ Container@OBSERVER_WIDGETS:
Container@PLAYER_WIDGETS: Container@PLAYER_WIDGETS:
Id:PLAYER_WIDGETS Id:PLAYER_WIDGETS
Children: Children:
LogicTicker:
Id:WIN_LOSS_WATCHER
Button@CHEATS_BUTTON: Button@CHEATS_BUTTON:
Id:CHEATS_BUTTON Id:CHEATS_BUTTON
X:WINDOW_RIGHT-400 X:WINDOW_RIGHT-400
@@ -98,23 +100,6 @@ Container@PLAYER_WIDGETS:
WorldCommand: WorldCommand:
Width:WINDOW_RIGHT Width:WINDOW_RIGHT
Height:WINDOW_BOTTOM 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: SupportPowers:
TooltipContainer:TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
X:10 X:10