Skip to content

Commit

Permalink
Fixed Fine Adjustments window (inability to close it or change the va…
Browse files Browse the repository at this point in the history
…lues)

Now saves both angle snap value and whether it was on/off after exiting editor session
Fixed issue with fine adjust translation wouldn't work if snap was on
  • Loading branch information
linuxgurugamer committed May 19, 2016
1 parent ff36be3 commit 1c589d0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 47 deletions.
16 changes: 9 additions & 7 deletions EditorExtensionsRedux.userprefs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<Properties StartupItem="Packagers\BetaPackage.mdproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
<MonoDevelop.Ide.Workbench ActiveDocument="README.md">
<MonoDevelop.Ide.Workbench ActiveDocument="EditorExtensionsRedux\Properties\AssemblyInfo.cs">
<Files>
<File FileName="EditorExtensionsRedux\Utility.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\buildRelease.bat" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Config\ConfigManager.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Logging.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\PartInfoWindow.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.version" Line="9" Column="13" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.version" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\Enums.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\StripSymmetry.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\GUIWindow.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\deploy.bat" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\StripSymmetry\ExtensionMethods.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\Config\ConfigData.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\SettingsWindow.cs" Line="1" Column="1" />
<File FileName="EditorExtensionsRedux\FineAdjustWindow.cs" Line="121" Column="22" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.cs" Line="555" Column="37" />
<File FileName="EditorExtensionsRedux\GizmoEvents.cs" Line="121" Column="41" />
<File FileName="README.md" Line="7" Column="1" />
<File FileName="EditorExtensionsRedux\Properties\AssemblyInfo.cs" Line="15" Column="1" />
<File FileName="EditorExtensionsRedux\EditorExtensionsRedux.cs" Line="542" Column="8" />
<File FileName="EditorExtensionsRedux\GizmoEvents.cs" Line="23" Column="37" />
<File FileName="README.md" Line="8" Column="88" />
<File FileName="EditorExtensionsRedux\Properties\AssemblyInfo.cs" Line="12" Column="1" />
<File FileName="EditorExtensionsRedux\FineAdjustWindow.cs" Line="276" Column="50" />
<File FileName="EditorExtensionsRedux\SelectRoot2Behaviour.cs" Line="174" Column="84" />
<File FileName="EditorExtensionsRedux\NoOffsetLimits\NoOffsetLimitsBehaviour.cs" Line="48" Column="51" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
15 changes: 14 additions & 1 deletion EditorExtensionsRedux/EditorExtensionsRedux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public class EditorExtensions : MonoBehaviour
float orgSphZoomSens = 0;
// End Fwiffo

static float lastSrfAttachAngleSnap = 15.0f;
static bool last_VAB_USE_ANGLE_SNAP = true;
#endregion

// public EditorExtensions (){}
Expand Down Expand Up @@ -265,8 +267,11 @@ public void Start ()
GameEvents.onEditorSymmetryModeChange.Add (EditorSymmetryModeChange);


editor.srfAttachAngleSnap = 0;
// editor.srfAttachAngleSnap = 0;
editor.srfAttachAngleSnap = lastSrfAttachAngleSnap;
GameSettings.VAB_USE_ANGLE_SNAP = last_VAB_USE_ANGLE_SNAP;
Log.Info ("editor.srfAttachAngleSnap: " + editor.srfAttachAngleSnap.ToString ());

}

//Unity OnDestroy
Expand Down Expand Up @@ -535,6 +540,9 @@ void Update ()
// if (gizmoOffsetHandle == null)
// gizmoOffsetHandle = HighLogic.FindObjectOfType<EditorGizmos.GizmoOffsetHandle> ();

if (GameSettings.VAB_USE_ANGLE_SNAP)
GameEvents.onEditorSnapModeChange.Fire (false);

float offset = FineAdjustWindow.Instance.offset;

Log.Info ("\nmoving part: EditorLogic.SelectedPart.attPos: " + EditorLogic.SelectedPart.attPos);
Expand Down Expand Up @@ -1106,6 +1114,7 @@ void AngleSnapCycle (bool modKeyDown, bool fineKeyDown)
editor.srfAttachAngleSnap = 0;
}


