public void DrawAxis(Rect windowRect) { // Draw graph 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); 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)); Util.DrawRect(graphRect, Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2, graphRect.y, 1, graphRect.height), Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2 + graphRect.width / 2 * Axis.OutputValue, graphRect.y, 1, graphRect.height), Color.yellow); // Draw key mappers GUILayout.BeginHorizontal(); GUILayout.Button(new GUIContent(Axis.NegativeBind != null ? Axis.NegativeBind.Name : "None", "Key Mapper Negative"), Elements.Buttons.Red); if (GUI.tooltip == "Key Mapper Negative") { foreach (KeyValuePair <Guid, Controller> entry in Controller.Devices) { foreach (Button b in entry.Value.Buttons) { if (b.IsDown) { Axis.NegativeBind = b; } } } foreach (KeyCode key in Enum.GetValues(typeof(KeyCode))) { if (key >= KeyCode.JoystickButton0 && key <= KeyCode.Joystick8Button19) { continue; } if (UnityEngine.Input.GetKey(key)) { Axis.NegativeBind = key == KeyCode.Backspace ? null : new Key(key); break; } } } GUILayout.Button(new GUIContent(Axis.PositiveBind != null ? Axis.PositiveBind.Name : "None", "Key Mapper Positive"), Elements.Buttons.Red); if (GUI.tooltip == "Key Mapper Positive") { foreach (KeyValuePair <Guid, Controller> entry in Controller.Devices) { foreach (Button b in entry.Value.Buttons) { if (b.IsDown) { Axis.PositiveBind = b; } } } foreach (KeyCode key in Enum.GetValues(typeof(KeyCode))) { if (key >= KeyCode.JoystickButton0 && key <= KeyCode.Joystick8Button19) { continue; } if (UnityEngine.Input.GetKey(key)) { Axis.PositiveBind = key == KeyCode.Backspace ? null : new Key(key); break; } } } GUILayout.EndHorizontal(); // Draw Sensitivity slider Axis.Sensitivity = Util.DrawSlider("Sensitivity", Axis.Sensitivity, 0, 10, sens_string, out sens_string); // Draw Gravity slider Axis.Gravity = Util.DrawSlider("Gravity", Axis.Gravity, 0, 10, grav_string, out grav_string); // Draw Momentum slider Axis.Momentum = Util.DrawSlider("Momentum", Axis.Momentum, 0, 10, momn_string, out momn_string); // Draw toggles GUILayout.BeginHorizontal(); Axis.Raw = GUILayout.Toggle(Axis.Raw, "", Util.ToggleStyle, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Raw ", new GUIStyle(Elements.Labels.Default) { margin = new RectOffset(0, 0, 14, 0) }); Axis.Snap = GUILayout.Toggle(Axis.Snap, "", Util.ToggleStyle, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Snap ", new GUIStyle(Elements.Labels.Default) { margin = new RectOffset(0, 0, 14, 0) }); GUILayout.EndHorizontal(); // Set notes note = "<color=#FFFF00><b>Device disconnected</b></color>"; var disconnected = false; if (Axis.PositiveBind != null && !Axis.PositiveBind.Connected) { disconnected = true; note += "\n'" + Axis.PositiveBind.Name + "' is not connected."; } if (Axis.NegativeBind != null && !Axis.NegativeBind.Connected) { disconnected = true; note += "\n'" + Axis.NegativeBind.Name + "' is not connected."; } if (!disconnected) { note = null; } }
public void DrawAxis(Rect windowRect) { if (!PythonEnvironment.Loaded) { GUILayout.Label("<b>Additional library needed</b>\n" + "Custom axis runs on IronPython engine.\n" + "Press download to install it automatically."); if (GUILayout.Button(download_button_text) && !downloading_in_progress) { InstallIronPython(); } } else { error = null; note = null; // Draw graph GUILayout.BeginHorizontal(); string text; if (Axis.Status == AxisStatus.OK) { text = Axis.OutputValue.ToString("0.00"); } else { text = InputAxis.GetStatusString(Axis.Status); } GUILayout.Label(" <color=#808080><b>" + text + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }, GUILayout.Height(28)); 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 (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); } // Draw start/stop button if (GUILayout.Button(Axis.Running ? "STOP" : "START", new GUIStyle(Elements.Buttons.Red) { margin = new RectOffset(8, 8, 0, 0) }, GUILayout.Width(80))) { Axis.Running = !Axis.Running; } GUILayout.EndHorizontal(); // Draw initialisation code text area GUILayout.Label("Initialisation code", Util.LabelStyle); initialisationScrollPosition = GUILayout.BeginScrollView(initialisationScrollPosition, GUILayout.Height(100)); Axis.InitialisationCode = GUILayout.TextArea(Axis.InitialisationCode); GUILayout.EndScrollView(); // Draw update code text area GUILayout.Label("Update code", Util.LabelStyle); updateScrollPosition = GUILayout.BeginScrollView(updateScrollPosition, GUILayout.Height(200)); Axis.UpdateCode = GUILayout.TextArea(Axis.UpdateCode); GUILayout.EndScrollView(); // Draw Global toggle GUILayout.BeginHorizontal(); Axis.GlobalScope = GUILayout.Toggle(Axis.GlobalScope, "", Util.ToggleStyle, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Run in global scope", new GUIStyle(Elements.Labels.Default) { margin = new RectOffset(0, 0, 14, 0) }); GUILayout.EndHorizontal(); GUILayout.Box(GUIContent.none, GUILayout.Height(8)); // Display linked axes if (Axis.LinkedAxes.Count > 0) { GUILayout.Label("Linked axes", new GUIStyle(Elements.Labels.Title) { alignment = TextAnchor.MiddleCenter }); foreach (var name in Axis.LinkedAxes) { GUILayout.Label(name, new GUIStyle(Elements.Labels.Default) { alignment = TextAnchor.MiddleCenter }); } } // Display error if (Axis.Error != null) { error = "<color=#FF0000><b>Python error</b></color>\n" + Axis.Error; } } }
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); } }
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(); } }
public void DrawAxis(Rect windowRect) { // Graph rect Rect graphRect = GUILayoutUtility.GetAspectRect((float)Screen.width / (float)Screen.height); // Axis value GUI.Label(new Rect(graphRect.x, graphRect.y, graphRect.width, 20), " <color=#808080><b>" + Axis.OutputValue.ToString("0.00") + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }); // Screen size GUI.Label(new Rect(graphRect.x, graphRect.y + graphRect.height - 20, graphRect.width, 20), " <color=#808080><b>" + Screen.width + " / " + Screen.height + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleCenter }); // Screen frame Util.DrawRect(graphRect, Color.gray); float mouse_pos = Axis.Axis == global::Axis.X ? UnityEngine.Input.mousePosition.x : UnityEngine.Input.mousePosition.y; float screen_size = Axis.Axis == global::Axis.X ? Screen.width : Screen.height; float range_size = Axis.Range == 0 ? 1 : screen_size * Axis.Range / 2f; float center = screen_size / 2f + screen_size / 2f * Axis.Center; if (Axis.Axis == global::Axis.X) { // Draw range frame float frame_left = Mathf.Clamp(graphRect.width * ((center - range_size) / screen_size), 0, graphRect.width); float frame_right = Mathf.Clamp(graphRect.width * ((center + range_size) / screen_size), 0, graphRect.width); Util.DrawRect(new Rect( graphRect.x + frame_left, graphRect.y, frame_right - frame_left, graphRect.height), Color.white); // Draw center line Util.FillRect(new Rect( graphRect.x + graphRect.width * (center / screen_size), graphRect.y, 1, graphRect.height), Color.white); // Draw mouse position float line_pos = Mathf.Clamp((mouse_pos / screen_size), 0, 1); Util.FillRect(new Rect( graphRect.x + graphRect.width * line_pos, graphRect.y, 1, graphRect.height), Color.yellow); } else { // Draw range frame float frame_top = Mathf.Clamp(graphRect.height * ((screen_size - center - range_size) / screen_size), 0, graphRect.height); float frame_bottom = Mathf.Clamp(graphRect.height * ((screen_size - center + range_size) / screen_size), 0, graphRect.height); Util.DrawRect(new Rect( graphRect.x, graphRect.y + frame_top, graphRect.width, frame_bottom - frame_top), Color.white); // Draw center line Util.FillRect(new Rect( graphRect.x, graphRect.y + graphRect.height * ((screen_size - center) / screen_size), graphRect.width, 1), Color.white); // Draw mouse position float line_pos = Mathf.Clamp(((screen_size - mouse_pos) / screen_size), 0, 1); Util.FillRect(new Rect( graphRect.x, graphRect.y + graphRect.height * line_pos, graphRect.width, 1), Color.yellow); } // Draw axis toggles GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", Axis.Axis == global::Axis.X ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(80))) { Axis.Axis = global::Axis.X; } if (GUILayout.Button("Y", Axis.Axis == global::Axis.Y ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(80))) { Axis.Axis = global::Axis.Y; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Draw sliders Axis.Center = Util.DrawSlider("Center", Axis.Center, -1, 1, center_string, out center_string); Axis.Range = Util.DrawSlider("Range", Axis.Range, 0, 1, range_string, out range_string); }
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)); }
public void DrawAxis(Rect windowRect) { if (!DeviceManager.SDL_Initialized) { #if windows GUILayout.Label("<b>Additional library needed</b>\n" + "Controller axis requires SDL2 library to work.\n" + "Press download to install it automatically.\n\n"+ "<b>Platform</b>\n" + "You are using Windows version of ACM.\n"+ "If you are using some other operating system,\n"+ "download the correct version of the mod."); if (GUILayout.Button(download_button_text) && !downloading_in_progress && !DeviceManager.SDL_Installed) DeviceManager.InstallSDL(); #elif linux GUILayout.Label("<b>Additional library needed</b>\n" + "Controller axis requires SDL2 library to work.\n" + "Run the command below to install it.\n\n"+ "<b>Platform</b>\n" + "You are using Linux version of ACM.\n" + "If you are using some other operating system,\n" + "download the correct version of the mod."); GUILayout.TextField("sudo apt-get install libsdl2-2.0-0"); #elif osx GUILayout.Label("<b>Additional library needed</b>\n" + "Controller axis requires SDL2 library to work.\n" + "Download it at the link below.\n\n"+ "<b>Platform</b>\n" + "You are using OSX version of ACM.\n" + "If you are using some other operating system,\n" + "download the correct version of the mod."); if (GUILayout.Button("www.libsdl.org/download-2.0.php")) Application.OpenURL("www.libsdl.org/download-2.0.php"); #endif } else if (Controller.NumDevices == 0) { note = "<color=#FFFF00><b>No controllers connected.</b></color>\n"+ "Connect a joystick or controller to use this axis."; } else if (controller_index < 0) { note = "<color=#FFFF00><b>Associated controller not connected.</b></color>\n" + "The device this axis is bound to is not found.\n"+ "\n<b>Device GUID</b>\n" + Axis.GUID; if (GUILayout.Button("Use another controller")) { controller_index = 0; Axis.GUID = Controller.DeviceList[controller_index]; } } else { error = null; note = null; controller = Controller.Get(Axis.GUID); Axis.Axis %= controller.NumAxes; // Graph 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, windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right); // Axis value GUI.Label(new Rect(graphRect.x, graphRect.y, graphRect.width, 20), " <color=#808080><b>"+ Axis.OutputValue.ToString("0.00")+"</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }); // Draw drag controls if (Axis.OffsetX == 0 && Axis.OffsetY == 0) { GUI.Label(new Rect(graphRect.x, graphRect.y + graphRect.height - 20, graphRect.width, 20), "<color=#808080><b>DRAG TO SET OFFSET</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleCenter }); } else { GUI.Label(new Rect(graphRect.x, graphRect.y + graphRect.height - 20, (graphRect.width - 16) / 2, 20), " <color=#808080><b>X: " + Axis.OffsetX.ToString("0.00") + "\tY:" + Axis.OffsetY.ToString("0.00") + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }); if (GUI.Button(new Rect(graphRect.x + (graphRect.width - 16) / 2, graphRect.y + graphRect.height - 20, (graphRect.width - 16) / 2, 20), "<color=#808080><b>RESET OFFSET</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleRight })) { Axis.OffsetX = 0; Axis.OffsetY = 0; } } // Draw graph DrawGraph(); // Listen for drag var mousePos = UnityEngine.Input.mousePosition; mousePos.y = Screen.height - mousePos.y; var drag_handle = new Rect(windowRect.x + graphRect.x, windowRect.y + graphRect.y, graphRect.width, graphRect.height); var drag_range = (graphRect.width) / 2f; if (!dragging && UnityEngine.Input.GetMouseButtonDown(0) && drag_handle.Contains(mousePos)) { dragging = true; click_position = mousePos; click_position.x += Axis.OffsetX * drag_range; click_position.y += Axis.OffsetY * drag_range; } if (dragging) { Axis.OffsetX = Mathf.Clamp((click_position.x - mousePos.x) / drag_range, -1f, 1f); Axis.OffsetY = Mathf.Clamp((click_position.y - mousePos.y) / drag_range, -1f, 1f); if (UnityEngine.Input.GetMouseButtonUp(0)) { dragging = false; } } // Draw graph input and frame Util.DrawRect(graphRect, Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2, graphRect.y, 1, graphRect.height), Color.gray); Util.FillRect(new Rect( graphRect.x, graphRect.y + graphRect.height / 2, graphRect.width, 1), Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2 + graphRect.width / 2 * Axis.InputValue, graphRect.y, 1, graphRect.height), Color.yellow); // Draw controller selection GUILayout.BeginHorizontal(); if (GUILayout.Button("<", controller_index > 0 ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(30)) && controller_index > 0) { controller_index--; Axis.GUID = Controller.DeviceList[controller_index]; } GUILayout.Label(controller != null ? controller.Name : "<color=#FF0000>Disconnected controller</color>", new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }); if (GUILayout.Button(">", controller_index < Controller.NumDevices - 1 ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(30)) && controller_index < Controller.NumDevices - 1) { controller_index++; Axis.GUID = Controller.DeviceList[controller_index]; } if (controller == null) return; GUILayout.EndHorizontal(); // Draw axis selection GUILayout.BeginHorizontal(); if (GUILayout.Button("<", Axis.Axis > 0 ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(30)) && Axis.Axis > 0) Axis.Axis--; GUILayout.Label(controller.AxisNames[Axis.Axis], new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }); if (GUILayout.Button(">", Axis.Axis < Controller.Get(Axis.GUID).NumAxes - 1 ? Elements.Buttons.Default : Elements.Buttons.Disabled, GUILayout.Width(30)) && Axis.Axis < Controller.Get(Axis.GUID).NumAxes - 1) Axis.Axis++; GUILayout.EndHorizontal(); // Draw Sensitivity slider Axis.Sensitivity = Util.DrawSlider("Sensitivity", Axis.Sensitivity, 0, 5, sens_string, out sens_string); // Draw Curvature slider Axis.Curvature = Util.DrawSlider("Curvaure", Axis.Curvature, 0, 3, curv_string, out curv_string); // Draw Deadzone slider Axis.Deadzone = Util.DrawSlider("Deadzone", Axis.Deadzone, 0, 0.5f, dead_string, out dead_string); GUILayout.BeginHorizontal(); // Draw Invert toggle Axis.Invert = GUILayout.Toggle(Axis.Invert, "", Util.ToggleStyle, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Invert", new GUIStyle(Elements.Labels.Default) { margin = new RectOffset(0, 0, 14, 0) }); // Draw Raw toggle Axis.Smooth = GUILayout.Toggle(Axis.Smooth, "", Util.ToggleStyle, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Smooth", new GUIStyle(Elements.Labels.Default) { margin = new RectOffset(0, 0, 14, 0) }); GUILayout.EndHorizontal(); } }