示例#1
0
 public void DrawAll()
 {
     GUI.Reset();
     Title.Draw();
     Menu.Draw();
     MenuCommandSeparator.Draw();
     CommandLogSeparator.Draw();
     LogTextBox.Draw();
     ControlsLabel.Draw();
 }
示例#2
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;
                }
            }
        }