Saner load code for cnc. Installing not yet implemented.

This commit is contained in:
Paul Chote
2011-05-09 20:39:26 +12:00
parent 3d347848f3
commit 372d2f5426
11 changed files with 170 additions and 97 deletions

View File

@@ -21,7 +21,7 @@ namespace OpenRA.FileFormats
Mods, Folders, Packages, Rules, ServerTraits, Mods, Folders, Packages, Rules, ServerTraits,
Sequences, Cursors, Chrome, Assemblies, ChromeLayout, Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
Weapons, Voices, Music, Movies, TileSets, ChromeMetrics; Weapons, Voices, Music, Movies, TileSets, ChromeMetrics;
public readonly string LoadScreen; public readonly MiniYaml LoadScreen;
public readonly int TileSize = 24; public readonly int TileSize = 24;
public Manifest(string[] mods) public Manifest(string[] mods)
@@ -47,8 +47,7 @@ namespace OpenRA.FileFormats
Movies = YamlList(yaml, "Movies"); Movies = YamlList(yaml, "Movies");
TileSets = YamlList(yaml, "TileSets"); TileSets = YamlList(yaml, "TileSets");
ChromeMetrics = YamlList(yaml, "ChromeMetrics"); ChromeMetrics = YamlList(yaml, "ChromeMetrics");
LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value;
LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value.Value;
if (yaml.FirstOrDefault( x => x.Key == "TileSize" ) != null) if (yaml.FirstOrDefault( x => x.Key == "TileSize" ) != null)
TileSize = int.Parse(yaml.First( x => x.Key == "TileSize" ).Value.Value); TileSize = int.Parse(yaml.First( x => x.Key == "TileSize" ).Value.Value);

View File

@@ -35,8 +35,8 @@ namespace OpenRA
{ {
Manifest = new Manifest( mods ); Manifest = new Manifest( mods );
ObjectCreator = new ObjectCreator( Manifest ); ObjectCreator = new ObjectCreator( Manifest );
LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen); LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen.Value);
LoadScreen.Init(); LoadScreen.Init(Manifest.LoadScreen.NodesDict.ToDictionary(x => x.Key, x => x.Value.Value));
LoadScreen.Display(); LoadScreen.Display();
WidgetLoader = new WidgetLoader( this ); WidgetLoader = new WidgetLoader( this );
} }
@@ -122,8 +122,8 @@ namespace OpenRA
public interface ILoadScreen public interface ILoadScreen
{ {
void Init(Dictionary<string, string> info);
void Display(); void Display();
void Init();
void StartGame(); void StartGame();
} }
} }

View File

@@ -380,6 +380,8 @@ namespace OpenRA.Widgets
} }
public interface IWidgetDelegate { } public interface IWidgetDelegate { }
// TODO: This can die once ra init is sane
public interface IWidgetDelegateEx : IWidgetDelegate public interface IWidgetDelegateEx : IWidgetDelegate
{ {
void Init(); void Init();

View File

@@ -14,6 +14,8 @@ using System.Linq;
using OpenRA.Support; using OpenRA.Support;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Widgets; using OpenRA.Widgets;
using OpenRA.FileFormats;
using System;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
@@ -25,6 +27,7 @@ namespace OpenRA.Mods.Cnc
"Splitting Atoms..." "Splitting Atoms..."
}; };
Dictionary<string,string> Info;
Stopwatch lastLoadScreen = new Stopwatch(); Stopwatch lastLoadScreen = new Stopwatch();
Rectangle StripeRect, BgRect; Rectangle StripeRect, BgRect;
Sprite Stripe, Logo, Bg; Sprite Stripe, Logo, Bg;
@@ -32,8 +35,9 @@ namespace OpenRA.Mods.Cnc
Renderer r; Renderer r;
SpriteFont Font; SpriteFont Font;
public void Init() 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;
@@ -73,8 +77,22 @@ namespace OpenRA.Mods.Cnc
public void StartGame() public void StartGame()
{ {
Widget.RootWidget.RemoveChildren(); TestAndContinue();
Game.modData.WidgetLoader.LoadWidget( new Dictionary<string,object>(), Widget.RootWidget, "INIT_SETUP" ); }
void TestAndContinue()
{
if (!FileSystem.Exists(Info["TestFile"]))
{
var args = new Dictionary<string, object>()
{
{ "continueLoading", (Action)(() => TestAndContinue()) },
{ "installData", Info }
};
Game.modData.WidgetLoader.LoadWidget(args, Widget.RootWidget, Info["InstallerWidget"]);
}
else
Game.LoadShellMap();
} }
} }
} }

