Remove GameInitInfoWidget and routing startup via widgets in RA.
This commit is contained in:
@@ -327,8 +327,6 @@
|
||||
<Compile Include="Buildings\ShakeOnDeath.cs" />
|
||||
<Compile Include="Buildings\SoundOnDamageTransition.cs" />
|
||||
<Compile Include="Activities\RAHarvesterDockSequence.cs" />
|
||||
<Compile Include="Widgets\GameInitInfoWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\GameInitLogic.cs" />
|
||||
<Compile Include="AttackWander.cs" />
|
||||
<Compile Include="ScaredyCat.cs" />
|
||||
<Compile Include="Widgets\RadarWidget.cs" />
|
||||
@@ -356,6 +354,8 @@
|
||||
<Compile Include="StrategicVictoryConditions.cs" />
|
||||
<Compile Include="Lint\CheckTraitPrerequisites.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RADownloadPackagesLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -11,14 +11,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class RALoadScreen : ILoadScreen
|
||||
{
|
||||
Dictionary<string, string> Info;
|
||||
static string[] Comments = new[] { "Filling Crates...", "Charging Capacitors...", "Reticulating Splines...",
|
||||
"Planting Trees...", "Building Bridges...", "Aging Empires...",
|
||||
"Compiling EVA...", "Constructing Pylons...", "Activating Skynet...",
|
||||
@@ -33,6 +36,7 @@ namespace OpenRA.Mods.RA
|
||||
Renderer r;
|
||||
public void Init(Dictionary<string, string> info)
|
||||
{
|
||||
Info = info;
|
||||
// Avoid standard loading mechanisms so we
|
||||
// can display loadscreen as early as possible
|
||||
r = Game.Renderer;
|
||||
@@ -64,11 +68,57 @@ namespace OpenRA.Mods.RA
|
||||
r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
|
||||
r.EndFrame( new NullInputHandler() );
|
||||
}
|
||||
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
Game.ConnectionStateChanged += orderManager =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
switch (orderManager.Connection.ConnectionState)
|
||||
{
|
||||
case ConnectionState.PreConnecting:
|
||||
Widget.LoadWidget("MAINMENU_BG", Widget.RootWidget, new WidgetArgs());
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
Widget.OpenWindow("CONNECTING_BG",
|
||||
new WidgetArgs() { { "host", orderManager.Host }, { "port", orderManager.Port } });
|
||||
break;
|
||||
case ConnectionState.NotConnected:
|
||||
Widget.OpenWindow("CONNECTION_FAILED_BG",
|
||||
new WidgetArgs() { { "orderManager", orderManager } });
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
TestAndContinue();
|
||||
}
|
||||
|
||||
void TestAndContinue()
|
||||
{
|
||||
Widget.ResetAll();
|
||||
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Widget.RootWidget, "INIT_SETUP" );
|
||||
if (!FileSystem.Exists(Info["TestFile"]))
|
||||
{
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "continueLoading", () => TestAndContinue() },
|
||||
{ "installData", Info }
|
||||
};
|
||||
Widget.OpenWindow(Info["InstallerMenuWidget"], args);
|
||||
}
|
||||
else
|
||||
{
|
||||
Game.LoadShellMap();
|
||||
Widget.ResetAll();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#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.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets
|
||||
{
|
||||
class GameInitInfoWidget : Widget
|
||||
{
|
||||
public string TestFile = "";
|
||||
public string GameTitle = "";
|
||||
public string PackageURL = "";
|
||||
public string PackagePath = "";
|
||||
public string InstallMode = "";
|
||||
|
||||
public string ResolvedPackagePath { get { return PackagePath.Replace("^", Platform.SupportDir); } }
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
#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 System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class GameInitLogic : ILogicWithInit
|
||||
{
|
||||
GameInitInfoWidget Info;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public GameInitLogic([ObjectCreator.Param] Widget widget)
|
||||
{
|
||||
Info = (widget as GameInitInfoWidget);
|
||||
}
|
||||
|
||||
void ILogicWithInit.Init()
|
||||
{
|
||||
Game.ConnectionStateChanged += orderManager =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
switch (orderManager.Connection.ConnectionState)
|
||||
{
|
||||
case ConnectionState.PreConnecting:
|
||||
Widget.LoadWidget("MAINMENU_BG", Widget.RootWidget, new WidgetArgs());
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
Widget.OpenWindow("CONNECTING_BG",
|
||||
new WidgetArgs() { { "host", orderManager.Host }, { "port", orderManager.Port } });
|
||||
break;
|
||||
case ConnectionState.NotConnected:
|
||||
Widget.OpenWindow("CONNECTION_FAILED_BG",
|
||||
new WidgetArgs() { { "orderManager", orderManager } });
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
TestAndContinue();
|
||||
}
|
||||
|
||||
void TestAndContinue()
|
||||
{
|
||||
if (FileSystem.Exists(Info.TestFile))
|
||||
{
|
||||
Game.LoadShellMap();
|
||||
Widget.ResetAll();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
}
|
||||
else
|
||||
{
|
||||
MainMenuButtonsLogic.DisplayModSelector();
|
||||
ShowInstallMethodDialog();
|
||||
}
|
||||
}
|
||||
|
||||
void ShowInstallMethodDialog()
|
||||
{
|
||||
var window = Widget.OpenWindow("INIT_CHOOSEINSTALL");
|
||||
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "continueLoading", () => { Widget.CloseWindow(); TestAndContinue(); } },
|
||||
};
|
||||
|
||||
window.GetWidget<ButtonWidget>("DOWNLOAD").OnClick = () => ShowDownloadDialog();
|
||||
window.GetWidget<ButtonWidget>("FROMCD").OnClick = () =>
|
||||
Widget.OpenWindow("INSTALL_FROMCD_PANEL", args);
|
||||
|
||||
window.GetWidget<ButtonWidget>("QUIT").OnClick = () => Game.Exit();
|
||||
}
|
||||
|
||||
void ShowDownloadDialog()
|
||||
{
|
||||
var window = Widget.OpenWindow("INIT_DOWNLOAD");
|
||||
var status = window.GetWidget<LabelWidget>("STATUS");
|
||||
status.GetText = () => "Initializing...";
|
||||
var progress = window.GetWidget<ProgressBarWidget>("PROGRESS");
|
||||
|
||||
// Save the package to a temp file
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadChange = i =>
|
||||
{
|
||||
status.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024);
|
||||
progress.Percentage = i.ProgressPercentage;
|
||||
};
|
||||
|
||||
Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) =>
|
||||
{
|
||||
if (i.Error != null)
|
||||
ShowError(window, i.Error.Message);
|
||||
else if (!cancelled)
|
||||
{
|
||||
// Automatically extract
|
||||
status.GetText = () => "Extracting...";
|
||||
progress.Indeterminate = true;
|
||||
|
||||
if (ExtractZip(window, file, Info.ResolvedPackagePath))
|
||||
Game.RunAfterTick(TestAndContinue);
|
||||
}
|
||||
};
|
||||
|
||||
var dl = new Download(Info.PackageURL, file, onDownloadChange, onDownloadComplete);
|
||||
window.GetWidget<ButtonWidget>("CANCEL").OnClick = () => { dl.Cancel(); ShowInstallMethodDialog(); };
|
||||
window.GetWidget<ButtonWidget>("RETRY").OnClick = () => { dl.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
|
||||
void ShowError(Widget window, string e)
|
||||
{
|
||||
if (window.GetWidget<LabelWidget>("STATUS") != null) /* ugh */
|
||||
{
|
||||
window.GetWidget<LabelWidget>("STATUS").GetText = () => e;
|
||||
window.GetWidget<ButtonWidget>("RETRY").IsVisible = () => true;
|
||||
window.GetWidget<ButtonWidget>("CANCEL").IsVisible = () => true;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExtractZip(Widget window, string zipFile, string dest)
|
||||
{
|
||||
var status = window.GetWidget<LabelWidget>("STATUS");
|
||||
return InstallUtils.ExtractZip( zipFile, dest,
|
||||
s => status.GetText = () => s,
|
||||
e => ShowError(window, e));
|
||||
}
|
||||
}
|
||||
}
|
||||
113
OpenRA.Mods.RA/Widgets/Logic/RADownloadPackagesLogic.cs
Normal file
113
OpenRA.Mods.RA/Widgets/Logic/RADownloadPackagesLogic.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
#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 System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class RADownloadPackagesLogic
|
||||
{
|
||||
Widget panel;
|
||||
Dictionary<string,string> installData;
|
||||
ProgressBarWidget progressBar;
|
||||
LabelWidget statusLabel;
|
||||
Action continueLoading;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public RADownloadPackagesLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] Dictionary<string,string> installData,
|
||||
[ObjectCreator.Param] Action continueLoading)
|
||||
{
|
||||
this.installData = installData;
|
||||
this.continueLoading = continueLoading;
|
||||
|
||||
panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
|
||||
|
||||
ShowDownloadDialog();
|
||||
}
|
||||
|
||||
void ShowDownloadDialog()
|
||||
{
|
||||
statusLabel.GetText = () => "Initializing...";
|
||||
progressBar.SetIndeterminate(true);
|
||||
var retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON");
|
||||
retryButton.IsVisible = () => false;
|
||||
|
||||
var cancelButton = panel.GetWidget<ButtonWidget>("CANCEL_BUTTON");
|
||||
|
||||
// Save the package to a temp file
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = new string[] { Platform.SupportDir, "Content", "ra" }.Aggregate(Path.Combine);
|
||||
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
|
||||
{
|
||||
if (progressBar.Indeterminate)
|
||||
progressBar.SetIndeterminate(false);
|
||||
|
||||
progressBar.Percentage = i.ProgressPercentage;
|
||||
statusLabel.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024);
|
||||
};
|
||||
|
||||
Action<string> onExtractProgress = s =>
|
||||
{
|
||||
Game.RunAfterTick(() => statusLabel.GetText = () => s);
|
||||
};
|
||||
|
||||
Action<string> onError = s =>
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
statusLabel.GetText = () => "Error: "+s;
|
||||
retryButton.IsVisible = () => true;
|
||||
});
|
||||
};
|
||||
|
||||
Action<AsyncCompletedEventArgs, bool> onDownloadComplete = (i, cancelled) =>
|
||||
{
|
||||
if (i.Error != null)
|
||||
{
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
{
|
||||
onError("Download cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
// Automatically extract
|
||||
statusLabel.GetText = () => "Extracting...";
|
||||
progressBar.SetIndeterminate(true);
|
||||
if (InstallUtils.ExtractZip(file, dest, onExtractProgress, onError))
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
continueLoading();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var dl = new Download(installData["PackageURL"], file, onDownloadProgress, onDownloadComplete);
|
||||
|
||||
cancelButton.OnClick = () => { dl.Cancel(); Widget.CloseWindow(); };
|
||||
retryButton.OnClick = () => { dl.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
}
|
||||
}
|
||||
42
OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs
Normal file
42
OpenRA.Mods.RA/Widgets/Logic/RAInstallLogic.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#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 System.Collections.Generic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class RAInstallLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public RAInstallLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] Dictionary<string,string> installData,
|
||||
[ObjectCreator.Param] Action continueLoading)
|
||||
{
|
||||
var panel = widget.GetWidget("INSTALL_PANEL");
|
||||
var args = new WidgetArgs()
|
||||
{
|
||||
{ "continueLoading", () => { Widget.CloseWindow(); continueLoading(); } },
|
||||
{ "installData", installData }
|
||||
};
|
||||
|
||||
panel.GetWidget<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Widget.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
|
||||
|
||||
panel.GetWidget<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
|
||||
Widget.OpenWindow("INSTALL_FROMCD_PANEL", args);
|
||||
|
||||
panel.GetWidget<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
MainMenuButtonsLogic.DisplayModSelector();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user