Exemple #1
0
        private void textBox_NewName_TextChanged(object sender, EventArgs e)
        {
            string textBoxContent = PathHelper.RemoveIllegalPathSymbols(textBox_NewName.Text.Trim());

            textBoxContent = LevelHandling.RemoveIllegalNameSymbols(textBoxContent);

            // If the name hasn't changed, but the level folder name is different
            if (textBoxContent == _ide.SelectedLevel.Name && Path.GetFileName(_ide.SelectedLevel.FolderPath) != textBoxContent)
            {
                // If the level is not an external level
                if (_ide.SelectedLevel.FolderPath.StartsWith(_ide.Project.LevelsPath, StringComparison.OrdinalIgnoreCase))
                {
                    checkBox_RenameDirectory.Enabled = true;
                    checkBox_RenameDirectory.Checked = true;
                }

                checkBox_RenameScriptEntry.Checked = false;
                checkBox_RenameScriptEntry.Enabled = false;
            }
            // If the name changed, but the level folder name is the same
            else if (textBoxContent != _ide.SelectedLevel.Name && Path.GetFileName(_ide.SelectedLevel.FolderPath) == textBoxContent)
            {
                checkBox_RenameDirectory.Checked = false;
                checkBox_RenameDirectory.Enabled = false;

                // If there are no errors in the script (in this case, if no errors are displayed)
                if (!label_ScriptError.Visible && !label_LanguageError.Visible)
                {
                    checkBox_RenameScriptEntry.Enabled = true;
                    checkBox_RenameScriptEntry.Checked = true;
                }
            }
            // If the name hasn't changed and the level folder name is the same
            else if (textBoxContent == _ide.SelectedLevel.Name)
            {
                checkBox_RenameDirectory.Checked = false;
                checkBox_RenameDirectory.Enabled = false;

                checkBox_RenameScriptEntry.Checked = false;
                checkBox_RenameScriptEntry.Enabled = false;
            }
            else             // Basically every other scenario
            {
                // If the level is not an external level
                if (_ide.SelectedLevel.FolderPath.StartsWith(_ide.Project.LevelsPath, StringComparison.OrdinalIgnoreCase))
                {
                    checkBox_RenameDirectory.Enabled = true;
                    checkBox_RenameDirectory.Checked = true;
                }

                // If there are no errors in the script (in this case, if no errors are displayed)
                if (!label_ScriptError.Visible && !label_LanguageError.Visible)
                {
                    checkBox_RenameScriptEntry.Enabled = true;
                    checkBox_RenameScriptEntry.Checked = true;
                }
            }

            button_Apply.Enabled = !string.IsNullOrWhiteSpace(textBoxContent);
        }
Exemple #2
0
        private void CreateAndAddLevelToProject(string levelName, string levelFolderPath, string dataFileName, string specificFileName)
        {
            // Create the ProjectLevel instance
            ProjectLevel importedLevel = new ProjectLevel
            {
                Name         = levelName,
                FolderPath   = levelFolderPath,
                DataFileName = dataFileName,
                SpecificFile = specificFileName
            };

            UpdateLevelSettings(importedLevel);

            if (checkBox_GenerateSection.Checked)
            {
                int  ambientSoundID = (int)numeric_SoundID.Value;
                bool horizon        = checkBox_EnableHorizon.Checked;

                // // // //
                GeneratedScriptLines = LevelHandling.GenerateScriptLines(importedLevel, ambientSoundID, horizon);
                // // // //
            }

            // // // //
            ImportedLevel = importedLevel;
            // // // //
        }
Exemple #3
0
 private void UpdateAllPrj2GameSettings(DirectoryInfo directory, ProjectLevel detectedLevel)
 {
     foreach (FileInfo file in directory.GetFiles("*.prj2", SearchOption.TopDirectoryOnly))
     {
         if (!ProjectLevel.IsBackupFile(file.Name))
         {
             LevelHandling.UpdatePrj2GameSettings(file.FullName, detectedLevel, _ide.Project);
         }
     }
 }
