Ejemplo n.º 1
0
        /// <summary>
        /// Draws UI for module control
        /// </summary>
        /// <param name="rcGuiId">Rc GUI identifier.</param>
        public void DrawRcGUI(int rcGuiId)
        {
            if (currentModule == null)
            {
                rcVisible = false;
                return;
            }

            double currentTime = Planetarium.GetUniversalTime();
            string tooltip     = "";

            GUILayout.BeginVertical();

            //TimeSpan t = TimeSpan.FromSeconds (currentTime - currentModule.lastTime);
            //Layout.Label (
            //	string.Format (
            //		"Idle for {0:D2}h:{1:D2}m:{2:D2}s",
            //		t.Hours,
            //		t.Minutes,
            //		t.Seconds
            //	)
            //);

            // If required power is greater ther total power generated, then average speed can be lowered up to 50%
            double speedReduction = 0;

            if (currentModule.powerRequired > (currentModule.solarPower + currentModule.otherPower))
            {
                speedReduction = (currentModule.powerRequired - (currentModule.solarPower + currentModule.otherPower)) / currentModule.powerRequired * 100;
            }

            Layout.LabelAndText("Target latitude", currentModule.targetLatitude.ToString());
            Layout.LabelAndText("Target longitude", currentModule.targetLongitude.ToString());

            Layout.LabelAndText("Distance to target", (currentModule.distanceToTarget - currentModule.distanceTravelled).ToString("N0"));
            //Layout.LabelAndText ("Distance to target", currentModule.distanceToTarget.ToString("N0"));
            //Layout.LabelAndText ("Distance travelled", currentModule.distanceTravelled.ToString("N0"));

            if (currentModule.averageSpeed > 0)
            {
                tooltip  = "Average speed base: " + currentModule.maxSpeedBase.ToString("F") + "\n";
                tooltip += "Online wheels modifier: " + currentModule.wheelsPercentualModifier.ToString() + "%\n";
                if (currentModule.isManned)
                {
                    tooltip += "Driver bonus: " + currentModule.crewSpeedBonus.ToString() + "%\n";
                }
                else
                {
                    tooltip += "Unmanned rover penalty: 80%\n";
                }
                if (speedReduction > 0)
                {
                    tooltip += "Unsufficient power penalty: " + (speedReduction > 75 ? "100" : speedReduction.ToString("F")) + "%\n";
                }
                tooltip += "Speed at night: " + currentModule.averageSpeedAtNight.ToString("F");
            }
            else
            {
                tooltip = "Wheels aren't online";
            }
            Layout.LabelTextAndButton("Average speed", currentModule.averageSpeed.ToString("F"), tooltip);

            tooltip  = "Solar power: " + currentModule.solarPower.ToString("F") + "\n";
            tooltip += "Generators and reactors: " + currentModule.otherPower.ToString("F");
            Layout.LabelTextAndButton("Generated power", (currentModule.solarPower + currentModule.otherPower).ToString("F"), tooltip);

            //Layout.LabelAndText ("Solar power", currentModule.solarPower.ToString("F"));
            //Layout.LabelAndText ("Other power", currentModule.otherPower.ToString("F"));

            Layout.LabelAndText("Required power", currentModule.powerRequired.ToString("F")
                                + (speedReduction == 0 ? "" : (((speedReduction > 0) && (speedReduction <= 75)) ? " (Not enough power, average speed was reduced by " + speedReduction.ToString("F") + "%)" : " (Not enough power!)")));

            //Layout.LabelAndText ("Solar powered", currentModule.solarPowered.ToString ());
            //Layout.LabelAndText ("Is manned", currentModule.isManned.ToString ());

            if (Layout.Button("Pick target on map", Palette.yellow))
            {
                currentModule.PickTarget();
            }
            if (Layout.Button("Set to active target", Palette.yellow))
            {
                currentModule.SetToActive();
            }
            if (Layout.Button("Set to active waypoint", Palette.yellow))
            {
                currentModule.SetToWaypoint();
            }
            if (!currentModule.isActive)
            {
                if (Layout.Button("Poehali!!!", Palette.green))
                {
                    currentModule.Activate();
                }
            }
            else
            {
                if (Layout.Button("Deactivate", Palette.red))
                {
                    currentModule.Deactivate();
                }
            }
            if (Layout.Button("System Check", Palette.yellow))
            {
                currentModule.SystemCheck();
            }

            if (Layout.Button("Close", Palette.red))
            {
                rcVisible = false;
            }

            GUILayout.EndVertical();
            GUI.DragWindow();

            if (Event.current.type == EventType.Repaint)
            {
                //Show tooltip
                if (!string.IsNullOrEmpty(GUI.tooltip))
                {
                    GUIContent tooltipContent = new GUIContent(GUI.tooltip);
                    Vector2    tooltipSize    = Styles.tooltip.CalcSize(tooltipContent);
                    Vector2    mouseScreenPos = new Vector2(Input.mousePosition.x - rcRect.x - tooltipSize.x / 2, Screen.height - Input.mousePosition.y - rcRect.y + 20);
                    GUI.Label(new Rect(mouseScreenPos, tooltipSize), GUI.tooltip, Styles.tooltip);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws main UI
        /// </summary>
        /// <param name="guiId">GUI identifier.</param>
        public void DrawGUI(int guiId)
        {
            double currentTime = Planetarium.GetUniversalTime();

            GUILayout.BeginVertical();
            mainWindowScrollPosition = GUILayout.BeginScrollView(mainWindowScrollPosition);
            for (int i = 0; i < activeRovers.Count; i++)
            {
                var rover = activeRovers [i];
                switch (rover.status)
                {
                case "current":
                    GUI.contentColor = Color.white;
                    break;

                case "roving":
                    GUI.contentColor = Palette.green;
                    break;

                case "idle":
                    GUI.contentColor = Palette.yellow;
                    break;

                case "awaiting sunlight":
                    GUI.contentColor = Palette.red;
                    break;
                }
                GUILayout.BeginHorizontal();
                if (Layout.Button(rover.vessel.vesselName, GUILayout.Width(200)))
                {
                    if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
                    {
                        PlanetariumCamera.fetch.SetTarget(rover.vessel.mapObject);
                    }
                    if (HighLogic.LoadedSceneIsFlight)
                    {
                        MapView.EnterMapView();
                        PlanetariumCamera.fetch.SetTarget(rover.vessel.mapObject);
                    }
                }
                if (Layout.Button("Switch to", GUILayout.Width(100)))
                {
                    if (rover.vessel.loaded)
                    {
                        FlightGlobals.SetActiveVessel(rover.vessel);
                    }
                    else
                    {
                        GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.OVERWRITE);
                        FlightDriver.StartAndFocusVessel("persistent", FlightGlobals.Vessels.IndexOf(rover.vessel));
                    }
                }

                Layout.Label(rover.vessel.mainBody.bodyDisplayName.Replace("^N", ""), GUILayout.Width(75));
                Layout.Label(rover.status + (rover.status == "roving" ? rover.status2 : ""), GUILayout.Width(125));

                if (rover.status == "roving" || rover.status == "awaiting sunlight")
                {
                    Layout.Label(
                        "v̅ = " + rover.AverageSpeed.ToString("N") + ", yet to travel " +
                        rover.yetToTravel.ToString("N0") + " meters"
                        );
                }

                if (rover.status == "idle")
                {
                    TimeSpan t = TimeSpan.FromSeconds(currentTime - rover.LastTime);

                    string idlePeriod = string.Format(
                        "{0:D2}h:{1:D2}m:{2:D2}s",
                        t.Hours,
                        t.Minutes,
                        t.Seconds
                        );

                    Layout.Label(idlePeriod);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            GUI.contentColor = Color.white;
            autoDewarp       = Layout.Toggle(autoDewarp, "Automagic Dewarp");
//			useKSPSkin = Layout.Toggle (useKSPSkin, "Use KSP Skin");
            GUILayout.BeginHorizontal();
            if (Layout.Button("Close", GUILayout.Height(25)))
            {
                if (appLauncherButton != null)
                {
                    appLauncherButton.SetFalse();
                }
                else
                {
                    onToggle();
                }
            }
            if (Layout.Button("Switch Toolbar", GUILayout.Height(25), GUILayout.Width(150)))
            {
                useToolbar = !useToolbar;
                DestroyLauncher();
                CreateLauncher();
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (Layout.Button("BV Control Panel", GUILayout.Height(25), GUILayout.Width(200)))
                {
                    if ((currentModule != null) && !currentModule.isShutdown)
                    {
                        currentModule.SystemCheck();
                        rcVisible = true;
                        if (appLauncherButton != null)
                        {
                            appLauncherButton.SetFalse();
                        }
                        else
                        {
                            onToggle();
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }