コード例 #1
0
        /* User clicks "clone character" button */
        private void CloneCharacterButton_Click(object sender, RoutedEventArgs e)
        {
            if (CharacterID.Text.Length == 0 || !CharacterID.Text.ToLower().Equals(CharacterID.Text) || !CharacterID.Text.Replace(" ", "").Equals(CharacterID.Text))
            {
                MessageBox.Show("Your character ID must contain no spaces, no capitals or match an existing character ID");
                return;
            }

            if (CharacterName.Text.Length > 50)
            {
                MessageBox.Show("Your character name should be less than 50 characters in length");
                return;
            }

            /* Logic to clone the character */
            Character clonedCharacter = CharacterBeingCloned;

            clonedCharacter.description    = clonedCharacter.description.Replace(clonedCharacter.name, CharacterName.Text);
            clonedCharacter.classinfo.name = ActiveProject.Project.prefix + CharacterID.Text;

            ActiveProject.Project.characters.Add(clonedCharacter);

            MainWindow mainWindow = WindowFinder.FindOpenWindowByType <MainWindow>();

            mainWindow.ProjectDataTree.Items.Refresh();
            mainWindow.ProjectDataTree.UpdateLayout();

            this.Close();
        }
コード例 #2
0
        public static void TreeAddSources()
        {
            MainWindow mainWindow = WindowFinder.FindOpenWindowByType <MainWindow>();

            mainWindow.ProjectCharacters.ItemsSource = ActiveProject.Project.characters;

            /* Show the Tree Views */
            mainWindow.ProjectDataTree.Visibility  = Visibility.Visible;
            mainWindow.ImportedDataTree.Visibility = Visibility.Visible;
        }
コード例 #3
0
        /* User clicks "create project" button */
        private void CreateProjectButton_Click(object sender, RoutedEventArgs e)
        {
            if (MapName.Text.Length == 0 || !MapName.Text.ToLower().Equals(MapName.Text) || !MapName.Text.Replace(" ", "").Equals(MapName.Text))
            {
                MessageBox.Show("Your map name must contain no spaces, no capitals and not match an existing map");
                return;
            }

            if (Prefix.Text.Length == 0 || !Prefix.Text.ToLower().Equals(Prefix.Text) || !Prefix.Text.Replace(" ", "").Equals(Prefix.Text))
            {
                MessageBox.Show("Your prefix must contain no spaces, no capitals and not match an existing map");
                return;
            }

            if (Maps.SelectedItem == null || Maps.SelectedItem.ToString().Length == 0)
            {
                MessageBox.Show("Please select a valid base map");
                return;
            }

            if (Directory.Exists(Path.Combine(Settings.UsersProjectHome, MapName.Text)))
            {
                MessageBox.Show("A map with this name already exists in your projects folder");
                return;
            }

            if (ImportedData.importedMaps.Where(x => x.name == MapName.Text).Any())
            {
                MessageBox.Show("A map with this name already exists in game");
                return;
            }

            /* Append Underscore */
            if (!Prefix.Text.EndsWith("_"))
            {
                Prefix.Text = Prefix.Text + "_";
            }

            MainWindow mainWindow = WindowFinder.FindOpenWindowByType <MainWindow>();

            /* Setup Current Project */
            ActiveProject.Project           = new Project();
            ActiveProject.Project.name      = MapName.Text;
            ActiveProject.Project.map       = ImportedData.importedMaps.Where(x => x.name == Maps.SelectedItem.ToString()).FirstOrDefault();
            ActiveProject.Project.directory = Path.Combine(Settings.UsersProjectHome, ActiveProject.Project.name);
            ActiveProject.Project.file      = Path.Combine(Settings.UsersProjectHome, ActiveProject.Project.name, ActiveProject.Project.name + ".mbwb");
            ActiveProject.Project.prefix    = Prefix.Text;

            /* Create the Project Directory */
            Directory.CreateDirectory(ActiveProject.Project.directory);

            /* Create Maps and ext_data */
            Directory.CreateDirectory(Path.Combine(ActiveProject.Project.directory, "maps"));
            Directory.CreateDirectory(Path.Combine(ActiveProject.Project.directory, "ext_data"));


            /* Extract the map from it's PK3 */
            using (ZipArchive zipFile = ZipFile.OpenRead(Path.Combine(Settings.MBIIDirectory, ActiveProject.Project.map.parentPK3)))
            {
                ZipArchiveEntry mapFile = zipFile.GetEntry(ActiveProject.Project.map.entryPath);
                mapFile.ExtractToFile(Path.Combine(ActiveProject.Project.directory, "maps", ActiveProject.Project.map.fileName));
            }

            /* Rename the BSP to that of current project name */
            File.Move(Path.Combine(ActiveProject.Project.directory, "maps", ActiveProject.Project.map.fileName), Path.Combine(ActiveProject.Project.directory, "maps", ActiveProject.Project.name + ".bsp"));

            /* Prefill teams, characters and siege info if this base map has available */
            Siege defaultSiege = ImportedData.importedSieges.Where(x => x.map == ActiveProject.Project.map.name).FirstOrDefault();

            if (defaultSiege != null && defaultSiege.team1 != null && defaultSiege.team2 != null)
            {
                ActiveProject.Project.siege = defaultSiege;

                foreach (Team team in ImportedData.importedTeams.Where(x => x.name == ActiveProject.Project.siege.team1.useTeam || x.name == ActiveProject.Project.siege.team2.useTeam).ToList())
                {
                    Team newTeam = team;
                    team.name = ActiveProject.Project.prefix + team.name;

                    foreach (Character character in team.Characters())
                    {
                        Character newCharacter = character;
                        character.classinfo.name = ActiveProject.Project.prefix + character.classinfo.name;
                        ActiveProject.Project.characters.Add(newCharacter);
                    }

                    /* TODO: We still need to loop the team and change character names to include new prefix here */

                    ActiveProject.Project.teams.Add(newTeam);
                }
            }

            /* Save Project */
            ActiveProject.Save();

            /* Update the GUI */
            ActiveProject.TreeAddSources();

            this.Close();
        }
