From a4d85689c49cb011af683e180fca903489a357c3 Mon Sep 17 00:00:00 2001 From: ZiwKerman Date: Fri, 30 Sep 2016 08:55:30 +0100 Subject: [PATCH 1/3] Rough 1.2 compatibility --- .../Command/ServoController.cs | 19 +++++++--- .../InfernalRobotics/Gui/UIAssetsLoader.cs | 10 ------ .../InfernalRobotics/InfernalRobotics.csproj | 9 ----- .../InfernalRobotics/Module/ModuleIRServo.cs | 36 ++++++++++++++----- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/InfernalRobotics/InfernalRobotics/Command/ServoController.cs b/InfernalRobotics/InfernalRobotics/Command/ServoController.cs index c3ffee1d..0a8dd0ee 100644 --- a/InfernalRobotics/InfernalRobotics/Command/ServoController.cs +++ b/InfernalRobotics/InfernalRobotics/Command/ServoController.cs @@ -286,7 +286,7 @@ private void OnVesselChange(Vessel v) Logger.Log("[ServoController] OnVesselChange finished successfully", Logger.Level.Debug); } - private void OnVesselWasModified(Vessel v) + private void OnVesselPartCountModified(Vessel v) { RebuildServoGroupsFlight (); } @@ -312,7 +312,7 @@ private void Awake() if (scene == GameScenes.FLIGHT) { GameEvents.onVesselChange.Add(OnVesselChange); - GameEvents.onVesselWasModified.Add(OnVesselWasModified); + GameEvents.onVesselPartCountChanged.Add(OnVesselPartCountModified); GameEvents.onVesselLoaded.Add (OnVesselLoaded); GameEvents.onVesselDestroy.Add (OnVesselUnloaded); GameEvents.onVesselGoOnRails.Add (OnVesselUnloaded); @@ -345,7 +345,16 @@ public static void SetWheelAutoStruts(bool value, Vessel v) if (!HighLogic.LoadedSceneIsFlight) return; - var activeVesselWheels = v.FindPartModulesImplementing(); + /*foreach(var p in v.Parts) + { + if(!value) + { + p.autoStrutMode = Part.AutoStrutMode.Off; + p.UpdateAutoStrut (); + } + } +*/ + /*var activeVesselWheels = v.FindPartModulesImplementing(); foreach(var mwb in activeVesselWheels) { if (value) @@ -358,7 +367,7 @@ public static void SetWheelAutoStruts(bool value, Vessel v) mwb.autoStrut = value; - } + }*/ } @@ -407,7 +416,7 @@ private void OnDestroy() GameEvents.onVesselChange.Remove(OnVesselChange); GameEvents.onPartAttach.Remove(OnPartAttach); GameEvents.onPartRemove.Remove(OnPartRemove); - GameEvents.onVesselWasModified.Remove(OnVesselWasModified); + GameEvents.onVesselWasModified.Remove(OnVesselPartCountModified); GameEvents.onEditorShipModified.Remove(OnEditorShipModified); GameEvents.onEditorLoad.Remove(OnEditorLoad); GameEvents.onEditorRestart.Remove(OnEditorRestart); diff --git a/InfernalRobotics/InfernalRobotics/Gui/UIAssetsLoader.cs b/InfernalRobotics/InfernalRobotics/Gui/UIAssetsLoader.cs index 3f3203b8..3e2c020f 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/UIAssetsLoader.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/UIAssetsLoader.cs @@ -162,16 +162,6 @@ private void LoadBundleAssets() } - public void LoadBundleFromDisk(string path) - { - IRAssetBundle = AssetBundle.CreateFromFile(path); - - LoadBundleAssets(); - - //had to move bundle unloading further down in time due to unexplained and unreproducable on my PC issues for some users - //IRAssetBundle.Unload(false); - } - public void Start() { var assemblyFile = Assembly.GetExecutingAssembly().Location; diff --git a/InfernalRobotics/InfernalRobotics/InfernalRobotics.csproj b/InfernalRobotics/InfernalRobotics/InfernalRobotics.csproj index 188fd3b0..466bfac6 100644 --- a/InfernalRobotics/InfernalRobotics/InfernalRobotics.csproj +++ b/InfernalRobotics/InfernalRobotics/InfernalRobotics.csproj @@ -34,9 +34,6 @@ ..\..\..\KSP_LIB\Assembly-CSharp-firstpass.dll - - - @@ -51,12 +48,6 @@ ..\..\..\KSP_LIB\KSPAssets.dll - - ..\..\..\KSP_LIB\KSPCore.dll - - - ..\..\..\KSP_LIB\KSPUtil.dll - ..\..\..\KSP_LIB\UnityEngine.UI.dll diff --git a/InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs b/InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs index b518438c..9b7fa7ef 100644 --- a/InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs +++ b/InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs @@ -12,7 +12,7 @@ namespace InfernalRobotics.Module { - public class ModuleIRServo : PartModule, IRescalable + public class ModuleIRServo : PartModule, IRescalable, IJointLockState { //BEGIN Servo&Utility related KSPFields @@ -626,7 +626,7 @@ protected virtual void BuildAttachments() AttachToParent (); } - var node = part.findAttachNodeByPart (part.parent); + var node = part.FindAttachNodeByPart (part.parent); if(translateJoint && (node == null || !(node.id.Contains(bottomNode) || part.attachMode == AttachModes.SRF_ATTACH))) translateAxis *= -1; @@ -740,15 +740,25 @@ public void ConfigureInterpolator() /// true, if joint was setup, false otherwise. public virtual bool SetupJoints() { - if (JointSetupDone) - return false; - if (!rotateJoint && !translateJoint || part.attachJoint == null) { JointSetupDone = false; return false; } + if (part.attachJoint.Joint.xDrive.maximumForce > 0.0001) + { + JointSetupDone = false; + Logger.Log ("Resetting Joint", Logger.Level.Debug); + if(joint) + { + DestroyImmediate (joint); + } + } + + if (JointSetupDone) + return false; + // Catch reversed joint // Maybe there is a best way to do it? if (transform.position != part.attachJoint.Joint.connectedBody.transform.position) @@ -935,7 +945,7 @@ public virtual bool SetupJoints() // Reset default joint drives var resetDrv = new JointDrive { - mode = JointDriveMode.PositionAndVelocity, + //mode = JointDriveMode.PositionAndVelocity, positionSpring = 0, positionDamper = 0, maximumForce = 0 @@ -948,6 +958,8 @@ public virtual bool SetupJoints() part.attachJoint.Joint.zDrive = resetDrv; part.attachJoint.Joint.enableCollision = false; + + JointSetupDone = true; return true; } @@ -1052,6 +1064,11 @@ protected virtual void UpdateJointSettings(float torque, float springPower, floa EnforceJointLimits (); } + bool IJointLockState.IsJointUnlocked () + { + return true; + } + /// /// Called every FixedUpdate, reads next target position and /// updates the rotation/translation correspondingly. @@ -1294,9 +1311,10 @@ protected double GetAvailableElectricCharge() return electricChargeRequired; } PartResourceDefinition resDef = PartResourceLibrary.Instance.GetDefinition(ELECTRIC_CHARGE_RESOURCE_NAME); - var resources = new List(); - part.GetConnectedResources(resDef.id, resDef.resourceFlowMode, resources); - return resources.Count <= 0 ? 0f : resources.Sum (r => r.amount); + + double amount, maxAmount; + part.GetConnectedResourceTotals (resDef.id, resDef.resourceFlowMode, out amount, out maxAmount); + return amount; } public void Update() From 7db4a4fe4db8d4e60cc8d7f37bd8432e3cd971e3 Mon Sep 17 00:00:00 2001 From: ZiwKerman Date: Tue, 18 Oct 2016 08:09:01 +0100 Subject: [PATCH 2/3] Fix the hanging issue when deleting the first group and some visuals. --- .../InfernalRobotics/Gui/ServoDropHandler.cs | 1 + .../InfernalRobotics/Gui/WindowManager.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/InfernalRobotics/InfernalRobotics/Gui/ServoDropHandler.cs b/InfernalRobotics/InfernalRobotics/Gui/ServoDropHandler.cs index 23fd1380..8a170a32 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/ServoDropHandler.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/ServoDropHandler.cs @@ -43,6 +43,7 @@ public void onServoDrop(ServoDragHandler dragHandler) var newGroupIndex = dragHandler.dropZone.parent.GetSiblingIndex(); ServoController.MoveServo(ServoController.Instance.ServoGroups[oldGroupIndex], ServoController.Instance.ServoGroups[newGroupIndex], s); + WindowManager.guiRebuildPending = true; break; } } diff --git a/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs b/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs index 28a15878..e3ac06ec 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs @@ -1075,16 +1075,23 @@ private void InitEditorGroupControls(GameObject newServoGroupLine, ServoControll while (g.Servos.Any()) { var s = g.Servos.First(); - ServoController.MoveServo(g, ServoController.Instance.ServoGroups[0], s); + if(g != ServoController.Instance.ServoGroups[0]) + ServoController.MoveServo(g, ServoController.Instance.ServoGroups[0], s); + else + ServoController.MoveServo (g, ServoController.Instance.ServoGroups [1], s); } - ServoController.Instance.ServoGroups.Remove(g); - + g = null; RebuildUI(); + return; } }); if (ServoController.Instance.ServoGroups.Count < 2) + { groupDeleteButton.interactable = false; + groupDeleteButton.enabled = false; + } + var groupDeleteButtonTooltip = groupDeleteButton.gameObject.AddComponent(); groupDeleteButtonTooltip.tooltipText = "Delete Group"; From d6077f6c51d77a198259afcf0b67f9bbf7c1c489 Mon Sep 17 00:00:00 2001 From: ZiwKerman Date: Tue, 18 Oct 2016 11:18:55 +0100 Subject: [PATCH 3/3] Other small fixes (GroupToggles, Minor color adjustments, visual glitches) --- .../Control/Servo/ServoPreset.cs | 1 + .../InfernalRobotics/Gui/EditorCategory.cs | 2 +- .../Gui/IRBuildAid/IRBuildAidManager.cs | 4 +- .../InfernalRobotics/Gui/WindowManager.cs | 104 +++++++++++------- 4 files changed, 70 insertions(+), 41 deletions(-) diff --git a/InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs b/InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs index 2444e7de..419eeced 100644 --- a/InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs +++ b/InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs @@ -66,6 +66,7 @@ public void Save(bool symmetry = false) } module.presetPositionsSerialized = rawServo.presetPositionsSerialized; module.ParsePresetPositions(); + module.defaultPosition = rawServo.defaultPosition; //force sync the default position as well } } } diff --git a/InfernalRobotics/InfernalRobotics/Gui/EditorCategory.cs b/InfernalRobotics/InfernalRobotics/Gui/EditorCategory.cs index 6ff8e4f0..c201ce52 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/EditorCategory.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/EditorCategory.cs @@ -22,7 +22,7 @@ void Awake() private void IRCustomFilter() { const string FILTER_CATEGORY = "Filter by Function"; - const string CUSTOM_CATEGORY_NAME = "Robotic Parts"; + const string CUSTOM_CATEGORY_NAME = "Robotic"; //var texture_on = new Texture2D(36, 36, TextureFormat.RGBA32, false); //var texture_off = new Texture2D(36, 36, TextureFormat.RGBA32, false); diff --git a/InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/IRBuildAidManager.cs b/InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/IRBuildAidManager.cs index fe8d6418..c79dba01 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/IRBuildAidManager.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/IRBuildAidManager.cs @@ -17,8 +17,8 @@ public class IRBuildAidManager : MonoBehaviour public static Color endPoint1Color = new Color(1f, 1f, 0, 0.5f); public static Color endPoint2Color = new Color(1f, 1f, 0, 0.5f); - public static Color mainLineColor1 = new Color(1f, 0.85f, 0, 0.5f); - public static Color mainLineColor2 = new Color(0.85f, 1f, 0, 0.5f); + public static Color mainLineColor1 = new Color(0.88f, 0.7f, 0.188f, 0.7f); + public static Color mainLineColor2 = new Color(0.7f, 0.5f, 0, 0.5f); public static Color presetPositionsColor = new Color(1f, 1f, 1f, 0.5f); public static Color currentPositionColor = new Color(0f, 1f, 0f, 0.5f); diff --git a/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs b/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs index e3ac06ec..92d14fe6 100644 --- a/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs +++ b/InfernalRobotics/InfernalRobotics/Gui/WindowManager.cs @@ -406,8 +406,6 @@ private void InitFlightControlWindow(bool startSolid = true) foreach(var pair in _servoGroupUIControls) { pair.Key.Stop(); - pair.Key.MovingNegative = false; - pair.Key.MovingPositive = false; } guiRebuildPending = true; //TODO: we need to reset oll Movement Toggles @@ -415,6 +413,10 @@ private void InitFlightControlWindow(bool startSolid = true) var stopAllTooltip = stopAllButton.gameObject.AddComponent(); stopAllTooltip.tooltipText = "Panic! Stop all servos!"; + + //toggle preset mode if needed + ToggleFlightPresetMode (guiFlightPresetModeOn); + } private void InitFlightGroupControls(GameObject newServoGroupLine, ServoController.ControlGroup g) @@ -452,19 +454,10 @@ private void InitFlightGroupControls(GameObject newServoGroupLine, ServoControll groupMoveLeftToggle.isOn = g.MovingNegative; groupMoveLeftToggle.onValueChanged.AddListener(v => { - if (g.MovingNegative) - { - g.Stop(); - g.MovingNegative = false; - g.MovingPositive = false; - } - else - { - if(g.MovingPositive) - { - hlg.GetChild("ServoGroupMoveRightToggleButton").GetComponent().isOn = false; - } - g.MoveLeft(); + g.Stop (); + if (v) { + hlg.GetChild ("ServoGroupMoveRightToggleButton").GetComponent ().isOn = false; + g.MoveLeft (); g.MovingNegative = true; g.MovingPositive = false; } @@ -500,18 +493,10 @@ private void InitFlightGroupControls(GameObject newServoGroupLine, ServoControll groupMoveRightToggle.isOn = g.MovingPositive; groupMoveRightToggle.onValueChanged.AddListener(v => { - if (g.MovingPositive) - { - g.Stop(); - g.MovingNegative = false; - g.MovingPositive = false; - } - else + g.Stop(); + if (v) { - if (g.MovingNegative) - { - hlg.GetChild("ServoGroupMoveLeftToggleButton").GetComponent().isOn = false; - } + hlg.GetChild ("ServoGroupMoveLeftToggleButton").GetComponent ().isOn = false; g.MoveRight(); g.MovingNegative = false; g.MovingPositive = true; @@ -679,7 +664,7 @@ private void ToggleFlightPresetMode(bool value) } } - public void PresetInputOnEndEdit(string tmp, int i) + public void PresetInputOnEndEdit(string tmp, int i, GameObject buttonRef = null) { if (presetWindowServo == null) return; @@ -694,6 +679,7 @@ public void PresetInputOnEndEdit(string tmp, int i) } presetWindowServo.Preset[i] = tmpValue; presetWindowServo.Preset.Sort(); + TogglePresetEditWindow (presetWindowServo, true, buttonRef); } } @@ -731,7 +717,7 @@ public void TogglePresetEditWindow (IServo servo, bool value, GameObject buttonR //need a better way to tie them to each other _presetsWindow.transform.SetParent(UIMasterController.Instance.appCanvas.transform, false); - if (_presetsWindowPosition == Vector3.zero) + if (_presetsWindowPosition == Vector3.zero && buttonRef != null) _presetsWindow.transform.position = buttonRef.transform.position + new Vector3(30, 0, 0); else _presetsWindow.transform.position = ClampWindowPosition(_presetsWindowPosition); @@ -743,19 +729,33 @@ public void TogglePresetEditWindow (IServo servo, bool value, GameObject buttonR { closeButton.GetComponent