private void PromptExportMap(Map map) { LogTextBox.ClearContent(); string destinationFolderPath = Path.Combine(Program.customMapsPath, map.Name); try { if (Directory.Exists(destinationFolderPath)) { LogTextBox.WriteLine(string.Format(Text.ConfirmExportAndOverwrite, destinationFolderPath)); int response = SelectionPrompt.PromptSelection(exportCommands, new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 2 }); switch (response) { case 0: // Overwrite ExportMap(map, destinationFolderPath, true); break; case 1: // Export with Timestamp string timestamp = DateTime.Now.ToString("_yyyy-MM-dd_HH-mm-ss.fffffff"); //string timestamp = DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK"); ExportMap(map, destinationFolderPath + timestamp, false); break; } } else { ExportMap(map, destinationFolderPath, false); } } catch (Exception e) { ignoreNextSelectionChangedEvent = true; LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); } }
public void ShowBackups() { if (backedUpSaves.Count == 0) { LogTextBox.WriteLine(Text.NoBackedUpSaves); return; } BackedUpSavesList.Clear(); BackedUpSavesList.Draw(); BackedUpSavesList.Select(0); bool promptQuit = false; while (!promptQuit) { var selection = BackedUpSavesList.PromptSelection(); if (selection.Command == Properties.Command.Confirm) { BackedUpSavesList.HighlightCurrentItem(); var response = SelectionPrompt.PromptSelection(new string[] { Text.LoadBackup }, true); if (response == 0) // Load Backup { SwapSaves(selection.Text); RefreshInfo(); LogTextBox.WriteLine(string.Format(Text.LoadedBackup, selection.Text)); promptQuit = true; } else { BackedUpSavesList.SelectCurrentItem(); } } else if (selection.Command == Properties.Command.Cancel) { promptQuit = true; } } WriteSummary(); }
public override void Selected(GUI.Selection selection) { if (selection.List.IsEmpty) { return; } LogTextBox.ClearContent(); LaunchableMapsList.HighlightCurrentItem(); Map map = null; string mapName; if (selection.RowIndex == 0) { mapName = Text.MainGame; } else { map = ((GUI.SelectableMap)selection.SelectedItem).Map; mapName = map.Name; } var options = new GUI.SelectionPrompt.Options() { AllowCancel = true }; if (selection.RowIndex == 0) // main map { options.DisabledItems.Add(2); // Disable "Set Startup Level" } else { if (string.IsNullOrEmpty(map.StartupLevel)) { options.DisabledItems.Add(1); // Disable "New Game" } if (!Program.saveManagerWindow.MapHasSave(map)) { options.DisabledItems.Add(0); // Disable "Continue" } } int response = SelectionPrompt.PromptSelection( new string[] { Text.Continue, Text.NewGame, Text.SetStartupLevel }, options); switch (response) { case 0: // Continue try { if (Program.manageSaves && Program.saveManagerWindow.GetCurrentSavedMapName() != mapName) { LogTextBox.WriteLine(Text.PreparingSaveFile); Program.saveManagerWindow.SwapSaves(mapName); } LaunchGame(null); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); } break; case 1: // New Game try { if (Program.manageSaves) { LogTextBox.WriteLine(Text.BackingUpCurrentSave); Program.saveManagerWindow.BackupCurrentSave(); Program.saveManagerWindow.SetCurrentSave(mapName); } LaunchGame((selection.RowIndex == 0) ? null : map); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); } break; case 2: // Set Startup Level SetStartupLevel(map); DetailsTextBox.WriteLongMapInfo(map); break; } LaunchableMapsList.SelectCurrentItem(); }
private bool VerifyNothingOverwritten(LoadableMap map) { // Check which files already exist var existingLevels = new List <string>(); foreach (var level in map.Levels) { string correspondingLevel = Path.Combine(Program.installedLevelsPath, level); if (File.Exists(correspondingLevel)) { existingLevels.Add(level); } } var existingScripts = new List <string>(); foreach (var script in map.Scripts) { string correspondingScript = Path.Combine(Program.installedScriptsPath, script); if (File.Exists(correspondingScript)) { existingScripts.Add(script); } } if (existingLevels.Count > 0 || existingScripts.Count > 0) { LogTextBox.ClearContent(); LogTextBox.WriteLine("Map is not marked as installed, but one or more files already exist. Overwrite?"); LogTextBox.WriteLine(string.Format("Levels: {0}", string.Join(',', existingLevels.ToArray()))); LogTextBox.WriteLine(string.Format("Scripts: {0}", string.Join(',', existingLevels.ToArray()))); string[] selections; GUI.SelectionPrompt.Options options; if (map.IsValid) { selections = new string[] { Text.Overwrite, Text.BackupAndInstall }; options = new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 2, }; } else { selections = new string[] { Text.Overwrite, Text.BackupAndInstall, Text.ShowIssues }; options = new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 3, }; } int response = SelectionPrompt.PromptSelection(selections, options); LogTextBox.ClearContent(); switch (response) { case 0: InstallMap(map, true); break; case 1: // TODO: Verify in case backups would be overwritten. LogTextBox.WriteLine(Text.BackingUpFiles); Program.backupsWindow.BackUpInstalledMapFiles(map); LogTextBox.AppendLastLine(" " + Text.BackupFinished); InstallMap(map, true); break; default: LogTextBox.WriteShortMapInfo(map); break; } return(false); } else { return(true); } }
public override void Selected(GUI.Selection selection) { selection.SelectedItem.Highlight(); if (selection.ColumnIndex == 0) // Installed Maps -> Uninstall { var selectedMap = Program.installedMaps[selection.RowIndex]; LogTextBox.ClearContent(); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedMap.IsValid) { selections = new string[] { Text.Uninstall }; } else { selections = new string[] { Text.Uninstall, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: if (selectedMap.IsWIP) { LogTextBox.WriteLine(Text.CantUninstallWIP); ignoreNextSelectionChangedEvent = true; } else { var currentRow = Menu.CurrentRow; UninstallMap(selectedMap); bool keepIgnoringSelectionChanged = ignoreNextSelectionChangedEvent; if (InstalledMapsList.CanNavigate) { InstalledMapsList.Select(currentRow); } else { Menu.NavigateToDefault(); } ignoreNextSelectionChangedEvent = keepIgnoringSelectionChanged; } break; case 1: selectedMap.ShowIssues(); DrawAll(); break; } } else if (selection.ColumnIndex == 1) // Available Maps -> Install/Reinstall/Overwrite { var selectedLoadableMap = Program.availableMaps[selection.RowIndex]; var alreadyInstalledMap = FindInstalledMap(selectedLoadableMap.Name); if (alreadyInstalledMap != null) // If the map is already installed { LogTextBox.ClearContent(); LogTextBox.WriteLine(string.Format(Text.PromptReinstall, alreadyInstalledMap.Name)); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedLoadableMap.IsValid) { selections = new string[] { Text.Reinstall }; } else { selections = new string[] { Text.Reinstall, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: ReinstallMap(alreadyInstalledMap, selectedLoadableMap); break; case 1: selectedLoadableMap.ShowIssues(); DrawAll(); break; default: LogTextBox.WriteShortMapInfo(selectedLoadableMap); break; } } else if (VerifyNothingOverwritten(selectedLoadableMap)) { LogTextBox.ClearContent(); string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (selectedLoadableMap.IsValid) { selections = new string[] { Text.Install }; } else { selections = new string[] { Text.Install, Text.ShowIssues }; options.Index = 1; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: InstallMap(selectedLoadableMap, false); break; case 1: selectedLoadableMap.ShowIssues(); DrawAll(); break; default: LogTextBox.WriteShortMapInfo(selectedLoadableMap); break; } } } selection.List.Select(selection.RowIndex); }
private void EditLevels(Map map) { RefreshLevelList(map); levelList.NavigateToDefault(); bool quitPrompt = false; while (!quitPrompt) { GUI.Selection selection = levelList.PromptSelection(); switch (selection.Command) { case Properties.Command.Confirm: switch (selection.RowIndex) { case 0: // Add New Level if (levelNameInput.PromptText()) { LogTextBox.ClearContent(); string levelName = levelNameInput.Text; // Check if level already exists string levelDestination = Path.Combine(Program.installedLevelsPath, levelName + Program.LevelFileExtension); string scriptDestination = Path.Combine(Program.installedScriptsPath, levelName + Program.ScriptFileExtension); if (File.Exists(levelDestination) || File.Exists((scriptDestination))) { LogTextBox.WriteLine(string.Format(Text.LevelOrScriptAlreadyExists, levelName + Program.LevelFileExtension, levelName + Program.ScriptFileExtension)); } else { File.Copy(Program.emptyLevelTemplatePath, levelDestination); File.Copy(Program.emptyScriptTemplatePath, scriptDestination); map.AddLevel(levelName); Program.SaveInstalledMaps(); RefreshLevelList(map); LogTextBox.WriteLine(string.Format(Text.AddedLevel, levelName)); } } break; case 1: // Assign Existing Levels LogTextBox.Clear(); AssignExistingLevels(map); assignedLevelsList.Clear(); LogTextBox.Draw(); break; case 2: // Separator break; default: // Level LogTextBox.ClearContent(); string selectedLevelName = selection.Text; string currentLevelName = selectedLevelName + Program.LevelFileExtension; string currentScriptName = selectedLevelName + Program.ScriptFileExtension; string levelSource = Path.Combine(Program.installedLevelsPath, currentLevelName); string scriptSource = Path.Combine(Program.installedScriptsPath, currentScriptName); switch (SelectionPrompt.PromptSelection(levelCommands, true)) { case 0: // Rename levelRenameInput.Top = levelList.Top + selection.RowIndex; bool renamed = levelRenameInput.PromptText(new GUI.TextInput.PromptOptions(false, true, false, selectedLevelName)); if (renamed) { string newLevelName = levelRenameInput.Text; string levelDestination = Path.Combine(Program.installedLevelsPath, newLevelName + Program.LevelFileExtension); string scriptDestination = Path.Combine(Program.installedScriptsPath, newLevelName + Program.ScriptFileExtension); if (File.Exists(levelDestination) || File.Exists((scriptDestination))) { LogTextBox.WriteLine(string.Format(Text.LevelOrScriptAlreadyExists, newLevelName + Program.LevelFileExtension, newLevelName + Program.ScriptFileExtension)); } else { try { map.RenameLevel(selectedLevelName, newLevelName); File.Move(levelSource, levelDestination); File.Move(scriptSource, scriptDestination); Program.SaveInstalledMaps(); RefreshLevelList(map); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); if (File.Exists(levelDestination)) { LogTextBox.WriteLine(string.Format(Text.RevertLevelRename, currentLevelName)); File.Move(levelDestination, levelSource); LogTextBox.AppendLastLine(Text.Renamed); } if (File.Exists(scriptDestination)) { LogTextBox.WriteLine(string.Format(Text.RevertScriptRename, currentScriptName)); File.Move(scriptDestination, scriptSource); LogTextBox.AppendLastLine(Text.Renamed); } } } } break; case 1: // Delete LogTextBox.WriteLine(string.Format(Text.ConfirmDelete, currentLevelName, currentScriptName)); LogTextBox.WriteLine(Text.AreYouSureYouWantToContinue); LogTextBox.WriteLine(Text.UnassignInsteadOfDelteInstructions); int confirmation = SelectionPrompt.PromptSelection(confirmDeleteCommands, new GUI.SelectionPrompt.Options() { AllowCancel = true, Index = 1 }); if (confirmation == 0) // Confirmed deletion { try { LogTextBox.ClearContent(); map.RemoveLevel(selectedLevelName); Program.SaveInstalledMaps(); LogTextBox.WriteLine(string.Format(Text.Deleting, currentLevelName)); File.Delete(levelSource); LogTextBox.AppendLastLine(Text.Deleted); LogTextBox.WriteLine(string.Format(Text.Deleting, currentScriptName)); File.Delete(scriptSource); LogTextBox.AppendLastLine(Text.Deleted); } catch (Exception e) { LogTextBox.WriteLine(string.Format(Text.ErrorWithMessage, e.Message)); } RefreshLevelList(map); } break; } break; } levelList.SelectCurrentItem(); break; case Properties.Command.Cancel: quitPrompt = true; break; } } }
public override void Selected(GUI.Selection selection) { switch (selection.RowIndex) { case 0: ShowOnlyWIPCheckBox.Checked = !ShowOnlyWIPCheckBox.Checked; RefreshMapList(); mapList.NavigateToDefault(); break; case 1: if (NewMapNameInput.PromptText()) { var newMap = new Map( NewMapNameInput.Text, null, null, null, null, new string[0], new string[0], true); Program.installedMaps.Add(newMap); Program.SaveInstalledMaps(); RefreshMapList(); } mapList.Select(mapList.Items.Count - 1); break; case 2: // Separator break; default: mapList.HighlightCurrentItem(); var selectedMap = (GUI.SelectableMap)(selection.SelectedItem); var map = selectedMap.Map; string[] selections; var options = new GUI.SelectionPrompt.Options() { AllowCancel = true, }; if (map.IsValid) { selections = mapCommands; } else { selections = mapCommandsWithIssues; options.Index = 3; } int response = SelectionPrompt.PromptSelection(selections, options); switch (response) { case 0: // Edit Map Info EditMapInfo(map); break; case 1: // Edit Levels EditLevels(map); mapList.Clear(); mapList.Draw(); break; case 2: // Export PromptExportMap(map); break; case 3: // Show Issues map.ShowIssues(); DrawAll(); break; } mapList.SelectCurrentItem(); break; } }