Пример #1
0
 public void Drop(Part part, Part fromPart)
 {
     if (!KISAddonPointer.isRunning)
     {
         ModuleKISPickup pickupModule = GetActivePickupNearest(fromPart);
         if (pickupModule)
         {
             KISAddonPointer.allowPart  = KISAddonPointer.allowEva = KISAddonPointer.allowMount = KISAddonPointer.allowStatic = true;
             KISAddonPointer.allowStack = pickupModule.allowPartStack;
             KISAddonPointer.maxDist    = pickupModule.maxDistance;
             if (draggedItem != null)
             {
                 KISAddonPointer.scale = draggedItem.GetScale();
             }
             else
             {
                 KISAddonPointer.scale = 1;
             }
             KISAddonPointer.StartPointer(part, OnPointerAction, OnPointerState, pickupModule.transform);
             pointerMode = PointerMode.Drop;
         }
         else
         {
             KIS_Shared.DebugError("No active pickup nearest !");
         }
     }
     KISAddonCursor.StopPartDetection();
 }
Пример #2
0
 void OnMouseGrabExitPart(Part p)
 {
     if (grabActive)
     {
         KISAddonCursor.CursorEnable("KIS/Textures/grab", "Grab", "");
     }
     else
     {
         KISAddonCursor.CursorDefault();
     }
     p.SetHighlight(false, false);
     grabOk = false;
 }
Пример #3
0
 void OnVesselChange(Vessel vesselChange)
 {
     if (KISAddonPointer.isRunning)
     {
         KISAddonPointer.StopPointer();
     }
     grabActive  = false;
     draggedItem = null;
     draggedPart = null;
     movingPart  = null;
     KISAddonCursor.StopPartDetection();
     KISAddonCursor.CursorDefault();
 }
Пример #4
0
 public void DisableGrabMode()
 {
     if (!KISAddonPointer.isRunning)
     {
         List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>();
         if (pickupModules.Count > 0)
         {
             if (!draggedPart)
             {
                 grabActive = false;
                 KISAddonCursor.StopPartDetection();
                 KISAddonCursor.CursorDefault();
             }
         }
     }
 }
Пример #5
0
 public void EnableGrabMode()
 {
     if (!KISAddonPointer.isRunning)
     {
         List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>();
         // Grab only if pickup module is present on vessel
         if (pickupModules.Count > 0)
         {
             if (!draggedPart)
             {
                 KISAddonCursor.StartPartDetection(OnMouseGrabPartClick, OnMouseGrabEnterPart, null, OnMouseGrabExitPart);
                 KISAddonCursor.CursorEnable("KIS/Textures/grab", "Grab", "");
                 grabActive = true;
             }
         }
     }
 }
Пример #6
0
 void OnMouseDetachExitPart(Part p)
 {
     if (detachActive)
     {
         KISAddonCursor.CursorEnable("KIS/Textures/detach", "Detach", "");
     }
     else
     {
         KISAddonCursor.CursorDefault();
     }
     p.SetHighlight(false, false);
     p.SetHighlightDefault();
     if (p.parent)
     {
         p.parent.SetHighlight(false, false);
         p.parent.SetHighlightDefault();
     }
     detachOk = false;
 }
Пример #7
0
        public void DisableAttachMode()
        {
            List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>();

            if (pickupModules.Count > 0)
            {
                if (!draggedPart && !grabActive && !KISAddonPointer.isRunning)
                {
                    detachActive = false;
                    KISAddonCursor.StopPartDetection();
                    KISAddonCursor.CursorDefault();
                }
                if (KISAddonPointer.isRunning && KISAddonPickup.instance.pointerMode == KISAddonPickup.PointerMode.Attach)
                {
                    KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Drop;
                    KIS_Shared.PlaySoundAtPoint("KIS/Sounds/click", FlightGlobals.ActiveVessel.transform.position);
                }
            }
        }
