예제 #1
0
        public SimpleFormDialog(uint formId, BedrockFormManager parent, SimpleForm form, InputManager inputManager) : base(formId, parent, inputManager)
        {
            StackMenu             = new GuiStackMenu();
            StackMenu.Anchor      = Alignment.Fill;
            StackMenu.ChildAnchor = Alignment.MiddleFill;

            if (!string.IsNullOrWhiteSpace(form.Content))
            {
                StackMenu.AddMenuItem(form.Content, () => {}, false);
                StackMenu.AddSpacer();
            }

            var btns = form.Buttons.ToArray();

            for (var index = 0; index < btns.Length; index++)
            {
                var button = btns[index];
                int idx    = index;

                Action submitAction = () =>
                {
                    var packet = McpeModalFormResponse.CreateObject();
                    packet.formId = formId;
                    packet.data   = idx.ToString();
                    //JsonConvert.SerializeObject(idx)
                    parent.SendResponse(packet);

                    parent.Hide(formId);
                };

                if (button.Image != null)
                {
                    switch (button.Image.Type)
                    {
                    case "url":
                        StackMenu.AddChild(new FormImageButton(button.Image.Url, button.Text, submitAction));
                        continue;
                        break;

                    case "path":
                        break;
                    }
                }

                StackMenu.AddMenuItem(button.Text, submitAction);
            }

            Container.AddChild(StackMenu);

            Container.AddChild(new GuiTextElement()
            {
                Anchor    = Alignment.TopCenter,
                Text      = form.Title,
                FontStyle = FontStyle.Bold,
                Scale     = 2f,
                TextColor = TextColor.White
            });

            AddChild(Container);
        }
예제 #2
0
파일: FormBase.cs 프로젝트: astroffnet/Alex
        public FormBase(uint formId, BedrockFormManager parent, InputManager inputManager)
        {
            FormId       = formId;
            Parent       = parent;
            InputManager = inputManager;

            Background = new Color(Color.Black, 0.5f);

            Container        = new GuiContainer();
            Container.Anchor = Alignment.FillCenter;

            AddChild(Container);
        }
예제 #3
0
        public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager)
        {
            Container.AddChild(new GuiTextElement()
            {
                Anchor    = Alignment.TopCenter,
                Text      = form.Title,
                FontStyle = FontStyle.Bold,
                Scale     = 2f,
                TextColor = TextColor.White
            });

            Form = form;

            GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer();

            stackContainer.Orientation = Orientation.Vertical;
            stackContainer.Anchor      = Alignment.Fill;
            stackContainer.ChildAnchor = Alignment.MiddleFill;

            var margin = new Thickness(5, 5);

            foreach (var element in form.Content)
            {
                switch (element)
                {
                case Label label:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text   = label.Text,
                            Margin = margin
                        });
                }
                break;

                case Input input:
                {
                    GuiTextInput guiInput = new GuiTextInput()
                    {
                        Value       = input.Value,
                        PlaceHolder = input.Placeholder,
                        Margin      = margin
                    };

                    guiInput.ValueChanged += (sender, s) => { input.Value = s; };

                    stackContainer.AddChild(guiInput);
                }
                break;

                case Toggle toggle:
                {
                    GuiToggleButton guiToggle;
                    stackContainer.AddChild(guiToggle = new GuiToggleButton(toggle.Text)
                        {
                            Margin = margin,
                            Value  = !toggle.Value
                        });

                    guiToggle.DisplayFormat = new ValueFormatter <bool>((val) =>
                        {
                            return($"{toggle.Text}: {val.ToString()}");
                        });

                    guiToggle.Value = toggle.Value;

                    guiToggle.ValueChanged += (sender, b) => { toggle.Value = b; };
                }
                break;

                case Slider slider:
                {
                    GuiSlider guiSlider;
                    stackContainer.AddChild(guiSlider = new GuiSlider()
                        {
                            Label        = { Text = slider.Text },
                            Value        = slider.Value,
                            MaxValue     = slider.Max,
                            MinValue     = slider.Min,
                            StepInterval = slider.Step,
                            Margin       = margin
                        });

                    guiSlider.ValueChanged += (sender, d) => { slider.Value = (float)d; };
                }
                break;

                case StepSlider stepSlider:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported stepslider",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;

                case Dropdown dropdown:
                {
                    stackContainer.AddChild(new GuiTextElement()
                        {
                            Text      = "Unsupported dropdown",
                            TextColor = TextColor.Red,
                            Margin    = margin
                        });
                }
                break;
                }
            }

            SubmitButton = new GuiButton("Submit", SubmitPressed);

            stackContainer.AddChild(SubmitButton);

            Container.AddChild(stackContainer);
        }