Ejemplo n.º 1
0
        void FixedUpdate()
        {
            Vessel vessel = CurrentVessel();

            if (vessel == null || vessel.patchedConicSolver == null)
            {
                return;
            }
            // Following needed to adjust values for slider, which can only use float
            // Only do it 1/sec to avoid any unnecessary cpu
            if (Planetarium.GetUniversalTime() > lastTime)
            {
                lastTime = Planetarium.GetUniversalTime() + 1;
                if (vessel != null && vessel.patchedConicSolver.maneuverNodes.Count > 1)
                {
                    div = 1;
                    while (vessel.patchedConicSolver.maneuverNodes.First().UT / div > float.MaxValue ||
                           vessel.patchedConicSolver.maneuverNodes.Last().UT / div > float.MaxValue)
                    {
                        div++;
                    }

                    if (startTimeNow)
                    {
                        sliderBeginTime = (float)Planetarium.GetUniversalTime() + 60;
                    }
                    else
                    {
                        sliderBeginTime = (float)vessel.patchedConicSolver.maneuverNodes.First().UT / div;
                    }

                    if (endTimeInfo == null)
                    {
                        sliderEndtime = (float)vessel.patchedConicSolver.maneuverNodes.Last().UT / div;
                        var a = setTimeSelection(sliderEndtime / div);
                    }
                    else
                    {
                        sliderEndtime = (endTimeInfo.years * DaysPerYear * HoursPerDay * 3600 +
                                         endTimeInfo.days * HoursPerDay * 3600 +
                                         endTimeInfo.hours * 3600 +
                                         endTimeInfo.minutes * 60 +
                                         endTimeInfo.seconds + (float)Planetarium.GetUniversalTime()) / div;
                    }

                    if (timeSel < sliderBeginTime)
                    {
                        timeSel = sliderBeginTime;
                    }
                    if (timeSel > sliderEndtime)
                    {
                        timeSel = sliderEndtime;
                    }
                }
            }
            if (vessel != null && lastVessel != vessel)
            {
                if (vessel.patchedConicSolver.maneuverNodes.Count > 0)
                {
                    desiredTimeInfo = setTimeSelection(vessel.patchedConicSolver.maneuverNodes.First().UT);
                }
                lastVessel = vessel;
            }
        }
