void OnMouseGrabExitPart(Part p) { if (grabActive) { KISAddonCursor.CursorEnable("KIS/Textures/grab", "Grab", ""); } else { KISAddonCursor.CursorDefault(); } p.SetHighlight(false, false); grabOk = false; }
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; } } } }
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; }
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; } }
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); } } }
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; }
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; }