Exemple #1
0
        /// Constructor
        /// Give the navigator to which this control is for
        public Controls(Navigator navigator)
        {
            // Defaults window
            defaultWindow = new DefaultWindow(navigator);

            // Assign navigator field
            this.navigator = navigator;
            Debug.Log(this.navigator.ToString());

            // Controls window id
            id = GUIUtility.GetControlID(FocusType.Keyboard);

            // Initial time
            if (navigator.UT0 == 0)
            {
                UT0 = Planetarium.GetUniversalTime();
            }
            else
            {
                UT0 = navigator.UT0;
            }
            Debug.Log(UT0.ToString());

            // Off navigator control
            navigatorOff = Control.Default(navigator, this);

            // If the navigator doesn't have saved controls, return default
            if (String.IsNullOrEmpty(navigator.frames) ||
                String.IsNullOrEmpty(navigator.angle0s) ||
                String.IsNullOrEmpty(navigator.angle1s) ||
                String.IsNullOrEmpty(navigator.angle2s) ||
                String.IsNullOrEmpty(navigator.throttles) ||
                String.IsNullOrEmpty(navigator.sailons) ||
                String.IsNullOrEmpty(navigator.durations))
            {
                ncontrols = 1;
                controls  = new List <Control>();
                controls.Add(Control.Default(navigator, this));
            }
            else
            { // Otherwise, parse saved controls
                // Split into arrays
                var frameStrings    = navigator.frames.Split(delimiter);
                var angle0Strings   = navigator.angle0s.Split(delimiter);
                var angle1Strings   = navigator.angle1s.Split(delimiter);
                var angle2Strings   = navigator.angle2s.Split(delimiter);
                var throttleStrings = navigator.throttles.Split(delimiter);
                var durationStrings = navigator.durations.Split(delimiter);
                var sailonStrings   = navigator.sailons.Split(delimiter);

                // Find number of controls
                ncontrols =
                    Math.Min(frameStrings.Length,
                             Math.Min(angle0Strings.Length,
                                      Math.Min(angle1Strings.Length,
                                               Math.Min(angle2Strings.Length,
                                                        Math.Min(throttleStrings.Length,
                                                                 Math.Min(durationStrings.Length,
                                                                          sailonStrings.Length))))));

                // Initialize controls array
                controls = new List <Control>();

                // Populate controls
                for (var i = 0; i < ncontrols; i++)
                {
                    var angles = new float[] { Utils.ParseSingle(angle0Strings[i]),
                                               Utils.ParseSingle(angle1Strings[i]),
                                               Utils.ParseSingle(angle2Strings[i]) };
                    controls.Add(new Control(navigator,
                                             this,
                                             angles,
                                             Utils.ParseSingle(throttleStrings[i]),
                                             Utils.ParseBool(sailonStrings[i]),
                                             Utils.ParseDouble(durationStrings[i]),
                                             navigator.defaultIWarp,
                                             frameStrings[i]));
                }
            }

            // Preview
            preview = new Preview(navigator);
        }
        bool updateTargetLine = false; // Indicate if target line needs updating

        #endregion Fields

        #region Constructors

        // Constructor
        // Give the navigator to which this control is for
        public Controls(Navigator navigator)
        {
            // Defaults window
            defaultWindow = new DefaultWindow(navigator);

            // Assign navigator field
            this.navigator = navigator;
            Debug.Log(this.navigator.ToString());

            // Controls window id
            id = GUIUtility.GetControlID(FocusType.Keyboard);

            // Initial time
            if (navigator.UT0 == 0) {
            UT0 = Planetarium.GetUniversalTime();
            } else {
            UT0 = navigator.UT0;
            }
            Debug.Log(UT0.ToString());

            // Off navigator control
            navigatorOff = Control.Default(navigator, this);

            // If the navigator doesn't have saved controls, return default
            if (String.IsNullOrEmpty(navigator.frames) ||
            String.IsNullOrEmpty(navigator.angle0s) ||
            String.IsNullOrEmpty(navigator.angle1s) ||
            String.IsNullOrEmpty(navigator.angle2s) ||
            String.IsNullOrEmpty(navigator.throttles) ||
            String.IsNullOrEmpty(navigator.sailons) ||
            String.IsNullOrEmpty(navigator.durations)) {
            ncontrols = 1;
            controls = new List<Control>();
            controls.Add(Control.Default(navigator, this));

            } else { // Otherwise, parse saved controls

            // Split into arrays
            var frameStrings = navigator.frames.Split(delimiter);
            var angle0Strings = navigator.angle0s.Split(delimiter);
            var angle1Strings = navigator.angle1s.Split(delimiter);
            var angle2Strings = navigator.angle2s.Split(delimiter);
            var throttleStrings = navigator.throttles.Split(delimiter);
            var durationStrings = navigator.durations.Split(delimiter);
            var sailonStrings = navigator.sailons.Split(delimiter);

            // Find number of controls
            ncontrols =
            Math.Min(frameStrings.Length,
                 Math.Min(angle0Strings.Length,
                      Math.Min(angle1Strings.Length,
                           Math.Min(angle2Strings.Length,
                            Math.Min(throttleStrings.Length,
                                 Math.Min(durationStrings.Length,
                                      sailonStrings.Length))))));

            // Initialize controls array
            controls = new List<Control>();

            // Populate controls
            for(var i = 0; i < ncontrols; i++) {
            var angles = new float [] { Utils.ParseSingle(angle0Strings[i]),
                        Utils.ParseSingle(angle1Strings[i]),
                        Utils.ParseSingle(angle2Strings[i]) };
            controls.Add(new Control(navigator,
                         this,
                         angles,
                         Utils.ParseSingle(throttleStrings[i]),
                         Utils.ParseBool(sailonStrings[i]),
                         Utils.ParseDouble(durationStrings[i]),
                         navigator.defaultIWarp,
                         frameStrings[i]));
            }
            }

            // Preview
            preview = new Preview(navigator);
        }