Ejemplo n.º 2
0
        private void WindowGUI(int windowID)
        {
            GUIStyle textFieldLabel = new GUIStyle(GUI.skin.textField);
            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);
            GUILayout.BeginVertical();


            GUIStyle MyScrollView    = new GUIStyle(HighLogic.Skin.scrollView);
            var      scrollbar_stlye = new GUIStyle(MyScrollView);

            scrollbar_stlye.padding  = new RectOffset(3, 3, 3, 3);
            scrollbar_stlye.border   = new RectOffset(3, 3, 3, 3);
            scrollbar_stlye.margin   = new RectOffset(1, 1, 1, 1);
            scrollbar_stlye.overflow = new RectOffset(1, 1, 1, 1);



            Vessel vessel = CurrentVessel();

            if (vessel == null)
            {
                return;
            }
            if (vessel.patchedConicSolver.maneuverNodes.Any())
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(5);
                scrollVector = GUILayout.BeginScrollView(scrollVector, scrollbar_stlye); //, GUILayout.Width(266), GUILayout.Height(225));
                foreach (var t1 in vessel.patchedConicSolver.maneuverNodes)
                {
                    TimeInfo t = setTimeSelection(t1.UT);

                    GUILayout.BeginHorizontal();
                    string l = t.years.ToString() + "y, " +
                               t.days.ToString() + "d, " +
                               t.hours.ToString() + "h, " +
                               t.minutes.ToString() + "m, " +
                               t.seconds.ToString() + "s";
                    if (GUILayout.Button(l))
                    {
                        desiredTimeInfo = setTimeSelection(t1.UT);
                        startTimeNow    = false;
                        timeSel         = (float)t1.UT / div;
                    }
#if false
                    GUILayout.Label("y", GUILayout.ExpandWidth(false));
                    GUILayout.Label(t.years.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("d", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.days.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("h", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.hours.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("m", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.minutes.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("s", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.seconds.ToString(), textFieldLabel, GUILayout.Width(40));
#endif
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }


            // need to add 0.25 here to deal with floating point roundoff.
            // setTimeSelection(DesiredTime + 0.25);
            GUILayout.Label("Desired Time:", GUILayout.ExpandWidth(true));
            GUILayout.BeginHorizontal();
            GUILayout.Label("y", GUILayout.ExpandWidth(false));
            desiredTimeInfo.years = uint.Parse(GUILayout.TextField(desiredTimeInfo.years.ToString(), GUILayout.Width(40)));
            GUILayout.Label("d", GUILayout.ExpandWidth(false));
            desiredTimeInfo.days = uint.Parse(GUILayout.TextField(desiredTimeInfo.days.ToString(), GUILayout.Width(40)));
            GUILayout.Label("h", GUILayout.ExpandWidth(false));
            desiredTimeInfo.hours = uint.Parse(GUILayout.TextField(desiredTimeInfo.hours.ToString(), GUILayout.Width(40)));
            GUILayout.Label("m", GUILayout.ExpandWidth(false));
            desiredTimeInfo.minutes = uint.Parse(GUILayout.TextField(desiredTimeInfo.minutes.ToString(), GUILayout.Width(40)));
            GUILayout.Label("s", GUILayout.ExpandWidth(false));
            desiredTimeInfo.seconds = uint.Parse(GUILayout.TextField(desiredTimeInfo.seconds.ToString(), GUILayout.Width(40)));
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            var newTimeSel = GUILayout.HorizontalSlider(timeSel, sliderBeginTime, sliderEndtime);
            if (newTimeSel != timeSel)
            {
                desiredTimeInfo = setTimeSelection(newTimeSel * div);
                timeSel         = newTimeSel;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start Time Now"))
            {
                startTimeNow = true;
            }

            if (GUILayout.Button(endTimeInfo == null? "Set End Time":"Unset End Time") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                if (endTimeInfo == null)
                {
                    endTimeInfo = desiredTimeInfo;
                }
                else
                {
                    endTimeInfo = null;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            ITargetable curTarget = FlightGlobals.fetch.VesselTarget;
            if (curTarget != null)
            {
                Vector3d target_PosAtUT = FlightGlobals.fetch.VesselTarget.GetOrbit().getPositionAtUT(DesiredTime);

                Vector3d vessel_posAtUT = vessel.orbit.getPositionAtUT(DesiredTime);
                if (vessel.patchedConicSolver.maneuverNodes.Any())
                {
                    vessel_posAtUT = vessel.patchedConicSolver.maneuverNodes.Last().nextPatch.getPositionAtUT(DesiredTime);
                }
                long targetDistAtUT = (long)Vector3d.Distance(target_PosAtUT, vessel_posAtUT) / 1000; //cast to long to cut off decimal places
                GUILayout.Label("Target dist. at UT (km)", GUILayout.ExpandWidth(false));
                GUILayout.TextField(targetDistAtUT.ToString(), GUILayout.Width(100));
            }
            GUILayout.EndHorizontal();


            if (GUILayout.Button("Next Node") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                startTimeNow    = false;
                endTimeInfo     = null;
                desiredTimeInfo = setTimeSelection(vessel.patchedConicSolver.maneuverNodes.First().UT);
                GUI.changed     = false;
                timeSel         = (float)vessel.patchedConicSolver.maneuverNodes.First().UT / div;
            }
            if (GUILayout.Button("Last Node") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                startTimeNow    = false;
                endTimeInfo     = null;
                desiredTimeInfo = setTimeSelection(vessel.patchedConicSolver.maneuverNodes.Last().UT);
                GUI.changed     = false;
                timeSel         = (float)vessel.patchedConicSolver.maneuverNodes.Last().UT / div;
            }

            GUILayout.EndVertical();

            DesiredTime = UT + desiredTimeInfo.years * DaysPerYear * HoursPerDay * 3600.0 +
                          desiredTimeInfo.days * HoursPerDay * 3600.0 +
                          desiredTimeInfo.hours * 3600.0 +
                          desiredTimeInfo.minutes * 60.0 + desiredTimeInfo.seconds;

            GUI.DragWindow();
        }
Ejemplo n.º 3
0
        private void WindowGUI(int windowID)
        {
            GUIStyle textFieldLabel = new GUIStyle(GUI.skin.textField);
            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);
            GUILayout.BeginVertical();


            GUIStyle MyScrollView    = new GUIStyle(HighLogic.Skin.scrollView);
            var      scrollbar_stlye = new GUIStyle(MyScrollView);

            scrollbar_stlye.padding  = new RectOffset(3, 3, 3, 3);
            scrollbar_stlye.border   = new RectOffset(3, 3, 3, 3);
            scrollbar_stlye.margin   = new RectOffset(1, 1, 1, 1);
            scrollbar_stlye.overflow = new RectOffset(1, 1, 1, 1);



            if (vessel.patchedConicSolver.maneuverNodes.Any())
            {
                GUILayout.BeginHorizontal();

                GUILayout.Space(5);
                scrollVector = GUILayout.BeginScrollView(scrollVector, scrollbar_stlye); //, GUILayout.Width(266), GUILayout.Height(225));
                foreach (var t1 in vessel.patchedConicSolver.maneuverNodes)
                {
                    TimeInfo t = setTimeSelection(t1.UT);

                    GUILayout.BeginHorizontal();
                    string l = t.years.ToString() + "y, " +
                               t.days.ToString() + "d, " +
                               t.hours.ToString() + "h, " +
                               t.minutes.ToString() + "m, " +
                               t.seconds.ToString() + "s";
                    if (GUILayout.Button(l))
                    {
                        desiredTimeInfo = setTimeSelection(t1.UT);
                        startTimeNow    = false;
                        timeSel         = (float)t1.UT / div;
                    }
#if false
                    GUILayout.Label("y", GUILayout.ExpandWidth(false));
                    GUILayout.Label(t.years.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("d", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.days.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("h", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.hours.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("m", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.minutes.ToString(), textFieldLabel, GUILayout.Width(40));
                    GUILayout.Label("s", GUILayout.ExpandWidth(false));
                    GUILayout.TextField(t.seconds.ToString(), textFieldLabel, GUILayout.Width(40));
#endif
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();
                GUILayout.EndHorizontal();
            }


            // need to add 0.25 here to deal with floating point roundoff.
            // setTimeSelection(DesiredTime + 0.25);
            GUILayout.Label("Desired Time:", GUILayout.ExpandWidth(true));
            GUILayout.BeginHorizontal();
            GUILayout.Label("y", GUILayout.ExpandWidth(false));
            desiredTimeInfo.years = uint.Parse(GUILayout.TextField(desiredTimeInfo.years.ToString(), GUILayout.Width(40)));
            GUILayout.Label("d", GUILayout.ExpandWidth(false));
            desiredTimeInfo.days = uint.Parse(GUILayout.TextField(desiredTimeInfo.days.ToString(), GUILayout.Width(40)));
            GUILayout.Label("h", GUILayout.ExpandWidth(false));
            desiredTimeInfo.hours = uint.Parse(GUILayout.TextField(desiredTimeInfo.hours.ToString(), GUILayout.Width(40)));
            GUILayout.Label("m", GUILayout.ExpandWidth(false));
            desiredTimeInfo.minutes = uint.Parse(GUILayout.TextField(desiredTimeInfo.minutes.ToString(), GUILayout.Width(40)));
            GUILayout.Label("s", GUILayout.ExpandWidth(false));
            desiredTimeInfo.seconds = uint.Parse(GUILayout.TextField(desiredTimeInfo.seconds.ToString(), GUILayout.Width(40)));
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            var newTimeSel = GUILayout.HorizontalSlider(timeSel, sliderBeginTime, sliderEndtime);
            if (newTimeSel != timeSel)
            {
                desiredTimeInfo = setTimeSelection(newTimeSel * div);
                timeSel         = newTimeSel;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Start Time Now"))
            {
                startTimeNow = true;
            }

            if (GUILayout.Button(endTimeInfo == null? "Set End Time":"Unset End Time") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                if (endTimeInfo == null)
                {
                    endTimeInfo = desiredTimeInfo;
                }
                else
                {
                    endTimeInfo = null;
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Next Node") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                startTimeNow    = false;
                endTimeInfo     = null;
                desiredTimeInfo = setTimeSelection(vessel.patchedConicSolver.maneuverNodes.First().UT);
                GUI.changed     = false;
                timeSel         = (float)vessel.patchedConicSolver.maneuverNodes.First().UT / div;
            }
            if (GUILayout.Button("Last Node") && vessel.patchedConicSolver.maneuverNodes.Any())
            {
                startTimeNow    = false;
                endTimeInfo     = null;
                desiredTimeInfo = setTimeSelection(vessel.patchedConicSolver.maneuverNodes.Last().UT);
                GUI.changed     = false;
                timeSel         = (float)vessel.patchedConicSolver.maneuverNodes.Last().UT / div;
            }

            HighLogic.CurrentGame.Parameters.CustomParams <Slingshotter>().useBlizzy = GUILayout.Toggle(HighLogic.CurrentGame.Parameters.CustomParams <Slingshotter>().useBlizzy, "Use Blizzy toolbar, if available");
            GUILayout.EndVertical();

            DesiredTime = UT + desiredTimeInfo.years * DaysPerYear * HoursPerDay * 3600.0 +
                          desiredTimeInfo.days * HoursPerDay * 3600.0 +
                          desiredTimeInfo.hours * 3600.0 +
                          desiredTimeInfo.minutes * 60.0 + desiredTimeInfo.seconds;

            GUI.DragWindow();
        }