From 9b364db8d78019c0a0e2861897e0acca3483ccd2 Mon Sep 17 00:00:00 2001 From: Jonathan Bayer Date: Sat, 14 May 2016 21:10:28 -0400 Subject: [PATCH] Removed old code from the FineAdjust Update function which was causing an exception Reduced height of popup menu Fixed bug where clicking on the symmetry sprite (the one which changes the angle snap degrees) when the angle was zero would not allow surface attachments to anything other than the +z axis: "I can place the battery only on the +z axis of the structure. I cannot place it on -z, +x, -x" Removed performance issue when Fine Adjustments window was shown Reduced performance impact when fine adjustments are being done --- EditorExtensionsRedux.userprefs | 18 +- .../EditorExtensionsRedux.cs | 167 ++++++++++-------- .../EditorExtensionsRedux.csproj | 2 +- EditorExtensionsRedux/FineAdjustWindow.cs | 95 ++++++---- EditorExtensionsRedux/deploy.bat | 4 +- README.md | 7 + 6 files changed, 168 insertions(+), 125 deletions(-) diff --git a/EditorExtensionsRedux.userprefs b/EditorExtensionsRedux.userprefs index 0320391..85ccb68 100755 --- a/EditorExtensionsRedux.userprefs +++ b/EditorExtensionsRedux.userprefs @@ -1,13 +1,13 @@  - - + + - + - + - + @@ -16,11 +16,11 @@ - + - - - + + + diff --git a/EditorExtensionsRedux/EditorExtensionsRedux.cs b/EditorExtensionsRedux/EditorExtensionsRedux.cs index 369e528..a803ff8 100755 --- a/EditorExtensionsRedux/EditorExtensionsRedux.cs +++ b/EditorExtensionsRedux/EditorExtensionsRedux.cs @@ -390,6 +390,8 @@ void InitConfig () } } + EditorGizmos.GizmoOffsetHandle gizmoOffsetHandle = null; + EditorGizmos.GizmoRotateHandle gizmoRotateHandle = null; //Unity update void Update () { @@ -523,14 +525,16 @@ void Update () if (_fineAdjustWindow.isEnabled ()) { Vector3 axis; - if (HighLogic.FindObjectsOfType ().Length > 0) { + var gizmosOffset = HighLogic.FindObjectsOfType (); + if (gizmosOffset.Length > 0) { + gizmoRotateHandle = null; if (EditorLogic.SelectedPart != null) { - var gizmosOffset = HighLogic.FindObjectsOfType (); - var gizmoOffsetHandle = HighLogic.FindObjectOfType (); + //var gizmosOffset = HighLogic.FindObjectsOfType (); + if (gizmoOffsetHandle == null) + gizmoOffsetHandle = HighLogic.FindObjectOfType (); float offset = FineAdjustWindow.Instance.offset; - Log.Info ("\nmoving part: EditorLogic.SelectedPart.attPos: " + EditorLogic.SelectedPart.attPos); Log.Info ("moving part: EditorLogic.SelectedPart.attPos0: " + EditorLogic.SelectedPart.attPos0); /* @@ -550,13 +554,13 @@ public class Config */ - if (Input.GetKey(cfg.KeyMap.Down)) { - axis = Vector3.down; + if (Input.GetKey (cfg.KeyMap.Down)) { + axis = Vector3.down; Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVESTART, gizmoOffsetHandle, axis); Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVE, gizmoOffsetHandle, axis, offset); Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVEEND, gizmoOffsetHandle, axis, 0.0f); } - if (Input.GetKey (cfg.KeyMap.Up)) { + if (Input.GetKey (cfg.KeyMap.Up)) { axis = Vector3.up; Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVESTART, gizmoOffsetHandle, axis); Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVE, gizmoOffsetHandle, axis, offset); @@ -564,8 +568,8 @@ public class Config } if (Input.GetKey (cfg.KeyMap.Left)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.forward; + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.forward; else axis = Vector3.right; Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVESTART, gizmoOffsetHandle, axis); @@ -573,8 +577,8 @@ public class Config Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVEEND, gizmoOffsetHandle, axis, 0.0f); } if (Input.GetKey (cfg.KeyMap.Right)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.back; + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.back; else axis = Vector3.left; Refl.Invoke (gizmosOffset [0], EditorExtensions.c.GIZMOOFFSET_ONHANDLEMOVESTART, gizmoOffsetHandle, axis); @@ -584,7 +588,7 @@ public class Config } if (Input.GetKey (cfg.KeyMap.Forward)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) + if (EditorDriver.editorFacility == EditorFacility.VAB) axis = Vector3.right; else axis = Vector3.back; @@ -594,7 +598,7 @@ public class Config } if (Input.GetKey (cfg.KeyMap.Back)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) + if (EditorDriver.editorFacility == EditorFacility.VAB) axis = Vector3.left; else axis = Vector3.forward; @@ -605,68 +609,76 @@ public class Config } } - } - - - if (HighLogic.FindObjectsOfType ().Length > 0) { - if (EditorLogic.SelectedPart != null) { - var gizmosRotate = HighLogic.FindObjectsOfType (); - var gizmoRotateHandle = HighLogic.FindObjectOfType (); - float rotation = FineAdjustWindow.Instance.rotation; - - if (Input.GetKey (cfg.KeyMap.Down)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.forward; - else - axis = Vector3.left; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - } - if (Input.GetKey (cfg.KeyMap.Up)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.back; - else - axis = Vector3.right; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - } - if (Input.GetKey (cfg.KeyMap.Left)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.right; - else - axis = Vector3.forward; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - } - if (Input.GetKey (cfg.KeyMap.Right)) { - if (EditorDriver.editorFacility == EditorFacility.VAB) - axis = Vector3.left; - else - axis = Vector3.back; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - - } - if (Input.GetKey (cfg.KeyMap.Forward)) { + else + gizmoOffsetHandle = null; + } else { + gizmoOffsetHandle = null; + var gizmosRotate = HighLogic.FindObjectsOfType (); + if (gizmosRotate.Length > 0) { + if (EditorLogic.SelectedPart != null) { + //var gizmosRotate = HighLogic.FindObjectsOfType (); + if (gizmoRotateHandle == null) + gizmoRotateHandle = HighLogic.FindObjectOfType (); + float rotation = FineAdjustWindow.Instance.rotation; + + if (Input.GetKey (cfg.KeyMap.Down)) { + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.forward; + else + axis = Vector3.left; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + } + if (Input.GetKey (cfg.KeyMap.Up)) { + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.back; + else + axis = Vector3.right; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + } + if (Input.GetKey (cfg.KeyMap.Left)) { + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.right; + else + axis = Vector3.forward; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + } + if (Input.GetKey (cfg.KeyMap.Right)) { + if (EditorDriver.editorFacility == EditorFacility.VAB) + axis = Vector3.left; + else + axis = Vector3.back; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + + } + if (Input.GetKey (cfg.KeyMap.Forward)) { - axis = Vector3.up; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - - } - if (Input.GetKey (cfg.KeyMap.Back)) { - axis = Vector3.down; - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); - Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); - + axis = Vector3.up; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + + } + if (Input.GetKey (cfg.KeyMap.Back)) { + axis = Vector3.down; + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, gizmoRotateHandle, axis); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, gizmoRotateHandle, axis, rotation); + Refl.Invoke (gizmosRotate [0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, gizmoRotateHandle, axis, 0.0f); + + } } + else + gizmoRotateHandle = null; } + else + gizmoRotateHandle = null; } } @@ -1081,7 +1093,7 @@ void AngleSnapCycle (bool modKeyDown, bool fineKeyDown) editor.srfAttachAngleSnap = 0; } - //at angle snap 0, turn off angle snap and show stock circle sprite +//at angle snap 0, turn off angle snap and show stock circle sprite if (editor.srfAttachAngleSnap == 0) { GameSettings.VAB_USE_ANGLE_SNAP = false; } else { @@ -1199,7 +1211,7 @@ public void SettingsWindowClosed () bool _showMenu = false; Rect _menuRect = new Rect (); const float _menuWidth = 100.0f; - const float _menuHeight = 105.0f; + const float _menuHeight = 100.0f; const int _toolbarHeight = 42; //37 @@ -1358,6 +1370,12 @@ void OSDMessage (string message) void AdjustSnapLocations () { + if (editor.srfAttachAngleSnap == 0) { + GameSettings.VAB_USE_ANGLE_SNAP = false; + } else { + GameSettings.VAB_USE_ANGLE_SNAP = true; + } + //symmetry & angle sprite/label size and position symmetryLabelStyle.fontSize = (int)Math.Round (FONTSIZE * GameSettings.UI_SCALE); osdLabelStyle.fontSize = (int)Math.Round (22 * GameSettings.UI_SCALE); @@ -1428,6 +1446,7 @@ private void ShowSnapLabels () } else if (editor.symmetryMethod == SymmetryMethod.Mirror) { symmetryLabelValue = (editor.symmetryMode == 0) ? "M" : "MM"; } +// Log.Info ("ShowSnapLabels disabling sprites, GameSettings.VAB_USE_ANGLE_SNAP: " + GameSettings.VAB_USE_ANGLE_SNAP.ToString()); //always hide stock symmetry and mirror sprites editor.symmetrySprite.gameObject.SetActive (false); diff --git a/EditorExtensionsRedux/EditorExtensionsRedux.csproj b/EditorExtensionsRedux/EditorExtensionsRedux.csproj index 2b7c4ad..1e0dc6c 100755 --- a/EditorExtensionsRedux/EditorExtensionsRedux.csproj +++ b/EditorExtensionsRedux/EditorExtensionsRedux.csproj @@ -36,7 +36,7 @@ false - + diff --git a/EditorExtensionsRedux/FineAdjustWindow.cs b/EditorExtensionsRedux/FineAdjustWindow.cs index 4007d59..103271e 100755 --- a/EditorExtensionsRedux/FineAdjustWindow.cs +++ b/EditorExtensionsRedux/FineAdjustWindow.cs @@ -21,7 +21,7 @@ public class FineAdjustWindow : MonoBehaviour void Awake () { Log.Debug ("FineAdjustWindow Awake()"); - CloseWindow (); + this.enabled = false; Instance = this; } @@ -49,6 +49,7 @@ void CloseWindow () void OnDisable () { + } void OnGUI () @@ -73,6 +74,7 @@ enum AdjustmentType }; Part activePuc; + Part oldActivePuc; bool fineAdjustActive = false; @@ -96,6 +98,9 @@ float getDelta(int i) { return 0.1f; } + private string[] _toolbarStrings = { "Translation", "Rotation" }; + int toolbarInt = 0; + void WindowContent (int windowID) { string adjTypeStr = ""; @@ -103,43 +108,52 @@ void WindowContent (int windowID) var lstyle = new GUIStyle (GUI.skin.label); //var errstyle = new GUIStyle (GUI.skin.label); //errstyle.normal.textColor = Color.red; - if (fineAdjustActive && (DateTime.Now.Second % 2 == 0) ) { + if (fineAdjustActive && (DateTime.Now.Second % 2 == 0) ) { lstyle.normal.textColor = Color.yellow; } - Part puc = null, sp = EditorLogic.SelectedPart; - /* if (sp == null) */ { - if (fineAdjustActive) - puc = activePuc; - else - puc = EditorLogic.SelectedPart; //Utility.GetPartUnderCursor (); - - GUILayout.BeginHorizontal (); - GUILayout.Label ("Adjustment Type: ", lstyle); + Part puc = null; + + if (fineAdjustActive) + puc = activePuc; + else + puc = EditorLogic.SelectedPart; //Utility.GetPartUnderCursor (); + toolbarInt = GUILayout.Toolbar (toolbarInt, _toolbarStrings); + if (toolbarInt == 0) { + adjType = AdjustmentType.translation; + adjTypeStr = "Translation"; + } else { + adjType = AdjustmentType.rotation; + adjTypeStr = "Rotation"; + } + #if false + GUILayout.BeginHorizontal (); + GUILayout.Label ("Adjustment Type: ", lstyle); - if (HighLogic.FindObjectsOfType ().Length > 0){ - adjType = AdjustmentType.translation; - adjTypeStr = "Translation"; - } - if (HighLogic.FindObjectsOfType ().Length > 0){ - adjType = AdjustmentType.rotation; - adjTypeStr = "Rotation"; - } + if (HighLogic.FindObjectsOfType ().Length > 0){ + adjType = AdjustmentType.translation; + adjTypeStr = "Translation"; + } + if (HighLogic.FindObjectsOfType ().Length > 0){ + adjType = AdjustmentType.rotation; + adjTypeStr = "Rotation"; + } + GUILayout.Label (adjTypeStr, lstyle); - GUILayout.Label (adjTypeStr, lstyle); - GUILayout.EndHorizontal (); + GUILayout.EndHorizontal (); - GUILayout.BeginHorizontal (); - GUILayout.Label ("Current Part:", lstyle); - GUILayout.Label (puc ? puc.name : "none", lstyle); - GUILayout.EndHorizontal (); - GUILayout.BeginHorizontal (); - GUILayout.Label ("Symmetry Method: ", lstyle); - if (puc != null) - GUILayout.Label (puc.symMethod.ToString ()); - GUILayout.EndHorizontal (); - } + #endif + + GUILayout.BeginHorizontal (); + GUILayout.Label ("Current Part:", lstyle); + GUILayout.Label (puc ? puc.name : "none", lstyle); + GUILayout.EndHorizontal (); + GUILayout.BeginHorizontal (); + GUILayout.Label ("Symmetry Method: ", lstyle); + if (puc != null) + GUILayout.Label (puc.symMethod.ToString ()); + GUILayout.EndHorizontal (); GUILayout.BeginHorizontal (); if (adjType != AdjustmentType.translation || puc != EditorLogic.RootPart) { @@ -240,19 +254,22 @@ void WindowContent (int windowID) } - Vector3 origAttPos0, origLocalPosition; - Quaternion origAttRotation0; - - void Update () + void LateUpdate () { - Part sp = EditorLogic.SelectedPart; + //Part sp = EditorLogic.SelectedPart; /* if (sp == null) */ { if (!fineAdjustActive) { activePuc = EditorLogic.SelectedPart; //Utility.GetPartUnderCursor (); - origAttPos0 = activePuc.attPos0; - origLocalPosition = activePuc.transform.localScale; - origAttRotation0 = activePuc.attRotation0; + if (activePuc != oldActivePuc) { + oldActivePuc = activePuc; + if (HighLogic.FindObjectsOfType ().Length > 0) { + toolbarInt = 0; + } + if (HighLogic.FindObjectsOfType ().Length > 0) { + toolbarInt = 1; + } + } } if (activePuc != null) { diff --git a/EditorExtensionsRedux/deploy.bat b/EditorExtensionsRedux/deploy.bat index 5e2d729..0b6fa66 100755 --- a/EditorExtensionsRedux/deploy.bat +++ b/EditorExtensionsRedux/deploy.bat @@ -22,7 +22,7 @@ set d=%H%\Gamedata\EditorExtensionsRedux if exist %d% goto three mkdir %d% :three -set d=%H%\Gamedata\EditorExtensionsRedux\Plugin +set d=%H%\Gamedata\EditorExtensionsRedux\Plugins if exist %d% goto four mkdir %d% :four @@ -42,7 +42,7 @@ mkdir %d% -copy /Y "%~dp0bin\Debug\EditorExtensionsRedux.dll" "%H%\GameData\EditorExtensionsRedux\Plugin" +copy /Y "%~dp0bin\Debug\EditorExtensionsRedux.dll" "%H%\GameData\EditorExtensionsRedux\Plugins" copy /Y "%~dp0bin\Debug\Textures\*.png" "%H%\GameData\EditorExtensionsRedux\Textures" copy /Y "%~dp0bin\Debug\EditorExtensionsRedux.version" "%H%\GameData\EditorExtensionsRedux" diff --git a/README.md b/README.md index 43cd467..6126412 100755 --- a/README.md +++ b/README.md @@ -3,6 +3,13 @@ ## ## +## Changes in 3.2.9 + Removed old code from the FineAdjust Update function which was causing an exception + Reduced height of popup menu + Fixed bug where clicking on the symmetry sprite (the one which changes the angle snap degrees) when the angle was zero + would not allow surface attachments to anything other than the +z axis: + "I can place the battery only on the +z axis of the structure. I cannot place it on -z, +x, -x" + ## Changes in 3.2.8 Added code from Fwiffo to fix bug where changing the angle snap while in rotate mode would not affect the rotate gizmo Added code from Fwiffo for Rapid Zoom