Пример #8
0
 private void OnPointerState(KISAddonPointer.PointerTarget pTarget, KISAddonPointer.PointerState pState, Part hoverPart, AttachNode hoverNode)
 {
     if (pState == KISAddonPointer.PointerState.OnMouseEnterNode)
     {
         if (pTarget == KISAddonPointer.PointerTarget.PartMount)
         {
             string keyAnchor = "[" + GameSettings.Editor_toggleSymMethod.name + "]";
             KISAddonCursor.CursorEnable("KIS/Textures/mount", "Mount", "(Press " + keyAnchor + " to change node, [Escape] to cancel)");
         }
         if (pTarget == KISAddonPointer.PointerTarget.PartNode)
         {
             pointerMode = pointerMode;
         }
     }
     if (pState == KISAddonPointer.PointerState.OnMouseExitNode || pState == KISAddonPointer.PointerState.OnChangeAttachNode)
     {
         pointerMode = pointerMode;
     }
 }
Пример #9
0
        public void EnableAttachMode()
        {
            List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>();

            // Attach/detach only if pickup module is present on vessel
            if (pickupModules.Count > 0)
            {
                if (!draggedPart && !grabActive && !KISAddonPointer.isRunning)
                {
                    KISAddonCursor.StartPartDetection(OnMouseDetachPartClick, OnMouseDetachEnterPart, null, OnMouseDetachExitPart);
                    KISAddonCursor.CursorEnable("KIS/Textures/detach", "Detach", "");
                    detachActive = true;
                }
                if (KISAddonPointer.isRunning && KISAddonPointer.pointerTarget != KISAddonPointer.PointerTarget.PartMount)
                {
                    KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Attach;
                    KIS_Shared.PlaySoundAtPoint("KIS/Sounds/click", FlightGlobals.ActiveVessel.transform.position);
                }
            }
        }
Пример #10
0
 private void Pickup()
 {
     icon = new KIS_IconViewer(draggedPart, draggedIconResolution);
     KISAddonCursor.StartPartDetection();
     grabActive = false;
     KISAddonCursor.CursorDisable();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.SetControlLock(ControlTypes.VESSEL_SWITCHING, "KISpickup");
         // Disable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (Keva.JetpackDeployed)
             {
                 Keva.JetpackDeployed = false;
                 jetpackLock          = true;
                 KIS_Shared.DebugLog("Jetpack mouse input disabled");
             }
         }
     }
 }
Пример #11
0
        void OnMouseDetachPartClick(Part part)
        {
            if (KISAddonPointer.isRunning)
            {
                return;
            }
            if (hoverInventoryGui())
            {
                return;
            }
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (!detachOk)
            {
                return;
            }
            if (!HasActivePickupInRange(part))
            {
                return;
            }
            detachActive = false;
            KISAddonCursor.StopPartDetection();
            KISAddonCursor.CursorDefault();
            ModuleKISItem item = part.GetComponent <ModuleKISItem>();

            if (item)
            {
                if (item.staticAttached)
                {
                    item.GroundDetach();
                    if (item.allowPartAttach == 1)
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part);
                        KIS_Shared.PlaySoundAtPoint(pickupModule.detachStaticSndPath, pickupModule.part.transform.position);
                    }
                    if (item.allowPartAttach == 2)
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true);
                        KIS_Shared.PlaySoundAtPoint(pickupModule.detachStaticSndPath, pickupModule.part.transform.position);
                    }
                    return;
                }
            }

            part.decouple();

            if (item)
            {
                if (item.allowPartAttach == 1)
                {
                    ModuleKISPickup pickupModule = GetActivePickupNearest(part);
                    KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position);
                }
                if (item.allowPartAttach == 2)
                {
                    ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                    KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position);
                }
            }
            else
            {
                ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position);
            }
        }
Пример #12
0
        void OnMouseDetachEnterPart(Part part)
        {
            if (!detachActive)
            {
                return;
            }
            detachOk = false;
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (KISAddonPointer.isRunning)
            {
                return;
            }
            if (hoverInventoryGui())
            {
                return;
            }
            if (draggedPart)
            {
                return;
            }
            ModuleKISPartDrag  pDrag       = part.GetComponent <ModuleKISPartDrag>();
            ModuleKISItem      item        = part.GetComponent <ModuleKISItem>();
            ModuleKISPartMount parentMount = null;

            if (part.parent)
            {
                parentMount = part.parent.GetComponent <ModuleKISPartMount>();
            }

            // Do nothing if part is EVA
            if (part.vessel.isEVA)
            {
                return;
            }

            // Check part distance
            if (!HasActivePickupInRange(part))
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooFar", "Too far", "(Move closer to the part)");
                return;
            }


            // Check if part is static attached
            if (item)
            {
                if (item.staticAttached)
                {
                    ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true);
                    if ((item.allowStaticAttach == 1) || (pickupModule && item.allowStaticAttach == 2))
                    {
                        part.SetHighlightColor(XKCDColors.Periwinkle);
                        part.SetHighlight(true, false);
                        KISAddonCursor.CursorEnable("KIS/Textures/detachOk", "Detach from ground", '(' + part.partInfo.title + ')');
                        detachOk = true;
                        return;
                    }
                    else
                    {
                        if (FlightGlobals.ActiveVessel.isEVA)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached from the ground without a tool)");
                            return;
                        }
                        else
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach from ground function is not supported on this part)");
                            return;
                        }
                    }
                }
            }


            // Check if part can be detached
            if (!parentMount)
            {
                if (part.children.Count > 0 || part.parent)
                {
                    //Part with a child or a parent
                    if (item)
                    {
                        if (item.allowPartAttach == 0)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't detach", "(This part can't be detached)");
                            return;
                        }
                        else if (item.allowPartAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(Part can't be detached without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                        if (!pickupModule)
                        {
                            if (FlightGlobals.ActiveVessel.isEVA)
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(Part can't be detached without a tool)");
                                return;
                            }
                            else
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Part without childs and parent
                    return;
                }
            }

            // Check if part is a root
            if (!part.parent)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Root part", "(Cannot detach a root part)");
                return;
            }

            // Detach icon
            part.SetHighlightColor(XKCDColors.Periwinkle);
            part.SetHighlight(true, false);
            part.parent.SetHighlightColor(XKCDColors.Periwinkle);
            part.parent.SetHighlight(true, false);
            KISAddonCursor.CursorEnable("KIS/Textures/detachOk", "Detach", '(' + part.partInfo.title + ')');
            detachOk = true;
        }
