Files
OpenRA/OpenRA.Mods.RA/OpenWidgetAtGameStart.cs
2011-09-26 08:40:39 +13:00

71 lines
1.8 KiB
C#

#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 OpenRA.Traits;
using OpenRA.Widgets;
using System.Collections.Generic;
namespace OpenRA.Mods.RA
{
// Legacy crap
public class OpenWidgetAtGameStartInfo : ITraitInfo
{
public readonly string Widget = "INGAME_ROOT";
public readonly string ObserverWidget = null;
public object Create(ActorInitializer init) { return new OpenWidgetAtGameStart(this); }
}
public class OpenWidgetAtGameStart: IWorldLoaded
{
readonly OpenWidgetAtGameStartInfo Info;
public OpenWidgetAtGameStart(OpenWidgetAtGameStartInfo Info)
{
this.Info = Info;
}
public void WorldLoaded(World world)
{
// Remove all open widgets
Widget.ResetAll();
if (world.LocalPlayer != null)
Game.OpenWindow(world, Info.Widget);
else if (Info.ObserverWidget != null)
Game.OpenWindow(world, Info.ObserverWidget);
}
}
// New version
public class LoadWidgetAtGameStartInfo : ITraitInfo
{
public readonly string Widget = null;
public readonly bool ClearRootWidget = true;
public object Create(ActorInitializer init) { return new LoadWidgetAtGameStart(this); }
}
public class LoadWidgetAtGameStart: IWorldLoaded
{
readonly LoadWidgetAtGameStartInfo Info;
public LoadWidgetAtGameStart(LoadWidgetAtGameStartInfo Info)
{
this.Info = Info;
}
public void WorldLoaded(World world)
{
// Clear any existing widget state
if (Info.ClearRootWidget)
Widget.ResetAll();
Game.LoadWidget(world, Info.Widget, Widget.RootWidget, new WidgetArgs());
}
}
}