Skip to content

Commit

Permalink
Fixed fine adjust to dynamically get gizmo offsets. This fixes the br…
Browse files Browse the repository at this point in the history
…oken FineAdjust in 1.11 and is compatible with 1.10
  • Loading branch information
linuxgurugamer committed Jan 27, 2021
1 parent 06c7d0f commit 06c87dd
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 205 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ChangeLog

3.4.2
Fixed fine adjust to dynamically get gizmo offsets. This fixes the broken FineAdjust in 1.11 and is compatible with 1.10

3.4.1.1
Fixed typo in stock settings page

Expand Down
4 changes: 2 additions & 2 deletions EditorExtensionsRedux.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"VERSION": {
"MAJOR": 3,
"MINOR": 4,
"PATCH": 1,
"BUILD": 1
"PATCH": 2,
"BUILD": 0
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
2 changes: 1 addition & 1 deletion EditorExtensionsRedux/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

using System.Reflection;

[assembly: AssemblyVersion("3.4.0.3")]
[assembly: AssemblyVersion("3.4.1.1")]
134 changes: 109 additions & 25 deletions EditorExtensionsRedux/EditorExtensionsRedux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class Constants

public bool Init()
{
#if false
if (Versioning.version_major == 1 && Versioning.version_minor == 1 && Versioning.Revision == 0 /*&& Versioning.BuildID == 1024 */)
{
// SelectRoot
Expand Down Expand Up @@ -321,6 +322,7 @@ 12 ssScaling

return true;
}
#endif
#if false
if (Versioning.version_major == 1 && Versioning.version_minor == 4 && Versioning.Revision == 1)
{
Expand Down Expand Up @@ -392,6 +394,7 @@ 12 ssScaling
int c = 0;
foreach (FieldInfo FI in el.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
Log.Info("FI.Name: " + FI.Name);
switch (FI.Name)
{
case "selectedPart":
Expand Down Expand Up @@ -422,9 +425,10 @@ 12 ssScaling
if (leMethods != null)
{
c = 0;
foreach (MethodInfo FI in leMethods)
foreach (MethodInfo MI in leMethods)
{
switch (FI.Name)
Log.Info("MI.Name: " + MI.Name);
switch (MI.Name)
{
case "UpdateSymmetry":
UPDATESYMMETRY = c; break;
Expand Down Expand Up @@ -466,6 +470,9 @@ 12 ssScaling
c++;
}
}



if (SELECTEDPART == -1 ||
ST_ROOT_SELECT == -1 ||
ST_ROOT_UNSELECTED == -1 ||
Expand Down Expand Up @@ -493,6 +500,74 @@ 12 ssScaling
}
}

public class GIZMOS
{
public static bool offsetInitted = false, rotateInitted = false;
public GIZMOS(Constants c, bool doRotate = false, bool doOffset = false)

{
if (doRotate && !rotateInitted)
{
#if false
var gizmosRotate = HighLogic.FindObjectsOfType<EditorGizmos.GizmoRotate>();
if (gizmosRotate.Length == 0)
{
Log.Error("gizmosRotate.Length is 0");
return;
}
#endif
rotateInitted = true;
//var gizmoRotate = gizmosRotate[0];

MethodInfo[] egMethods = typeof(EditorGizmos.GizmoRotate).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

Log.Info("egMethods.length: " + egMethods.Length);
for (int cnt = 0; cnt < egMethods.Length; cnt++)
{
switch (egMethods[cnt].Name)
{
case "OnHandleRotateStart":
c.GIZMOROTATE_ONHANDLEROTATESTART = cnt;
break;
case "OnHandleRotate":
c.GIZMOROTATE_ONHANDLEROTATE = cnt ;
break;
case "OnHandleRotateEnd":
c.GIZMOROTATE_ONHANDLEROTATEEND = cnt;
break;
}
}
Log.Info("GIZMOROTATE_ONHANDLEROTATESTART: " + c.GIZMOROTATE_ONHANDLEROTATESTART +
", GIZMOROTATE_ONHANDLEROTATE: " + c.GIZMOROTATE_ONHANDLEROTATE +
", GIZMOROTATE_ONHANDLEROTATEEND: " + c.GIZMOROTATE_ONHANDLEROTATEEND);
}
if (doOffset && !offsetInitted)
{
MethodInfo[] egMethods = typeof(EditorGizmos.GizmoOffset).GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

offsetInitted = true;
for (int cnt = 0; cnt < egMethods.Length; cnt++)
{
switch (egMethods[cnt].Name)
{
case "OnHandleMoveStart":
c.GIZMOOFFSET_ONHANDLEMOVESTART = cnt;
break;
case "OnHandleMove":
c.GIZMOOFFSET_ONHANDLEMOVE = cnt ;
break;
case "OnHandleMoveEnd":
c.GIZMOOFFSET_ONHANDLEMOVEEND = cnt ;
break;
}
}
Log.Info("GIZMOOFFSET_ONHANDLEMOVESTART: " + c.GIZMOOFFSET_ONHANDLEMOVESTART +
", GIZMOOFFSET_ONHANDLEMOVE: " + c.GIZMOOFFSET_ONHANDLEMOVE +
", GIZMOOFFSET_ONHANDLEMOVEEND: " + c.GIZMOOFFSET_ONHANDLEMOVEEND);
}
}
}

[KSPAddon(KSPAddon.Startup.EditorAny, false)]
public partial class EditorExtensions : MonoBehaviour
{
Expand All @@ -508,7 +583,7 @@ public partial class EditorExtensions : MonoBehaviour

public NoOffsetBehaviour.FreeOffsetBehaviour fob;

#region member vars
#region member vars



Expand Down Expand Up @@ -550,7 +625,7 @@ public partial class EditorExtensions : MonoBehaviour
static int preResetSymmetryMode = 0;

static bool last_VAB_USE_ANGLE_SNAP = true;
#endregion
#endregion

// public EditorExtensions (){}

Expand Down Expand Up @@ -1279,11 +1354,15 @@ void Update()
#if true
if (_fineAdjustWindow.isEnabled())
{

Vector3 axis;
// var gizmosOffset = HighLogic.FindObjectsOfType<EditorGizmos.GizmoOffset> ();
// if (gizmosOffset.Length > 0) {
if (GizmoEvents.offsetGizmoActive)
{

new GIZMOS(c, false, true);

GizmoEvents.gizmoRotateHandle = null;
GizmoEvents.rotateGizmoActive = false;
if (EditorLogic.SelectedPart != null)
Expand Down Expand Up @@ -1384,8 +1463,11 @@ public class Config
GizmoEvents.offsetGizmoActive = false;
}
}
else

if (GizmoEvents.rotateGizmoActive)
{
new GIZMOS(c, true, false);

GizmoEvents.gizmoOffsetHandle = null;
GizmoEvents.offsetGizmoActive = false;
// var gizmosRotate = HighLogic.FindObjectsOfType<EditorGizmos.GizmoRotate> ();
Expand All @@ -1405,6 +1487,7 @@ public class Config
axis = Vector3.forward;
else
axis = Vector3.left;

Refl.Invoke(GizmoEvents.gizmosRotate[0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATESTART, GizmoEvents.gizmoRotateHandle, axis);
Refl.Invoke(GizmoEvents.gizmosRotate[0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATE, GizmoEvents.gizmoRotateHandle, axis, rotation);
Refl.Invoke(GizmoEvents.gizmosRotate[0], EditorExtensions.c.GIZMOROTATE_ONHANDLEROTATEEND, GizmoEvents.gizmoRotateHandle, axis, 0.0f);
Expand Down Expand Up @@ -1509,7 +1592,7 @@ bool IsPartNodeAttached(Part p)
return false;
}

#region Alignments
#region Alignments

void AlignToTopOfParent(Part p)
{
Expand Down Expand Up @@ -1594,7 +1677,7 @@ void MoveParts()
{
List<PartMovement> pmToDel = null;

for (int i = partMovement.Count - 1; i >= 0; i--)
for (int i = partMovement.Count - 1; i >= 0; i--)
{
PartMovement pm = partMovement[i];
try
Expand All @@ -1617,7 +1700,8 @@ void MoveParts()
pmToDel = new List<PartMovement>();
pmToDel.Add(pm);
}
} catch
}
catch
{
partMovement.Remove(pm);
}
Expand Down Expand Up @@ -1794,7 +1878,7 @@ void CenterHorizontallyOnPoint(Part p, float yDiff)
pm.startTime = Time.fixedTime;
pm.endtime = Time.fixedTime + pm.time;


pm.endPos = new Vector3(0, p.transform.localPosition.y + yDiff, 0f);
//p.transform.localPosition = new Vector3(p.transform.localPosition.x, p.transform.localPosition.y, 0f);
//p.attPos0.z = 0f;
Expand Down Expand Up @@ -1954,9 +2038,9 @@ void AlignCompoundPart(CompoundPart part, bool snapHeights)
}
}

#endregion
#endregion

#region Editor Actions
#region Editor Actions

void AddUndo()
{
Expand Down Expand Up @@ -2237,9 +2321,9 @@ bool GizmoActive()
}
}

#endregion
#endregion

#region GUI
#region GUI

//private Rect _settingsWindowRect;
GUIStyle osdLabelStyle, symmetryLabelStyle;
Expand Down Expand Up @@ -2559,15 +2643,15 @@ void MenuContent(int WindowID)
foreach (Part p in parts)
{
if (!doNotMessWithAutoStrutModes.Contains(p.autoStrutMode)) try
{
p.autoStrutMode = Part.AutoStrutMode.Grandparent;
p.ToggleAutoStrut();
}
catch(Exception e)
{
p.autoStrutMode = Part.AutoStrutMode.Off;
Debug.LogException(e);
}
{
p.autoStrutMode = Part.AutoStrutMode.Grandparent;
p.ToggleAutoStrut();
}
catch (Exception e)
{
p.autoStrutMode = Part.AutoStrutMode.Off;
Debug.LogException(e);
}
}
OSDMessage("Autostruts turned OFF for all current Parts in Vessel (except forced).");
}
Expand Down Expand Up @@ -2690,7 +2774,7 @@ void OSDMessage(string message)
ScreenMessages.PostScreenMessage(message, cfg.OnScreenMessageTime, ScreenMessageStyle.LOWER_CENTER);
}

#region Snap labels
#region Snap labels

const int FONTSIZE = 14;

Expand Down Expand Up @@ -2888,8 +2972,8 @@ private void ShowSnapLabels()
}
}

#endregion
#endregion

#endregion
#endregion
}
}
31 changes: 18 additions & 13 deletions EditorExtensionsRedux/EditorExtensionsRedux.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -9,14 +9,15 @@
<OutputType>Library</OutputType>
<RootNamespace>EditorExtensionsRedux</RootNamespace>
<AssemblyName>EditorExtensionsRedux</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<ReleaseVersion>2.0</ReleaseVersion>
<AssemblyInfoFilePath>Properties\AssemblyInfo.cs</AssemblyInfoFilePath>
<UpdateAssemblyVersion>False</UpdateAssemblyVersion>
<UpdateAssemblyFileVersion>False</UpdateAssemblyFileVersion>
<UpdateAssemblyInfoVersion>False</UpdateAssemblyInfoVersion>
<AssemblyVersionSettings>
</AssemblyVersionSettings>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
Expand Down Expand Up @@ -126,25 +127,29 @@
</ItemGroup>
<PropertyGroup>
<PostBuildEvent>
start /D D:\Users\jbb\github\EditorExtensionsRedux /WAIT deploy.bat $(TargetDir) $(TargetFileName)
set KSPDIR=$(KSPDIR)

IF "%25KSPDIR%25"=="" (

ECHO Configuration error - KSPDIR not specified in project.

if $(ConfigurationName) == Release (
ECHO Either set KSPDIR environment variable or edit BetterLoadSaveGame.Common.props

PAUSE

start /D D:\Users\jbb\github\EditorExtensionsRedux /WAIT buildRelease.bat $(TargetDir) $(TargetFileName)

GOTO DONE

)
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
set textTemplatingPath="%25ProgramFiles(x86)%25\Microsoft Visual Studio\2017\Community\Common7\IDE \texttransform.exe"

start /D $(SolutionDir) /WAIT deploy.bat $(TargetDir) $(TargetFileName) $(TargetName)

if $(ConfigurationName) == Release (

%25textTemplatingPath%25 "$(ProjectDir)AssemblyVersion.tt"</PreBuildEvent>
start /D $(SolutionDir) /WAIT buildRelease.bat $(TargetDir) $(TargetFileName) $(TargetName)

)</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>"$(DevEnvDir)\texttransform.exe" "$(ProjectDir)AssemblyVersion.tt"</PreBuildEvent>
</PropertyGroup>
</Project>
</Project>
Loading

0 comments on commit 06c87dd

Please sign in to comment.