コード例 #1
0
        public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            _draggable = true;
            if (worker != null && !target.NormalTargetExists && Event.current.type == EventType.Layout)
            {
                worker.stop = true;
                worker      = null;
                plot        = null;
            }

            selectionMode = (Mode)GuiUtils.ComboBox.Box((int)selectionMode, modeNames, this);
            if (Event.current.type == EventType.Repaint)
            {
                windowWidth = (int)GUILayoutUtility.GetLastRect().width;
            }

            switch (selectionMode)
            {
            case Mode.LimitedTime:
                GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_adv_label5"), maxArrivalTime);//Max arrival time
                if (worker != null && !worker.Finished)
                {
                    GuiUtils.SimpleLabel(Localizer.Format("#MechJeb_adv_computing") + worker.Progress + "%");
                }
                break;

            case Mode.Porkchop:
                DoPorkchopGui(o, universalTime, target);
                break;
            }

            if (worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
            {
                ComputeTimes(o, target.TargetOrbit, universalTime);
            }

            if (GUI.changed || worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
            {
                ComputeStuff(o, universalTime, target);
            }
        }
コード例 #2
0
		void ComputeStuff(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			errorMessage = CheckPreconditions(o, target);
			if (errorMessage == null)
				errorMessage = "";
			else
				return;

			if (worker != null)
				worker.stop = true;
			plot = null;

			switch (selectionMode)
			{
			case Mode.LimitedTime:
				worker = new TransferCalculator (o, target.TargetOrbit, universalTime, maxArrivalTime, minSamplingStep);
				break;
			case Mode.Porkchop:
				worker = new AllGraphTransferCalculator(o, target.TargetOrbit, minDepartureTime, maxDepartureTime, minTransferTime, maxTransferTime, windowWidth, porkchop_Height);
				break;
			}
		}
コード例 #3
0
		void ComputeStuff(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			errorMessage = CheckPreconditions(o, target);
			if (errorMessage == null)
				errorMessage = "";
			else
				return;

			if (worker != null)
				worker.stop = true;
			plot = null;

			switch (selectionMode)
			{
			case Mode.LimitedTime:
				worker = new TransferCalculator (o, target.TargetOrbit, universalTime, maxArrivalTime, minSamplingStep);
				break;
			case Mode.Porkchop:
				worker = new AllGraphTransferCalculator(o, target.TargetOrbit, minDepartureTime, maxDepartureTime, minTransferTime, maxTransferTime, windowWidth, porkchop_Height);
				break;
			}
		}
コード例 #4
0
		private void DoPorkchopGui(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
            // That mess is why you should not compute anything inside a GUI call
            // TODO : rewrite all that...
			if (worker == null)
			{
			    if (Event.current.type == EventType.Layout)
			        layoutSkipped = true;
			    return;
			}
            if (Event.current.type == EventType.Layout)
                layoutSkipped = false;
            if (layoutSkipped)
                return;

            string dv = " - ";
			string departure = " - ";
			string duration = " - ";
			if (worker.Finished && worker.computed.GetLength(1) == porkchop_Height)
			{
				if (plot == null && Event.current.type == EventType.Layout)
				{

                    int width = worker.computed.GetLength(0);
                    int height = worker.computed.GetLength(1);

                    if (texture != null && (texture.width != width || texture.height != height))
                    {
                        Object.Destroy(texture);
                        texture = null;
                    }

                    if (texture == null)
                        texture = new Texture2D(width, height, TextureFormat.RGB24, false);

                    Porkchop.RefreshTexture(worker.computed, texture);

                    plot = new PlotArea(
						worker.minDepartureTime,
						worker.maxDepartureTime,
						worker.minTransferTime,
						worker.maxTransferTime,
						texture,
						(xmin, xmax, ymin, ymax) => {
							minDepartureTime = Math.Max(xmin, universalTime);
							maxDepartureTime = xmax;
							minTransferTime = Math.Max(ymin, 3600);
							maxTransferTime = ymax;
							GUI.changed = true;
						});
					plot.selectedPoint = new int[]{worker.bestDate, worker.bestDuration};
				}
			}
			if (plot != null)
			{
				var point = plot.selectedPoint;
				if (plot.hoveredPoint != null)
					point = plot.hoveredPoint;

				var p = worker.computed[point[0], point[1]];
				if (p != null)
				{
					dv = MuUtils.ToSI(p.dV.magnitude) + "m/s";
					if (worker.DateFromIndex(point[0]) < Planetarium.GetUniversalTime())
						departure = "any time now";
					else
						departure = GuiUtils.TimeToDHMS(worker.DateFromIndex(point[0]) - Planetarium.GetUniversalTime());
					duration = GuiUtils.TimeToDHMS(worker.DurationFromIndex(point[1]));
				}
				plot.DoGUI();
				if (!plot.draggable) _draggable = false;
			}
			else
			{
				GUIStyle progressStyle = new GUIStyle
				{
					font = GuiUtils.skin.font,
					fontSize = GuiUtils.skin.label.fontSize,
					fontStyle = GuiUtils.skin.label.fontStyle,
					normal = {textColor = GuiUtils.skin.label.normal.textColor}
				};

				GUILayout.Box("Computing: " + worker.Progress + "%", progressStyle, new GUILayoutOption[] {
					GUILayout.Width(windowWidth),
					GUILayout.Height(porkchop_Height)});
			}
			GUILayout.BeginHorizontal();
			GUILayout.Label("ΔV: " + dv);
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Reset", GuiUtils.yellowOnHover))
				ComputeTimes(o, target.TargetOrbit, universalTime);
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			GUILayout.Label("Select: ");
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Lowest ΔV"))
			{
				plot.selectedPoint = new int[]{ worker.bestDate, worker.bestDuration };
				GUI.changed = false;
			}

			if (GUILayout.Button("ASAP"))
			{
				int bestDuration = 0;
				for (int i = 1; i < worker.computed.GetLength(1); i++)
				{
					if (worker.computed[0, bestDuration].dV.sqrMagnitude > worker.computed[0, i].dV.sqrMagnitude)
						bestDuration = i;
				}
				plot.selectedPoint = new int[]{ 0, bestDuration };
				GUI.changed = false;
			}
			GUILayout.EndHorizontal();

			GUILayout.Label("Departure in " + departure);
			GUILayout.Label("Transit duration " + duration);
		}
コード例 #5
0
        private void DoPorkchopGui(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            CelestialBody targetCelestial = target.Target as CelestialBody;

            // That mess is why you should not compute anything inside a GUI call
            // TODO : rewrite all that...
            if (worker == null)
            {
                if (Event.current.type == EventType.Layout)
                {
                    layoutSkipped = true;
                }
                return;
            }
            if (Event.current.type == EventType.Layout)
            {
                layoutSkipped = false;
            }
            if (layoutSkipped)
            {
                return;
            }

            string dv        = " - ";
            string departure = " - ";
            string duration  = " - ";

            if (worker.Finished && worker.computed.GetLength(1) == porkchop_Height)
            {
                if (plot == null && Event.current.type == EventType.Layout)
                {
                    int width  = worker.computed.GetLength(0);
                    int height = worker.computed.GetLength(1);

                    if (texture != null && (texture.width != width || texture.height != height))
                    {
                        Object.Destroy(texture);
                        texture = null;
                    }

                    if (texture == null)
                    {
                        texture = new Texture2D(width, height, TextureFormat.RGB24, false);
                    }

                    Porkchop.RefreshTexture(worker.computed, texture);

                    plot = new PlotArea(
                        worker.minDepartureTime,
                        worker.maxDepartureTime,
                        worker.minTransferTime,
                        worker.maxTransferTime,
                        texture,
                        (xmin, xmax, ymin, ymax) => {
                        minDepartureTime = Math.Max(xmin, universalTime);
                        maxDepartureTime = xmax;
                        minTransferTime  = Math.Max(ymin, 3600);
                        maxTransferTime  = ymax;
                        GUI.changed      = true;
                    });
                    plot.selectedPoint = new int[] { worker.bestDate, worker.bestDuration };
                }
            }
            if (plot != null)
            {
                var point = plot.selectedPoint;
                if (plot.hoveredPoint != null)
                {
                    point = plot.hoveredPoint;
                }

                var p = worker.computed[point[0], point[1]];
                if (p > 0)
                {
                    dv = MuUtils.ToSI(p) + "m/s";
                    if (worker.DateFromIndex(point[0]) < Planetarium.GetUniversalTime())
                    {
                        departure = Localizer.Format("#MechJeb_adv_label1");//any time now
                    }
                    else
                    {
                        departure = GuiUtils.TimeToDHMS(worker.DateFromIndex(point[0]) - Planetarium.GetUniversalTime());
                    }
                    duration = GuiUtils.TimeToDHMS(worker.DurationFromIndex(point[1]));
                }
                plot.DoGUI();
                if (!plot.draggable)
                {
                    _draggable = false;
                }
            }
            else
            {
                GUIStyle progressStyle = new GUIStyle
                {
                    font      = GuiUtils.skin.font,
                    fontSize  = GuiUtils.skin.label.fontSize,
                    fontStyle = GuiUtils.skin.label.fontStyle,
                    normal    = { textColor = GuiUtils.skin.label.normal.textColor }
                };

                GUILayout.Box(Localizer.Format("#MechJeb_adv_computing") + worker.Progress + "%", progressStyle, GUILayout.Width(windowWidth), GUILayout.Height(porkchop_Height));//"Computing:"
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("ΔV: " + dv);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(Localizer.Format("#MechJeb_adv_reset_button"), GuiUtils.yellowOnHover))
            {
                ComputeTimes(o, target.TargetOrbit, universalTime);
            }
            GUILayout.EndHorizontal();

            includeCaptureBurn = GUILayout.Toggle(includeCaptureBurn, Localizer.Format("#MechJeb_adv_captureburn"));//"include capture burn"

            // fixup the default value of the periapsis if the target changes
            if (targetCelestial != null && lastTargetCelestial != targetCelestial)
            {
                if (targetCelestial.atmosphere)
                {
                    periapsisHeight = targetCelestial.atmosphereDepth / 1000 + 10;
                }
                else
                {
                    periapsisHeight = 100;
                }
            }

            GuiUtils.SimpleTextBox(Localizer.Format("#MechJeb_adv_periapsis"), periapsisHeight, "km");

            GUILayout.BeginHorizontal();
            GUILayout.Label(Localizer.Format("#MechJeb_adv_label2"));       //"Select: "
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(Localizer.Format("#MechJeb_adv_button1"))) //Lowest ΔV
            {
                plot.selectedPoint = new int[] { worker.bestDate, worker.bestDuration };
                GUI.changed        = false;
            }

            if (GUILayout.Button(Localizer.Format("#MechJeb_adv_button2")))//ASAP
            {
                int bestDuration = 0;
                for (int i = 1; i < worker.computed.GetLength(1); i++)
                {
                    if (worker.computed[0, bestDuration] > worker.computed[0, i])
                    {
                        bestDuration = i;
                    }
                }
                plot.selectedPoint = new int[] { 0, bestDuration };
                GUI.changed        = false;
            }
            GUILayout.EndHorizontal();

            GUILayout.Label(Localizer.Format("#MechJeb_adv_label3") + " " + departure); //Departure in
            GUILayout.Label(Localizer.Format("#MechJeb_adv_label4") + " " + duration);  //Transit duration

            lastTargetCelestial = targetCelestial;
        }
コード例 #6
0
        private void DoPorkchopGui(Orbit o, double universalTime, MechJebModuleTargetController target)
        {
            if (worker == null)
            {
                return;
            }
            string dv        = " - ";
            string departure = " - ";
            string duration  = " - ";

            if (worker.Finished && worker.computed.GetLength(1) == porkchop_Height)
            {
                if (plot == null && Event.current.type == EventType.Layout)
                {
                    plot = new PlotArea(
                        worker.minDepartureTime,
                        worker.maxDepartureTime,
                        worker.minTransferTime,
                        worker.maxTransferTime,
                        new Porkchop(worker.computed).texture,
                        (xmin, xmax, ymin, ymax) => {
                        minDepartureTime = Math.Max(xmin, universalTime);
                        maxDepartureTime = xmax;
                        minTransferTime  = Math.Max(ymin, 3600);
                        maxTransferTime  = ymax;
                        GUI.changed      = true;
                    });
                    plot.selectedPoint = new int[] { worker.bestDate, worker.bestDuration };
                }
            }
            if (plot != null)
            {
                var point = plot.selectedPoint;
                if (plot.hoveredPoint != null)
                {
                    point = plot.hoveredPoint;
                }

                var p = worker.computed[point[0], point[1]];
                if (p != null)
                {
                    dv = MuUtils.ToSI(p.dV.magnitude) + "m/s";
                    if (worker.DateFromIndex(point[0]) < Planetarium.GetUniversalTime())
                    {
                        departure = "any time now";
                    }
                    else
                    {
                        departure = GuiUtils.TimeToDHMS(worker.DateFromIndex(point[0]) - Planetarium.GetUniversalTime());
                    }
                    duration = GuiUtils.TimeToDHMS(worker.DurationFromIndex(point[1]));
                }
                plot.DoGUI();
                if (!plot.draggable)
                {
                    _draggable = false;
                }
            }
            else
            {
                GUIStyle progressStyle = new GUIStyle
                {
                    font      = GuiUtils.skin.font,
                    fontSize  = GuiUtils.skin.label.fontSize,
                    fontStyle = GuiUtils.skin.label.fontStyle,
                    normal    = { textColor = GuiUtils.skin.label.normal.textColor }
                };

                GUILayout.Box("Computing: " + worker.Progress + "%", progressStyle, new GUILayoutOption[] {
                    GUILayout.Width(windowWidth),
                    GUILayout.Height(porkchop_Height)
                });
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("ΔV: " + dv);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset", GuiUtils.yellowOnHover))
            {
                ComputeTimes(o, target.TargetOrbit, universalTime);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Select: ");
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Lowest ΔV"))
            {
                plot.selectedPoint = new int[] { worker.bestDate, worker.bestDuration };
                GUI.changed        = false;
            }

            if (GUILayout.Button("ASAP"))
            {
                int bestDuration = 0;
                for (int i = 1; i < worker.computed.GetLength(1); i++)
                {
                    if (worker.computed[0, bestDuration].dV.sqrMagnitude > worker.computed[0, i].dV.sqrMagnitude)
                    {
                        bestDuration = i;
                    }
                }
                plot.selectedPoint = new int[] { 0, bestDuration };
                GUI.changed        = false;
            }
            GUILayout.EndHorizontal();

            GUILayout.Label("Departure in " + departure);
            GUILayout.Label("Transit duration " + duration);
        }
コード例 #7
0
		private void DoPorkchopGui(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			if (worker == null)
				return;
			string dv = " - ";
			string departure = " - ";
			string duration = " - ";
			if (worker.Finished && worker.computed.GetLength(1) == porkchop_Height)
			{
				if (plot == null && Event.current.type == EventType.Layout)
				{
					plot = new PlotArea(
						worker.minDepartureTime,
						worker.maxDepartureTime,
						worker.minTransferTime,
						worker.maxTransferTime,
						new Porkchop(worker.computed).texture,
						(xmin, xmax, ymin, ymax) => {
							minDepartureTime = Math.Max(xmin, universalTime);
							maxDepartureTime = xmax;
							minTransferTime = Math.Max(ymin, 3600);
							maxTransferTime = ymax;
							GUI.changed = true;
						});
					plot.selectedPoint = new int[]{worker.bestDate, worker.bestDuration};
				}
			}
			if (plot != null)
			{
				var point = plot.selectedPoint;
				if (plot.hoveredPoint != null)
					point = plot.hoveredPoint;

				var p = worker.computed[point[0], point[1]];
				if (p != null)
				{
					dv = MuUtils.ToSI(p.dV.magnitude) + "m/s";
					if (worker.DateFromIndex(point[0]) < Planetarium.GetUniversalTime())
						departure = "any time now";
					else
						departure = GuiUtils.TimeToDHMS(worker.DateFromIndex(point[0]) - Planetarium.GetUniversalTime());
					duration = GuiUtils.TimeToDHMS(worker.DurationFromIndex(point[1]));
				}
				plot.DoGUI();
				if (!plot.draggable) _draggable = false;
			}
			else
			{
				GUIStyle progressStyle = new GUIStyle
				{
					font = GuiUtils.skin.font,
					fontSize = GuiUtils.skin.label.fontSize,
					fontStyle = GuiUtils.skin.label.fontStyle,
					normal = {textColor = GuiUtils.skin.label.normal.textColor}
				};

				GUILayout.Box("Computing: " + worker.Progress + "%", progressStyle, new GUILayoutOption[] {
					GUILayout.Width(windowWidth),
					GUILayout.Height(porkchop_Height)});
			}
			GUILayout.BeginHorizontal();
			GUILayout.Label("ΔV: " + dv);
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Reset", GuiUtils.yellowOnHover))
				ComputeTimes(o, target.TargetOrbit, universalTime);
			GUILayout.EndHorizontal();

			GUILayout.BeginHorizontal();
			GUILayout.Label("Select: ");
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("Lowest ΔV"))
			{
				plot.selectedPoint = new int[]{ worker.bestDate, worker.bestDuration };
				GUI.changed = false;
			}

			if (GUILayout.Button("ASAP"))
			{
				int bestDuration = 0;
				for (int i = 1; i < worker.computed.GetLength(1); i++)
				{
					if (worker.computed[0, bestDuration].dV.sqrMagnitude > worker.computed[0, i].dV.sqrMagnitude)
						bestDuration = i;
				}
				plot.selectedPoint = new int[]{ 0, bestDuration };
				GUI.changed = false;
			}
			GUILayout.EndHorizontal();

			GUILayout.Label("Departure in " + departure);
			GUILayout.Label("Transit duration " + duration);
		}
コード例 #8
0
		public override void DoParametersGUI(Orbit o, double universalTime, MechJebModuleTargetController target)
		{
			_draggable = true;
			if (worker != null && !target.NormalTargetExists && Event.current.type == EventType.Layout)
			{
				worker.stop = true;
				worker = null;
				plot = null;
			}

			selectionMode = (Mode) GuiUtils.ComboBox.Box((int) selectionMode, modeNames, this);
			if (Event.current.type == EventType.Repaint)
				windowWidth = (int)GUILayoutUtility.GetLastRect().width;

			switch (selectionMode)
			{
			case Mode.LimitedTime:
				GuiUtils.SimpleTextBox("Max arrival time", maxArrivalTime);
				if (worker != null && !worker.Finished)
					GuiUtils.SimpleLabel("Computing: " + worker.Progress + "%");
				break;
			case Mode.Porkchop:
				DoPorkchopGui(o, universalTime, target);
				break;
			}

			if (worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
				ComputeTimes(o, target.TargetOrbit, universalTime);

			if (GUI.changed || worker == null || worker.destinationOrbit != target.TargetOrbit || worker.originOrbit != o)
				ComputeStuff(o, universalTime, target);
		}