public bool isEndpointTunnelable()
 {
     List<Vessel> endpoints = SpaceDockUtilities.GetSpaceDocks();
     foreach (Vessel sd in endpoints)
     {
         if (sd == this.vessel)
         {
             continue;
         }
         RemoteEndpoint potentialDock = new RemoteEndpoint(sd);
         if (potentialDock.GetPreciseDistanceToDestination(vessel).magnitude < HyperEndpoint.TUNNEL_JUMP_DISTANCE)
         {
             return true;
         }
     }
     return false;
 }
        private void WindowGUI(int windowID)
        {
            Boolean isLegal = false;
            GUIStyle mySty = new GUIStyle(GUI.skin.button);
            mySty.normal.textColor = mySty.focused.textColor = Color.white;
            mySty.hover.textColor = mySty.active.textColor = Color.yellow;
            mySty.onNormal.textColor = mySty.onFocused.textColor = mySty.onHover.textColor = mySty.onActive.textColor = Color.green;
            mySty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle headingStyle = new GUIStyle(GUI.skin.label);
            headingStyle.alignment = TextAnchor.MiddleCenter;
            headingStyle.fontStyle = FontStyle.Bold;

            GUILayout.BeginVertical();
            GUIStyle labelStyle = new GUIStyle(GUI.skin.label);

            if (GetCargoMode() == CargoMode.Idle)
            {
                GUILayout.Label("Drive Targeting:", headingStyle);
                List<Vessel> dockList = new List<Vessel>();
                foreach (Vessel v in FlightGlobals.Vessels)
                {
                    //skip our own vessel
                    if (v == this.vessel)
                    {
                        continue;
                    }
                    //Add all spacedocks to the list.
                    if (SpaceDockUtilities.IsSpaceDock(v))
                    {
                        dockList.Add(v);
                    }
                }

               targetIndex = GUILayout.SelectionGrid(targetIndex, dockList.ConvertAll(v => v.vesselName).ToArray(), 1, mySty, GUILayout.ExpandWidth(true));
               if (targetIndex != previousIndex)
               {
                   try
                   {
                       Vessel v = dockList[targetIndex];
                       print("Choosing: " + v.name);
                       chosenLaunchFacility = new RemoteEndpoint(v);
                       SetDestination(chosenLaunchFacility);
                       previousIndex = targetIndex;
                       targetVessel = v;
                   }
                   catch
                   {
                   }
               }
            }
            String range = "No Target";
            String jumpLabel = "Hyperjump Not Possible";
            if (targetVessel != null)
            {

                if (isEndpointLocal(targetVessel))
                {
                    range = "In Range";
                    jumpLabel = "Activate Local Jump";
                    isLegal = true;
                }
                else if (isEndpointTunnelable())
                {
                    range = "In Tunnel Range";
                    jumpLabel = "Activate Tunnel Jump";
                    isLegal = true;
                }
                else
                {
                    range = "Out of Range";
                    jumpLabel = "Hyperjump Not Possible";
                    isLegal = false;
                }

            }
             GUILayout.Label("Drive Controls:", headingStyle);
             driveUnlocked = GUILayout.Toggle(driveUnlocked, "Unlock Drive Controls");
             if (driveUnlocked)
             {
                 GUIStyle jumpSty = new GUIStyle(GUI.skin.button);
                 jumpSty.normal.textColor = Color.green;
                 jumpSty.active.textColor = jumpSty.hover.textColor = Color.red;
                 if(isLegal)
                 {

                     if (GUILayout.Button(jumpLabel, jumpSty))
                     {
                         SetCargoMode(CargoMode.JumpRequested);
                         emitter.minEmission = PARTICLES_ON;
                         emitter.maxEmission = PARTICLES_ON * 2;

                     }
                }
                 if (GUILayout.Button("Set Hyperjump Drive Idle"))
                 {
                     SetCargoMode(CargoMode.Idle);
                     emitter.minEmission = PARTICLES_IDLE;
                     emitter.maxEmission = PARTICLES_IDLE * 2;

                 }

             }

            GUILayout.Label("Drive Status:", headingStyle);
            GUIStyle statusStyle = new GUIStyle(GUI.skin.label);
            statusStyle.normal.textColor = Color.yellow;
            if (targetVessel != null)
            {
                GUILayout.Label("Target: " + Vessel.GetSituationString(targetVessel) + "\n" + range + " (" + getDistanceApprox(targetVessel) + ")", statusStyle);
            }
            GUILayout.Label(getModeStatus(GetCargoMode()), statusStyle);
            GUILayout.EndVertical();

            //DragWindow makes the window draggable. The Rect specifies which part of the window it can by dragged by, and is
            //clipped to the actual boundary of the window. You can also pass no argument at all and then the window can by
            //dragged by any part of it. Make sure the DragWindow command is AFTER all your other GUI input stuff, or else
            //it may "cover up" your controls and make them stop responding to the mouse.
            GUI.DragWindow(new Rect(0, 0, 10000, 20));
        }
 public bool isEndpointLocal(Vessel v)
 {
     RemoteEndpoint potentialDock = new RemoteEndpoint(v);
     return (potentialDock.GetPreciseDistanceToDestination(vessel).magnitude < LOCAL_JUMP_DISTANCE);
 }
Exemple #4
0
 public void SetDestination(RemoteEndpoint destination)
 {
     this.destination = destination;
 }