Beispiel #1
0
        public override void OnMouseReleasedAnywhere(Vector2i location, Mouse.Button button)
        {
            if (_active == true)
            {
                OnConfirmed?.Invoke(this, Value);
            }

            _active = false;
        }
        partial void OnClicked(int component)
        {
            Vector2Distribution distribution = Value;

            if (DistributionType == PropertyDistributionType.Curve)
            {
                AnimationCurve[] curves = AnimationUtility.SplitCurve2D(distribution.GetMinCurve());
                if (component < curves.Length)
                {
                    CurveEditorWindow.Show(curves[component], (success, curve) =>
                    {
                        if (!success)
                        {
                            return;
                        }

                        curves[component] = curve;

                        Vector2Curve compoundCurve = AnimationUtility.CombineCurve2D(curves);
                        Value = new Vector2Distribution(compoundCurve);
                        OnChanged?.Invoke();
                        OnConfirmed?.Invoke();
                    });
                }
            }
            else if (DistributionType == PropertyDistributionType.RandomCurveRange)
            {
                AnimationCurve[] minCurves = AnimationUtility.SplitCurve2D(distribution.GetMinCurve());
                AnimationCurve[] maxCurves = AnimationUtility.SplitCurve2D(distribution.GetMaxCurve());

                if (component < minCurves.Length && component < maxCurves.Length)
                {
                    CurveEditorWindow.Show(minCurves[component], maxCurves[component],
                                           (success, minCurve, maxCurve) =>
                    {
                        if (!success)
                        {
                            return;
                        }

                        minCurves[component] = minCurve;
                        maxCurves[component] = maxCurve;

                        Vector2Curve minCompoundCurves = AnimationUtility.CombineCurve2D(minCurves);
                        Vector2Curve maxCompoundCurves = AnimationUtility.CombineCurve2D(maxCurves);

                        Value = new Vector2Distribution(minCompoundCurves, maxCompoundCurves);
                        OnChanged?.Invoke();
                        OnConfirmed?.Invoke();
                    });
                }
            }
        }
 partial void OnConstantConfirmed()
 {
     OnConfirmed?.Invoke();
 }
        /// <summary>
        /// Refresh the controls and regenerate gui elements
        /// </summary>
        /// <param name="constructor">Is run from constructor</param>
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            MyGuiControlLabel caption = new MyGuiControlLabel(null, null, m_caption);

            caption.OriginAlign = VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            caption.Position    = new Vector2(0, Size.Value.Y / -2 + PADDING.Y);

            Controls.Add(caption);

            MyGuiControlParentTableLayout table = new MyGuiControlParentTableLayout(6, true, PADDING);

            table.AddTableSeparator();

            m_xBox = new MyGuiControlTextbox(type: MyGuiControlTextboxType.DigitsOnly);
            m_yBox = new MyGuiControlTextbox(type: MyGuiControlTextboxType.DigitsOnly);
            m_zBox = new MyGuiControlTextbox(type: MyGuiControlTextboxType.DigitsOnly);

            m_xBox.Size = new Vector2(0.1f, m_xBox.Size.Y);
            m_yBox.Size = new Vector2(0.1f, m_yBox.Size.Y);
            m_zBox.Size = new Vector2(0.1f, m_zBox.Size.Y);

            m_xBox.SetText(new StringBuilder("0"));
            m_yBox.SetText(new StringBuilder("0"));
            m_zBox.SetText(new StringBuilder("0"));

            table.AddTableRow(new MyGuiControlLabel(text: "X:"), m_xBox, new MyGuiControlLabel(text: "Y:"), m_yBox, new MyGuiControlLabel(text: "Z:"), m_zBox);

            table.AddTableSeparator();

            table.ApplyRows();

            table.Position    = new Vector2(0, caption.Position.Y + caption.Size.Y + PADDING.Y);
            table.OriginAlign = VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;

            Controls.Add(table);

            m_okButton                = new MyGuiControlButton();
            m_okButton.Text           = MyCommonTexts.Ok.ToString();
            m_okButton.OriginAlign    = VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM;
            m_okButton.Position       = new Vector2(-PADDING.X, Size.Value.Y / 2 - PADDING.Y);
            m_okButton.ButtonClicked += delegate
            {
                var    xb = new StringBuilder();
                var    yb = new StringBuilder();
                var    zb = new StringBuilder();
                double x  = 0;
                double y  = 0;
                double z  = 0;
                m_xBox.GetText(xb);
                m_yBox.GetText(yb);
                m_zBox.GetText(zb);
                if (double.TryParse(xb.ToString(), out x) && double.TryParse(yb.ToString(), out y) && double.TryParse(zb.ToString(), out z))
                {
                    OnConfirmed?.Invoke(new Vector3D(x, y, z));
                    CloseScreen();
                }
                else
                {
                    m_errorLabel.Visible = true;
                }
            };

            m_cancelButton                = new MyGuiControlButton();
            m_cancelButton.Text           = MyCommonTexts.Cancel.ToString();
            m_cancelButton.OriginAlign    = VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            m_cancelButton.Position       = new Vector2(PADDING.X, Size.Value.Y / 2 - PADDING.Y);
            m_cancelButton.ButtonClicked += delegate
            {
                CloseScreen();
            };

            Controls.Add(m_okButton);
            Controls.Add(m_cancelButton);


            m_errorLabel             = new MyGuiControlLabel(null, null, "Those are not valid coordinates.", font: "Red");
            m_errorLabel.OriginAlign = VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            m_errorLabel.Position    = new Vector2(Size.Value.X / -2 + PADDING.X, m_xBox.Position.Y + m_xBox.Size.Y);
            m_errorLabel.Visible     = false;

            Controls.Add(m_errorLabel);
        }