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); }
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; } }
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; } }
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; } }