//at angle snap 0, turn off angle snap and show stock circle sprite
if (editor.srfAttachAngleSnap == 0) {
GameSettings.VAB_USE_ANGLE_SNAP = false;
Expand All @@ -1118,6 +1127,9 @@ void AngleSnapCycle (bool modKeyDown, bool fineKeyDown)
GameSettings.VAB_USE_ANGLE_SNAP = true;
}

lastSrfAttachAngleSnap = editor.srfAttachAngleSnap;
last_VAB_USE_ANGLE_SNAP = GameSettings.VAB_USE_ANGLE_SNAP;

updateGizmoSnaps ();
// Fwiffo
// Fix offset gizmo if shown
Expand Down Expand Up @@ -1397,6 +1409,7 @@ void AdjustSnapLocations ()
} else {
// GameSettings.VAB_USE_ANGLE_SNAP = true;
}
last_VAB_USE_ANGLE_SNAP = GameSettings.VAB_USE_ANGLE_SNAP;

//symmetry & angle sprite/label size and position
symmetryLabelStyle.fontSize = (int)Math.Round (FONTSIZE * GameSettings.UI_SCALE);
Expand Down
75 changes: 40 additions & 35 deletions EditorExtensionsRedux/FineAdjustWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public bool isEnabled()
void CloseWindow ()
{
this.enabled = false;

Log.Info ("CloseWindow enabled: " + this.enabled.ToString ());
}

void OnDisable ()
Expand All @@ -54,7 +54,7 @@ void OnDisable ()

