private void MoveAttach(Part tgtPart, Vector3 pos, Quaternion rot, string srcAttachNodeID = null, AttachNode tgtAttachNode = null) { KIS_Shared.DebugLog("Move part & attach"); KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachStart, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode); KIS_Shared.DecoupleFromAll(movingPart); movingPart.transform.position = pos; movingPart.transform.rotation = rot; ModuleKISItem moduleItem = movingPart.GetComponent <ModuleKISItem>(); bool useExternalPartAttach = false; if (moduleItem) { if (moduleItem.useExternalPartAttach) { useExternalPartAttach = true; } } if (tgtPart && !useExternalPartAttach) { KIS_Shared.CouplePart(movingPart, tgtPart, srcAttachNodeID, tgtAttachNode); } KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode); KISAddonPointer.StopPointer(); movingPart = null; draggedItem = null; draggedPart = null; }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; prefabModule = availablePart.partPrefab.GetComponent <ModuleKISItem>(); volume = KIS_Shared.GetPartVolume(availablePart); cost = GetCost(); // Set launchID if (partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (prefabModule) { equipable = prefabModule.equipable; stackable = prefabModule.stackable; equipSlot = prefabModule.equipSlot; usableFromEva = prefabModule.usableFromEva; usableFromContainer = prefabModule.usableFromContainer; usableFromPod = prefabModule.usableFromPod; usableFromEditor = prefabModule.usableFromEditor; carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { Logger.logInfo( "No non-stackable module or a resource found on the part, set the item as stackable"); stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name) || availablePart.name.IndexOf('.') != -1 && KISAddonConfig.stackableList.Contains(availablePart.name.Replace('.', '_'))) { Logger.logInfo("Part name present in settings.cfg (node StackableItemOverride)," + " force item as stackable"); stackable = true; } }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; this.prefabModule = availablePart.partPrefab.GetComponent <ModuleKISItem>(); this.volume = GetVolume(); this.cost = GetCost(); // Set launchID if (this.partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (this.prefabModule) { if (this.prefabModule.volumeOverride > 0) { this.volume = this.prefabModule.volumeOverride; } this.equipable = prefabModule.equipable; this.stackable = prefabModule.stackable; this.equipSlot = prefabModule.equipSlot; this.usableFromEva = prefabModule.usableFromEva; this.usableFromContainer = prefabModule.usableFromContainer; this.usableFromPod = prefabModule.usableFromPod; this.usableFromEditor = prefabModule.usableFromEditor; this.carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { KIS_Shared.DebugLog("No non-stackable module and ressource found on the part, set item as stackable"); this.stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name)) { KIS_Shared.DebugLog("Part name present in settings.cfg (node StackableItemOverride), force item as stackable"); this.stackable = true; } }
public TweakEquippableItem(string partName) { avPart = PartLoader.getPartInfoByName(partName); if (avPart == null) { DebugEx.Error("Cannot find part {0} for main menu tweaker", partName); } itemModule = avPart.partPrefab.FindModuleImplementing <ModuleKISItem>(); if (itemModule == null || !itemModule.equipable && !itemModule.carriable) { DebugEx.Warning("Part is not a KIS carriable/equippable item: {0}", avPart.name); avPart = null; return; } }
public TweakEquippableItem(string partName, bool matchMeshesBySuffix) { this.matchMeshesBySuffix = matchMeshesBySuffix; avPart = PartLoader.getPartInfoByName(partName); if (avPart == null) { Debug.LogErrorFormat("Cannot find part {0} for main menu tweaker", partName); } itemModule = avPart.partPrefab.FindModuleImplementing <ModuleKISItem>(); if (itemModule == null || !itemModule.equipable && !itemModule.carriable) { Debug.LogWarningFormat("Part is not a KIS carriable/equippable item: {0}", avPart.name); avPart = null; return; } }
/// <summary>Sets the part to be adjusted.</summary> /// <param name="part">The part to set.</param> void SetPart(Part part) { parentPart = part; if (part != null) { itemModule = part.partInfo.partPrefab.GetComponent <ModuleKISItem>(); if (itemModule != null) { itemPosition.Reset(); itemDirection.Reset(); } } else { itemModule = null; } }
void Awake() { GameEvents.onGUIEditorToolbarReady.Add(SubCategories); avPartItems.Clear(); foreach (AvailablePart avPart in PartLoader.LoadedPartsList) { if (avPart.name == "kerbalEVA" || avPart.name == "kerbalEVA_RD" || !avPart.partPrefab) { continue; } ModuleKISItem moduleItem = avPart.partPrefab.GetComponent <ModuleKISItem>(); if (moduleItem && moduleItem.editorItemsCategory) { avPartItems.Add(avPart); } } }
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); } }
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; }
public ModuleKISItem(object obj) { _moduleKISItem = (KIS.ModuleKISItem)obj; }
void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; prefabModule = availablePart.partPrefab.GetComponent<ModuleKISItem>(); volume = KIS_Shared.GetPartVolume(availablePart); cost = GetCost(); // Set launchID if (partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (prefabModule) { equipable = prefabModule.equipable; stackable = prefabModule.stackable; equipSlot = prefabModule.equipSlot; usableFromEva = prefabModule.usableFromEva; usableFromContainer = prefabModule.usableFromContainer; usableFromPod = prefabModule.usableFromPod; usableFromEditor = prefabModule.usableFromEditor; carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { Logger.logInfo( "No non-stackable module or a resource found on the part, set the item as stackable"); stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name) || availablePart.name.IndexOf('.') != -1 && KISAddonConfig.stackableList.Contains(availablePart.name.Replace('.', '_'))) { Logger.logInfo("Part name present in settings.cfg (node StackableItemOverride)," + " force item as stackable"); stackable = true; } }
private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity) { this.inventory = inventory; this.quantity = quantity; this.prefabModule = availablePart.partPrefab.GetComponent<ModuleKISItem>(); this.volume = GetVolume(); this.cost = GetCost(); // Set launchID if (this.partNode.HasValue("launchID")) { if (int.Parse(this.partNode.GetValue("launchID")) == 0) { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } } else { this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true); } if (this.prefabModule) { if (this.prefabModule.volumeOverride > 0) { this.volume = this.prefabModule.volumeOverride; } this.equipable = prefabModule.equipable; this.stackable = prefabModule.stackable; this.equipSlot = prefabModule.equipSlot; this.usableFromEva = prefabModule.usableFromEva; this.usableFromContainer = prefabModule.usableFromContainer; this.usableFromPod = prefabModule.usableFromPod; this.usableFromEditor = prefabModule.usableFromEditor; this.carriable = prefabModule.carriable; } int nonStackableModule = 0; foreach (PartModule pModule in availablePart.partPrefab.Modules) { if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName)) { nonStackableModule++; } } if (nonStackableModule == 0 && GetResources().Count == 0) { KIS_Shared.DebugLog("No non-stackable module and ressource found on the part, set item as stackable"); this.stackable = true; } if (KISAddonConfig.stackableList.Contains(availablePart.name)) { KIS_Shared.DebugLog("Part name present in settings.cfg (node StackableItemOverride), force item as stackable"); this.stackable = true; } }