Пример #1
0
        public void InitializeWorldsList()
        {
            DirectoryInfo serverDir = new DirectoryInfo(Path.Combine(App.ServerPath, Server.Name));

            if (!serverDir.Exists)
            {
                return;
            }

            Application.Current.Dispatcher?.Invoke(() => Worlds.Clear());
            foreach (DirectoryInfo directory in serverDir.EnumerateDirectories())
            {
                WorldValidationInfo worldVal = DirectoryValidator.ValidateWorldDirectory(directory);
                if (worldVal.IsValid)
                {
                    World world = new World(worldVal.Name, this, directory);
                    if (Server.ServerSettings.LevelName.Equals(world.Name))
                    {
                        world.IsActive = true;
                    }

                    Application.Current.Dispatcher?.Invoke(() => Worlds.Add(world));
                }
            }
        }
Пример #2
0
        void LoadWorldList()
        {
            if (Worlds.Count > 0)
            {
                Worlds.Clear();
            }
            if (!File.Exists(Paths.WorldListFileName))
            {
                return;
            }

            try {
                XDocument doc  = XDocument.Load(Paths.WorldListFileName);
                XElement  root = doc.Root;
                if (root == null)
                {
                    MessageBox.Show("Worlds.xml is empty or corrupted.");
                    return;
                }

                string errorLog = "";
                using (LogRecorder logRecorder = new LogRecorder()) {
                    foreach (XElement el in root.Elements("World"))
                    {
                        try {
                            Worlds.Add(new WorldListEntry(el));
                        } catch (Exception ex) {
                            errorLog += ex + Environment.NewLine;
                        }
                    }
                    if (logRecorder.HasMessages)
                    {
                        MessageBox.Show(logRecorder.MessageString, "World list loading warnings.");
                    }
                }
                if (errorLog.Length > 0)
                {
                    MessageBox.Show("Some errors occured while loading the world list:" + Environment.NewLine + errorLog, "Warning");
                }

                FillWorldList();
                XAttribute mainWorldAttr = root.Attribute("main");
                if (mainWorldAttr != null)
                {
                    foreach (WorldListEntry world in Worlds)
                    {
                        if (world.Name.ToLower() == mainWorldAttr.Value.ToLower())
                        {
                            cMainWorld.SelectedItem = world.Name;
                            break;
                        }
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("Error occured while loading the world list: " + Environment.NewLine + ex, "Warning");
            }

            Worlds.ListChanged += SomethingChanged;
        }
Пример #3
0
        private void LoadSaveList()
        {
            Worlds.Clear();
            var list = new List <WorldResource>();

            #region local saves

            if (Directory.Exists(BaseLocalPath.SavesPath))
            {
                var userPaths = Directory.GetDirectories(BaseLocalPath.SavesPath);

                foreach (var userPath in userPaths)
                {
                    var userName = Path.GetFileName(userPath);
                    list.AddRange(FindSaveFiles(userPath, userName, SaveWorldType.Local, BaseLocalPath));
                }
            }

            #endregion

            #region Host Server

            if (Directory.Exists(BaseDedicatedServerHostPath.SavesPath))
            {
                list.AddRange(FindSaveFiles(BaseDedicatedServerHostPath.SavesPath, "Local / Console", SaveWorldType.DedicatedServerHost, BaseDedicatedServerHostPath));
            }

            #endregion

            #region Service Server

            if (Directory.Exists(BaseDedicatedServerServicePath.SavesPath))
            {
                var instancePaths = Directory.GetDirectories(BaseDedicatedServerServicePath.SavesPath);

                foreach (var instancePath in instancePaths)
                {
                    var lastLoadedPath = Path.Combine(instancePath, "Saves");

                    if (Directory.Exists(lastLoadedPath))
                    {
                        var instanceName = Path.GetFileName(instancePath);
                        var dataPath     = new UserDataPath(lastLoadedPath, Path.Combine(instancePath, "Mods"));
                        list.AddRange(FindSaveFiles(lastLoadedPath, instanceName, SaveWorldType.DedicatedServerService, dataPath));
                    }
                }
            }

            #endregion

            foreach (var item in list.OrderByDescending(w => w.LastLoadTime))
            {
                Worlds.Add(item);
            }
        }
Пример #4
0
        public void CreateGUI()
        {
            GUI.RootComponent.ClearChildren();
            Worlds.Clear();
            const int edgePadding = 32;
            Panel     mainWindow  = new Panel(GUI, GUI.RootComponent)
            {
                LocalBounds = new Rectangle(edgePadding, edgePadding, Game.GraphicsDevice.Viewport.Width - edgePadding * 2, Game.GraphicsDevice.Viewport.Height - edgePadding * 2)
            };
            GridLayout layout = new GridLayout(GUI, mainWindow, 10, 4);

            Label title = new Label(GUI, layout, "Load World", GUI.TitleFont);

            layout.SetComponentPosition(title, 0, 0, 1, 1);

            scroller = new ScrollView(GUI, layout);
            layout.SetComponentPosition(scroller, 0, 1, 3, 8);

            LoadWorlds();

            layout.UpdateSizes();

            int cols = Math.Max(scroller.LocalBounds.Width / 256, 1);
            int rows = Math.Max(Math.Max(scroller.LocalBounds.Height / 256, 1), (int)Math.Ceiling((float)Worlds.Count / (float)cols));

            scrollGrid = new GridLayout(GUI, scroller, rows, cols)
            {
                LocalBounds    = new Rectangle(edgePadding, edgePadding, scroller.LocalBounds.Width - edgePadding, rows * 256),
                WidthSizeMode  = GUIComponent.SizeMode.Fixed,
                HeightSizeMode = GUIComponent.SizeMode.Fixed
            };

            CreateWorldPictures(scrollGrid, cols);


            CreateLoadThreads(4);

            PropertiesPanel = new GroupBox(GUI, layout, "Selected");

            layout.SetComponentPosition(PropertiesPanel, 3, 1, 1, 8);

            Button back = new Button(GUI, layout, "Back", GUI.DefaultFont, Button.ButtonMode.ToolButton, GUI.Skin.GetSpecialFrame(GUISkin.Tile.LeftArrow));

            layout.SetComponentPosition(back, 3, 9, 1, 1);
            back.OnClicked += back_OnClicked;
        }
Пример #5
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);
            }
        }