Exemplo n.º 1
0
        public PopupSaveCommands(List <KeyValuePair <Turtle.SkiaTurtleE.CommandTypes, int> > command_list, EventHandler on_success)
        {
            InitializeComponent();
            this.Success = on_success;

            this.mCommandList = command_list;


            this.Appearing += (s, e) => {
                if (this.mCommandList.Count <= 0)
                {
                    this.Close();
                }
            };

            this.btnSave.Clicked += (s, e) =>
            {
                string name = this.txtName.Text;
                if (Turtle.SaveManager.IsCommandListNameAvailable(name))
                {
                    if (Turtle.SaveManager.SaveCommandList(name, this.mCommandList.ToList()))
                    {
                        Turtle.SoundManager.Play(Turtle.SoundManager.SND_CLICK);
                        this.Success?.Invoke(this, EventArgs.Empty);
                        this.Close(true);
                    }
                    else
                    {
                        Turtle.SoundManager.Play(Turtle.SoundManager.SND_ERROR);
                        PopupMessage.Show("Error", $"Failed to save {name}.");
                    }
                }
                else
                {
                    Turtle.SoundManager.Play(Turtle.SoundManager.SND_ERROR);
                    PopupMessage.Show("Error", $"Name '{name}' is already in use.");
                }
            };
        }
        public PopupAddCommand(EventHandler on_success)
        {
            InitializeComponent();

            this.Success = on_success;

            int len = Enum.GetNames(typeof(Turtle.SkiaTurtleE.CommandTypes)).Length;

            for (int i = 0; i < len; i++)
            {
                ImageSource img;
                string      txt;

                if (Turtle.SkiaTurtleE.GetCommandTypeInfo((Turtle.SkiaTurtleE.CommandTypes)i, out img, out txt))
                {
                    mListItems.Add(new CommandTypeItem()
                    {
                        _id = (Turtle.SkiaTurtleE.CommandTypes)i, StyleBackgroundColor = style_color_normal, Icon = img, Text = txt
                    });
                }
                else
                {
                    throw new NotSupportedException($"Enum of type: {typeof(Turtle.SkiaTurtleE.CommandTypes)} is not supported. (it needs to be in order 0 1 2 ...)");
                }
            }

            this.lstCommandTypes.ItemsSource = mListItems;

            if (LastSelectedIndex > -1)
            {
                this.lstCommandTypes.SelectedItem = mListItems[LastSelectedIndex];
                this.select_item(LastSelectedIndex);
            }



            this.lstCommandTypes.ItemSelected += (s, e) => this.select_item(e.SelectedItemIndex);


            this.btnAdd.Clicked += (s, e) =>
            {
                var curr = this.mListItems[LastSelectedIndex];


                this.ResultCommand = curr._id;


                if (Turtle.SkiaTurtleE.DoCommandNeedExtra(this.ResultCommand))
                {
                    if (this.ResultCommand == Turtle.SkiaTurtleE.CommandTypes.PenColor)
                    {
                        this.ResultUnits = this.clrColorSelector.Selected;
                        this.ResultColor = this.clrColorSelector.SelectedColor.ToFormsColor();
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(this.txtUnits.Text) || int.TryParse(this.txtUnits.Text, out int units) == false)
                        {
                            Turtle.SoundManager.Play(Turtle.SoundManager.SND_ERROR);
                            PopupMessage popupMessage = new PopupMessage("Invalid Units", "Please Input valid units.");
                            PopupNavigation.Instance.PushAsync(popupMessage);
                            //DisplayAlert("Invalid Units", "Please Input valid units.", "OK");
                            return;
                        }

                        this.ResultUnits = units;
                    }
                }
                Turtle.SoundManager.Play(Turtle.SoundManager.SND_CLICK);
                this.Success?.Invoke(this, EventArgs.Empty);
                PopupNavigation.Instance.PopAsync();
            };
        }
Exemplo n.º 3
0
        public static void Show(string title, string message, bool animate = true)
        {
            var pop = new PopupMessage(title, message);

            PopupNavigation.Instance.PushAsync(pop, animate);
        }