Пример #1
0
        private void addButtons()
        {
            var factory       = _editor.Editor.Factory;
            var font          = _editor.Editor.Settings.Defaults.TextFont;
            var border        = factory.Graphics.Borders.SolidColor(GameViewColors.Border, 2f);
            var idleConfig    = new AGSTextConfig(GameViewColors.TextBrush, alignment: Alignment.MiddleCenter, font: font);
            var hoveredConfig = new AGSTextConfig(GameViewColors.HoveredTextBrush, alignment: Alignment.MiddleCenter, font: font);
            var idle          = new ButtonAnimation(border, idleConfig, GameViewColors.Button);
            var hovered       = new ButtonAnimation(border, hoveredConfig, GameViewColors.Button);
            var pushed        = new ButtonAnimation(factory.Graphics.Borders.SolidColor(Colors.Black, 2f), idleConfig, GameViewColors.Button);

            var buttonsPanel = factory.UI.GetPanel("MethodWizardButtonsPanel", WIDTH, 20f, MARGIN_HORIZONTAL, 50f, _parent);

            buttonsPanel.Tint = Colors.Transparent;

            var layout = buttonsPanel.AddComponent <IStackLayoutComponent>();

            layout.Direction       = LayoutDirection.Horizontal;
            layout.CenterLayout    = true;
            layout.RelativeSpacing = 1f;
            layout.AbsoluteSpacing = 40f;
            layout.StartLocation   = WIDTH / 2f;

            const float buttonWidth = 80f;
            var         okButton    = factory.UI.GetButton("MethodWizardOkButton", idle, hovered, pushed, 0f, 0f, buttonsPanel, "OK", width: buttonWidth, height: 20f);

            okButton.MouseClicked.Subscribe(async() =>
            {
                Dictionary <string, object> map = new Dictionary <string, object>();
                foreach (var param in _inspector.Inspector.Properties.SelectMany(p => p.Value))
                {
                    map[param.Name] = param.GetValue();
                }
                if (!await _validate(map))
                {
                    return;
                }

                _modal?.LoseFocus();
                _parent.DestroyWithChildren(_editor.Editor.State);
                _taskCompletionSource.TrySetResult(map);
            });

            var cancelButton = factory.UI.GetButton("MethodWizardCancelButton", idle, hovered, pushed, 0f, 0f, buttonsPanel, "Cancel", width: buttonWidth, height: 20f);

            cancelButton.MouseClicked.Subscribe(() =>
            {
                _modal?.LoseFocus();
                _parent.DestroyWithChildren(_editor.Editor.State);
                _taskCompletionSource.TrySetResult(null);
            });

            layout.StartLayout();
        }