View File

@@ -79,6 +79,7 @@
<Compile Include="Widgets\CncMapChooserLogic.cs" /> <Compile Include="Widgets\CncMapChooserLogic.cs" />
<Compile Include="Widgets\CncConnectionLogic.cs" /> <Compile Include="Widgets\CncConnectionLogic.cs" />
<Compile Include="Widgets\CncIngameChromeLogic.cs" /> <Compile Include="Widgets\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\CncInstallLogic.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -0,0 +1,50 @@
#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.Net;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using OpenRA.FileFormats;
using OpenRA.Network;
using OpenRA.Widgets;
using System.Threading;
using OpenRA.Mods.RA.Widgets;
namespace OpenRA.Mods.Cnc.Widgets
{
public class CncInstallLogic : IWidgetDelegate
{
[ObjectCreator.UseCtor]
public CncInstallLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Dictionary<string,string> installData,
[ObjectCreator.Param] Action continueLoading)
{
var panel = widget.GetWidget("INSTALL_PANEL");
var args = new Dictionary<string, object>()
{
{ "continueLoading", continueLoading },
{ "installData", installData }
};
panel.GetWidget<CncMenuButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
Widget.OpenWindow("INSTALL_DOWNLOAD_PANEL", args);
panel.GetWidget<CncMenuButtonWidget>("INSTALL_BUTTON").OnClick = () =>
Widget.OpenWindow("INSTALL_FROMCD_PANEL", args);
//panel.GetWidget<CncMenuButtonWidget>("MODS_BUTTON").OnClick = ShowModDialog;
panel.GetWidget<CncMenuButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
}
}
}

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA
{ {
public class NullLoadScreen : ILoadScreen public class NullLoadScreen : ILoadScreen
{ {
public void Init() {} public void Init(Dictionary<string, string> info) {}
public void Display() public void Display()
{ {
if (Game.Renderer == null) if (Game.Renderer == null)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
Renderer r; Renderer r;
SpriteFont Font; SpriteFont Font;
public void Init() public void Init(Dictionary<string, string> 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

View File

@@ -179,34 +179,6 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
} }
} }
// General support methods
public class Download
{
WebClient wc;
bool cancelled;
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
{
wc = new WebClient();
wc.Proxy = null;
wc.DownloadProgressChanged += (_,a) => onProgress(a);
wc.DownloadFileCompleted += (_,a) => onComplete(a, cancelled);
Game.OnQuit += () => Cancel();
wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => Cancel();};
wc.DownloadFileAsync(new Uri(url), path);
}
public void Cancel()
{
Game.OnQuit -= () => Cancel();
wc.CancelAsync();
cancelled = true;
}
}
bool ExtractZip(Widget window, string zipFile, string dest) bool ExtractZip(Widget window, string zipFile, string dest)
{ {
if (!File.Exists(zipFile)) if (!File.Exists(zipFile))
@@ -299,6 +271,33 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
} }
} }
public class Download
{
WebClient wc;
bool cancelled;
public Download(string url, string path, Action<DownloadProgressChangedEventArgs> onProgress, Action<AsyncCompletedEventArgs, bool> onComplete)
{
wc = new WebClient();
wc.Proxy = null;
wc.DownloadProgressChanged += (_,a) => onProgress(a);
wc.DownloadFileCompleted += (_,a) => onComplete(a, cancelled);
Game.OnQuit += () => Cancel();
wc.DownloadFileCompleted += (_,a) => {Game.OnQuit -= () => Cancel();};
wc.DownloadFileAsync(new Uri(url), path);
}
public void Cancel()
{
Game.OnQuit -= () => Cancel();
wc.CancelAsync();
cancelled = true;
}
}
static class InstallUtils static class InstallUtils
{ {
static IEnumerable<ZipEntry> GetEntries(this ZipInputStream z) static IEnumerable<ZipEntry> GetEntries(this ZipInputStream z)

View File

@@ -1,67 +1,65 @@
GameInitInfo@INIT_SETUP: Container@INSTALL_PANEL:
Id:INIT_SETUP Id:INSTALL_PANEL
TestFile: conquer.mix Delegate:CncInstallLogic
GameTitle: Command & Conquer
PackageURL:http://open-ra.org/get-dependency.php?file=cnc-packages
PackagePath:^/Content/cnc
InstallMode:cnc
Delegate:GameInitDelegate
Background@INIT_CHOOSEINSTALL:
Id:INIT_CHOOSEINSTALL
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2 Y:(WINDOW_BOTTOM - 150)/2
Width:500 Width:640
Height:160 Height:150
Children: Children:
Label@TITLE: Label@TITLE:
X:0
Y:20
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Y:0-25
Text:Install Required Font:BigBold
Contrast:true
Align:Center Align:Center
Bold:True Text:Install Game Content
Label@DESC1: Background@bg:
X:0 Width:640
Y:65 Height:150
Width:PARENT_RIGHT Background:panel-black
Height:25 Children:
Text:OpenRA requires the original C&C game content. Label@INFO:
Align:Center X:165
Label@DESC2: Y:40
X:0 Width:PARENT_RIGHT-30
Y:70 Height:25
Width:PARENT_RIGHT Text:OpenRA requires the original C&C content files.
Height:25 Font:Bold
Text:Content can be downloaded, or copied from the install CD. Label@INFO:
Visible:false X:165
Align:Center Y:70
Button@DOWNLOAD: Width:PARENT_RIGHT-180
Id:DOWNLOAD Height:25
X:PARENT_RIGHT - 280 WordWrap:true
Y:PARENT_BOTTOM - 45 Text:OpenRA can download these files (excluding music and videos) from the internet, or you can install from the original C&C CD.
Width:120 Font:Bold
Height:25 CncMenuButton@QUIT_BUTTON:
Text:Download Id:QUIT_BUTTON
Bold:True Y:149
Button@FROMCD: Width:140
Id:FROMCD Height:35
X:PARENT_RIGHT - 420
Y:PARENT_BOTTOM - 45
Width:120
Height:25
Visible:false
Text:From CD
Bold:True
Button@QUIT:
Id:QUIT
X:PARENT_RIGHT - 140
Y:PARENT_BOTTOM - 45
Width:120
Height:25
Text:Quit Text:Quit
Bold:True CncMenuButton@MODS_BUTTON:
Id:MODS_BUTTON
X:150
Y:149
Width:140
Height:35
Text:Change Mod
CncMenuButton@DOWNLOAD_BUTTON:
Id:DOWNLOAD_BUTTON
X:350
Y:149
Width:140
Height:35
Text:Download
CncMenuButton@INSTALL_BUTTON:
Id:INSTALL_BUTTON
X:500
Y:149
Width:140
Height:35
Text:Use CD
Background@INIT_DOWNLOAD: Background@INIT_DOWNLOAD:
Id:INIT_DOWNLOAD Id:INIT_DOWNLOAD

View File

@@ -4,6 +4,7 @@ Metadata:
Version: {DEV_VERSION} Version: {DEV_VERSION}
Author: The OpenRA Developers Author: The OpenRA Developers
Standalone: true Standalone: true
Folders: Folders:
. .
./mods/cnc ./mods/cnc
@@ -92,6 +93,11 @@ TileSets:
mods/cnc/tilesets/snow.yaml mods/cnc/tilesets/snow.yaml
LoadScreen: CncLoadScreen LoadScreen: CncLoadScreen
InstallerWidget: INSTALL_PANEL
TestFile: conquer.mix
PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages
PackagePath: ^/Content/cnc
ServerTraits: ServerTraits:
PlayerCommands PlayerCommands
LobbyCommands LobbyCommands