diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 6b0cc26335..5af877849d 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -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); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 16796ff105..45e214e60a 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -35,8 +35,8 @@ namespace OpenRA { Manifest = new Manifest( mods ); ObjectCreator = new ObjectCreator( Manifest ); - LoadScreen = ObjectCreator.CreateObject(Manifest.LoadScreen); - LoadScreen.Init(); + LoadScreen = ObjectCreator.CreateObject(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 info); void Display(); - void Init(); void StartGame(); } } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 94fa3225f6..367a75c1a3 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -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(); diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index a73f7b2342..1d26b8f77e 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -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 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 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(), Widget.RootWidget, "INIT_SETUP" ); + TestAndContinue(); + } + + void TestAndContinue() + { + if (!FileSystem.Exists(Info["TestFile"])) + { + var args = new Dictionary() + { + { "continueLoading", (Action)(() => TestAndContinue()) }, + { "installData", Info } + }; + Game.modData.WidgetLoader.LoadWidget(args, Widget.RootWidget, Info["InstallerWidget"]); + } + else + Game.LoadShellMap(); } } } diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 9097616fd4..70872d0c8b 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -79,6 +79,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs new file mode 100755 index 0000000000..9f83e31e99 --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncInstallLogic.cs @@ -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 installData, + [ObjectCreator.Param] Action continueLoading) + { + var panel = widget.GetWidget("INSTALL_PANEL"); + var args = new Dictionary() + { + { "continueLoading", continueLoading }, + { "installData", installData } + }; + + panel.GetWidget("DOWNLOAD_BUTTON").OnClick = () => + Widget.OpenWindow("INSTALL_DOWNLOAD_PANEL", args); + + panel.GetWidget("INSTALL_BUTTON").OnClick = () => + Widget.OpenWindow("INSTALL_FROMCD_PANEL", args); + + //panel.GetWidget("MODS_BUTTON").OnClick = ShowModDialog; + panel.GetWidget("QUIT_BUTTON").OnClick = Game.Exit; + } + } +} diff --git a/OpenRA.Mods.RA/NullLoadScreen.cs b/OpenRA.Mods.RA/NullLoadScreen.cs index 6e01e3453e..957b53731a 100644 --- a/OpenRA.Mods.RA/NullLoadScreen.cs +++ b/OpenRA.Mods.RA/NullLoadScreen.cs @@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA { public class NullLoadScreen : ILoadScreen { - public void Init() {} + public void Init(Dictionary info) {} public void Display() { if (Game.Renderer == null) diff --git a/OpenRA.Mods.RA/RALoadScreen.cs b/OpenRA.Mods.RA/RALoadScreen.cs index 0d9f70349f..4cf2ae6111 100644 --- a/OpenRA.Mods.RA/RALoadScreen.cs +++ b/OpenRA.Mods.RA/RALoadScreen.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA Renderer r; SpriteFont Font; - public void Init() + public void Init(Dictionary info) { // Avoid standard loading mechanisms so we // can display loadscreen as early as possible diff --git a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs index 244e06bf5f..fb587a7ea2 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/GameInitDelegate.cs @@ -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 onProgress, Action 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 onProgress, Action 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 GetEntries(this ZipInputStream z) diff --git a/mods/cnc/chrome/gameinit.yaml b/mods/cnc/chrome/gameinit.yaml index 2ac683d7f1..ed500ebc39 100644 --- a/mods/cnc/chrome/gameinit.yaml +++ b/mods/cnc/chrome/gameinit.yaml @@ -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 - Height:25 - Text:OpenRA requires the original C&C game content. - Align:Center - Label@DESC2: - X:0 - 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 - Height:25 + 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 content files. + Font:Bold + Label@INFO: + X:165 + Y:70 + 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 diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index ec9ac68c20..3b15ee98c2 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -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