Ejemplo n.º 1
0
        public PowerArgsGamesIntro() : base(52, 7)
        {
            Background = ConsoleColor.Black;
            factory    = new SceneFactory(new List <ItemReviver>()
            {
                new LetterReviver()
            });
            AddedToVisualTree.SubscribeOnce(() =>
            {
                this.CenterBoth();

                Application.FocusManager.GlobalKeyHandlers.PushForLifetime(ConsoleKey.Enter, null, () =>
                {
                    Cleanup();
                }, this);
            });
        }
Ejemplo n.º 2
0
        private void ConfigueEditor()
        {
            if (innerEditor != null)
            {
                this.Controls.Remove(innerEditor);
            }

            innerEditor = Add(new ConsoleBitmapEditor(currentLevel != null ? currentLevel.Width : Level.DefaultWidth, currentLevel != null ? currentLevel.Height : Level.DefaultHeight)).CenterBoth();
            innerEditor.BitmapChanged.SubscribeForLifetime(() => hasUnsavedChanges = true, innerEditor);

            var commandBar = Add(new StackPanel()
            {
                Height = 1, Orientation = Orientation.Horizontal
            }).FillHorizontally().DockToTop();
            var tagBar = Add(new Label()).FillHorizontally().DockToTop(padding: 1);

            innerEditor.CursorMoved.SubscribeForLifetime(() => tagBar.Text = FormatTags(), this);

            innerEditor.CreateStandardButtons().ForEach(b => commandBar.Add(b));
            var newCommand = commandBar.Add(new Button()
            {
                Text = "New".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.N, ConsoleModifiers.Alt)
            });
            var openCommand = commandBar.Add(new Button()
            {
                Text = "Open".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.O, ConsoleModifiers.Alt)
            });

            saveCommand = commandBar.Add(new Button()
            {
                Text = "Save".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.S, ConsoleModifiers.Alt)
            });
            var saveAsCommand = commandBar.Add(new Button()
            {
                Text = "Save as".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.A, ConsoleModifiers.Alt)
            });
            var discardCommand = commandBar.Add(new Button()
            {
                Text = "Discard".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.D, ConsoleModifiers.Alt)
            });
            var tagCommand = commandBar.Add(new Button()
            {
                Text = "Tag".ToConsoleString(), Shortcut = new KeyboardShortcut(ConsoleKey.T, ConsoleModifiers.Alt)
            });

            newCommand.Pressed.SubscribeForLifetime(() =>
            {
                if (hasUnsavedChanges == false)
                {
                    LoadLevel(null);
                    currentLevelPath = null;
                }
                else
                {
                    UnsavedChanges(() =>
                    {
                        LoadLevel(null);
                        currentLevelPath = null;
                    });
                }
            }, this);


            saveCommand.Pressed.SubscribeForLifetime(() =>
            {
                if (currentLevelPath != null)
                {
                    var level = ExtractLevel();
                    var text  = Serialize(level);
                    File.WriteAllText(currentLevelPath, text);
                    hasUnsavedChanges = false;
                }
                else
                {
                    saveAsCommand.Pressed.Fire();
                }
            }, this);


            saveAsCommand.Pressed.SubscribeForLifetime(() =>
            {
                Dialog.ShowRichTextInput(new RichTextDialogOptions()
                {
                    Message = "Choose a name for this level".ToConsoleString(),
                    TextBox = new TextBox()
                    {
                        Value = currentLevelPath != null ? currentLevelPath.ToConsoleString() : Path.Combine(Environment.CurrentDirectory, "Level1" + LevelFileExtension).ToConsoleString()
                    }
                }).Then((val) =>
                {
                    currentLevelPath = val.ToString();
                    saveCommand.Pressed.Fire();
                });
            }, this);

            discardCommand.Pressed.SubscribeForLifetime(() =>
            {
                Dialog.ShowYesConfirmation("Are you sure you want to discard your unsaved changed?").Then(() =>
                {
                    if (currentLevelPath != null)
                    {
                        Load(currentLevelPath);
                    }
                    else
                    {
                        ConfigueEditor();
                    }
                });
            }, this);

            tagCommand.Pressed.SubscribeForLifetime(() =>
            {
                if (tags.TryGetValue(innerEditor.CursorPosition, out List <string> tagsForPosition) == false)
                {
                    tagsForPosition = new List <string>();
                    tags.Add(innerEditor.CursorPosition, tagsForPosition);
                }

                var tagsString = string.Join(";", tagsForPosition);

                Dialog.ShowRichTextInput(new RichTextDialogOptions()
                {
                    Message = "Add/edit semi-colon delimited tags. Press enter to cmmmit".ToYellow(),
                    TextBox = new TextBox()
                    {
                        Value = tagsString.ToConsoleString()
                    }
                }).Then((newString) =>
                {
                    var split = newString.ToString().Split(';').ToList();
                    tagsForPosition.Clear();
                    tagsForPosition.AddRange(split);
                });
            }, this);
            tags.Clear();
            if (currentLevelPath == null)
            {
                AddedToVisualTree.SubscribeOnce(() => Application.QueueAction(newCommand.Pressed.Fire));
            }
            else
            {
                AddedToVisualTree.SubscribeOnce(() => Application.QueueAction(() => Load(currentLevelPath)));
            }
        }