public LoadSaveGameState(DwarfGame Game, GameStateManager StateManager) :
            base(Game, StateManager)
        {
            this.ProceedButtonText = "Load";
            this.NoItemsText       = "No saves found.";

            this.ItemSource = () =>
            {
                System.IO.DirectoryInfo savedirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetSaveDirectory());
                return(savedirectory.EnumerateDirectories().Select(d => d.FullName).ToList());
            };

            this.ScreenshotSource = (path) =>
            {
                var screenshots = System.IO.Directory.GetFiles(path, "*.png");
                if (screenshots.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(TextureManager.LoadInstanceTexture(screenshots[0], false));
                }
            };

            this.OnProceedClicked = (path) =>
            {
                StateManager.ClearState();
                StateManager.PushState(new LoadState(Game, Game.StateManager,
                                                     new WorldGenerationSettings
                {
                    ExistingFile = path,
                    Name         = path
                }));
            };

            this.ValidateItem = (path) =>
            {
                try
                {
                    var saveGame = SaveGame.CreateFromDirectory(path);
                    return(Program.CompatibleVersions.Contains(saveGame.Metadata.Version));
                }
                catch (Exception)
                {
                    return(false);
                }
            };

            this.InvalidItemText = "This save was created with a different version of DwarfCorp and cannot be loaded.";
        }
Beispiel #2
0
        public LoadSaveGameState(DwarfGame Game, GameStateManager StateManager) :
            base(Game, StateManager)
        {
            this.ProceedButtonText = "Load";
            this.NoItemsText       = "No saves found.";

            this.ItemSource = () =>
            {
                System.IO.DirectoryInfo savedirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetSaveDirectory());
                var dirs = savedirectory.EnumerateDirectories().ToList();
                dirs.Sort((a, b) => b.LastWriteTime.CompareTo(a.LastWriteTime));
                return(dirs.ToList());
            };

            this.ScreenshotSource = (path) =>
            {
                var screenshots = System.IO.Directory.GetFiles(path, "*.png");
                if (screenshots.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(AssetManager.LoadUnbuiltTextureFromAbsolutePath(screenshots[0]));
                }
            };

            this.OnProceedClicked = (path) =>
            {
                StateManager.ClearState();
                StateManager.PushState(new LoadState(Game, Game.StateManager,
                                                     new WorldGenerationSettings
                {
                    ExistingFile = path,
                    Name         = path
                }));
            };

            this.ValidateItem = (path) =>
            {
                try
                {
                    var saveGame = SaveGame.CreateFromDirectory(path);
                    if (!Program.CompatibleVersions.Contains(saveGame.Metadata.Version))
                    {
                        return(String.Format("Incompatible version {0}", saveGame.Metadata.Version));
                    }
                    var overworld = saveGame.Metadata.OverworldFile;
                    if (!System.IO.Directory.Exists(DwarfGame.GetWorldDirectory() + Program.DirChar + overworld))
                    {
                        return(String.Format("Overworld \"{0}\" does not exist.", overworld));
                    }
                    return("");
                }
                catch (Exception e)
                {
                    return(String.Format("Error while loading {0}", e.Message));
                }
            };

            this.GetItemName = (path) =>
            {
                try
                {
                    var saveGame = SaveGame.CreateFromDirectory(path);
                    return(saveGame.Metadata.OverworldFile);
                }
                catch (Exception)
                {
                    return("?");
                }
            };

            this.InvalidItemText = "This save was created with a different version of DwarfCorp and cannot be loaded.";
        }