remove shared 'window' field, fix crashes in GameIniDelegate

This commit is contained in:
Chris Forbes
2011-01-28 07:34:57 +13:00
parent d3ddefbaa3
commit 6ddce1c171

View File

@@ -26,7 +26,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
public class GameInitDelegate : IWidgetDelegate public class GameInitDelegate : IWidgetDelegate
{ {
GameInitInfoWidget Info; GameInitInfoWidget Info;
Widget window;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public GameInitDelegate([ObjectCreator.Param] Widget widget) public GameInitDelegate([ObjectCreator.Param] Widget widget)
@@ -116,7 +115,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
void ShowInstallMethodDialog() void ShowInstallMethodDialog()
{ {
window = Widget.OpenWindow("INIT_CHOOSEINSTALL"); var window = Widget.OpenWindow("INIT_CHOOSEINSTALL");
window.GetWidget("DOWNLOAD").OnMouseUp = mi => { ShowDownloadDialog(); return true; }; window.GetWidget("DOWNLOAD").OnMouseUp = mi => { ShowDownloadDialog(); return true; };
window.GetWidget("FROMCD").OnMouseUp = mi => PromptForCD(); window.GetWidget("FROMCD").OnMouseUp = mi => PromptForCD();
@@ -135,7 +134,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
void InstallFromCD(string path) void InstallFromCD(string path)
{ {
window = Widget.OpenWindow("INIT_COPY"); var window = Widget.OpenWindow("INIT_COPY");
var status = window.GetWidget<LabelWidget>("STATUS"); var status = window.GetWidget<LabelWidget>("STATUS");
var progress = window.GetWidget<ProgressBarWidget>("PROGRESS"); var progress = window.GetWidget<ProgressBarWidget>("PROGRESS");
progress.Indeterminate = true; progress.Indeterminate = true;
@@ -152,7 +151,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
if (s.Substring(0,5) == "Error") if (s.Substring(0,5) == "Error")
{ {
error = true; error = true;
ShowDownloadError(s); ShowDownloadError(window, s);
} }
if (s.Substring(0,6) == "Status") if (s.Substring(0,6) == "Status")
window.GetWidget<LabelWidget>("STATUS").GetText = () => s.Substring(7).Trim(); window.GetWidget<LabelWidget>("STATUS").GetText = () => s.Substring(7).Trim();
@@ -167,12 +166,12 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
if (Info.InstallMode == "ra") if (Info.InstallMode == "ra")
Game.Utilities.InstallRAFilesAsync(path, FileSystem.SpecialPackageRoot+Info.PackagePath, parseOutput, onComplete); Game.Utilities.InstallRAFilesAsync(path, FileSystem.SpecialPackageRoot+Info.PackagePath, parseOutput, onComplete);
else else
ShowDownloadError("Installing from CD not supported"); ShowDownloadError(window, "Installing from CD not supported");
} }
void ShowDownloadDialog() void ShowDownloadDialog()
{ {
window = Widget.OpenWindow("INIT_DOWNLOAD"); var window = Widget.OpenWindow("INIT_DOWNLOAD");
var status = window.GetWidget<LabelWidget>("STATUS"); var status = window.GetWidget<LabelWidget>("STATUS");
status.GetText = () => "Initializing..."; status.GetText = () => "Initializing...";
var progress = window.GetWidget<ProgressBarWidget>("PROGRESS"); var progress = window.GetWidget<ProgressBarWidget>("PROGRESS");
@@ -187,7 +186,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) => Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) =>
{ {
if (i.Error != null) if (i.Error != null)
ShowDownloadError(window, i.Error.Message); ShowDownloadError(window, i.Error.Message);
else if (!cancelled) else if (!cancelled)
{ {
@@ -199,7 +198,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
{ {
if (s.Substring(0,5) == "Error") if (s.Substring(0,5) == "Error")
{ {
error = true; error = true;
ShowDownloadError(window, s); ShowDownloadError(window, s);
} }
if (s.Substring(0,6) == "Status") if (s.Substring(0,6) == "Status")
@@ -220,11 +219,14 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
window.GetWidget("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); return true; }; window.GetWidget("CANCEL").OnMouseUp = mi => { dl.Cancel(); ShowInstallMethodDialog(); return true; };
window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; }; window.GetWidget("RETRY").OnMouseUp = mi => { dl.Cancel(); ShowDownloadDialog(); return true; };
} }
void ShowDownloadError(Widget window, string e) void ShowDownloadError(Widget window, string e)
{ {
window.GetWidget<LabelWidget>("STATUS").GetText = () => e; if (window.GetWidget<LabelWidget>("STATUS") != null) /* ugh */
window.GetWidget<ButtonWidget>("RETRY").IsVisible = () => true; {
window.GetWidget<LabelWidget>("STATUS").GetText = () => e;
window.GetWidget<ButtonWidget>("RETRY").IsVisible = () => true;
window.GetWidget<ButtonWidget>("CANCEL").IsVisible = () => true;
} }
} }