Example #1
0
        public override void Load(ConfigNode node)
        {
            base.Load(node);

            ConfigNode[]             itemNodes = node.GetNodes(kInventoryNode);
            ConfigNode               itemNode;
            WBIInventoryManifestItem inventoryItem;

            for (int index = 0; index < itemNodes.Length; index++)
            {
                itemNode = itemNodes[index];

                inventoryItem                = new WBIInventoryManifestItem();
                inventoryItem.quantity       = int.Parse(itemNode.GetValue(kQuantity));
                inventoryItem.partName       = itemNode.GetValue(kPartName);
                inventoryItem.volume         = float.Parse(itemNode.GetValue(kVolume));
                inventoryItem.partConfigNode = itemNode.GetNode(kPartConfig);

                inventoryItems.Add(inventoryItem);
            }
        }
Example #2
0
        protected void drawConfirmPage()
        {
            GUILayout.BeginVertical();
            //Payload Summary
            GUILayout.Label("<color=white><b>Payload:</b></color>");

            scrollPosResources = GUILayout.BeginScrollView(scrollPosResources, resourcePaneOptions);

            //Resources
            int totalResources = sourceDisplayNames.Length;
            WBIResourceTotals resourceTotals;

            for (int index = 0; index < totalResources; index++)
            {
                resourceTotals = sourceVesselResources[sourceDisplayNames[index]];
                if (resourceTotals.transferPercent < 0.0001f)
                {
                    continue;
                }

                GUILayout.BeginScrollView(panelPos, resourcePanelOptions);
                GUILayout.BeginVertical();

                //Resource name
                GUILayout.Label("<color=white><b>" + resourceTotals.displayName + "</b></color>");

                //Amount text field
                GUILayout.Label("<color=white> Units: " + string.Format("{0:f2}", resourceTotals.amount * resourceTotals.transferPercent) + "</color>");

                GUILayout.EndVertical();
                GUILayout.EndScrollView();

                sourceVesselResources[sourceDisplayNames[index]] = resourceTotals;
            }

            //Packing list
            if (packingList.Count > 0)
            {
                WBIPackingItem packingItem;
                int            totalItems = packingList.Count;
                for (int index = 0; index < totalItems; index++)
                {
                    //Get the packing item
                    packingItem = packingList[index];

                    //If selected list out the item
                    if (packingItem.isSelected)
                    {
                        GUILayout.Label("<color=white>" + packingItem.partTitle + "(" + packingItem.quantity + ")</color>");
                    }
                }
            }

            GUILayout.EndScrollView();

            //Buttons
            GUILayout.BeginHorizontal();
            //Back button
            if (GUILayout.Button(kBackLabel))
            {
                pageID = PipelineViewPages.ChooseResources;
            }

            //Launch button
            //At this time, deduct the required resources and payload resources
            if (GUILayout.Button(kLaunchLabel))
            {
                //Pay EC cost
                double amountToTransfer = electricityCostPerTonne * projectileMass;
                this.part.RequestResource("ElectricCharge", amountToTransfer, ResourceFlowMode.ALL_VESSEL);

                //Pay LFO units
                this.part.RequestResource("LiquidFuel", liquidFuelUnits, ResourceFlowMode.ALL_VESSEL);
                this.part.RequestResource("Oxidizer", oxidizerUnits, ResourceFlowMode.ALL_VESSEL);

                //Pay guidance data cost
                if (setGuidanceDataAmount != null)
                {
                    setGuidanceDataAmount(totalGuidanceData - totalDataCost);
                }

                //Create the resource manifest
                WBIResourceManifest manifest = new WBIResourceManifest();
                manifest.destinationID = selectedPipelineNode.moduleValues.GetValue("uniqueIdentifier");

                //Deduct payload resources and load them into the transfer request.
                for (int index = 0; index < totalResources; index++)
                {
                    //Get the totals, skipping any that has no transfer percent
                    resourceTotals = sourceVesselResources[sourceDisplayNames[index]];
                    if (resourceTotals.transferPercent < 0.0001f)
                    {
                        continue;
                    }

                    //Deduct the resource amount from the vessel
                    amountToTransfer = resourceTotals.amount * resourceTotals.transferPercent;
                    this.part.RequestResource(resourceTotals.resourceName, amountToTransfer, ResourceFlowMode.ALL_VESSEL);

                    //Add the resource to the transfer manifest.
                    manifest.resourceAmounts.Add(resourceTotals.resourceName, amountToTransfer);
                }
                if (manifest.resourceAmounts.Count > 0)
                {
                    WBIManifestScenario.Instance.AddManifest(manifest);
                }

                //Create the Inventory manifest
                if (packingList.Count > 0)
                {
                    int totalItems = packingList.Count;

                    WBIKISInventoryManifest inventoryManifest = new WBIKISInventoryManifest();
                    inventoryManifest.destinationID = selectedPipelineNode.moduleValues.GetValue("uniqueIdentifier");

                    WBIPackingItem           packingItem;
                    WBIInventoryManifestItem manifestItem;
                    for (int index = 0; index < totalItems; index++)
                    {
                        //Get the packing item
                        packingItem = packingList[index];
                        if (!packingItem.isSelected)
                        {
                            continue;
                        }

                        //Fill out the manifest
                        manifestItem          = new WBIInventoryManifestItem();
                        manifestItem.partName = packingItem.kisItem.availablePart.name;
                        manifestItem.quantity = packingItem.quantity;
                        manifestItem.volume   = packingItem.volume;
                        ConfigNode partNode = new ConfigNode(WBIKISInventoryManifest.kPartNode);
                        packingItem.kisItem.availablePart.partConfig.CopyTo(partNode);
                        ConfigNode partConfigNode = new ConfigNode(WBIKISInventoryManifest.kPartConfig);
                        partConfigNode.AddNode(partNode);
                        manifestItem.partConfigNode = partConfigNode;
                        inventoryManifest.inventoryItems.Add(manifestItem);

                        //Remove the item from the inventory
                        inventory.DeleteItem(packingItem.slot);
                    }
                    WBIManifestScenario.Instance.AddManifest(inventoryManifest);
                    packingList.Clear();
                }

                //Play launch effects and inform user.
                ScreenMessages.PostScreenMessage(kShipmentLaunched + selectedPipelineNode.vesselName, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);

                //Change page
                pageID = PipelineViewPages.SelectVessel;
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }