示例#1
0
 public void SendResponse(McpeModalFormResponse response)
 {
     if (NetworkProvider is BedrockClient client)
     {
         client.SendPacket(response);
     }
 }
示例#2
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);
        }
示例#3
0
        private void SubmitPressed()
        {
            Parent.Hide(FormId);

            var packet = McpeModalFormResponse.CreateObject();

            packet.formId = FormId;
            packet.data   = Serialize();

            //JsonConvert.SerializeObject(idx)
            Parent.SendResponse(packet);

            //Submit.
        }
 public void HandleMcpeModalFormResponse(McpeModalFormResponse message)
 {
 }
示例#5
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.MiddleCenter;
            StackMenu.Background  = Color.Black * 0.35f;

            if (!string.IsNullOrWhiteSpace(form.Content))
            {
                StackMenu.AddLabel(FixContrast(form.Content));
                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;
                    }
                }

                var item = StackMenu.AddMenuItem(button.Text, submitAction);
            }

            Background = Color.Transparent;

            var width  = 356;
            var height = width;

            ContentContainer.Width  = ContentContainer.MinWidth = ContentContainer.MaxWidth = width;
            ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = height;

            SetFixedSize(width, height);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            Container.Anchor = Alignment.MiddleCenter;

            var bodyWrapper = new GuiContainer();

            bodyWrapper.Anchor  = Alignment.Fill;
            bodyWrapper.Padding = new Thickness(5, 0);
            bodyWrapper.AddChild(StackMenu);

            Container.AddChild(bodyWrapper);

            Container.AddChild(Header = new GuiStackContainer()
            {
                Anchor      = Alignment.TopFill,
                ChildAnchor = Alignment.BottomCenter,
                Height      = 32,
                Padding     = new Thickness(3),
                Background  = Color.Black * 0.5f
            });

            Header.AddChild(new GuiTextElement()
            {
                Text      = FixContrast(form.Title),
                TextColor = TextColor.White,
                Scale     = 2f,
                FontStyle = FontStyle.DropShadow,

                Anchor = Alignment.BottomCenter,
            });

            StackMenu.Margin = new Thickness(0, Header.Height, 0, 0);
        }
示例#6
0
        /// <inheritdoc />
        public ModalFormDialog(uint formId, BedrockFormManager parent, ModalForm form, InputManager inputManager) : base(
                formId, parent, inputManager)
        {
            Background = Color.Transparent;

            var width  = 356;
            var height = width;

            ContentContainer.Width  = ContentContainer.MinWidth = ContentContainer.MaxWidth = width;
            ContentContainer.Height = ContentContainer.MinHeight = ContentContainer.MaxHeight = height;

            SetFixedSize(width, height);

            ContentContainer.AutoSizeMode = AutoSizeMode.None;

            Container.Anchor = Alignment.MiddleCenter;

            Container.AddChild(Footer = new GuiMultiStackContainer(row =>
            {
                row.Anchor = Alignment.BottomFill;
                //row.Orientation = Orientation.Horizontal;
                row.ChildAnchor = Alignment.BottomFill;
                //row.Margin = new Thickness(3);
                row.Width    = 356;
                row.MaxWidth = 356;
            })
            {
                Height = 24,

                Orientation = Orientation.Vertical,
                Anchor      = Alignment.BottomFill,
                ChildAnchor = Alignment.BottomCenter,
                Background  = Color.Black * 0.5f
            });

            Footer.AddRow(row =>
            {
                row.AddChild(new GuiButton(form.Button1, () =>
                {
                    var packet    = McpeModalFormResponse.CreateObject();
                    packet.formId = formId;
                    packet.data   = "true";
                    //JsonConvert.SerializeObject(idx)
                    parent.SendResponse(packet);

                    parent.Hide(formId);
                })
                {
                    Enabled = true,
                });
                row.AddChild(new GuiButton(form.Button2, () =>
                {
                    var packet    = McpeModalFormResponse.CreateObject();
                    packet.formId = formId;
                    packet.data   = "false";
                    //JsonConvert.SerializeObject(idx)
                    parent.SendResponse(packet);

                    parent.Hide(formId);
                })
                {
                    Enabled = true
                });
            });

            Container.AddChild(Body = new GuiStackContainer()
            {
                //Margin = new Thickness(0, Header.Height, 0, Footer.Height),
                //AutoSizeMode = AutoSizeMode.None,
                //Height = 100,
                //MaxHeight = 100,
                Orientation = Orientation.Vertical,
                Anchor      = Alignment.Fill,
                ChildAnchor = Alignment.MiddleCenter,
                Background  = Color.Black * 0.35f
                              //HorizontalScrollMode = ScrollMode.Hidden
            });

            var text = form.Content;

            var newString = "";

            //	char[] help = new[] { '.', '?', '!' };
            for (int i = 0; i < text.Length - 1; i++)
            {
                var c = text[i];
                newString += c;

                if (c == '.' || c == '?' || c == '!')
                {
                    //newString += "\n";

                    Body.AddChild(new GuiTextElement(newString));

                    /*row.AddChild(new GuiTextElement(form.Content)
                     * {
                     *      Wrap = true,
                     *      MaxWidth = 320
                     * });*/


                    newString = "";

                    if (i != text.Length - 1 && text[i + 1] == ' ')
                    {
                        i++;
                    }
                }
            }

            if (newString.Length > 0)
            {
                Body.AddChild(new GuiTextElement(newString));
            }

            Container.AddChild(Header = new GuiStackContainer()
            {
                Anchor      = Alignment.TopFill,
                ChildAnchor = Alignment.BottomCenter,
                Height      = 32,
                Padding     = new Thickness(3),
                Background  = Color.Black * 0.5f
            });

            Header.AddChild(new GuiTextElement()
            {
                Text      = form.Title,
                TextColor = TextColor.White,
                Scale     = 2f,
                FontStyle = FontStyle.DropShadow,

                Anchor = Alignment.BottomCenter,
            });

            Body.Margin = new Thickness(0, Header.Height, 0, Footer.Height);
            //	Body.MaxHeight = Body.Height = height - 64;
        }