make it crash nicely when you inherit from a bogus actor type
This commit is contained in:
committed by
Chris Forbes
parent
cee021ef17
commit
1af23079eb
@@ -41,7 +41,8 @@ namespace OpenRA
|
|||||||
MiniYaml parent;
|
MiniYaml parent;
|
||||||
allUnits.TryGetValue( inherits.Value, out parent );
|
allUnits.TryGetValue( inherits.Value, out parent );
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
return null;
|
throw new InvalidOperationException(
|
||||||
|
"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));
|
||||||
|
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,13 +123,18 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public void PostInit(Dictionary<string, object> args)
|
public void PostInit(Dictionary<string, object> args)
|
||||||
{
|
{
|
||||||
if( Delegate != null )
|
if (Delegate == null)
|
||||||
{
|
return;
|
||||||
|
|
||||||
args["widget"] = this;
|
args["widget"] = this;
|
||||||
Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>(Delegate, args);
|
|
||||||
|
var iwd = Game.modData.ObjectCreator.CreateObject<IWidgetDelegate>(Delegate, args)
|
||||||
|
as IWidgetDelegateEx;
|
||||||
|
if (iwd != null)
|
||||||
|
iwd.Init();
|
||||||
|
|
||||||
args.Remove("widget");
|
args.Remove("widget");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
public virtual Rectangle EventBounds { get { return RenderBounds; } }
|
||||||
public virtual Rectangle GetEventBounds()
|
public virtual Rectangle GetEventBounds()
|
||||||
@@ -339,16 +344,19 @@ namespace OpenRA.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContainerWidget : Widget {
|
public class ContainerWidget : Widget
|
||||||
|
{
|
||||||
public Func<string> GetBackground;
|
public Func<string> GetBackground;
|
||||||
public string Background = null;
|
public string Background = null;
|
||||||
|
|
||||||
public ContainerWidget() : base()
|
public ContainerWidget()
|
||||||
|
: base()
|
||||||
{
|
{
|
||||||
GetBackground = () => Background;
|
GetBackground = () => Background;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContainerWidget(ContainerWidget other) : base(other)
|
public ContainerWidget(ContainerWidget other)
|
||||||
|
: base(other)
|
||||||
{
|
{
|
||||||
Background = other.Background;
|
Background = other.Background;
|
||||||
GetBackground = other.GetBackground;
|
GetBackground = other.GetBackground;
|
||||||
@@ -364,5 +372,10 @@ namespace OpenRA.Widgets
|
|||||||
public override string GetCursor(int2 pos) { return null; }
|
public override string GetCursor(int2 pos) { return null; }
|
||||||
public override Widget Clone() { return new ContainerWidget(this); }
|
public override Widget Clone() { return new ContainerWidget(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IWidgetDelegate { }
|
public interface IWidgetDelegate { }
|
||||||
|
public interface IWidgetDelegateEx : IWidgetDelegate
|
||||||
|
{
|
||||||
|
void Init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||||
{
|
{
|
||||||
public class GameInitDelegate : IWidgetDelegate
|
public class GameInitDelegate : IWidgetDelegateEx
|
||||||
{
|
{
|
||||||
GameInitInfoWidget Info;
|
GameInitInfoWidget Info;
|
||||||
|
|
||||||
@@ -31,7 +31,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
public GameInitDelegate([ObjectCreator.Param] Widget widget)
|
public GameInitDelegate([ObjectCreator.Param] Widget widget)
|
||||||
{
|
{
|
||||||
Info = (widget as GameInitInfoWidget);
|
Info = (widget as GameInitInfoWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
Game.ConnectionStateChanged += orderManager =>
|
Game.ConnectionStateChanged += orderManager =>
|
||||||
{
|
{
|
||||||
Widget.CloseWindow();
|
Widget.CloseWindow();
|
||||||
@@ -60,7 +63,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (FileSystem.Exists(Info.TestFile))
|
if (FileSystem.Exists(Info.TestFile))
|
||||||
ContinueLoading(widget);
|
ContinueLoading();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MainMenuButtonsDelegate.DisplayModSelector();
|
MainMenuButtonsDelegate.DisplayModSelector();
|
||||||
@@ -115,7 +118,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
Action onComplete = () =>
|
Action onComplete = () =>
|
||||||
{
|
{
|
||||||
if (!error)
|
if (!error)
|
||||||
Game.RunAfterTick(() => ContinueLoading(Info));
|
Game.RunAfterTick(ContinueLoading);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Info.InstallMode == "ra")
|
if (Info.InstallMode == "ra")
|
||||||
@@ -151,19 +154,19 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
var error = false;
|
var error = false;
|
||||||
Action<string> parseOutput = s =>
|
Action<string> parseOutput = s =>
|
||||||
{
|
{
|
||||||
if (s.Substring(0,5) == "Error")
|
if (s.StartsWith("Error"))
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
ShowDownloadError(window, s);
|
ShowDownloadError(window, s);
|
||||||
}
|
}
|
||||||
if (s.Substring(0,6) == "Status")
|
if (s.StartsWith("Status"))
|
||||||
window.GetWidget<LabelWidget>("STATUS").GetText = () => s.Substring(7).Trim();
|
window.GetWidget<LabelWidget>("STATUS").GetText = () => s.Substring(7).Trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
Action onComplete = () =>
|
Action onComplete = () =>
|
||||||
{
|
{
|
||||||
if (!error)
|
if (!error)
|
||||||
Game.RunAfterTick(() => ContinueLoading(Info));
|
Game.RunAfterTick(ContinueLoading);
|
||||||
};
|
};
|
||||||
|
|
||||||
Game.RunAfterTick(() => Game.Utilities.ExtractZipAsync(file, FileSystem.SpecialPackageRoot+Info.PackagePath, parseOutput, onComplete));
|
Game.RunAfterTick(() => Game.Utilities.ExtractZipAsync(file, FileSystem.SpecialPackageRoot+Info.PackagePath, parseOutput, onComplete));
|
||||||
@@ -185,7 +188,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContinueLoading(Widget widget)
|
void ContinueLoading()
|
||||||
{
|
{
|
||||||
Game.LoadShellMap();
|
Game.LoadShellMap();
|
||||||
Widget.RootWidget.RemoveChildren();
|
Widget.RootWidget.RemoveChildren();
|
||||||
|
|||||||
Reference in New Issue
Block a user