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

View File

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

View File

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

View File

@@ -14,6 +14,8 @@ using System.Linq;
using OpenRA.Support;
using OpenRA.Graphics;
using OpenRA.Widgets;
using OpenRA.FileFormats;
using System;
namespace OpenRA.Mods.Cnc
{
@@ -25,6 +27,7 @@ namespace OpenRA.Mods.Cnc
"Splitting Atoms..."
};
Dictionary<string,string> Info;
Stopwatch lastLoadScreen = new Stopwatch();
Rectangle StripeRect, BgRect;
Sprite Stripe, Logo, Bg;
@@ -32,8 +35,9 @@ namespace OpenRA.Mods.Cnc
Renderer r;
SpriteFont Font;
public void Init()
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;
@@ -73,8 +77,22 @@ namespace OpenRA.Mods.Cnc
public void StartGame()
{
Widget.RootWidget.RemoveChildren();
Game.modData.WidgetLoader.LoadWidget( new Dictionary<string,object>(), Widget.RootWidget, "INIT_SETUP" );
TestAndContinue();
}
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\CncConnectionLogic.cs" />
<Compile Include="Widgets\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\CncInstallLogic.cs" />
</ItemGroup>
<ItemGroup>
<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 void Init() {}
public void Init(Dictionary<string, string> info) {}
public void Display()
{
if (Game.Renderer == null)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
Renderer r;
SpriteFont Font;
public void Init()
public void Init(Dictionary<string, string> info)
{
// Avoid standard loading mechanisms so we
// 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)
{
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 IEnumerable<ZipEntry> GetEntries(this ZipInputStream z)

View File

@@ -1,67 +1,65 @@
GameInitInfo@INIT_SETUP:
Id:INIT_SETUP
TestFile: conquer.mix
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
Container@INSTALL_PANEL:
Id:INSTALL_PANEL
Delegate:CncInstallLogic
X:(WINDOW_RIGHT - WIDTH)/2
Y:(WINDOW_BOTTOM - HEIGHT)/2
Width:500
Height:160
Y:(WINDOW_BOTTOM - 150)/2
Width:640
Height:150
Children:
Label@TITLE:
X:0
Y:20
Width:PARENT_RIGHT
Height:25
Text:Install Required
Y:0-25
Font:BigBold
Contrast:true
Align:Center
Bold:True
Label@DESC1:
X:0
Y:65
Width:PARENT_RIGHT
Text:Install Game Content
Background@bg:
Width:640
Height:150
Background:panel-black
Children:
Label@INFO:
X:165
Y:40
Width:PARENT_RIGHT-30
Height:25
Text:OpenRA requires the original C&C game content.
Align:Center
Label@DESC2:
X:0
Text:OpenRA requires the original C&C content files.
Font:Bold
Label@INFO:
X:165
Y:70
Width:PARENT_RIGHT
Height:25
Text:Content can be downloaded, or copied from the install CD.
Visible:false
Align:Center
Button@DOWNLOAD:
Id:DOWNLOAD
X:PARENT_RIGHT - 280
Y:PARENT_BOTTOM - 45
Width:120
Height:25
Text:Download
Bold:True
Button@FROMCD:
Id:FROMCD
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
Width:PARENT_RIGHT-180
Height:25
WordWrap:true
Text:OpenRA can download these files (excluding music and videos) from the internet, or you can install from the original C&C CD.
Font:Bold
CncMenuButton@QUIT_BUTTON:
Id:QUIT_BUTTON
Y:149
Width:140
Height:35
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:
Id:INIT_DOWNLOAD

View File

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