Remove unused InitDelegates() method. Don't mutate the Children list directly.

This commit is contained in:
Paul Chote
2011-01-23 10:13:14 +13:00
parent 3fe549d0a4
commit 646863b85b
6 changed files with 14 additions and 18 deletions

View File

@@ -141,8 +141,8 @@ namespace OpenRA.Widgets
Action HideDropDown = () => Action HideDropDown = () =>
{ {
Widget.RootWidget.Children.Remove(fullscreenMask); Widget.RootWidget.RemoveChild(fullscreenMask);
Widget.RootWidget.Children.Remove(panel); Widget.RootWidget.RemoveChild(panel);
}; };
HideDropDown += () => Game.BeforeGameStart -= HideDropDown; HideDropDown += () => Game.BeforeGameStart -= HideDropDown;

View File

@@ -39,10 +39,10 @@ namespace OpenRA.Widgets
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void ClearChildren() public override void RemoveChildren()
{ {
Children.Clear();
ContentHeight = 0; ContentHeight = 0;
base.RemoveChildren();
} }
public override void AddChild(Widget child) public override void AddChild(Widget child)

View File

@@ -28,13 +28,13 @@ namespace OpenRA.Widgets
public string Delegate = null; public string Delegate = null;
public string EventHandler = null; public string EventHandler = null;
public bool Visible = true; public bool Visible = true;
public readonly List<Widget> Children = new List<Widget>(); public readonly List<Widget> Children = new List<Widget>();
// Calculated internally // Calculated internally
public Rectangle Bounds; public Rectangle Bounds;
public Widget Parent = null; public Widget Parent = null;
static List<string> Delegates = new List<string>();
public static Stack<Widget> WindowList = new Stack<Widget>(); public static Stack<Widget> WindowList = new Stack<Widget>();
// Common Funcs that most widgets will want // Common Funcs that most widgets will want
@@ -121,22 +121,16 @@ namespace OpenRA.Widgets
height); height);
} }
public void PostInit( Dictionary<string, object> args ) public void PostInit(Dictionary<string, object> args)
{ {
if( Delegate != null ) if( Delegate != null )
{ {
args[ "widget" ] = this; args["widget"] = this;
Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>( Delegate, args ); Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>(Delegate, args);
args.Remove( "widget" ); args.Remove("widget");
} }
} }
public void InitDelegates()
{
foreach(var d in Delegates)
Game.CreateObject<IWidgetDelegate>(d);
}
public virtual Rectangle EventBounds { get { return RenderBounds; } } public virtual Rectangle EventBounds { get { return RenderBounds; } }
public virtual Rectangle GetEventBounds() public virtual Rectangle GetEventBounds()
{ {
@@ -290,6 +284,8 @@ namespace OpenRA.Widgets
child.Parent = this; child.Parent = this;
Children.Add( child ); Children.Add( child );
} }
public virtual void RemoveChild(Widget child) { Children.Remove(child); }
public virtual void RemoveChildren() { Children.Clear(); }
public Widget GetWidget(string id) public Widget GetWidget(string id)
{ {

View File

@@ -301,7 +301,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{ {
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them) // This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
// Todo: handle this nicer // Todo: handle this nicer
Players.ClearChildren(); Players.RemoveChildren();
foreach (var slot in orderManager.LobbyInfo.Slots) foreach (var slot in orderManager.LobbyInfo.Slots)
{ {

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE"); var template = widget.GetWidget<LabelWidget>("REPLAY_TEMPLATE");
CurrentReplay = null; CurrentReplay = null;
rl.ClearChildren(); rl.RemoveChildren();
foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse()) foreach (var replayFile in Directory.GetFiles(replayDir, "*.rep").Reverse())
AddReplay(rl, replayFile, template); AddReplay(rl, replayFile, template);

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
var sl = bg.GetWidget<ScrollPanelWidget>("SERVER_LIST"); var sl = bg.GetWidget<ScrollPanelWidget>("SERVER_LIST");
sl.ClearChildren(); sl.RemoveChildren();
currentServer = null; currentServer = null;
if (games == null) if (games == null)