Beispiel #1
0
        protected override void OnInit(IGuiRenderer renderer)
        {
            Alex.Services.GetRequiredService <IEventDispatcher>().RegisterEvents(_tipPopupComponent);

            _bottomContainer.AddChild(_tipPopupComponent);

            _healthContainer.AddChild(_healthComponent);
            _healthContainer.AddChild(_hungerComponent);

            _healthAndHotbar.AddChild(_healthContainer);

            _healthAndHotbar.AddChild(_hotbar);

            _bottomContainer.AddRow(
                container =>
            {
                //		        container.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                container.Anchor      = Alignment.BottomCenter;
                container.ChildAnchor = Alignment.FillCenter;

                container.AddChild(_healthAndHotbar);
                //container.AddChild(_hotbar);
            });

            AddChild(_bottomContainer);

            AddChild(Chat);

            //AddChild(_hotbar);
            AddChild(new GuiCrosshair());
            AddChild(Title);

            AddChild(Scoreboard);
        }
Beispiel #2
0
 public void AddDebugLeft(string text)
 {
     _leftContainer.AddChild(new GuiTextElement(text, false)
     {
         TextColor         = TextColor.White,
         FontStyle         = FontStyle.DropShadow,
         Scale             = 1f,
         BackgroundOverlay = Color.Black * 0.25f
     });
 }
Beispiel #3
0
 public void AddDebugLeft(string text, bool hasBackground = true)
 {
     _leftContainer.AddChild(new GuiTextElement(text, hasBackground)
     {
         TextColor         = TextColor.White,
         FontStyle         = FontStyle.DropShadow,
         Scale             = 1f,
         BackgroundOverlay = Color.Black * 0.25f,
         TextAlignment     = TextAlignment.Left
     });
 }
Beispiel #4
0
        public SplashScreen()
        {
            Background = Color.White;
            Background.TextureResource = GuiTextures.SplashBackground;
            Background.RepeatMode      = TextureRepeatMode.ScaleToFit;

            AddChild(_progressBarContainer = new GuiContainer()
            {
                Width  = 300,
                Height = 35,
                Margin = new Thickness(12),

                Anchor = Alignment.BottomCenter,
            });

            _progressBarContainer.AddChild(_textDisplay = new GuiTextElement()
            {
                Text      = Text,
                TextColor = TextColor.Black,

                Anchor    = Alignment.TopLeft,
                HasShadow = false
            });

            _progressBarContainer.AddChild(_percentageDisplay = new GuiTextElement()
            {
                Text      = Text,
                TextColor = TextColor.Black,

                Anchor    = Alignment.TopRight,
                HasShadow = false
            });

            _progressBarContainer.AddChild(_progressBar = new GuiProgressBar()
            {
                Width  = 300,
                Height = 9,

                Anchor = Alignment.MiddleCenter,
            });

            _progressBarContainer.AddChild(_subTextDisplay = new GuiTextElement()
            {
                Text      = Text,
                TextColor = TextColor.Black,

                Anchor    = Alignment.BottomLeft,
                HasShadow = false
            });
        }
Beispiel #5
0
        public ScoreboardElement(string left, uint value)
        {
            //Orientation = Orientation.Horizontal;
            //ChildAnchor = Alignment.FillCenter;

            Left = new GuiTextElement()
            {
                Text   = left,
                Anchor = Alignment.TopLeft,
                //	Margin = new Thickness(0, 0, 2, 0),
                //ParentElement = this
            };

            Right = new GuiContainer()
            {
                Padding = new Thickness(2, 0, 0, 0),
                Anchor  = Alignment.TopRight
            };

            Right.AddChild(new GuiTextElement()
            {
                Anchor = Alignment.TopRight,
                Text   = $"  {value.ToString()}",
                //ParentElement = this
            });

            AddChild(Left);
            AddChild(Right);
        }
Beispiel #6
0
 public void AddDebugLeft(Func <string> getDebugString)
 {
     _leftContainer.AddChild(new GuiAutoUpdatingTextElement(getDebugString, true)
     {
         TextColor = TextColor.White,
         FontStyle = FontStyle.DropShadow,
         Scale     = 0.5f,
     });
 }
Beispiel #7
0
        public LoadingWorldState()
        {
            HeaderTitle.TranslationKey = "menu.loadingLevel";

            _textDisplay = new GuiTextElement()
            {
                Text      = Text,
                TextColor = TextColor.White,

                Anchor    = Alignment.TopLeft,
                HasShadow = false
            };

            _percentageDisplay = new GuiTextElement()
            {
                Text      = Text,
                TextColor = TextColor.White,

                Anchor    = Alignment.TopRight,
                HasShadow = false
            };

            _progressBar = new GuiProgressBar()
            {
                Width  = 300,
                Height = 9,

                Anchor = Alignment.BottomFill,
            };

            var progContainer = new GuiContainer()
            {
                Width  = 300,
                Height = 25,
            };

            progContainer.AddChild(_textDisplay);
            progContainer.AddChild(_percentageDisplay);
            progContainer.AddChild(_progressBar);

            var progressRow = Footer.AddRow(progContainer);

            UpdateProgress(LoadingState.ConnectingToServer, 10);
        }
Beispiel #8
0
 public void AddDebugLeft(Func<string> getDebugString)
 {
     _leftContainer.AddChild(new GuiAutoUpdatingTextElement(getDebugString, false)
     {
         TextColor = TextColor.White,
         FontStyle = FontStyle.DropShadow,
         Scale = 1f,
         BackgroundOverlay = Color.Black * 0.25f
     });
 }
Beispiel #9
0
        public void AddString(string text)
        {
            GuiContainer container = new GuiContainer();

            container.AddChild(new GuiTextElement(text)
            {
                Anchor = Alignment.CenterX
            });
            AddChild(container);
        }
Beispiel #10
0
        public ScoreboardObjective(string name, string displayName, int sortOrder, string criteriaName)
        {
            _displayNameElement = new GuiTextElement(displayName)
            {
                Anchor = Alignment.CenterX
            };

            Entries      = new ConcurrentDictionary <string, ScoreboardEntry>();
            Name         = name;
            DisplayName  = displayName;
            SortOrder    = sortOrder;
            CriteriaName = criteriaName;
            ChildAnchor  = Alignment.Fill;

            _container = new GuiContainer();
            _container.AddChild(_displayNameElement);

            AddChild(_container);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        public CustomFormDialog(uint formId, BedrockFormManager parent, CustomForm form, InputManager inputManager) : base(formId, parent, inputManager)
        {
            Form = form;

            GuiScrollableStackContainer stackContainer = new GuiScrollableStackContainer();

            stackContainer.Orientation = Orientation.Vertical;
            stackContainer.Anchor      = Alignment.Fill;
            stackContainer.ChildAnchor = Alignment.MiddleFill;
            stackContainer.Background  = Color.Black * 0.35f;
            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 = !string.IsNullOrWhiteSpace(input.Placeholder) ? input.Placeholder : input.Text,
                        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);

            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(stackContainer);

            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,
            });

            stackContainer.Margin = new Thickness(0, Header.Height, 0, 0);
        }