Remove GameInitInfoWidget and routing startup via widgets in RA.

This commit is contained in:
Paul Chote
2011-07-23 02:04:17 +12:00
parent 2d269155b1
commit abf63b3054
8 changed files with 240 additions and 208 deletions

View File

@@ -327,8 +327,6 @@
<Compile Include="Buildings\ShakeOnDeath.cs" /> <Compile Include="Buildings\ShakeOnDeath.cs" />
<Compile Include="Buildings\SoundOnDamageTransition.cs" /> <Compile Include="Buildings\SoundOnDamageTransition.cs" />
<Compile Include="Activities\RAHarvesterDockSequence.cs" /> <Compile Include="Activities\RAHarvesterDockSequence.cs" />
<Compile Include="Widgets\GameInitInfoWidget.cs" />
<Compile Include="Widgets\Logic\GameInitLogic.cs" />
<Compile Include="AttackWander.cs" /> <Compile Include="AttackWander.cs" />
<Compile Include="ScaredyCat.cs" /> <Compile Include="ScaredyCat.cs" />
<Compile Include="Widgets\RadarWidget.cs" /> <Compile Include="Widgets\RadarWidget.cs" />
@@ -356,6 +354,8 @@
<Compile Include="StrategicVictoryConditions.cs" /> <Compile Include="StrategicVictoryConditions.cs" />
<Compile Include="Lint\CheckTraitPrerequisites.cs" /> <Compile Include="Lint\CheckTraitPrerequisites.cs" />
<Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" /> <Compile Include="Widgets\Logic\RAInstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\RADownloadPackagesLogic.cs" />
<Compile Include="Widgets\Logic\RAInstallLogic.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -11,14 +11,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Support; using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Support;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class RALoadScreen : ILoadScreen public class RALoadScreen : ILoadScreen
{ {
Dictionary<string, string> Info;
static string[] Comments = new[] { "Filling Crates...", "Charging Capacitors...", "Reticulating Splines...", static string[] Comments = new[] { "Filling Crates...", "Charging Capacitors...", "Reticulating Splines...",
"Planting Trees...", "Building Bridges...", "Aging Empires...", "Planting Trees...", "Building Bridges...", "Aging Empires...",
"Compiling EVA...", "Constructing Pylons...", "Activating Skynet...", "Compiling EVA...", "Constructing Pylons...", "Activating Skynet...",
@@ -33,6 +36,7 @@ namespace OpenRA.Mods.RA
Renderer r; Renderer r;
public void Init(Dictionary<string, string> info) public void Init(Dictionary<string, string> info)
{ {
Info = info;
// Avoid standard loading mechanisms so we // Avoid standard loading mechanisms so we
// can display loadscreen as early as possible // can display loadscreen as early as possible
r = Game.Renderer; 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.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
r.EndFrame( new NullInputHandler() ); r.EndFrame( new NullInputHandler() );
} }
public void StartGame() 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(); 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");
}
} }
} }
} }

View File

@@ -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); } }
}
}

View File

@@ -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));
}
}
}

View 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(); };
}
}
}

View 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();
}
}
}

View File