void OnGUI ()
{
if (this.enabled) {
if (isEnabled() ) {
_windowTitle = string.Format ("Fine Adjustments");
var tstyle = new GUIStyle (GUI.skin.window);

Expand All @@ -79,6 +79,7 @@ enum AdjustmentType


AdjustmentType adjType = AdjustmentType.translation;
string adjTypeStr = "Translation";
public float offset = 0.01f;
public float rotation = 1.0f;
public int offsetDeltaIndex = 2;
Expand All @@ -101,9 +102,10 @@ float getDelta(int i) {
// private string[] _toolbarStrings = { "Translation", "Rotation" };
// int toolbarInt = 0;


void WindowContent (int windowID)
{
string adjTypeStr = "";

//GUI.skin = HighLogic.Skin;
var lstyle = new GUIStyle (GUI.skin.label);
//var errstyle = new GUIStyle (GUI.skin.label);
Expand All @@ -117,8 +119,9 @@ void WindowContent (int windowID)
puc = activePuc;
else
puc = EditorLogic.SelectedPart; //Utility.GetPartUnderCursor ();

// toolbarInt = GUILayout.Toolbar (toolbarInt, _toolbarStrings);
adjTypeStr = "None";
//adjTypeStr = "None";
if (GizmoEvents.offsetGizmoActive) {
adjType = AdjustmentType.translation;
adjTypeStr = "Translation";
Expand All @@ -134,9 +137,9 @@ void WindowContent (int windowID)
GUILayout.EndHorizontal ();


GUI.DragWindow ();
if (!GizmoEvents.offsetGizmoActive && !GizmoEvents.rotateGizmoActive)
return;

// if (!GizmoEvents.offsetGizmoActive && !GizmoEvents.rotateGizmoActive)
// return;

GUILayout.BeginHorizontal ();
GUILayout.Label ("Current Part:", lstyle);
Expand Down Expand Up @@ -196,54 +199,56 @@ void WindowContent (int windowID)


GUILayout.BeginHorizontal ();
if (adjType != AdjustmentType.translation || puc != EditorLogic.RootPart)
GUILayout.Label (adjTypeStr + " amount:", lstyle, GUILayout.MinWidth (150));
if (GUILayout.Button ("-", GUILayout.Width (20))) {
switch (adjType) {
case AdjustmentType.rotation:
rotation -= getDelta(rotationdeltaIndex);
if (rotation <= 0.0f)
rotation = getDelta(rotationdeltaIndex);
if (adjType != AdjustmentType.translation || puc != EditorLogic.RootPart) {
GUILayout.Label (adjTypeStr + " amount:", lstyle, GUILayout.MinWidth (150));
if (GUILayout.Button ("-", GUILayout.Width (20))) {
switch (adjType) {
case AdjustmentType.rotation:
rotation -= getDelta (rotationdeltaIndex);
if (rotation <= 0.0f)
rotation = getDelta (rotationdeltaIndex);

break;
case AdjustmentType.translation:
offset -= getDelta(offsetDeltaIndex);
if (offset <= 0.0f)
offset = getDelta(offsetDeltaIndex);
break;
case AdjustmentType.translation:
offset -= getDelta (offsetDeltaIndex);
if (offset <= 0.0f)
offset = getDelta (offsetDeltaIndex);

break;
break;
}
}
}
switch (adjType) {
case AdjustmentType.rotation:
GUILayout.Label (rotation.ToString (), "TextField");
break;
case AdjustmentType.translation:
GUILayout.Label (offset.ToString (), "TextField");
break;
}

if (GUILayout.Button ("+", GUILayout.Width (20))) {
switch (adjType) {
case AdjustmentType.rotation:
rotation += getDelta(rotationdeltaIndex);
GUILayout.Label (rotation.ToString (), "TextField");
break;
case AdjustmentType.translation:
offset += getDelta(offsetDeltaIndex);
GUILayout.Label (offset.ToString (), "TextField");
break;
}

if (GUILayout.Button ("+", GUILayout.Width (20))) {
switch (adjType) {
case AdjustmentType.rotation:
rotation += getDelta (rotationdeltaIndex);
break;
case AdjustmentType.translation:
offset += getDelta (offsetDeltaIndex);
break;
}

}
}
GUILayout.EndHorizontal ();

GUILayout.BeginHorizontal ();
if (GUILayout.Button ("Done")) {
Log.Info ("Done");
fineAdjustActive = false;
InputLockManager.RemoveControlLock ("EEX_FA");
CloseWindow ();
}
GUILayout.EndHorizontal ();

GUI.DragWindow ();
}


Expand Down
2 changes: 1 addition & 1 deletion EditorExtensionsRedux/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("3.2.12.*")]
[assembly: AssemblyVersion("3.2.13.*")]

3 changes: 0 additions & 3 deletions EditorExtensionsRedux/SelectRoot2Behaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public void Start() {
};
st_root_select.OnEnter += fixAlreadyHoveringPartFn;
OnCleanup += () => {
Log.Info("SelectRoot OnCleanup 1");
st_root_select.OnEnter -= fixAlreadyHoveringPartFn;
};

Expand All @@ -106,7 +105,6 @@ public void Start() {

st_root_select.OnEnter += postNewMessageFn;
OnCleanup += () => {
Log.Info("SelectRoot OnCleanup 2");
st_root_select.OnEnter -= postNewMessageFn;
};

Expand Down Expand Up @@ -174,7 +172,6 @@ private void InjectEvent(KFSMState state, KFSMEvent injectedEvent) {
state.AddEvent(injectedEvent);
OnCleanup += () => {
// ((List<KFSMEvent>)Refl.GetValue(state, "stateEvents")).Remove(injectedEvent);
Log.Info("SelectRoot OnCleanup 3");
// List<KFSMState> kfsmstatelist = (List<KFSMState>)Refl.GetValue(state, GET_STATEEVENTS);
#if false
foreach(var kfsmstate in kfsmstatelist)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
##
##

## Changes in 3.2.13
Fixed Fine Adjustments window (inability to close it or change the values)
Now saves both angle snap value and whether it was on/off after exiting editor session

## Changes in 3.2.12
Fixed rotation gizmo to not angle snap when anglesnap is off
Replaced code which did FindObjectsOftype with GizmoEvents class for performance improvement
Expand Down

0 comments on commit 1c589d0

Please sign in to comment.