Exemple #1
0
        private void Open(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
        {
            EndGnomeEdit();

            var dlg = new OpenFileDialog
            {
                Filter           = "Gnomoria saves|*.sav",
                DefaultExt       = ".sav",
                InitialDirectory = GnomanEmpire.SaveFolderPath() + "Worlds"
            };
            var result = dlg.ShowDialog(this);

            if (result == false)
            {
                return;
            }

            LoadButton.IsEnabled = false;
            Clear();

            ProgressBar.Visibility = Visibility.Visible;
            HeadingLabel.Content   = "Game loading...";

            File = new FileInfo(dlg.FileName);

            var worker = new BackgroundWorker();

            worker.DoWork             += LoaderLoad;
            worker.RunWorkerCompleted += LoaderComplete;
            worker.RunWorkerAsync();
        }
Exemple #2
0
 public void init_gnomoria(string gnomoria_directory)
 {
     gnomoria_path = gnomoria_directory;
     gnomoria_game = GnomanEmpire.Instance;
     gnomoria_game.Content.RootDirectory = System.IO.Path.Combine(gnomoria_path, "Content");
     System.IO.Directory.SetCurrentDirectory(gnomoria_path);
     typeof(GnomanEmpire).GetMethod("Initialize", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(gnomoria_game, null);
     save_directory = GnomanEmpire.SaveFolderPath("Worlds\\");
 }
        public override void SetupPanel()
        {
            Label label = new Label(this.Manager);

            label.Init();
            label.Top   = label.Margins.Top;
            label.Left  = label.Margins.Left;
            label.Text  = "Import Tracked Items:";
            label.Width = this.ClientWidth - label.Margins.Horizontal;
            this.Add(label);

            ListBox gameSaveList = new ListBox(this.Manager);

            gameSaveList.Init();
            gameSaveList.Top           = label.Top + label.Height;
            gameSaveList.Left          = gameSaveList.Margins.Left;
            gameSaveList.Width         = 300;
            gameSaveList.Height        = this.ClientHeight - gameSaveList.Top - gameSaveList.Margins.Bottom;
            gameSaveList.HideSelection = false;

            string[] files = Directory.GetFiles(GnomanEmpire.SaveFolderPath("TrackedItems\\"), "*.json");

            foreach (string text in files)
            {
                gameSaveList.list_0.Add(text.Replace(GnomanEmpire.SaveFolderPath("TrackedItems\\"), "").Replace(".json", ""));
            }

            this.Add(gameSaveList);

            Button button = new Button(this.Manager);

            button.Top    = gameSaveList.Top;
            button.Left   = gameSaveList.Left + gameSaveList.Width + gameSaveList.Margins.Right + button.Margins.Left;
            button.Width  = this.ClientWidth - button.Left - button.Margins.Right;
            button.Text   = "Import";
            button.Click += delegate(object s, Game.GUI.Controls.EventArgs e)
            {
                if (gameSaveList.ItemIndex >= 0 && gameSaveList.ItemIndex < gameSaveList.list_0.Count)
                {
                    ModMain.instance.LoadTrackedItems(gameSaveList.list_0[gameSaveList.ItemIndex].ToString());
                }
                GnomanEmpire.Instance.GuiManager.MenuStack.PopWindow();
            };
            this.Add(button);

            Button button2 = new Button(this.Manager);

            button2.Top    = button.Top + button.Height + button.Margins.Bottom + button2.Margins.Top;
            button2.Left   = button.Left;
            button2.Width  = this.ClientWidth - button2.Left - button2.Margins.Right;
            button2.Text   = "Back";
            button2.Click += delegate(object s, Game.GUI.Controls.EventArgs e)
            {
                GnomanEmpire.Instance.GuiManager.MenuStack.PopWindow();
            };
            this.Add(button2);
        }
Exemple #4
0
        public void load(string filename)
        {
            var    gnomoria_save_path = GnomanEmpire.SaveFolderPath("Worlds\\");
            string world_save_file;

            if (!try_extractRelativePath(filename, gnomoria_save_path, out world_save_file))
            {
                throw new Exception("Error: Can only open saves in your Gnomoria worlds save folder!");
            }
            System.IO.Directory.SetCurrentDirectory(gnomoria_path);
            gnomoria_game.LoadGame(world_save_file, false);
        }
Exemple #5
0
        public Result Initialize()
        {
            Result result = new Result(false, "");

            try
            {
                Console.WriteLine("[Game Model] Initialize: 7z Setup");
                SevenZip.SevenZipExtractor.SetLibraryPath("7z.dll");

                Console.WriteLine("[Game Model] Initialize: Running reflection");
                MethodInfo initMethod = typeof(GnomanEmpire).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance);
                initMethod.Invoke(GnomanEmpire.Instance, null);

                // Stop the music playing (it starts automatically when the Game object is initialized)
                GnomanEmpire.Instance.AudioManager.SetMusicVolume(0);
                GnomanEmpire.Instance.AudioManager.SetSFXVolume(0);

                // Exit the full screen mode if needed
                if (GnomanEmpire.Instance.Graphics.IsFullScreen)
                {
                    GnomanEmpire.Instance.Graphics.ToggleFullScreen();
                }

                Console.WriteLine("[Game Model] Initialize: Setting SaveFolderPath");
                mSaveGameFolder = GnomanEmpire.SaveFolderPath("Worlds\\");
                mSettingsFolder = GnomanEmpire.SaveFolderPath();

                Console.WriteLine("[Game Model] Initialize: Initializing Character Skills");
                InitializeCharacterAttributes();
                InitializeCharacterSkills();

                result.Success = true;
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                Console.WriteLine("[Game Model] Initialize: Exception encountered \"{0}\"", ex.InnerException.Message);
                result.ErrorMessage = "InvocationException: " + ex.InnerException.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("[Game Model] Initialize: Exception encountered \"{0}\"", ex.Message);
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Exemple #6
0
        internal void SaveTrackedItems(string name)
        {
            string path = GnomanEmpire.SaveFolderPath("TrackedItems\\") + name.Trim() + ".json";

            var groups = GnomanEmpire.Instance.Region.Fortress.StockManager.TrackedItemGroups;

            TrackedItemsModel model = new TrackedItemsModel();

            model.gameVersion = Game.Common.GameSaveHeader.CurrentVersion;

            foreach (TrackedItemGroup group in groups)
            {
                TrackedItemsModel.Group groupModel = new TrackedItemsModel.Group();
                groupModel.name = group.Name;

                // Export items
                foreach (string item in group.itemGroup_0.AllowedItems)
                {
                    groupModel.items.Add(item);
                }

                // Export allowed materials
                foreach (KeyValuePair <string, HashSet <string> > keyValuePair in group.dictionary_0)
                {
                    TrackedItemsModel.AllowedMaterialsForItem materialModel = new TrackedItemsModel.AllowedMaterialsForItem();

                    materialModel.item = keyValuePair.Key;

                    foreach (string material in keyValuePair.Value)
                    {
                        materialModel.materials.Add(material);
                    }

                    groupModel.allowedMaterials.Add(materialModel);
                }

                model.groups.Add(groupModel);
            }

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(model, Newtonsoft.Json.Formatting.Indented);

            System.IO.File.WriteAllText(path, json);
        }
Exemple #7
0
        internal void LoadTrackedItems(string name)
        {
            string path = GnomanEmpire.SaveFolderPath("TrackedItems\\") + name.Trim() + ".json";
            string json = System.IO.File.ReadAllText(path);

            TrackedItemsModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <TrackedItemsModel>(json);

            var groups = GnomanEmpire.Instance.Region.Fortress.StockManager.TrackedItemGroups;
            var hud    = GnomanEmpire.Instance.GuiManager.InGameHUD_0.GClass0_0;

            for (int i = groups.Count - 1; i >= 0; i--)
            {
                groups.RemoveAt(i);
                hud.RemoveStockTrackLabel(i);
            }

            foreach (TrackedItemsModel.Group groupModel in model.groups)
            {
                var group = new TrackedItemGroup();
                group.Name.Value = groupModel.name;

                // Import items

                foreach (string item in groupModel.items)
                {
                    group.AddAllowedItem(item);
                }

                // Import allowed materials

                foreach (TrackedItemsModel.AllowedMaterialsForItem allowedMaterials in groupModel.allowedMaterials)
                {
                    HashSet <string> materials = new HashSet <string>(allowedMaterials.materials);

                    group.dictionary_0.Add(allowedMaterials.item, materials);
                }

                groups.Add(group);

                hud.AddStockTrackLabel(group, false);
            }
        }