Exemple #1
0
        public void OnKISAction(Dictionary <string, object> eventData)
        {
            var action  = eventData["action"].ToString();
            var tgtPart = eventData["targetPart"] as Part;
            var tgtNode = eventData["targetNode"] as AttachNode;

            if (action == "Store")
            {
                if (winchConnected)
                {
                    winchConnected.UnplugHead(false);
                }
            }
            if (action == "DropEnd")
            {
                if (winchConnected)
                {
                    winchConnected.cableJointLength = winchConnected.cableRealLenght;
                    winchConnected.PlugHead(this, KASModuleWinch.PlugState.PlugDocked, false, false, true);
                }
            }
            if (action == "AttachStart")
            {
                if (tgtNode != null)
                {
                    KASModuleWinch moduleWinch = tgtNode.owner.GetComponent <KASModuleWinch>();
                    if (moduleWinch && winchConnected &&
                        moduleWinch.headState == KASModuleWinch.PlugState.Deployed &&
                        tgtNode.id == moduleWinch.connectedPortNodeName)
                    {
                        winchConnected.UnplugHead(false);
                        return;
                    }
                }
            }
            if (action == "AttachEnd")
            {
                if (winchConnected)
                {
                    winchConnected.cableJointLength = winchConnected.cableRealLenght;
                }
                if (tgtNode != null)
                {
                    KASModuleWinch moduleWinch = tgtNode.owner.GetComponent <KASModuleWinch>();
                    if (moduleWinch && moduleWinch.headState == KASModuleWinch.PlugState.Deployed &&
                        tgtNode.id == moduleWinch.connectedPortNodeName)
                    {
                        moduleWinch.PlugHead(this, KASModuleWinch.PlugState.PlugDocked, alreadyDocked: true);
                        StartCoroutine(WaitAndRemoveJoint());
                    }
                }
            }
        }
Exemple #2
0
        public void OnKISAction(BaseEventData baseEventData)
        {
            string     action  = baseEventData.GetString("action");
            Part       tgtPart = (Part)baseEventData.Get("targetPart");
            AttachNode tgtNode = (AttachNode)baseEventData.Get("targetNode");

            if (action == "Store")
            {
                if (winchConnected)
                {
                    winchConnected.UnplugHead(false);
                }
            }
            if (action == "DropEnd")
            {
                if (winchConnected)
                {
                    winchConnected.cableJointLength = winchConnected.cableRealLenght;
                    winchConnected.PlugHead(this, KASModuleWinch.PlugState.PlugDocked, false, false, true);
                }
            }
            if (action == "AttachStart")
            {
                if (tgtNode != null)
                {
                    KASModuleWinch moduleWinch = tgtNode.owner.GetComponent <KASModuleWinch>();
                    if (moduleWinch && winchConnected &&
                        moduleWinch.headState == KASModuleWinch.PlugState.Deployed &&
                        tgtNode.id == moduleWinch.connectedPortNodeName)
                    {
                        winchConnected.UnplugHead(false);
                        return;
                    }
                }
            }
            if (action == "AttachEnd")
            {
                if (winchConnected)
                {
                    winchConnected.cableJointLength = winchConnected.cableRealLenght;
                }
                if (tgtNode != null)
                {
                    KASModuleWinch moduleWinch = tgtNode.owner.GetComponent <KASModuleWinch>();
                    if (moduleWinch && moduleWinch.headState == KASModuleWinch.PlugState.Deployed &&
                        tgtNode.id == moduleWinch.connectedPortNodeName)
                    {
                        moduleWinch.PlugHead(this, KASModuleWinch.PlugState.PlugDocked, alreadyDocked: true);
                        StartCoroutine(WaitAndRemoveJoint());
                    }
                }
            }
        }
