Example #1
0
        public override void SetVisible(bool newValue)
        {
            base.SetVisible(newValue);

            if (newValue && FlightGlobals.ActiveVessel.situation == Vessel.Situations.LANDED)
            {
                Vessel[]                vessels = FlightGlobals.VesselsUnloaded.ToArray();
                Vessel                  vessel;
                PipeEndpointNode        endpointNode;
                List <PipeEndpointNode> endpoints = new List <PipeEndpointNode>();
                bool foundEndpipe;

                //Find vessels that have a pipe endpoint that are on the active vessel's celestial body.
                for (int index = 0; index < vessels.Length; index++)
                {
                    vessel = vessels[index];
                    if (vessel.mainBody == FlightGlobals.ActiveVessel.mainBody && vessel.situation == Vessel.Situations.LANDED)
                    {
                        foundEndpipe = false;
                        foreach (ProtoPartSnapshot protoPart in vessel.protoVessel.protoPartSnapshots)
                        {
                            foreach (ProtoPartModuleSnapshot protoModule in protoPart.modules)
                            {
                                if (protoModule.moduleName == "WBIPipeEndpoint")
                                {
                                    endpointNode              = new PipeEndpointNode();
                                    endpointNode.endpoint     = protoModule.moduleRef;
                                    endpointNode.moduleValues = protoModule.moduleValues; //Use this to tell who connects to whom
                                    endpointNode.vesselName   = vessel.vesselName;
                                    endpoints.Add(endpointNode);
                                    foundEndpipe = true;
                                    break;
                                }
                            }
                            if (foundEndpipe)
                            {
                                break;
                            }
                        }
                    }
                }
                pipeEndpoints = endpoints.ToArray();
            }
        }
Example #2
0
        protected void drawSelectVesselPage()
        {
            if (pipeEndpoints == null)
            {
                GUILayout.Label(kNoVesselsInRange);
                return;
            }

            GUILayout.BeginVertical();

            //Directions
            GUILayout.Label(kSelectVessel);

            //Selection list
            scrollPos = GUILayout.BeginScrollView(scrollPos);

            selectedIndex        = GUILayout.SelectionGrid(selectedIndex, vesselNames, 1);
            selectedPipelineNode = pipeEndpoints[selectedIndex];

            GUILayout.EndScrollView();

            //Next button
            if (GUILayout.Button(kNextLabel))
            {
                //Get transfer type
                transferType = getTransferType();

                //Make sure that the transfer is allowed
                if (transferType == WBITransferTypes.OrbitToGround && !allowOrbitToGround)
                {
                    ScreenMessages.PostScreenMessage(kNoOrbitToGroundMsg, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                }

                //Set next page
                else
                {
                    pageID = PipelineViewPages.ChooseResources;
                }
            }

            GUILayout.EndVertical();
        }
Example #3
0
        public void FindPipeEndpoints()
        {
            //We're only interested in vessels outside of physics range.
            Vessel[]                vessels = FlightGlobals.VesselsUnloaded.ToArray();
            Vessel                  vessel;
            PipeEndpointNode        endpointNode;
            List <PipeEndpointNode> endpoints = new List <PipeEndpointNode>();
            bool foundEndpipe;

            //Find vessels that have a pipe endpoint that are on the active vessel's celestial body.
            pipeEndpoints = null;
            for (int index = 0; index < vessels.Length; index++)
            {
                //Get the vessel
                vessel = vessels[index];

                //If the vessel is not on or orbiting the active vessel's celestial body, then we're done.
                if (vessel.mainBody != FlightGlobals.ActiveVessel.mainBody)
                {
                    continue;
                }

                //See if the vessel has an active pipeline. If so, add it to the list.
                foundEndpipe = false;
                foreach (ProtoPartSnapshot protoPart in vessel.protoVessel.protoPartSnapshots)
                {
                    foreach (ProtoPartModuleSnapshot protoModule in protoPart.modules)
                    {
                        if (protoModule.moduleName == "WBIPipeEndpoint")
                        {
                            if (canReceiveTransfers(vessel, protoModule))
                            {
                                endpointNode = new PipeEndpointNode();
                                endpointNode.moduleValues = protoModule.moduleValues; //Use this to tell who connects to whom
                                endpointNode.snapshot     = protoModule;
                                endpointNode.vessel       = vessel;
                                endpointNode.vesselName   = vessel.vesselName;
                                endpoints.Add(endpointNode);
                                foundEndpipe = true;
                                break;
                            }
                        }
                    }
                    if (foundEndpipe)
                    {
                        break;
                    }
                }
            }

            //Set up the array
            if (endpoints.Count > 0)
            {
                pipeEndpoints = endpoints.ToArray();

                List <string> vesselNameList = new List <string>();
                for (int index = 0; index < pipeEndpoints.Length; index++)
                {
                    vesselNameList.Add(pipeEndpoints[index].vesselName);
                }

                vesselNames = vesselNameList.ToArray();
            }
        }