Exemple #4
0
        private void button_Import_Click(object sender, EventArgs e)
        {
            button_Import.Enabled = false;

            try
            {
                string levelName = PathHelper.RemoveIllegalPathSymbols(textBox_LevelName.Text.Trim());
                levelName = LevelHandling.RemoveIllegalNameSymbols(levelName);

                if (string.IsNullOrWhiteSpace(levelName))
                {
                    throw new ArgumentException("You must enter a valid name for the level.");
                }

                if (radioButton_SelectedCopy.Checked && treeView.SelectedNodes.Count == 0)
                {
                    throw new ArgumentException("You must select which .prj2 files you want to import.");
                }

                // Check for name duplicates
                foreach (ProjectLevel projectLevel in _targetProject.Levels)
                {
                    if (projectLevel.Name.ToLower() == levelName.ToLower())
                    {
                        throw new ArgumentException("A level with the same name already exists on the list.");
                    }
                }

                string dataFileName = textBox_CustomFileName.Text.Trim();

                if (string.IsNullOrWhiteSpace(dataFileName))
                {
                    throw new ArgumentException("You must specify the custom DATA file name.");
                }

                if (radioButton_SpecifiedCopy.Checked || radioButton_SelectedCopy.Checked)
                {
                    ImportAndCopyFiles(levelName, dataFileName);
                }
                else if (radioButton_FolderKeep.Checked)
                {
                    ImportButKeepFiles(levelName, dataFileName);
                }
            }
            catch (Exception ex)
            {
                DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                button_Import.Enabled = true;

                DialogResult = DialogResult.None;
            }
        }
        public ImageHandling(LevelHandling level)
        {
            _level = level;
            _fonts = new FontCollection();
            _arial = _fonts.Install(@"Data/Font/ARIAL.TTF");

            _profileText   = new Font(_arial, 12, FontStyle.Regular);
            _profileHeader = new Font(_arial, 45, FontStyle.Regular);

            _profileWumpus     = Image.Load("Data/ProfileAssets/WumpusWonderlandProfile.png");
            _profileTemplate   = Image.Load("Data/ProfileAssets/Frames.png");
            _profileBackground = Image.Load("Data/ProfileAssets/Background.jpg");
            _profilePreText    = Image.Load("Data/ProfileAssets/Text.png");
        }
Exemple #6
0
        private void UpdateAllPrj2FilesInLevelDirectory(ProjectLevel importedLevel)
        {
            string[] files = Directory.GetFiles(importedLevel.FolderPath, "*.prj2", SearchOption.TopDirectoryOnly);

            progressBar.Visible = true;
            progressBar.BringToFront();
            progressBar.Maximum = files.Length;

            foreach (string file in files)
            {
                if (!ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                {
                    LevelHandling.UpdatePrj2GameSettings(file, importedLevel, _targetProject);
                }

                progressBar.Increment(1);
            }
        }
Exemple #7
0
        private void UpdateLevelSettings(ProjectLevel importedLevel)
        {
            if (radioButton_SpecifiedCopy.Checked)
            {
                string specifiedFileName = Path.GetFileName(textBox_Prj2Path.Tag.ToString());
                string internalFilePath  = Path.Combine(importedLevel.FolderPath, specifiedFileName);

                LevelHandling.UpdatePrj2GameSettings(internalFilePath, importedLevel, _targetProject);
            }
            else if (radioButton_SelectedCopy.Checked)
            {
                UpdateAllPrj2FilesInLevelDirectory(importedLevel);
            }
            else if (radioButton_FolderKeep.Checked)
            {
                DialogResult result = DarkMessageBox.Show(this, "Do you want to update the \"Game\" settings of all the .prj2 files in the\n" +
                                                          "specified folder to match the project settings?", "Update settings?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    UpdateAllPrj2FilesInLevelDirectory(importedLevel);
                }
            }
        }
Exemple #8
0
 public MissionModule(LevelHandling level) => _level = level;
 public CombatHandling(Random random, LevelHandling level)
 {
     _random = random;
     _level  = level;
 }
Exemple #10
0
        private void button_Import_Click(object sender, EventArgs e)
        {
            button_Import.Enabled = false;

            try
            {
                if (!File.Exists(textBox_ExePath.Text))
                {
                    throw new FileNotFoundException("The game's .exe file doesn't exist anymore.");
                }

                if (!File.Exists(textBox_LauncherPath.Text))
                {
                    throw new FileNotFoundException("The project's launcher file doesn't exist anymore.");
                }

                string projectName = PathHelper.RemoveIllegalPathSymbols(textBox_ProjectName.Text.Trim());

                if (string.IsNullOrWhiteSpace(projectName))
                {
                    throw new ArgumentException("You must enter a valid name for the project.");
                }

                if (projectName.ToLower() == "engine")                 // Safety
                {
                    throw new ArgumentException("Illegal project name.");
                }

                if (string.IsNullOrWhiteSpace(textBox_ScriptPath.Text))
                {
                    throw new ArgumentException("You must specify the /Script/ folder path of the project.");
                }

                if (string.IsNullOrWhiteSpace(textBox_LevelsPath.Text))
                {
                    throw new ArgumentException("You must specify the /Levels/ folder path for the project.");
                }

                if (ProjectChecker.IsProjectNameDuplicate(projectName))
                {
                    throw new ArgumentException("A project with the same name already exists on the list.");
                }

                TRVersion.Game gameVersion = GetGameVersion(textBox_ExePath.Text);

                string launcherFilePath = textBox_LauncherPath.Text;

                string projectPath = GetProjectDirectory(textBox_ExePath.Text);
                string enginePath  = Path.GetDirectoryName(textBox_ExePath.Text);
                string scriptPath  = textBox_ScriptPath.Text.Trim();
                string levelsPath  = textBox_LevelsPath.Text.Trim();

                // Check if a script.txt file exists in the specified /Script/ folder
                if (!File.Exists(Path.Combine(scriptPath, "script.txt")))
                {
                    throw new FileNotFoundException("Selected /Script/ folder does not contain a Script.txt file.");
                }

                // Check if the levelsPath directory exists, if so, check if it contains any valid .prj2 files
                if (Directory.Exists(levelsPath))
                {
                    // Check if the directory contains non-backup .prj2 files
                    List <string> prj2Files = LevelHandling.GetValidPrj2FilesFromDirectory(levelsPath);

                    if (prj2Files.Count > 0)
                    {
                        DialogResult result = DarkMessageBox.Show(this,
                                                                  "TombIDE will change the \"Game\" settings of all the .prj2 files\n" +
                                                                  "in the specified /Levels/ folder to match the imported project settings.\n" +
                                                                  "Would you like to to create a backup of the folder first?", "Create backup?",
                                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                        if (result == DialogResult.Yes)
                        {
                            CreateLevelsBackup(levelsPath);
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(levelsPath);
                }

                Project importedProject = new Project
                {
                    Name            = projectName,
                    GameVersion     = gameVersion,
                    DefaultLanguage = GameLanguage.English,
                    LaunchFilePath  = launcherFilePath,
                    ProjectPath     = projectPath,
                    EnginePath      = enginePath,
                    ScriptPath      = scriptPath,
                    LevelsPath      = levelsPath
                };

                // Create the .trproj file
                importedProject.Save();                 // .trproj = .xml but .trproj can be opened with TombIDE

                // // // // // // // //
                ImportedProject = importedProject;
                // // // // // // // //
            }
            catch (Exception ex)
            {
                DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                button_Import.Enabled = true;

                DialogResult = DialogResult.None;
            }
        }
        private void button_Create_Click(object sender, EventArgs e)
        {
            button_Create.Enabled = false;

            try
            {
                string levelName = PathHelper.RemoveIllegalPathSymbols(textBox_LevelName.Text.Trim());
                levelName = LevelHandling.RemoveIllegalNameSymbols(levelName);

                if (string.IsNullOrWhiteSpace(levelName))
                {
                    throw new ArgumentException("You must enter a valid name for your level.");
                }

                // Check for name duplicates
                foreach (ProjectLevel projectLevel in _targetProject.Levels)
                {
                    if (projectLevel.Name.ToLower() == levelName.ToLower())
                    {
                        throw new ArgumentException("A level with the same name already exists on the list.");
                    }
                }

                string dataFileName = textBox_CustomFileName.Text.Trim();

                if (string.IsNullOrWhiteSpace(dataFileName))
                {
                    throw new ArgumentException("You must specify the custom PRJ2 / DATA file name.");
                }

                string levelFolderPath = Path.Combine(_targetProject.LevelsPath, levelName);

                // Create the level folder
                if (!Directory.Exists(levelFolderPath))
                {
                    Directory.CreateDirectory(levelFolderPath);
                }

                if (Directory.EnumerateFileSystemEntries(levelFolderPath).ToArray().Length > 0)                 // 99% this will never accidentally happen
                {
                    throw new ArgumentException("A folder with the same name as the \"Level name\" already exists in\n" +
                                                "the project's /Levels/ folder and it's not empty.");
                }

                ProjectLevel createdLevel = new ProjectLevel
                {
                    Name         = levelName,
                    DataFileName = dataFileName,
                    FolderPath   = levelFolderPath
                };

                // Create a simple .prj2 file with pre-set project settings (game paths etc.)
                Level level = Level.CreateSimpleLevel();

                string prj2FilePath = Path.Combine(createdLevel.FolderPath, createdLevel.DataFileName) + ".prj2";
                string exeFilePath  = Path.Combine(_targetProject.EnginePath, _targetProject.GetExeFileName());

                string dataFilePath = Path.Combine(_targetProject.EnginePath, "data", createdLevel.DataFileName + _targetProject.GetLevelFileExtension());

                level.Settings.LevelFilePath = prj2FilePath;

                level.Settings.GameDirectory          = level.Settings.MakeRelative(_targetProject.EnginePath, VariableType.LevelDirectory);
                level.Settings.GameExecutableFilePath = level.Settings.MakeRelative(exeFilePath, VariableType.LevelDirectory);
                level.Settings.GameLevelFilePath      = level.Settings.MakeRelative(dataFilePath, VariableType.LevelDirectory);
                level.Settings.GameVersion            = _targetProject.GameVersion;

                Prj2Writer.SaveToPrj2(prj2FilePath, level);

                if (checkBox_GenerateSection.Checked)
                {
                    int  ambientSoundID = (int)numeric_SoundID.Value;
                    bool horizon        = checkBox_EnableHorizon.Checked;

                    // // // //
                    GeneratedScriptLines = LevelHandling.GenerateScriptLines(createdLevel, ambientSoundID, horizon);
                    // // // //
                }

                // // // //
                CreatedLevel = createdLevel;
                // // // //
            }
            catch (Exception ex)
            {
                DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                button_Create.Enabled = true;

                DialogResult = DialogResult.None;
            }
        }
Exemple #12
0
        private void button_Apply_Click(object sender, EventArgs e)
        {
            try
            {
                string newName = PathHelper.RemoveIllegalPathSymbols(textBox_NewName.Text.Trim());
                newName = LevelHandling.RemoveIllegalNameSymbols(newName);

                bool renameDirectory   = checkBox_RenameDirectory.Checked;
                bool renameScriptEntry = checkBox_RenameScriptEntry.Checked;

                if (newName == _ide.SelectedLevel.Name)
                {
                    // If the name hasn't changed, but the directory name is different and the user wants to rename it
                    if (Path.GetFileName(_ide.SelectedLevel.FolderPath) != newName && renameDirectory)
                    {
                        HandleDirectoryRenaming();

                        _ide.SelectedLevel.Rename(newName, true);
                        _ide.RaiseEvent(new IDE.SelectedLevelSettingsChangedEvent());
                    }
                    else
                    {
                        DialogResult = DialogResult.Cancel;
                    }
                }
                else
                {
                    // Check if a level with the same name already exists on the list
                    foreach (ProjectLevel projectLevel in _ide.Project.Levels)
                    {
                        if (projectLevel.Name.ToLower() == newName.ToLower())
                        {
                            // Check if the level we found IS the current _ide.SelectedLevel
                            if (projectLevel.FolderPath.ToLower() == _ide.SelectedLevel.FolderPath.ToLower())
                            {
                                if (renameDirectory)
                                {
                                    HandleDirectoryRenaming();
                                }

                                break;
                            }
                            else
                            {
                                throw new ArgumentException("A level with the same name already exists on the list.");
                            }
                        }
                    }

                    if (renameScriptEntry)
                    {
                        _ide.ScriptEditor_RenameLevel(_ide.SelectedLevel.Name, newName);
                    }

                    _ide.SelectedLevel.Rename(newName, renameDirectory);
                    _ide.RaiseEvent(new IDE.SelectedLevelSettingsChangedEvent());
                }
            }
            catch (Exception ex)
            {
                DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DialogResult = DialogResult.None;
            }
        }