コード例 #4
0
        /* Handles importing of all files from existing PK3 Files */
        public void BeginImport()
        {
            string[] pk3s = Directory.GetFiles(Settings.MBIIDirectory, "*.pk3");

            SiegeDeserializer seigeDeserializer = new SiegeDeserializer();

            UpdateProgressMax(pk3s.Count());

            foreach (string pk3 in pk3s)
            {
                Log($"Importing {Path.GetFileName(pk3)}");

                using (ZipArchive zipFile = ZipFile.OpenRead(pk3))
                {
                    foreach (ZipArchiveEntry entry in zipFile.Entries)
                    {
                        // Import Character File (.MBCH)
                        if (entry.FullName.Contains("ext_data/mb2/character/"))
                        {
                            if (entry.FullName.ToLower().Contains(".mbch"))
                            {
                                Log($"Importing {Path.GetFileName(entry.FullName)}");

                                using (var stream = entry.Open())
                                {
                                    StreamReader reader = new StreamReader(stream);
                                    string       text   = reader.ReadToEnd();

                                    try
                                    {
                                        ImportedData.importedCharacters.Add(seigeDeserializer.Deserialize <Character>(text));
                                    }
                                    catch (Exception e)
                                    {
                                        failedImports.Add($"{System.IO.Path.GetFileName(pk3)}/{entry.FullName}: {e.Message}");
                                    }
                                }
                            }
                        }

                        // Import Team File (.MBTC)
                        if (entry.FullName.Contains("ext_data/mb2/teamconfig/"))
                        {
                            if (entry.FullName.ToLower().Contains(".mbtc"))
                            {
                                Log($"Importing {Path.GetFileName(entry.FullName)}");

                                using (var stream = entry.Open())
                                {
                                    StreamReader reader = new StreamReader(stream);
                                    string       text   = reader.ReadToEnd();

                                    try
                                    {
                                        ImportedData.importedTeams.Add(seigeDeserializer.Deserialize <Team>(text));
                                    }
                                    catch (Exception e)
                                    {
                                        failedImports.Add($"{System.IO.Path.GetFileName(pk3)}/{entry.FullName}: {e.Message}");
                                    }
                                }
                            }
                        }

                        // Import Siege File (.SIEGE)
                        if (entry.FullName.Contains("maps/"))
                        {
                            if (entry.FullName.ToLower().Contains(".siege"))
                            {
                                Log($"Importing {Path.GetFileName(entry.FullName)}");

                                using (var stream = entry.Open())
                                {
                                    StreamReader reader = new StreamReader(stream);
                                    string       text   = reader.ReadToEnd();

                                    try
                                    {
                                        Siege siege = seigeDeserializer.Deserialize <Siege>(text);

                                        /* This allows us to keep track of what map this siege file belongs to */
                                        siege.map = entry.FullName.ToLower().Replace(".siege", "").Replace(@"maps/", "");

                                        ImportedData.importedSieges.Add(siege);
                                    }
                                    catch (Exception e)
                                    {
                                        failedImports.Add($"{System.IO.Path.GetFileName(pk3)}/{entry.FullName}: {e.Message}");
                                    }
                                }
                            }
                        }

                        // Import a map file (.BSP) */
                        if (entry.FullName.ToLower().Contains(".bsp"))
                        {
                            Log($"Importing {Path.GetFileName(entry.FullName)}");

                            ImportedData.importedMaps.Add(new Map()
                            {
                                parentPK3 = pk3,
                                fileName  = Path.GetFileName(entry.FullName),
                                name      = Path.GetFileNameWithoutExtension(entry.FullName),
                                entryPath = entry.FullName
                            });
                        }

                        // Import a map file (.skin) */
                        if (entry.FullName.ToLower().Contains(".skin"))
                        {
                            Log($"Importing {Path.GetFileName(entry.FullName)}");

                            ImportedData.importedSkins.Add(new Skin()
                            {
                                parentPK3 = pk3,
                                fileName  = Path.GetFileName(entry.FullName),
                                name      = Path.GetFileNameWithoutExtension(entry.FullName),
                                entryPath = entry.FullName,
                                modelName = Directory.GetParent(entry.FullName).Name
                            });
                        }

                        // Import a player model file (.gml) */
                        if (entry.FullName.ToLower().Contains(".glm") && entry.FullName.ToLower().Contains("players"))
                        {
                            Log($"Importing {Path.GetFileName(entry.FullName)}");

                            ImportedData.importedPlayerModels.Add(new PlayerModel()
                            {
                                parentPK3 = pk3,
                                fileName  = Path.GetFileName(entry.FullName),
                                name      = Directory.GetParent(entry.FullName).Name,
                                entryPath = entry.FullName,
                            });
                        }

                        // Import a weapon model file (.gml) */
                        if (entry.FullName.ToLower().Contains(".glm") && entry.FullName.ToLower().Contains("weapon"))
                        {
                            Log($"Importing {Path.GetFileName(entry.FullName)}");

                            ImportedData.importedWeaponModels.Add(new WeaponModel()
                            {
                                parentPK3 = pk3,
                                fileName  = Path.GetFileName(entry.FullName),
                                name      = Directory.GetParent(entry.FullName).Name,
                                entryPath = entry.FullName,
                            });
                        }
                    }
                }

                IncrementProgress();
            }

            Log($"Importing Complete...");

            /* Write latest failed imports to a log file */
            if (File.Exists(Settings.FailedImportLog))
            {
                File.Delete(Settings.FailedImportLog);
            }

            using (StreamWriter sw = File.CreateText(Settings.FailedImportLog))
            {
                sw.WriteLine("Failed Imports from Base Game Files");
                sw.WriteLine($"Last Run: {DateTime.Now.ToString("MM/dd/yyyy H:mm")}");
                sw.WriteLine("-----------------------------------------------------");

                foreach (string failedImport in failedImports)
                {
                    sw.WriteLine(failedImport);
                }
            }

            /* Any Additional Filtering or manipulation of imported data */
            ImportedData.importedCharacters = new ObservableCollection <Character>(ImportedData.importedCharacters
                                                                                   .Where(x => x.name != null && x.name.Trim() != "")
                                                                                   .OrderBy(x => x.name).ToList());

            Application.Current.Dispatcher.Invoke(() => {
                /* Close Splash */
                SplashLoading splashLoading = WindowFinder.FindOpenWindowByType <SplashLoading>();
                splashLoading.Close();

                MainWindow mainWindow = WindowFinder.FindOpenWindowByType <MainWindow>();

                /* Setup Imported Data Treeview Datasources */
                mainWindow.ImportedCharacters.ItemsSource = ImportedData.importedCharacters;

                /* Show Window */
                mainWindow.Show();
                mainWindow.Activate();
            });
        }