Ejemplo n.º 1
0
        private void OpenWorldCreationWindow()
        {
            worldCreationWindow = new Window(this)
            {
                Title               = Language.CreateNewWorld,
                StartPosition       = StartPosition.CenterCanvas,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                Resizing            = Resizing.None
            };

            VerticalLayout layout = new(worldCreationWindow)
            {
                Padding = Padding.Five,
                Margin  = Margin.Ten
            };

            Label info = new(layout)
            {
                Text = Language.EnterWorldName,
                HorizontalAlignment = HorizontalAlignment.Center,
                Padding             = Padding.Five
            };

            TextBox name = new(layout)
            {
                Text    = "Hello World",
                Padding = Padding.Five
            };

            Button create = new(layout)
            {
                Text    = Language.Create,
                Padding = Padding.Five
            };

            name.TextChanged += (_, _) => ValidateInput(out _);
            create.Pressed   += (_, _) => CreateWorld();

            void ValidateInput(out bool isValid)
            {
                string input = name.Text;

                isValid = worldProvider.IsWorldNameValid(input);

                name.TextColor = isValid ? Color.White : Color.Red;

                create.IsDisabled = !isValid;
                create.UpdateColors();
            }

            void CreateWorld()
            {
                ValidateInput(out bool isValid);

                if (isValid)
                {
                    worldProvider.CreateWorld(name.Text);
                }
            }
        }