@@ -1,14 +1,6 @@
GameInitInfo@INIT_SETUP: Background@INSTALL_PANEL:
Id:INIT_SETUP Id:INSTALL_PANEL
TestFile: redalert.mix Logic:RAInstallLogic
GameTitle: Red Alert
PackageURL:http://open-ra.org/get-dependency.php?file=ra-packages
PackagePath:^/Content/ra
InstallMode:ra
Logic:GameInitLogic
Background@INIT_CHOOSEINSTALL:
Id:INIT_CHOOSEINSTALL
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:500 Width:500
@@ -36,24 +28,24 @@ Background@INIT_CHOOSEINSTALL:
Height:25 Height:25
Text:Content can be downloaded, or copied from the install CD. Text:Content can be downloaded, or copied from the install CD.
Align:Center Align:Center
Button@DOWNLOAD: Button@DOWNLOAD_BUTTON:
Id:DOWNLOAD Id:DOWNLOAD_BUTTON
X:PARENT_RIGHT - 280 X:PARENT_RIGHT - 280
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:120 Width:120
Height:25 Height:25
Text:Download Text:Download
Font:Bold Font:Bold
Button@FROMCD: Button@INSTALL_BUTTON:
Id:FROMCD Id:INSTALL_BUTTON
X:PARENT_RIGHT - 420 X:PARENT_RIGHT - 420
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:120 Width:120
Height:25 Height:25
Text:From CD Text:Use CD
Font:Bold Font:Bold
Button@QUIT: Button@QUIT_BUTTON:
Id:QUIT Id:QUIT_BUTTON
X:PARENT_RIGHT - 140 X:PARENT_RIGHT - 140
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:120 Width:120
@@ -61,8 +53,9 @@ Background@INIT_CHOOSEINSTALL:
Text:Quit Text:Quit
Font:Bold Font:Bold
Background@INIT_DOWNLOAD: Background@INSTALL_DOWNLOAD_PANEL:
Id:INIT_DOWNLOAD Id:INSTALL_DOWNLOAD_PANEL
Logic:RADownloadPackagesLogic
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:500 Width:500
@@ -76,21 +69,21 @@ Background@INIT_DOWNLOAD:
Text:Downloading Red Alert Content Text:Downloading Red Alert Content
Align:Center Align:Center
Font:Bold Font:Bold
ProgressBar@PROGRESS: ProgressBar@PROGRESS_BAR:
Id:PROGRESS Id:PROGRESS_BAR
X:50 X:50
Y:55 Y:55
Width:PARENT_RIGHT - 100 Width:PARENT_RIGHT - 100
Height:25 Height:25
Label@STATUS: Label@STATUS_LABEL:
Id:STATUS Id:STATUS_LABEL
X:50 X:50
Y:80 Y:80
Width:PARENT_RIGHT - 100 Width:PARENT_RIGHT - 100
Height:25 Height:25
Align:Left Align:Left
Button@RETRY: Button@RETRY_BUTTON:
Id:RETRY Id:RETRY_BUTTON
X:PARENT_RIGHT - 280 X:PARENT_RIGHT - 280
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:120 Width:120
@@ -98,15 +91,16 @@ Background@INIT_DOWNLOAD:
Visible: false Visible: false
Text:Retry Text:Retry
Font:Bold Font:Bold
Button@CANCEL: Key:return
Id:CANCEL Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON
X:PARENT_RIGHT - 140 X:PARENT_RIGHT - 140
Y:PARENT_BOTTOM - 45 Y:PARENT_BOTTOM - 45
Width:120 Width:120
Height:25 Height:25
Text:Cancel Text:Cancel
Font:Bold Font:Bold
Key:escape
Background@INSTALL_FROMCD_PANEL: Background@INSTALL_FROMCD_PANEL:
Id:INSTALL_FROMCD_PANEL Id:INSTALL_FROMCD_PANEL
Logic:RAInstallFromCDLogic Logic:RAInstallFromCDLogic
@@ -168,6 +162,7 @@ Background@INSTALL_FROMCD_PANEL:
Height:25 Height:25
Text:Retry Text:Retry
Font:Bold Font:Bold
Key:return
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
X:PARENT_RIGHT - 140 X:PARENT_RIGHT - 140
@@ -175,4 +170,5 @@ Background@INSTALL_FROMCD_PANEL:
Width:120 Width:120
Height:25 Height:25
Text:Cancel Text:Cancel
Font:Bold Font:Bold
Key:escape

View File

@@ -84,6 +84,10 @@ Movies:
mods/ra/movies2.yaml mods/ra/movies2.yaml
LoadScreen: RALoadScreen LoadScreen: RALoadScreen
InstallerMenuWidget: INSTALL_PANEL
TestFile: redalert.mix
PackageURL: http://open-ra.org/get-dependency.php?file=ra-packages
ServerTraits: ServerTraits:
PlayerCommands PlayerCommands
LobbyCommands LobbyCommands