Exemplo n.º 1
0
        private void LoadMacros()
        {
            MacroList.Items.Clear();

            foreach (var macro in MacroManager.GetAllMacros().OrderBy(m => m.Text))
            {
                LoadMacro(macro);
            }

            EnableButtons();
        }
        private void LoadMacros()
        {
            MacroList.Items.Clear();

            foreach (var macro in MacroManager.GetAllMacros().OrderBy(m => m.Text))
            {
                var listBoxItem = new ListBoxItem
                {
                    Tag        = macro,
                    Content    = macro.Text,
                    IsSelected = macro.Text == last
                };

                MacroList.Items.Add(listBoxItem);
            }

            if (MacroList.SelectedIndex < 0 && MacroList.Items.Count > 0)
            {
                MacroList.SelectedIndex = 0;
            }

            EnableButtons();
        }
Exemplo n.º 3
0
        private void LoadPostSaveMacros([NotNull] object sender, [NotNull] EventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var macroName = GetPostSaveMacroName();

            PostSaveMacros.Items.Clear();

            PostSaveMacros.Items.Add(string.Empty);

            foreach (var macro in MacroManager.GetAllMacros().OrderBy(m => m.Text))
            {
                var comboBoxItem = new ComboBoxItem
                {
                    Tag = macro,
                    Content = macro.Text,
                    IsSelected = macro.Text == macroName
                };

                PostSaveMacros.Items.Add(comboBoxItem);
            }
        }
Exemplo n.º 4
0
        private void BuildCommands()
        {
            const int PAGE = 4;

            ScrollArea rightArea = new ScrollArea(190, 52 + 25 + 4, 150, 360, true);
            NiceButton addButton = new NiceButton(190, 20, 130, 20, ButtonAction.Activate, "New macro")
            {
                IsSelectable = false, ButtonParameter = (int)Buttons.NewMacro
            };

            addButton.MouseClick += (sender, e) =>
            {
                EntryDialog dialog = new EntryDialog(250, 150, "Macro name:", name =>
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        return;
                    }

                    MacroManager manager = Engine.SceneManager.GetScene <GameScene>().Macros;
                    List <Macro> macros  = manager.GetAllMacros();

                    if (macros.Any(s => s.Name == name))
                    {
                        return;
                    }

                    NiceButton nb;
                    rightArea.Add(nb = new NiceButton(0, 0, 130, 25, ButtonAction.Activate, name)
                    {
                        ButtonParameter = (int)Buttons.Last + 1 + rightArea.Children.Count,
                    });

                    nb.IsSelected = true;

                    _macroControl?.Dispose();

                    _macroControl = new MacroControl(name)
                    {
                        X = 400,
                        Y = 20,
                    };

                    Add(_macroControl, PAGE);

                    nb.MouseClick += (sss, eee) =>
                    {
                        _macroControl?.Dispose();
                        _macroControl = new MacroControl(name)
                        {
                            X = 400,
                            Y = 20,
                        };
                        Add(_macroControl, PAGE);
                    };
                });

                Engine.UI.Add(dialog);
            };

            Add(addButton, PAGE);

            NiceButton delButton = new NiceButton(190, 52, 130, 20, ButtonAction.Activate, "Delete macro")
            {
                IsSelectable = false, ButtonParameter = (int)Buttons.DeleteMacro
            };

            delButton.MouseClick += (ss, ee) =>
            {
                NiceButton nb = rightArea.FindControls <ScrollAreaItem>()
                                .SelectMany(s => s.Children.OfType <NiceButton>())
                                .SingleOrDefault(a => a.IsSelected);

                if (nb != null)
                {
                    QuestionGump dialog = new QuestionGump("Do you want\ndelete it?", b =>
                    {
                        if (!b)
                        {
                            return;
                        }

                        nb.Parent.Dispose();

                        if (_macroControl != null)
                        {
                            MacroCollectionControl control = _macroControl.FindControls <MacroCollectionControl>().SingleOrDefault();
                            if (control == null)
                            {
                                return;
                            }

                            Engine.SceneManager.GetScene <GameScene>().Macros.RemoveMacro(control.Macro);
                        }

                        if (rightArea.Children.OfType <ScrollAreaItem>().All(s => s.IsDisposed))
                        {
                            _macroControl?.Dispose();
                        }
                    });
                    Engine.UI.Add(dialog);
                }
            };

            Add(delButton, PAGE);
            Add(new Line(190, 52 + 25 + 2, 150, 1, Color.Gray.PackedValue), PAGE);
            Add(rightArea, PAGE);
            Add(new Line(191 + 150, 21, 1, 418, Color.Gray.PackedValue), PAGE);

            foreach (Macro macro in Engine.SceneManager.GetScene <GameScene>().Macros.GetAllMacros())
            {
                NiceButton nb;
                rightArea.Add(nb = new NiceButton(0, 0, 130, 25, ButtonAction.Activate, macro.Name)
                {
                    ButtonParameter = (int)Buttons.Last + 1 + rightArea.Children.Count,
                });

                nb.IsSelected = true;

                nb.MouseClick += (sss, eee) =>
                {
                    _macroControl?.Dispose();

                    _macroControl = new MacroControl(macro.Name)
                    {
                        X = 400,
                        Y = 20,
                    };

                    Add(_macroControl, PAGE);
                };
            }
        }