Beispiel #1
0
        private void DrawControl(Control c)
        {
            // Draw control label
            GUILayout.Label(c.Name, Elements.Labels.Title);

            // Draw axis select button
            GUILayout.BeginHorizontal();

            var buttonRect = GUILayoutUtility.GetRect(GUIContent.none, Elements.Buttons.Default);

            if (c.Axis == null)
            {
                if (GUI.Button(buttonRect, "Select Input Axis", Elements.Buttons.Disabled))
                {
                    var callback = new SelectAxisDelegate((InputAxis axis) => { c.Axis = axis.Name; c.Enabled = true; });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
            }
            else
            {
                var a = AxisManager.Get(c.Axis);
                if (GUI.Button(buttonRect, c.Axis, a != null ? a.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled : Elements.Buttons.Red))
                {
                    var callback = new SelectAxisDelegate((InputAxis axis) => { c.Axis = axis.Name; c.Enabled = true; });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
                if (a != null && GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default)
                {
                    fontSize = 20, padding = new RectOffset(-3, 0, 0, 0)
                }, GUILayout.Width(30), GUILayout.MaxHeight(28)))
                {
                    var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>();
                    Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width,
                                                      -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top);
                    Editor.windowRect.y = Mathf.Clamp(windowRect.y, 0, Screen.height - GUI.skin.window.padding.top);
                    Editor.EditAxis(a, new SelectAxisDelegate((InputAxis new_axis) => { c.Axis = new_axis.Name; }));
                }
                if (GUILayout.Button("×", Elements.Buttons.Red, GUILayout.Width(30)))
                {
                    c.Enabled = false;
                    c.Axis    = null;
                }
            }

            GUILayout.EndHorizontal();

            if (c.Enabled)
            {
                // Draw graph
                var    axis          = AxisManager.Get(c.Axis);
                float  axis_value    = axis != null ? axis.OutputValue : 0;
                float  control_value = 0;
                string text;
                if (axis == null)
                {
                    text = "NOT FOUND";
                }
                else
                {
                    if (axis_value > 0)
                    {
                        control_value = Mathf.Lerp(c.Center, c.Max, axis_value);
                    }
                    else
                    {
                        control_value = Mathf.Lerp(c.Center, c.Min, -axis_value);
                    }

                    if (axis.Status == AxisStatus.OK)
                    {
                        text = control_value.ToString("0.00");
                    }
                    else
                    {
                        text = InputAxis.GetStatusString(axis.Status);
                    }
                }

                GUILayout.Label("<color=#808080><b>" + text + "</b></color>",
                                new GUIStyle(Elements.Labels.Default)
                {
                    padding = new RectOffset(38, 38, 4, 0), richText = true, alignment = TextAnchor.MiddleLeft
                },
                                GUILayout.Height(20));

                var graphRect = GUILayoutUtility.GetLastRect();
                graphRect.x      += 30;
                graphRect.height += 44;
                graphRect.width  -= 60;

                Util.DrawRect(graphRect, Color.gray);
                Util.FillRect(new Rect(
                                  graphRect.x + graphRect.width / 2,
                                  graphRect.y,
                                  1,
                                  graphRect.height),
                              Color.gray);

                if (axis != null && axis.Status == AxisStatus.OK)
                {
                    Util.FillRect(new Rect(
                                      graphRect.x + graphRect.width / 2 + graphRect.width / 2 * axis_value,
                                      graphRect.y,
                                      1,
                                      graphRect.height),
                                  Color.yellow);
                }

                // Draw invert button
                if (GUI.Button(new Rect(graphRect.x + graphRect.width - 28, graphRect.y, 28, 28), "<size=24><color=#808080>⇄</color></size>", Elements.Labels.Default))
                {
                    c.Invert();
                }

                // Draw interval input fields
                GUILayout.BeginHorizontal();
                {
                    var oldColor = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f, 0.7f);

                    float min_parsed = c.Min;
                    c.min_string = Regex.Replace(
                        GUILayout.TextField(
                            c.min_string,
                            new GUIStyle(Elements.InputFields.Default)
                    {
                        alignment = TextAnchor.MiddleCenter
                    },
                            GUILayout.Width(60)),
                        @"[^0-9\-.]", "");
                    if (c.min_string != c.Min.ToString() &&
                        !c.min_string.EndsWith(".0") &&
                        !c.min_string.EndsWith(".") &&
                        c.min_string != "-" &&
                        c.min_string != "-0")
                    {
                        float.TryParse(c.min_string, out min_parsed);
                        c.Min        = min_parsed;
                        c.min_string = c.Min.ToString();
                    }

                    GUILayout.FlexibleSpace();

                    float cen_parsed = c.Center;
                    c.cen_string = Regex.Replace(
                        GUILayout.TextField(
                            c.cen_string,
                            new GUIStyle(Elements.InputFields.Default)
                    {
                        alignment = TextAnchor.MiddleCenter
                    },
                            GUILayout.Width(60)),
                        @"[^0-9\-.]", "");
                    if (c.cen_string != c.Center.ToString() &&
                        !c.cen_string.EndsWith(".0") &&
                        !c.cen_string.EndsWith(".") &&
                        c.cen_string != "-" &&
                        c.cen_string != "-0")
                    {
                        float.TryParse(c.cen_string, out cen_parsed);
                        c.Center     = cen_parsed;
                        c.cen_string = c.Center.ToString();
                    }

                    GUILayout.FlexibleSpace();

                    float max_parsed = c.Max;
                    c.max_string = Regex.Replace(
                        GUILayout.TextField(
                            c.max_string,
                            new GUIStyle(Elements.InputFields.Default)
                    {
                        alignment = TextAnchor.MiddleCenter
                    },
                            GUILayout.Width(60)),
                        @"[^0-9\-.]", "");
                    if (c.max_string != c.Max.ToString() &&
                        !c.max_string.EndsWith(".0") &&
                        !c.max_string.EndsWith(".") &&
                        c.max_string != "-" &&
                        c.max_string != "-0")
                    {
                        float.TryParse(c.max_string, out max_parsed);
                        c.Max        = max_parsed;
                        c.max_string = c.Max.ToString();
                    }

                    GUI.backgroundColor = oldColor;
                }
                GUILayout.EndHorizontal();
            }
        }
Beispiel #2
0
        public void DrawAxis(Rect windowRect)
        {
            // Draw graphs
            Rect graphRect = new Rect(
                GUI.skin.window.padding.left,
                GUI.skin.window.padding.top + 36,
                windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right,
                20);

            Rect leftGraphRect = new Rect(
                GUI.skin.window.padding.left,
                GUI.skin.window.padding.top + 100,
                (windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right) / 2 - 4,
                20);

            Rect rightGraphRect = new Rect(
                GUI.skin.window.padding.left + leftGraphRect.width + 8,
                GUI.skin.window.padding.top + 100,
                (windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right) / 2 - 4,
                20);

            Util.DrawRect(graphRect, Color.gray);
            Util.FillRect(new Rect(
                              graphRect.x + graphRect.width / 2,
                              graphRect.y,
                              1,
                              graphRect.height),
                          Color.gray);
            Util.DrawRect(leftGraphRect, Color.gray);
            Util.FillRect(new Rect(
                              leftGraphRect.x + leftGraphRect.width / 2,
                              leftGraphRect.y,
                              1,
                              leftGraphRect.height),
                          Color.gray);
            Util.DrawRect(rightGraphRect, Color.gray);
            Util.FillRect(new Rect(
                              rightGraphRect.x + rightGraphRect.width / 2,
                              rightGraphRect.y,
                              1,
                              rightGraphRect.height),
                          Color.gray);

            var   axis_a = AxisManager.Get(Axis.SubAxis1);
            var   axis_b = AxisManager.Get(Axis.SubAxis2);
            float a      = axis_a != null ? axis_a.OutputValue : 0;
            float b      = axis_b != null ? axis_b.OutputValue : 0;

            // Draw axis value
            GUILayout.Label("  <color=#808080><b>" + Axis.OutputValue.ToString("0.00") + "</b></color>",
                            new GUIStyle(Elements.Labels.Default)
            {
                richText = true, alignment = TextAnchor.MiddleLeft
            },
                            GUILayout.Height(20));

            // Draw method select
            int i           = (int)Axis.Method;
            int num_methods = Enum.GetValues(typeof(ChainAxis.ChainMethod)).Length;

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("<", Elements.Buttons.Default, GUILayout.Width(30)))
            {
                i--;
            }
            if (i < 0)
            {
                i += num_methods;
            }

            GUILayout.Label(Enum.GetNames(typeof(ChainAxis.ChainMethod))[i], new GUIStyle(Elements.InputFields.Default)
            {
                alignment = TextAnchor.MiddleCenter
            });

            if (GUILayout.Button(">", Elements.Buttons.Default, GUILayout.Width(30)))
            {
                i++;
            }
            if (i == num_methods)
            {
                i = 0;
            }

            Axis.Method = (ChainAxis.ChainMethod)i;

            GUILayout.EndHorizontal();

            // Draw sub axis values
            GUILayout.BeginHorizontal(GUILayout.Height(20));

            GUILayout.Label("  <color=#808080><b>" + (axis_a == null ? "" : axis_a.Status == AxisStatus.OK ? a.ToString("0.00") : InputAxis.GetStatusString(axis_a.Status)) + "</b></color>",
                            new GUIStyle(Elements.Labels.Default)
            {
                richText = true, alignment = TextAnchor.MiddleLeft
            },
                            GUILayout.MinWidth(leftGraphRect.width),
                            GUILayout.Height(20));

            GUILayout.Label("  <color=#808080><b>" + (axis_b == null ? "" : axis_b.Status == AxisStatus.OK ? b.ToString("0.00") : InputAxis.GetStatusString(axis_a.Status)) + "</b></color>",
                            new GUIStyle(Elements.Labels.Default)
            {
                richText = true, alignment = TextAnchor.MiddleLeft, margin = new RectOffset(8, 0, 0, 0)
            },
                            GUILayout.MinWidth(rightGraphRect.width),
                            GUILayout.Height(20));

            GUILayout.EndHorizontal();

            // Draw yellow lines
            if (Axis.Status == AxisStatus.OK)
            {
                Util.FillRect(new Rect(
                                  graphRect.x + graphRect.width / 2 + graphRect.width / 2 * Axis.OutputValue,
                                  graphRect.y,
                                  1,
                                  graphRect.height),
                              Color.yellow);
            }

            if (axis_a != null && Axis.Status == AxisStatus.OK)
            {
                Util.FillRect(new Rect(
                                  leftGraphRect.x + leftGraphRect.width / 2 + leftGraphRect.width / 2 * a,
                                  leftGraphRect.y,
                                  1,
                                  leftGraphRect.height),
                              Color.yellow);
            }

            if (axis_b != null && Axis.Status == AxisStatus.OK)
            {
                Util.FillRect(new Rect(
                                  rightGraphRect.x + rightGraphRect.width / 2 + rightGraphRect.width / 2 * b,
                                  rightGraphRect.y,
                                  1,
                                  rightGraphRect.height),
                              Color.yellow);
            }

            // Draw axis select buttons
            GUILayout.BeginHorizontal();

            var buttonRect = GUILayoutUtility.GetRect(new GUIContent(" "), spaar.ModLoader.UI.Elements.Buttons.Default, GUILayout.MaxWidth(leftGraphRect.width));

            if (Axis.SubAxis1 == null)
            {
                if (GUI.Button(buttonRect, "Select Input Axis", spaar.ModLoader.UI.Elements.Buttons.Disabled))
                {
                    error = null;
                    var callback = new SelectAxisDelegate((InputAxis axis) =>
                    {
                        try
                        {
                            Axis.SubAxis1 = axis.Name;
                        }
                        catch (InvalidOperationException e)
                        {
                            error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message;
                        }
                    });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
            }
            else
            {
                if (GUI.Button(buttonRect, Axis.SubAxis1, axis_a != null ? axis_a.Saveable ? spaar.ModLoader.UI.Elements.Buttons.Default : spaar.ModLoader.UI.Elements.Buttons.Disabled : spaar.ModLoader.UI.Elements.Buttons.Red))
                {
                    error = null;
                    var callback = new SelectAxisDelegate((InputAxis axis) =>
                    {
                        try
                        {
                            Axis.SubAxis1 = axis.Name;
                        }
                        catch (InvalidOperationException e)
                        {
                            error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message;
                        }
                    });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
            }

            if (Axis.SubAxis2 == null)
            {
                if (GUILayout.Button("Select Input Axis", spaar.ModLoader.UI.Elements.Buttons.Disabled, GUILayout.MaxWidth(rightGraphRect.width)))
                {
                    error = null;
                    var callback = new SelectAxisDelegate((InputAxis axis) =>
                    {
                        try
                        {
                            Axis.SubAxis2 = axis.Name;
                        }
                        catch (InvalidOperationException e)
                        {
                            error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message;
                        }
                    });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
            }
            else
            {
                if (GUILayout.Button(Axis.SubAxis2, axis_b != null ? axis_b.Saveable ? spaar.ModLoader.UI.Elements.Buttons.Default : spaar.ModLoader.UI.Elements.Buttons.Disabled : spaar.ModLoader.UI.Elements.Buttons.Red,
                                     GUILayout.MaxWidth(rightGraphRect.width)))
                {
                    error = null;
                    var callback = new SelectAxisDelegate((InputAxis axis) =>
                    {
                        try
                        {
                            Axis.SubAxis2 = axis.Name;
                        }
                        catch (InvalidOperationException e)
                        {
                            error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message;
                        }
                    });
                    if (popup == null)
                    {
                        popup = AxisSelector.Open(callback, true);
                    }
                    else
                    {
                        popup.Callback = callback;
                    }
                    popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                    popup.windowRect.y = windowRect.y + buttonRect.y - 8;
                }
            }

            GUILayout.EndHorizontal();

            // Check for mouse exit
            if (popup != null && !popup.ContainsMouse)
            {
                GameObject.Destroy(popup);
            }
        }
Beispiel #3
0
        private void DrawAxis(string axis)
        {
            GUILayout.BeginHorizontal();

            var buttonRect = GUILayoutUtility.GetRect(new GUIContent(" "), Elements.Buttons.Default);
            var a          = AxisManager.Get(axis);

            if (GUI.Button(buttonRect, axis, a != null ? a.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled : Elements.Buttons.Red))
            {
                var callback = new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); });
                if (popup == null)
                {
                    popup = AxisSelector.Open(callback, true);
                }
                else
                {
                    popup.Callback = callback;
                }
                popup.windowRect.x = windowRect.x + buttonRect.x - 8;
                popup.windowRect.y = windowRect.y + GUI.skin.window.padding.top + buttonRect.y - scrollPosition.y - 8;
            }

            if (a != null && GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default)
            {
                fontSize = 20, padding = new RectOffset(-3, 0, 0, 0)
            }, GUILayout.Width(30), GUILayout.MaxHeight(28)))
            {
                var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>();
                Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width,
                                                  -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top);
                Editor.windowRect.y = Mathf.Clamp(windowRect.y, 0, Screen.height - GUI.skin.window.padding.top);
                Editor.EditAxis(a, new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); }));
            }

            GUILayout.EndHorizontal();

            // Draw graph
            string text;

            if (a == null)
            {
                text = "NOT FOUND";
            }
            else if (a.Status != AxisStatus.OK)
            {
                text = InputAxis.GetStatusString(a.Status);
            }
            else
            {
                text = "";
            }

            GUILayout.Label("  <color=#808080><b>" + text + "</b></color>",
                            new GUIStyle(Elements.Labels.Default)
            {
                richText = true, alignment = TextAnchor.MiddleLeft, margin = new RectOffset(8, 8, 8, 8)
            },
                            GUILayout.Height(20));

            var graphRect = GUILayoutUtility.GetLastRect();

            Util.DrawRect(graphRect, Color.gray);
            Util.FillRect(new Rect(
                              graphRect.x + graphRect.width / 2,
                              graphRect.y,
                              1,
                              graphRect.height),
                          Color.gray);

            if (a != null && a.Status == AxisStatus.OK)
            {
                Util.FillRect(new Rect(
                                  graphRect.x + graphRect.width / 2 + graphRect.width / 2 * a.OutputValue,
                                  graphRect.y,
                                  1,
                                  graphRect.height),
                              Color.yellow);
            }

            // Draw assigned controls list
            foreach (Control c in Controls[axis])
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("×", new GUIStyle(Elements.Buttons.Red)
                {
                    margin = new RectOffset(8, 8, 0, 0)
                }, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    c.Axis    = null;
                    c.Enabled = false;
                }
                string block_name;
                try
                {
                    block_name = BlockHandlerController.GetID(c.BlockGUID);
                }
                catch
                {
                    block_name = "...";
                }
                GUILayout.Label("<b>" + c.Name + "</b> for " + block_name, Elements.Labels.LogEntry);
                GUILayout.EndHorizontal();
            }

            GUILayout.Box(GUIContent.none, GUILayout.Height(8));
        }