Пример #13
0
        void OnMouseGrabEnterPart(Part part)
        {
            if (!grabActive)
            {
                return;
            }
            grabOk = false;
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (KISAddonPointer.isRunning)
            {
                return;
            }
            if (hoverInventoryGui())
            {
                return;
            }
            if (draggedPart == part)
            {
                return;
            }
            ModuleKISPartDrag  pDrag       = part.GetComponent <ModuleKISPartDrag>();
            ModuleKISPartMount parentMount = null;

            if (part.parent)
            {
                parentMount = part.parent.GetComponent <ModuleKISPartMount>();
            }
            ModuleKISItem item = part.GetComponent <ModuleKISItem>();

            // Drag part over another one if possible (ex : mount)
            if (draggedPart && pDrag)
            {
                KISAddonCursor.CursorEnable(pDrag.dragIconPath, pDrag.dragText, '(' + pDrag.dragText2 + ')');
                return;
            }

            if (draggedPart)
            {
                KISAddonCursor.CursorDisable();
                return;
            }

            // Do nothing if part is EVA
            if (part.vessel.isEVA)
            {
                return;
            }

            // Check part distance
            if (!HasActivePickupInRange(part))
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooFar", "Too far", "(Move closer to the part)");
                return;
            }

            // Check part mass
            float pMass         = (part.mass + part.GetResourceMass());
            float pickupMaxMass = GetAllPickupMaxMassInRange(part);

            if (pMass > pickupMaxMass)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooHeavy", "Too heavy", "(Bring more kerbal [" + pMass + " > " + pickupMaxMass + ")");
                return;
            }

            // Check if part can be detached and grabbed
            if (!parentMount)
            {
                if (part.children.Count > 0 || part.parent)
                {
                    //Part with a child or a parent
                    if (item)
                    {
                        if (item.allowPartAttach == 0)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(This part can't be detached)");
                            return;
                        }
                        else if (item.allowPartAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                        if (!pickupModule)
                        {
                            if (FlightGlobals.ActiveVessel.isEVA)
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
                                return;
                            }
                            else
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Part without childs and parent
                    if (item)
                    {
                        if (item.staticAttached && item.allowStaticAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached from the ground without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach from ground function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            // check number of part attached
            if (part.parent)
            {
                if (part.children.Count > 0)
                {
                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(" + (part.children.Count + 1) + " parts is attached to it)");
                    return;
                }
            }
            else
            {
                if (part.children.Count > 1)
                {
                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(" + part.children.Count + " parts is attached to it)");
                    return;
                }
            }

            // Grab icon
            if (part.children.Count > 0 || part.parent)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/grabOk", "Detach & Grab", '(' + part.partInfo.title + ')');
            }
            else
            {
                KISAddonCursor.CursorEnable("KIS/Textures/grabOk", "Grab", '(' + part.partInfo.title + ')');
            }

            part.SetHighlight(true, false);
            grabOk = true;
        }
Пример #14
0
 void OnDragReleased()
 {
     KISAddonCursor.CursorDefault();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.RemoveControlLock("KISpickup");
         // Re-enable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (jetpackLock)
             {
                 Keva.JetpackDeployed = true;
                 jetpackLock          = false;
                 KIS_Shared.DebugLog("Jetpack mouse input re-enabled");
             }
         }
     }
     if (hoverInventoryGui())
     {
         // Couroutine to let time to KISModuleInventory to catch the draggedPart
         StartCoroutine(WaitAndStopDrag());
     }
     else
     {
         ModuleKISPartDrag pDrag = null;
         if (KISAddonCursor.hoveredPart)
         {
             if (KISAddonCursor.hoveredPart != draggedPart)
             {
                 pDrag = KISAddonCursor.hoveredPart.GetComponent <ModuleKISPartDrag>();
             }
         }
         if (pDrag)
         {
             if (draggedItem != null)
             {
                 draggedItem.DragToPart(KISAddonCursor.hoveredPart);
                 pDrag.OnItemDragged(draggedItem);
             }
             else
             {
                 pDrag.OnPartDragged(draggedPart);
             }
         }
         else
         {
             if (HighLogic.LoadedSceneIsEditor)
             {
                 if (draggedItem != null)
                 {
                     draggedItem.Delete();
                 }
             }
             if (HighLogic.LoadedSceneIsFlight)
             {
                 if (draggedItem != null)
                 {
                     Drop(draggedItem);
                 }
                 else
                 {
                     movingPart = draggedPart;
                     Drop(movingPart, movingPart);
                 }
             }
         }
         icon        = null;
         draggedPart = null;
     }
     KISAddonCursor.StopPartDetection();
 }
Пример #15
0
        private void OnPointerAction(KISAddonPointer.PointerTarget pointerTarget, Vector3 pos, Quaternion rot, Part tgtPart, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            if (pointerTarget == KISAddonPointer.PointerTarget.PartMount)
            {
                if (movingPart)
                {
                    MoveAttach(tgtPart, pos, rot, srcAttachNodeID, tgtAttachNode);
                }
                else
                {
                    CreateAttach(tgtPart, pos, rot, srcAttachNodeID, tgtAttachNode);
                }
                ModuleKISPartMount pMount = tgtPart.GetComponent <ModuleKISPartMount>();
                if (pMount)
                {
                    pMount.sndFxStore.audio.Play();
                }
            }

            if (pointerTarget == KISAddonPointer.PointerTarget.Part ||
                pointerTarget == KISAddonPointer.PointerTarget.PartNode ||
                pointerTarget == KISAddonPointer.PointerTarget.Static ||
                pointerTarget == KISAddonPointer.PointerTarget.KerbalEva)
            {
                if (pointerMode == PointerMode.Drop)
                {
                    if (movingPart)
                    {
                        MoveDrop(tgtPart, pos, rot);
                    }
                    else
                    {
                        CreateDrop(tgtPart, pos, rot);
                    }
                }
                if (pointerMode == PointerMode.Attach)
                {
                    if (movingPart)
                    {
                        MoveAttach(tgtPart, pos, rot, srcAttachNodeID, tgtAttachNode);
                    }
                    else
                    {
                        CreateAttach(tgtPart, pos, rot, srcAttachNodeID, tgtAttachNode);
                    }
                    // sound
                    ModuleKISPickup modulePickup = GetActivePickupNearest(pos);
                    if (tgtPart)
                    {
                        if (modulePickup)
                        {
                            AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.attachPartSndPath), pos);
                        }
                    }
                }
            }
            draggedItem = null;
            draggedPart = null;
            movingPart  = null;
            KISAddonCursor.CursorDefault();
        }