Exemple #3
0
        public void ContextMenuPlugDocked()
        {
            KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);

            if (winchModule)
            {
                winchModule.PlugHead(this, KASModuleWinch.PlugState.PlugDocked);
            }
            else
            {
                ScreenMessages.PostScreenMessage("You didn't have anything to plug !", 5, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Exemple #4
0
        void OnGUI()
        {
            if (!clickedWinch)
            {
                return;
            }

            GUI.skin = HighLogic.Skin;
            GUI.skin.label.alignment  = TextAnchor.MiddleCenter;
            GUI.skin.button.alignment = TextAnchor.MiddleCenter;

            guiButtonStyle = new GUIStyle(GUI.skin.button);
            guiButtonStyle.normal.textColor   = guiButtonStyle.focused.textColor = Color.white;
            guiButtonStyle.hover.textColor    = guiButtonStyle.active.textColor = Color.yellow;
            guiButtonStyle.onNormal.textColor = guiButtonStyle.onFocused.textColor = guiButtonStyle.onHover.textColor = guiButtonStyle.onActive.textColor = Color.green;
            guiButtonStyle.padding            = new RectOffset(4, 4, 4, 4);
            guiButtonStyle.alignment          = TextAnchor.MiddleCenter;

            Vector3 headScreenPoint = Camera.main.WorldToScreenPoint(clickedWinch.headTransform.position);

            GUILayout.BeginArea(new Rect(headScreenPoint.x, Screen.height - headScreenPoint.y, 200, 200));
            GUILayout.BeginVertical();

            if (clickedWinch.evaHolderPart)
            {
                if (GUILayout.Button("Drop (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.DropHead();;
                    clickedWinch = null;
                }
            }
            else
            {
                if (GUILayout.Button("Grab (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f)))
                {
                    clickedWinch.GrabHead(FlightGlobals.ActiveVessel);
                    clickedWinch = null;
                }
                if (clickedWinch)
                {
                    if (clickedWinch.headState == KASModuleWinch.PlugState.Deployed)
                    {
                        KASModuleGrab grabbedModule = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);
                        if (grabbedModule)
                        {
                            KASModulePort grabbedPort = grabbedModule.GetComponent <KASModulePort>();
                            if (grabbedPort)
                            {
                                if (GUILayout.Button("Plug grabbed", guiButtonStyle, GUILayout.Width(100f)))
                                {
                                    grabbedModule.Drop();
                                    grabbedPort.transform.rotation = Quaternion.FromToRotation(grabbedPort.portNode.forward, -clickedWinch.headPortNode.forward) * grabbedPort.transform.rotation;
                                    grabbedPort.transform.position = grabbedPort.transform.position - (grabbedPort.portNode.position - clickedWinch.headPortNode.position);
                                    clickedWinch.PlugHead(grabbedPort, KASModuleWinch.PlugState.PlugDocked);
                                    clickedWinch = null;
                                }
                            }
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
Exemple #5
0
        public void Drop()
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);
                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA)
                {
                    this.part.decouple();
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = false;
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.transform.parent          = null;
                this.part.rigidbody.isKinematic     = false;
                this.part.physicalSignificance      = Part.PhysicalSignificance.FULL;
                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");
                        grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                    }
                }

                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }
Exemple #6
0
        public void Drop(bool forAttach = false)
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);

                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA || grab_pending)
                {
                    this.part.decouple();
                }

                if (grab_pending)
                {
                    Destroy(evaNodeTransform.gameObject);
                    evaNodeTransform    = null;
                    evaHolderVesselName = null;
                    evaHolderPart       = null;
                    grabbed             = grab_pending = false;
                    RefreshContextMenu();
                    return;
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = (keepTriggers != null && keepTriggers.Contains(col));
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                KAS_Shared.ResetCollisionEnhancer(this.part);

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule && grabbedWinchHead.grabbedPortModule.part == part)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");

                        if (forAttach)
                        {
                            // Docked causes big problems when the part is later coupled
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugUndocked, fireSound: false);
                        }
                        else
                        {
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                        }
                    }
                }

                GameEvents.onCrewBoardVessel.Remove(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel));

                syncGrab            = false;
                keepTriggers        = null;
                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = grab_pending = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }