Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }