Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        public override void Selected(GUI.Selection selection)
        {
            if (selection.List.IsEmpty)
            {
                return;
            }
            LogTextBox.ClearContent();

            switch (selection.RowIndex)
            {
            case 0:                     // Backup current map
                LogTextBox.WriteLine(Text.BackingUpCurrentSave);
                BackupCurrentSave();
                RefreshInfo();
                WriteSummary();
                LogTextBox.WriteLine(string.Format(Text.BackedUpMap, currentSavedMapName));
                break;

            case 1:                     // View backups...
                CommandsList.HighlightCurrentItem();
                ShowBackups();
                CommandsList.SelectCurrentItem();
                break;

            case 2:
                if (Program.manageSaves)
                {
                    Program.manageSaves = false;
                    LogTextBox.WriteLine(Text.DisabledManageSaves);
                }
                else
                {
                    Program.manageSaves = true;
                    LogTextBox.WriteLine(Text.EnabledManageSaves);
                }
                Program.SaveSettings();
                WriteSummary();
                break;
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #6
0
        private void EditMapInfo(Map map)
        {
            mapInfoNameInput.Text             = map.Name;
            mapInfoVersionInput.Text          = map.Version ?? string.Empty;
            mapInfoAuthorInput.Text           = map.Author ?? string.Empty;
            mapInfoStartupLevelInput.Text     = map.StartupLevel ?? string.Empty;
            mapInfoShortDescriptionInput.Text = map.ShortDescription ?? string.Empty;
            mapInfoLongDescriptionInput.Text  = map.LongDescription ?? string.Empty;

            mapInfoList.SetItems(new string[] {
                Text.MapInfoMapName + map.Name,
                Text.MapInfoVersion + (string.IsNullOrEmpty(map.Version) ? Text.MapInfoNoVersion : map.Version),
                Text.MapInfoAuthor + (string.IsNullOrEmpty(map.Author) ? Text.MapInfoNoAuthor : map.Author),
                Text.MapInfoStartupLevel + (string.IsNullOrEmpty(map.StartupLevel) ? Text.MapInfoNoStartupLevel : map.StartupLevel),
                Text.MapInfoIsWIP + map.IsWIP.ToString(),
                Text.MapInfoShortDescription + (string.IsNullOrEmpty(map.ShortDescription) ? Text.MapInfoNoDescription : map.ShortDescription),
                Text.MapInfoLongDescription,
            });
            mapInfoList.Draw();
            mapInfoList.NavigateToDefault();

            bool promptQuit = false;

            while (!promptQuit)
            {
                var  result      = mapInfoList.PromptSelection();
                bool infoChanged = true;
                switch (result.Command)
                {
                case Properties.Command.Confirm:
                    switch (result.RowIndex)
                    {
                    case 0:                                     // Map Name
                        if (mapInfoNameInput.PromptText())
                        {
                            map.Name = mapInfoNameInput.Text;
                            mapInfoList.Items[0].Value = Text.MapInfoMapName + map.Name;
                            RefreshMapList();
                        }
                        break;

                    case 1:                                     // Version
                        if (mapInfoVersionInput.PromptText())
                        {
                            map.Version = mapInfoVersionInput.Text;
                            mapInfoList.Items[1].Value = Text.MapInfoVersion + (string.IsNullOrEmpty(map.Version) ? Text.MapInfoNoVersion : map.Version);
                        }
                        break;

                    case 2:                                     // Author
                        if (mapInfoAuthorInput.PromptText())
                        {
                            map.Author = mapInfoAuthorInput.Text;
                            mapInfoList.Items[2].Value = Text.MapInfoAuthor + (string.IsNullOrEmpty(map.Author) ? Text.MapInfoNoAuthor : map.Author);
                        }
                        break;

                    case 3:                                     // Startup Level
                        if (mapInfoStartupLevelInput.PromptText())
                        {
                            map.StartupLevel           = mapInfoStartupLevelInput.Text;
                            mapInfoList.Items[3].Value = Text.MapInfoStartupLevel + (string.IsNullOrEmpty(map.StartupLevel) ? Text.MapInfoNoStartupLevel : map.StartupLevel);
                            map.VerifyMap();
                        }
                        break;

                    case 4:                                     // Is WIP
                        map.IsWIP = !map.IsWIP;
                        mapInfoList.Items[4].Value = Text.MapInfoIsWIP + map.IsWIP.ToString();
                        break;

                    case 5:                                     // Short Description
                        if (mapInfoShortDescriptionInput.PromptText())
                        {
                            map.ShortDescription       = mapInfoShortDescriptionInput.Text;
                            mapInfoList.Items[5].Value = Text.MapInfoShortDescription + (string.IsNullOrEmpty(map.ShortDescription) ? Text.MapInfoNoDescription : map.ShortDescription);
                        }
                        break;

                    case 6:                                     // Long Description
                        LogTextBox.ClearContent();
                        LogTextBox.WriteLine("Press Shift + Enter to go to the next line.");
                        LogTextBox.WriteLine("Note: The multiline text editor is still in its early stages.");
                        LogTextBox.WriteLine("If you experience any issues, please adjust the description with a text editor after exporting your map.");
                        if (mapInfoLongDescriptionInput.PromptTextMultiline())
                        {
                            map.LongDescription = mapInfoLongDescriptionInput.Text;
                        }
                        LogTextBox.Clear();
                        break;

                    default:
                        infoChanged = false;
                        break;
                    }

                    if (infoChanged)
                    {
                        Program.SaveInstalledMaps();
                    }
                    break;

                case Properties.Command.Cancel:
                    promptQuit = true;
                    break;
                }
                mapInfoList.SelectCurrentItem();
            }
            mapInfoList.Clear();
        }
Beispiel #7
0
        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;
                }
            }
        }