diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 6311862a97..9390bcf932 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -244,7 +244,7 @@ namespace OpenRA Console.WriteLine("Loading mods: {0}",string.Join(",",mods)); modData = new ModData( mods ); - modData.Sucks(); + modData.LoadInitialAssets(); Sound.Initialize(); PerfHistory.items["render"].hasNormalTick = false; @@ -252,10 +252,7 @@ namespace OpenRA JoinLocal(); viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer); - - modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "PERF_BG" ); modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "MAINMENU_INIT" ); - Game.orderManager.LastTickTime = Environment.TickCount; } diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index d87b1e57db..516f9de1f2 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -23,10 +23,14 @@ namespace OpenRA.Graphics public static void Initialize(string[] sequenceFiles) { + // TODO: Convert cursor definitions to yaml and parse cursor palette info + Game.modData.Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false )); + cursors = new Dictionary(); foreach (var f in sequenceFiles) LoadSequenceSource(f); + } static void LoadSequenceSource(string filename) diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index a8404d4570..5ac0edf16e 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -27,6 +27,7 @@ namespace OpenRA public CursorSheetBuilder CursorSheetBuilder; public SpriteLoader SpriteLoader; public HardwarePalette Palette { get; private set; } + IFolder previousMapMount = null; public ModData( params string[] mods ) { @@ -39,33 +40,45 @@ namespace OpenRA AvailableMaps = FindMaps( Manifest.Mods ); WidgetLoader = new WidgetLoader( this ); } - - void LoadHackyPalettes() - { - Palette = new HardwarePalette(); - Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false )); - } - - public void Sucks() - { - // all this manipulation of static crap here is nasty and breaks - // horribly when you use ModData in unexpected ways. - - FileSystem.UnmountAll(); - foreach (var dir in Manifest.Folders) FileSystem.Mount(dir); + public void LoadInitialAssets() + { + // all this manipulation of static crap here is nasty and breaks + // horribly when you use ModData in unexpected ways. + FileSystem.UnmountAll(); + foreach (var dir in Manifest.Folders) + FileSystem.Mount(dir); + + Palette = new HardwarePalette(); ChromeProvider.Initialize( Manifest.Chrome ); SheetBuilder = new SheetBuilder( TextureChannel.Red ); CursorSheetBuilder = new CursorSheetBuilder( this ); - - SpriteLoader = new SpriteLoader(new[]{".shp"}, SheetBuilder); CursorProvider.Initialize(Manifest.Cursors); - LoadHackyPalettes(); } - - public void LoadPackages() + + public Map PrepareMap(string uid) { - foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg); + LoadScreen.Display(); + if (!AvailableMaps.ContainsKey(uid)) + throw new InvalidDataException("Invalid map uid: {0}".F(uid)); + var map = new Map(AvailableMaps[uid].Path); + + // Maps may contain custom assets + // TODO: why are they lowest priority? they should be highest. + if (previousMapMount != null) FileSystem.Unmount(previousMapMount); + previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); + FileSystem.Mount(previousMapMount); + + // Reinit all our assets + LoadInitialAssets(); + foreach (var pkg in Manifest.Packages) + FileSystem.Mount(pkg); + + Rules.LoadRules(Manifest, map); + SpriteLoader = new SpriteLoader( Rules.TileSets[map.Tileset].Extensions, SheetBuilder ); + SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); + + return map; } public static IEnumerable FindMapsIn(string dir) @@ -97,46 +110,6 @@ namespace OpenRA return ret; } - string cachedTileset = null; - bool previousMapHadSequences = true; - IFolder previousMapMount = null; - - public Map PrepareMap(string uid) - { - LoadScreen.Display(); - - if (!AvailableMaps.ContainsKey(uid)) - throw new InvalidDataException("Invalid map uid: {0}".F(uid)); - - var map = new Map(AvailableMaps[uid].Path); - - // unload the previous map mount if we have one - if (previousMapMount != null) FileSystem.Unmount(previousMapMount); - - // Adds the map its container to the FileSystem - // allowing the map to use custom assets - // Container should have the lowest priority of all (ie int max) - // Store a reference so we can unload it next time - previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); - FileSystem.Mount(previousMapMount); - Rules.LoadRules(Manifest, map); - - if (map.Tileset != cachedTileset - || previousMapHadSequences || map.Sequences.Count > 0) - { - SheetBuilder = new SheetBuilder( TextureChannel.Red ); - SpriteLoader = new SpriteLoader( Rules.TileSets[map.Tileset].Extensions, SheetBuilder ); - CursorSheetBuilder = new CursorSheetBuilder( this ); - CursorProvider.Initialize(Manifest.Cursors); - SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); - cachedTileset = map.Tileset; - } - - previousMapHadSequences = map.Sequences.Count > 0; - LoadHackyPalettes(); - - return map; - } } public interface ILoadScreen { void Display(); void Init(); } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs index 469c37b9cb..c65ea9768d 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates [ObjectCreator.UseCtor] public MainMenuButtonsDelegate([ObjectCreator.Param] Widget widget) { - // Main menu is the default window + Game.modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "PERF_BG" ); widget.GetWidget("MAINMENU_BUTTON_JOIN").OnMouseUp = mi => { Widget.OpenWindow("JOINSERVER_BG"); return true; }; widget.GetWidget("MAINMENU_BUTTON_CREATE").OnMouseUp = mi => { Widget.OpenWindow("CREATESERVER_BG"); return true; }; widget.GetWidget("MAINMENU_BUTTON_SETTINGS").OnMouseUp = mi => { Widget.OpenWindow("SETTINGS_MENU"); return true; }; diff --git a/OpenRA.Mods.RA/Widgets/Delegates/RAInitDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/RAInitDelegate.cs index 71fcb23732..98eefae688 100755 --- a/OpenRA.Mods.RA/Widgets/Delegates/RAInitDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/RAInitDelegate.cs @@ -45,18 +45,17 @@ namespace OpenRA.Mods.RA.Widgets.Delegates lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true; lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true; lobby.GetWidget("DISCONNECT_BUTTON").Visible = true; - //r.GetWidget("INGAME_ROOT").GetWidget("CHAT_DISPLAY").ClearChat(); break; } }; if (FileSystem.Exists("fake.mix")) - ContinueLoading(); + ContinueLoading(widget); else { widget.GetWidget("INIT_DOWNLOAD").OnMouseUp = mi => { - ContinueLoading(); + ContinueLoading(widget); return true; }; @@ -86,10 +85,10 @@ namespace OpenRA.Mods.RA.Widgets.Delegates p.Start(); } - void ContinueLoading() + void ContinueLoading(Widget widget) { - Game.modData.LoadPackages(); Game.LoadShellMap(); + Widget.RootWidget.Children.Remove(widget); Widget.OpenWindow("MAINMENU_BG"); } }