public override void SetVisible(bool newValue) { base.SetVisible(newValue); WindowTitle = this.part.partInfo.title; if (newValue) { //Set starting page pageID = PipelineViewPages.SelectVessel; //Find Pipelines FindPipeEndpoints(); //Get vessel resources sourceVesselResources.Clear(); getVesselResources(this.part.vessel, sourceVesselResources); if (sourceVesselResources.Keys.Count > 0) { sourceDisplayNames = sourceVesselResources.Keys.ToArray(); } else { sourceDisplayNames = null; } //Get inventory if any if (WBIKISWrapper.IsKISInstalled()) { inventory = WBIKISInventoryWrapper.GetInventory(this.part); } } }
protected void processDeliveries() { if (!HighLogic.LoadedSceneIsFlight) { return; } //We're interested in resource and inventory deliveries... List <WBIResourceManifest> resourceManifests = WBIResourceManifest.GetManifestsForDestination(this.uniqueIdentifier); Log("Resource manifests count: " + resourceManifests.Count); //Distribute the resources throughout the vessel WBIResourceManifest resourceManifest; int totalManifests = resourceManifests.Count; string[] resourceKeys; string resourceName; double amount; for (int index = 0; index < totalManifests; index++) { //Get the manifest resourceManifest = resourceManifests[index]; //Go through all the resources and distribute them resourceKeys = resourceManifest.resourceAmounts.Keys.ToArray(); for (int keyIndex = 0; keyIndex < resourceKeys.Length; keyIndex++) { //Get the name resourceName = resourceKeys[keyIndex]; //Get the amount amount = resourceManifest.resourceAmounts[resourceName]; //Distribute the resource this.part.RequestResource(resourceName, -amount, ResourceFlowMode.ALL_VESSEL); Log("Added " + amount + " units of " + resourceName); } } //Deliver inventory items if (WBIKISWrapper.IsKISInstalled()) { //Get the inventory and available volume WBIKISInventoryWrapper inventory = WBIKISInventoryWrapper.GetInventory(this.part); List <WBIKISInventoryWrapper> inventories = WBIKISInventoryWrapper.GetInventories(this.part.vessel); int currentIndex = 0; float contentVolume = 0; float availableVolume = 0; //Grab the first available inventory if (inventory == null) { inventory = inventories[0]; if (inventory == null) { return; } } //Get available volume inventory.RefreshMassAndVolume(); contentVolume = inventory.GetContentVolume(); availableVolume = inventory.maxVolume - contentVolume; //Get all the manifests List <WBIKISInventoryManifest> inventoryManifests = WBIKISInventoryManifest.GetManifestsForDestination(this.uniqueIdentifier); Log("Inventory manifest count: " + inventoryManifests.Count); WBIKISInventoryManifest inventoryManifest; WBIInventoryManifestItem inventoryItem; totalManifests = inventoryManifests.Count; int totalItems; AvailablePart availablePart = null; int skippedItems = 0; for (int index = 0; index < totalManifests; index++) { //Get the manifest inventoryManifest = inventoryManifests[index]; //Get the total items in the manifest totalItems = inventoryManifest.inventoryItems.Count; for (int itemIndex = 0; itemIndex < totalItems; itemIndex++) { //Get the item inventoryItem = inventoryManifest.inventoryItems[itemIndex]; Log("Looking for enough room for " + inventoryItem.partName); //If the inventory has room, then add it. if (inventoryItem.volume < availableVolume) { Log("Current inventory has room."); //Decrease the available volume availableVolume -= inventoryItem.volume; //Get the part info availablePart = PartLoader.getPartInfoByName(inventoryItem.partName); //Add the part inventory.AddItem(availablePart, inventoryItem.partConfigNode, inventoryItem.quantity); Log("Added " + inventoryItem.partName); } //See if another inventory has room else { while (currentIndex < inventories.Count) { currentIndex += 1; inventory = inventories[currentIndex]; Log("New inventory found"); inventory.RefreshMassAndVolume(); contentVolume = inventory.GetContentVolume(); availableVolume = inventory.maxVolume - contentVolume; //If the inventory has room, then add it. if (inventoryItem.volume < availableVolume) { //Decrease the available volume availableVolume -= inventoryItem.volume; //Get the part info availablePart = PartLoader.getPartInfoByName(inventoryItem.partName); //Add the part inventory.AddItem(availablePart, inventoryItem.partConfigNode, inventoryItem.quantity); Log("Added " + inventoryItem.partName); break; } else { skippedItems += 1; } } } } } //Inform the player if we skipped some items if (skippedItems > 0) { ScreenMessages.PostScreenMessage(kItemSkippedMsg, kMessageDuration, ScreenMessageStyle.UPPER_CENTER); } } }