Example #1
0
        private static void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();

            template.name = GUILayout.TextField(template.name);

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Latitude", GUILayout.Width(68));
            GUILayout.Label("Longitude", GUILayout.Width(68));
            GUILayout.EndVertical();

            GUILayout.Space(4);

            string val;
            float  floatVal;

            GUILayout.BeginVertical();
            val = GUILayout.TextField(latitude, GUILayout.Width(140));
            if (float.TryParse(val, out floatVal))
            {
                latitude       = val;
                recalcAltitude = true;
            }
            val = GUILayout.TextField(longitude, GUILayout.Width(140));
            if (float.TryParse(val, out floatVal))
            {
                longitude      = val;
                recalcAltitude = true;
            }

            GUILayout.EndVertical();

            GUILayout.Space(4);

            GUILayout.BeginVertical();
            if (GUILayout.Button(Util.GetContractIcon(template.id, template.seed)))
            {
                showIconPicker = !showIconPicker;

                selectedIcon  = Array.IndexOf(icons, icons.Where(c => c.tooltip == template.id).First());
                selectedColor = Array.IndexOf(seeds, template.seed);
                if (selectedIcon == -1)
                {
                    selectedIcon = 0;
                }
                if (selectedColor == -1)
                {
                    selectedColor = 0;
                }
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80);
            if (GUILayout.Toggle(useTerrainHeight, new GUIContent("Use terrain height for altitude", "Automatically set the altitude to ground level.")) != useTerrainHeight)
            {
                useTerrainHeight = !useTerrainHeight;
                recalcAltitude   = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Label("Altitude", GUILayout.Width(72));
            val = GUILayout.TextField(altitude, useTerrainHeight ? disabledText : GUI.skin.textField, GUILayout.Width(140));
            if (!useTerrainHeight && float.TryParse(val, out floatVal))
            {
                altitude = val;
            }
            GUILayout.EndHorizontal();

            if (HighLogic.LoadedScene == GameScenes.FLIGHT)
            {
                if (GUILayout.Button(new GUIContent("Use Active Vessel Location", "Set the location parameters to that of the currently active vessel.")))
                {
                    latitude       = FlightGlobals.ActiveVessel.latitude.ToString();
                    longitude      = FlightGlobals.ActiveVessel.longitude.ToString();
                    altitude       = FlightGlobals.ActiveVessel.altitude.ToString();
                    recalcAltitude = true;
                }
            }

            if (HighLogic.LoadedScene == GameScenes.FLIGHT && MapView.MapIsEnabled || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                string label = mapLocationMode ? "Cancel Set Location" : "Set Location on Map";
                if (GUILayout.Button(new GUIContent(label, "Set the location by clicking on the map.")))
                {
                    mapLocationMode = !mapLocationMode;
                }
            }
            else
            {
                mapLocationMode = false;
            }

            GUILayout.BeginHorizontal();
            bool save   = GUILayout.Button("Save");
            bool apply  = GUILayout.Button("Apply");
            bool cancel = GUILayout.Button("Cancel");

            if (save || apply)
            {
                template.latitude  = double.Parse(latitude);
                template.longitude = double.Parse(longitude);
                template.height    = Util.WaypointHeight(template, targetBody);
                template.altitude  = double.Parse(altitude) - template.height;
                if (windowMode == WindowMode.Add)
                {
                    CustomWaypoints.AddWaypoint(template);
                    selectedWaypoint = template;
                    template         = new Waypoint();
                }
                else
                {
                    selectedWaypoint.id        = template.id;
                    selectedWaypoint.name      = template.name;
                    selectedWaypoint.latitude  = template.latitude;
                    selectedWaypoint.longitude = template.longitude;
                    selectedWaypoint.altitude  = template.altitude;
                    selectedWaypoint.height    = template.height;
                    selectedWaypoint.seed      = template.seed;
                }
            }
            if (save || cancel)
            {
                windowMode = WindowMode.None;
            }
            else if (apply)
            {
                EditWaypoint(selectedWaypoint);
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUI.DragWindow();

            if (useTerrainHeight && recalcAltitude)
            {
                recalcAltitude = false;
                altitude       = Util.TerrainHeight(double.Parse(latitude), double.Parse(longitude), targetBody).ToString();
            }

            WaypointManager.Instance.SetToolTip(windowID - typeof(WaypointManager).FullName.GetHashCode());
        }
Example #2
0
        protected GUIContent ContractIcon(WaypointData wpd)
        {
            Texture2D texture = Util.GetContractIcon(wpd.waypoint.id, wpd.waypoint.seed);

            return(new GUIContent(texture, wpd.waypoint.contractReference != null ? wpd.waypoint.contractReference.Title : "No contract"));
        }
        protected void DrawWaypoint(WaypointData wpd)
        {
            // Not our planet
            CelestialBody celestialBody = FlightGlobals.currentMainBody;

            if (celestialBody == null || wpd.waypoint.celestialName != celestialBody.name)
            {
                return;
            }

            // Check if the waypoint should be visible
            if (!wpd.waypoint.visible)
            {
                return;
            }

            // Figure out waypoint label
            string label = wpd.waypoint.name + (wpd.waypoint.isClustered ? (" " + StringUtilities.IntegerToGreek(wpd.waypoint.index)) : "");

            // Set the alpha and do a nice fade
            wpd.SetAlpha();

            // Decide whether to actually draw the waypoint
            if (FlightGlobals.ActiveVessel != null)
            {
                // Figure out the distance to the waypoint
                Vessel v = FlightGlobals.ActiveVessel;

                // Only change alpha if the waypoint isn't the nav point
                if (!Util.IsNavPoint(wpd.waypoint))
                {
                    // Get the distance to the waypoint at the current speed
                    double speed      = v.srfSpeed < MIN_SPEED ? MIN_SPEED : v.srfSpeed;
                    double directTime = Util.GetStraightDistance(wpd) / speed;

                    // More than two minutes away
                    if (directTime > MIN_TIME || Config.waypointDisplay != Config.WaypointDisplay.ALL)
                    {
                        return;
                    }
                    else if (directTime >= MIN_TIME - FADE_TIME)
                    {
                        wpd.currentAlpha = (float)((MIN_TIME - directTime) / FADE_TIME) * Config.opacity;
                    }
                }
                // Draw the distance information to the nav point
                else
                {
                    // Draw the distance to waypoint text
                    if (Event.current.type == EventType.Repaint)
                    {
                        if (asb == null)
                        {
                            asb = UnityEngine.Object.FindObjectOfType <AltimeterSliderButtons>();
                            asbRectTransform = asb.GetComponent <RectTransform>();
                        }

                        float ybase = halfScreenHeight - asbRectTransform.position.y + asbRectTransform.sizeDelta.y * 0.5f + 4;
                        if (ybase < 0)
                        {
                            ybase = 0;
                        }


                        string timeToWP = GetTimeToWaypoint(wpd);
                        if (Config.hudDistance)
                        {
                            //GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Distance to " + label + ":", nameStyle);
                            //GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                            //    v.state != Vessel.State.DEAD ? Util.PrintDistance(wpd) : "N/A", valueStyle);
                            //ybase += 18f;
                            GUI.Label(new Rect(leftBoxLeft, ybase, leftBoxWidth, boxHeight), "Distance to " + label + ":", nameStyle);
                            GUI.Label(new Rect(rightBoxLeft, ybase, rightBoxWidth, boxHeight),
                                      v.state != Vessel.State.DEAD ? Util.PrintDistance(wpd) : "N/A", valueStyle);
                            ybase += boxHeight - 2;
                        }

                        if (timeToWP != null && Config.hudTime)
                        {
                            //GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "ETA to " + label + ":", nameStyle);
                            //GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                            //    v.state != Vessel.State.DEAD ? timeToWP : "N/A", valueStyle);
                            //ybase += 18f;
                            GUI.Label(new Rect(leftBoxLeft, ybase, leftBoxWidth, boxHeight), "ETA to " + label + ":", nameStyle);
                            GUI.Label(new Rect(rightBoxLeft, ybase, rightBoxWidth, boxHeight),
                                      v.state != Vessel.State.DEAD ? timeToWP : "N/A", valueStyle);
                            ybase += boxHeight - 2;
                        }

                        if (Config.hudHeading)
                        {
                            //GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Heading to " + label + ":", nameStyle);
                            //GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                            //    v.state != Vessel.State.DEAD ? wpd.heading.ToString("N1") : "N/A", valueStyle);
                            //ybase += 18f;
                            GUI.Label(new Rect(leftBoxLeft, ybase, leftBoxWidth, boxHeight), "Heading to " + label + ":", nameStyle);
                            GUI.Label(new Rect(rightBoxLeft, ybase, rightBoxWidth, boxHeight),
                                      v.state != Vessel.State.DEAD ? wpd.heading.ToString("N1") : "N/A", valueStyle);
                            ybase += boxHeight - 2;
                        }

                        if (Config.hudAngle && v.mainBody == wpd.celestialBody)
                        {
                            double distance   = Util.GetLateralDistance(wpd);
                            double heightDist = wpd.waypoint.altitude + wpd.waypoint.height - v.altitude;
                            double angle      = Math.Atan2(heightDist, distance) * 180.0 / Math.PI;

                            //GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Angle to " + label + ":", nameStyle);
                            //GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                            //    v.state != Vessel.State.DEAD ? angle.ToString("N2") : "N/A", valueStyle);
                            //ybase += 18f;
                            GUI.Label(new Rect(leftBoxLeft, ybase, leftBoxWidth, boxHeight), "Angle to " + label + ":", nameStyle);
                            GUI.Label(new Rect(rightBoxLeft, ybase, rightBoxWidth, boxHeight),
                                      v.state != Vessel.State.DEAD ? angle.ToString("N2") : "N/A", valueStyle);
                            ybase += boxHeight - 2;

                            if (v.srfSpeed >= 0.1)
                            {
                                double velAngle = 90 - Math.Acos(Vector3d.Dot(v.srf_velocity.normalized, v.upAxis)) * 180.0 / Math.PI;

                                //GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Velocity pitch angle:", nameStyle);
                                //GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                //    v.state != Vessel.State.DEAD ? velAngle.ToString("N2") : "N/A", valueStyle);
                                //ybase += 18f;
                                GUI.Label(new Rect(leftBoxLeft, ybase, leftBoxWidth, boxHeight), "Velocity pitch angle:", nameStyle);
                                GUI.Label(new Rect(rightBoxLeft, ybase, rightBoxWidth, boxHeight),
                                          v.state != Vessel.State.DEAD ? velAngle.ToString("N2") : "N/A", valueStyle);
                                //ybase += boxHeight - 2;
                            }
                        }
                    }
                }
            }

            // Don't draw the waypoint
            if (Config.waypointDisplay == Config.WaypointDisplay.NONE)
            {
                return;
            }

            // Translate to scaled space
            Vector3d localSpacePoint  = celestialBody.GetWorldSurfacePosition(wpd.waypoint.latitude, wpd.waypoint.longitude, wpd.waypoint.height + wpd.waypoint.altitude);
            Vector3d scaledSpacePoint = ScaledSpace.LocalToScaledSpace(localSpacePoint);

            // Don't draw if it's behind the camera
            if (Vector3d.Dot(PlanetariumCamera.Camera.transform.forward, scaledSpacePoint.normalized) < 0.0)
            {
                return;
            }

            // Translate to screen position
            Vector3 screenPos = PlanetariumCamera.Camera.WorldToScreenPoint(new Vector3((float)scaledSpacePoint.x, (float)scaledSpacePoint.y, (float)scaledSpacePoint.z));

            // Draw the marker at half-resolution (30 x 45) - that seems to match the one in the map view
            Rect markerRect = new Rect(screenPos.x - 15f, (float)Screen.height - screenPos.y - 45.0f, 30f, 45f);

            // Set the window position relative to the selected waypoint
            if (selectedWaypoint == wpd.waypoint)
            {
                windowPos = new Rect(markerRect.xMin - 97, markerRect.yMax + 12, 224, 60);
            }

            // Handling clicking on the waypoint
            if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
            {
                if (markerRect.Contains(Event.current.mousePosition))
                {
                    selectedWaypoint = wpd.waypoint;
                    windowPos        = new Rect(markerRect.xMin - 97, markerRect.yMax + 12, 224, 60);
                    waypointName     = label;
                    newClick         = false;
                }
                else if (newClick)
                {
                    selectedWaypoint = null;
                }
            }

            // Only handle on repaint events
            if (Event.current.type == EventType.Repaint)
            {
                // Half-res for the icon too (16 x 16)
                Rect iconRect = new Rect(screenPos.x - 8f, (float)Screen.height - screenPos.y - 39.0f, 16f, 16f);

                // Draw the marker
                Graphics.DrawTexture(markerRect, GameDatabase.Instance.GetTexture("Squad/Contracts/Icons/marker", false), new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, new Color(0.5f, 0.5f, 0.5f, 0.5f * (wpd.currentAlpha - 0.3f) / 0.7f));

                // Draw the icon, but support blinking
                if (!Util.IsNavPoint(wpd.waypoint) || !NavWaypoint.fetch.IsBlinking || (int)((Time.fixedTime - (int)Time.fixedTime) * 4) % 2 == 0)
                {
                    Graphics.DrawTexture(iconRect, /*ContractDefs.sprites[wpd.waypoint.id].texture */
                                         Util.GetContractIcon(wpd.waypoint.id, wpd.waypoint.seed), new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, SystemUtilities.RandomColor(wpd.waypoint.seed, wpd.currentAlpha));
                }

                // Hint text!
                if (iconRect.Contains(Event.current.mousePosition))
                {
                    // Add agency to label
                    if (wpd.waypoint.contractReference != null)
                    {
                        label += "\n" + wpd.waypoint.contractReference.Agent.Name;
                    }
                    float width   = 240f;
                    float height  = hintTextStyle.CalcHeight(new GUIContent(label), width);
                    float yoffset = height + 48.0f;
                    GUI.Box(new Rect(screenPos.x - width / 2.0f, (float)Screen.height - screenPos.y - yoffset, width, height), label, hintTextStyle);
                }
            }
        }