public override void OnEnter()
        {
            DefaultFont = Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Default);
            GUI         = new DwarfGUI(Game, DefaultFont, Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Title), Game.Content.Load <SpriteFont>(ContentPaths.Fonts.Small), Input);
            Input       = new InputManager();

            CreateGUI();
            SelectedDescriptor = null;
            IsInitialized      = true;
            base.OnEnter();
        }
        public void DeleteDescriptor(WorldLoadDescriptor selectedDescriptor)
        {
            Worlds.Remove(selectedDescriptor);
            int cols = Math.Max(scroller.LocalBounds.Width / 256, 1);

            CreateWorldPictures(scrollGrid, cols);
            PropertiesPanel.ClearChildren();

            try
            {
                System.IO.Directory.Delete(selectedDescriptor.DirectoryName, true);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
Exemple #3
0
        public void LoadDescriptor(WorldLoadDescriptor descriptor, WorldSettings settings)
        {
            try
            {
                lock (descriptor.Lock)
                {
                    if (!descriptor.IsLoaded)
                    {
                        return;
                    }

                    descriptor.File = new OverworldFile(descriptor.FileName, true, true);

                    Overworld.Map = descriptor.File.Data.CreateMap();

                    Overworld.Name  = descriptor.File.Data.Name;
                    settings.Width  = Overworld.Map.GetLength(1);
                    settings.Height = Overworld.Map.GetLength(0);

                    WorldGeneratorState.worldMap = descriptor.File.Data.CreateTexture(Game.GraphicsDevice, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1), descriptor.File.Data.SeaLevel);

                    JoinThreads();
                    StateManager.PopState();
                    StateManager.PushState(new WorldGeneratorState(Game, Game.StateManager)
                    {
                        Settings = Settings
                    });
                    WorldGeneratorState state = StateManager.GetState <WorldGeneratorState>();
                    state.Progress.Value     = 1.0f;
                    state.GenerationComplete = true;
                    state.DoneGenerating     = true;
                    state.Settings.Name      = descriptor.WorldName;
                    state.worldData          = new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)];
                    state.CreateMesh();
                    Worlds.Clear();
                }
            }
            catch (Exception e)
            {
                Dialog.Popup(GUI, "ERROR", "Failed to load world: " + e.Message, Dialog.ButtonType.OK);
            }
        }
 public void LoadWorlds()
 {
     ExitThreads = false;
     try
     {
         System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetGameDirectory() + ProgramData.DirChar + OverworldDirectory);
         foreach (System.IO.DirectoryInfo file in worldDirectory.EnumerateDirectories())
         {
             WorldLoadDescriptor descriptor = new WorldLoadDescriptor
             {
                 DirectoryName  = file.FullName,
                 WorldName      = file.FullName.Split(ProgramData.DirChar).Last(),
                 ScreenshotName = file.FullName + ProgramData.DirChar + "screenshot.png",
                 FileName       = file.FullName + ProgramData.DirChar + "world." + OverworldFile.CompressedExtension,
             };
             Worlds.Add(descriptor);
         }
     }
     catch (System.IO.IOException exception)
     {
         Console.Error.WriteLine(exception.Message);
         Dialog.Popup(GUI, "Error.", "Error loading worlds:\n" + exception.Message, Dialog.ButtonType.OK);
     }
 }
 private void worldPicture_OnClicked(int picture)
 {
     SelectedDescriptor = Worlds[picture];
     UpdateSelection();
 }
Exemple #6
0
 public void LoadWorlds()
 {
     ExitThreads = false;
     try
     {
         System.IO.DirectoryInfo worldDirectory = System.IO.Directory.CreateDirectory(DwarfGame.GetGameDirectory() + ProgramData.DirChar + OverworldDirectory);
         foreach(System.IO.DirectoryInfo file in worldDirectory.EnumerateDirectories())
         {
             WorldLoadDescriptor descriptor = new WorldLoadDescriptor
             {
                 DirectoryName = file.FullName,
                 WorldName = file.FullName.Split(ProgramData.DirChar).Last(),
                 ScreenshotName = file.FullName + ProgramData.DirChar + "screenshot.png",
                 FileName = file.FullName + ProgramData.DirChar + "world." + OverworldFile.CompressedExtension,
             };
             Worlds.Add(descriptor);
         }
     }
     catch(System.IO.IOException exception)
     {
         Console.Error.WriteLine(exception.Message);
         Dialog.Popup(GUI, "Error.", "Error loading worlds:\n" + exception.Message, Dialog.ButtonType.OK);
     }
 }
Exemple #7
0
        public void LoadDescriptor(WorldLoadDescriptor descriptor)
        {
            try
            {
                lock (descriptor.Lock)
                {
                    if (!descriptor.IsLoaded)
                    {
                        return;
                    }

                    descriptor.File = new OverworldFile(descriptor.FileName, true);

                    Overworld.Map = descriptor.File.Data.CreateMap();

                    Overworld.Name = descriptor.File.Data.Name;
                    PlayState.WorldWidth = Overworld.Map.GetLength(1);
                    PlayState.WorldHeight = Overworld.Map.GetLength(0);

                    WorldGeneratorState state = (WorldGeneratorState)(StateManager.States["WorldGeneratorState"]);

                    WorldGeneratorState.worldMap = descriptor.File.Data.CreateTexture(Game.GraphicsDevice, Overworld.Map.GetLength(0), Overworld.Map.GetLength(1));
                    JoinThreads();
                    StateManager.PopState();
                    StateManager.PushState("WorldGeneratorState");
                    state.Progress.Value = 1.0f;
                    state.GenerationComplete = true;
                    state.DoneGenerating = true;
                    state.Settings.Name = descriptor.WorldName;
                    state.worldData = new Color[Overworld.Map.GetLength(0) * Overworld.Map.GetLength(1)];

                    Worlds.Clear();
                }
            }
            catch (Exception e)
            {

                Dialog.Popup(GUI, "ERROR", "Failed to load world: " + e.Message, Dialog.ButtonType.OK);
            }
        }
Exemple #8
0
        public void DeleteDescriptor(WorldLoadDescriptor selectedDescriptor)
        {
            Worlds.Remove(selectedDescriptor);
            int cols = Math.Max(scroller.LocalBounds.Width / 256, 1);
            CreateWorldPictures(scrollGrid, cols);
            PropertiesPanel.ClearChildren();

            try
            {
                System.IO.Directory.Delete(selectedDescriptor.DirectoryName, true);
            }
            catch(Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }