/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="origin">The ColorSource to which to apply a pulsating brightness filter.</param>
 /// <param name="cycleMillis">The duration of a pulsate cycle, in milliseconds.</param>
 /// <param name="multiplier1">The brightness factor to apply at one end of a cycle. 0 = pulsates down to black (strongest effect), 1 = no dimming.</param>
 /// <param name="multiplier2">The brightness factor to apply at the other end of a cycle. 0 = pulsates down to black (strongest effect), 1 = no dimming.</param>
 /// <param name="phase">The phase of the animation.</param>
 public PulsateColorSource(IColorSource origin, long cycleMillis, float multiplier1, float multiplier2, float phase)
 {
     this.origin = origin;
     this.wave   = Animations.TriangleWave.of(cycleMillis, multiplier1, multiplier2, phase);
     if (phase == 0)
     {
         this.id = string.Format(
             "{0}({1},{2},{3},{4})",
             TYPE_NAME,
             origin.ColorSourceID,
             cycleMillis,
             multiplier1,
             multiplier2);
     }
     else
     {
         this.id = string.Format(
             "{0}({1},{2},{3},{4},{5})",
             TYPE_NAME,
             origin.ColorSourceID,
             cycleMillis,
             multiplier1,
             multiplier2,
             phase);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Try to set the colors of the meshes on the specified controller.
        /// </summary>
        /// <param name="controller"></param>
        public void SetColors(ModuleEmissiveControllerBase controller)
        {
            if (!TryInitialize(controller))
            {
                return;
            }

            int sourceIndex = 0;

            for (int emissiveIndex = 0; emissiveIndex < controller.Emissives.Count; ++emissiveIndex)
            {
                ModuleControllableEmissive emissive = controller.Emissives[emissiveIndex];
                for (int meshIndex = 0; meshIndex < emissive.Count; ++meshIndex)
                {
                    if (sourceIndex >= sources.Length)
                    {
                        return;
                    }
                    IColorSource source = sources[sourceIndex++];
                    if (source.HasColor)
                    {
                        emissive.SetColorAt(source.OutputColor, meshIndex);
                    }
                }
            }
        }
            public IfColorSource(IToggle toggle, string toggleID, IColorSource onSource, IColorSource offSource)
            {
                this.toggle    = toggle;
                this.onSource  = onSource;
                this.offSource = offSource;

                if ((offSource.ColorSourceID == Colors.ToString(DefaultColor.Off)) ||
                    (offSource.ColorSourceID == Colors.ToString(Color.black)))
                {
                    id = string.Format(
                        "{0}({1},{2})",
                        TYPE_NAME,
                        toggleID,
                        onSource.ColorSourceID);
                }
                else
                {
                    id = string.Format(
                        "{0}({1},{2},{3})",
                        TYPE_NAME,
                        toggleID,
                        onSource.ColorSourceID,
                        offSource.ColorSourceID);
                }
            }
Beispiel #4
0
 public override void ParseIDs()
 {
     base.ParseIDs();
     ready     = FindColorSource(readyColor);
     acquire   = FindColorSource(acquireColor);
     disengage = FindColorSource(disengageColor);
 }
Beispiel #5
0
 public override void ParseIDs()
 {
     base.ParseIDs();
     lowValueSource    = FindColorSource(lowValueColor);
     mediumValueSource = FindColorSource(mediumValueColor);
     highValueSource   = FindColorSource(highValueColor);
 }
Beispiel #6
0
 public BlinkColorSource(IColorSource onSource, long onMillis, IColorSource offSource, long offMillis, float phase)
 {
     this.blink     = Animations.Blink.of(onMillis, offMillis, phase);
     this.onSource  = onSource;
     this.offSource = offSource;
     if (phase == 0F)
     {
         this.id = string.Format(
             "{0}({1},{2},{3},{4})",
             TYPE_NAME,
             onSource.ColorSourceID,
             onMillis,
             offSource.ColorSourceID,
             offMillis);
     }
     else
     {
         this.id = string.Format(
             "{0}({1},{2},{3},{4},{5})",
             TYPE_NAME,
             onSource.ColorSourceID,
             onMillis,
             offSource.ColorSourceID,
             offMillis,
             phase);
     }
 }
 public override void ParseIDs()
 {
     base.ParseIDs();
     dataRate       = (SourceModule == null) ? 0.0 : SourceModule.DataRate;
     busySource     = FindColorSource(busyColor);
     inactiveSource = FindColorSource(inactiveColor);
 }
 public override void ParseIDs()
 {
     base.ParseIDs();
     forwardSource  = FindColorSource(forwardColor);
     backwardSource = FindColorSource(backwardColor);
     inactiveSource = FindColorSource(inactiveColor);
 }
Beispiel #9
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     ready     = FindColorSource(readyColor);
     acquire   = FindColorSource(acquireColor);
     disengage = FindColorSource(disengageColor);
 }
Beispiel #10
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            enabledSource  = FindColorSource(enabledColor);
            disabledSource = FindColorSource(disabledColor);
        }
            /// <summary>
            /// Try to get an "if" color source from a ParsedParameters. The expected format is:
            ///
            /// if(toggle, onSource)
            /// if(toggle, onSource, offSource)
            /// </summary>
            public static IColorSource TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (!TYPE_NAME.Equals(parsedParams.Identifier))
                {
                    return(null);
                }
                parsedParams.RequireCount(module, 2, 3);
                IToggle toggle = null;

                try
                {
                    toggle = Toggles.Require(module, parsedParams[0]);
                }
                catch (ArgumentException e)
                {
                    throw new ColorSourceException(module, "Invalid toggle specified for " + TYPE_NAME + "(): " + e.Message);
                }
                IColorSource onSource  = Find(module, parsedParams[1]);
                IColorSource offSource = (parsedParams.Count > 2) ? Find(module, parsedParams[2]) : BLACK;

                return(new IfColorSource(toggle, parsedParams[0], onSource, offSource));
            }
        /// <summary>
        /// Given a color source ID (which might be a literal color, the ID of a controller,
        /// or a parameterized source) and a count, try to get an array of that many color
        /// sources, each parsed from the source ID, but substituting the zero-based index for
        /// the string literal "index".
        /// </summary>
        /// <param name="module"></param>
        /// <param name="sourceID"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static IColorSource[] FindWithIndex(PartModule module, string sourceID, int count)
        {
            IColorSource[] sources = new IColorSource[count];
            int            index   = 0;

            try
            {
                for ( ; index < sources.Length; ++index)
                {
                    string withIndex = sourceID.Replace(INDEX_TAG, index.ToString()).Replace(COUNT_TAG, count.ToString());
                    sources[index] = FindPrivate(module, withIndex);
                }
            }
            catch (ColorSourceException e)
            {
                string message = "Invalid color source '" + sourceID + "' specified for " + module.ClassName + " on " + module.part.GetTitle() + ": " + e.Message;
                for (Exception cause = e.InnerException; cause != null; cause = cause.InnerException)
                {
                    message += " -> " + cause.Message;
                }
                Logging.Warn(message);
                if (Configuration.isVerbose)
                {
                    Logging.Exception(e);
                }
                for ( ; index < sources.Length; ++index)
                {
                    sources[index] = ERROR;
                }
            }
            return(sources);
        }
Beispiel #13
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            readySource    = FindColorSource(readyColor);
            inactiveSource = FindColorSource(inactiveColor);
        }
Beispiel #14
0
        public void SetColor(IColorSource colorSource)
        {
            try
            {
                EnsureBlinkIsOpen();
            }
            catch (InvalidOperationException)
            {
                main.Errors.Add("Could not open Blink1 - not connected.");
                return;
            }

            var rgb = colorSource.GetRgb();
            try
            {
                var success = blink.SetColor(rgb.Red, rgb.Green, rgb.Blue);
                if (!success)
                {
                    main.Errors.Add("Error when writing color to Blink1.");
                }
            }
            catch (InvalidOperationException)
            {
                main.Errors.Add(
                    "Could not set color - Blink1 is not connected.");
            }
        }
Beispiel #15
0
        /// <summary>
        /// Here when we're starting up.
        /// </summary>
        /// <param name="state"></param>
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            toggle         = Identifiers.FindFirst <IToggle>(part, toggleName);
            activeSource   = FindColorSource(activeColor);
            inactiveSource = FindColorSource(inactiveColor);
        }
 public override void ParseIDs()
 {
     base.ParseIDs();
     problemSource   = FindColorSource(problemColor);
     normalSource    = FindColorSource(normalColor);
     pilotOnlySource = FindColorSource(pilotOnlyColor);
     sasOnlySource   = FindColorSource(sasOnlyColor);
 }
 public override void ParseIDs()
 {
     base.ParseIDs();
     alreadyScannedSource = FindColorSource(alreadyScannedColor);
     potentialScanSource  = FindColorSource(potentialScanColor);
     readyScanSource      = FindColorSource(readyScanColor);
     unusableSource       = FindColorSource(unusableColor);
 }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            mediumValueSource   = FindColorSource(mediumValueColor);
            highValueSource     = FindColorSource(highValueColor);
            nextSituationUpdate = DateTime.MinValue;
        }
 public override void ParseIDs()
 {
     base.ParseIDs();
     dataSource        = FindColorSource(dataColor);
     partialDataSource = string.IsNullOrEmpty(partialDataColor) ? null : FindColorSource(partialDataColor);
     lowDataSource     = string.IsNullOrEmpty(lowDataColor) ? null : FindColorSource(lowDataColor);
     emptySource       = FindColorSource(emptyColor);
 }
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     this.startState      = state;
     this.problemSource   = FindColorSource(problemColor);
     this.normalSource    = FindColorSource(normalColor);
     this.pilotOnlySource = FindColorSource(pilotOnlyColor);
     this.sasOnlySource   = FindColorSource(sasOnlyColor);
 }
 public override void ParseIDs()
 {
     base.ParseIDs();
     highSource     = FindColorSource(highColor);
     mediumSource   = FindColorSource(mediumColor);
     lowSource      = FindColorSource(lowColor);
     criticalSource = FindColorSource(criticalColor);
     emptySource    = FindColorSource(emptyColor);
 }
Beispiel #22
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            alreadyScannedSource = FindColorSource(alreadyScannedColor);
            potentialScanSource  = FindColorSource(potentialScanColor);
            readyScanSource      = FindColorSource(readyScanColor);
            unusableSource       = FindColorSource(unusableColor);
        }
Beispiel #23
0
 public void SetColor(IColorSource colorSource)
 {
     App.Current.Dispatcher.Invoke(() =>
     {
         var rgb = colorSource.GetRgb();
         textBlock.Foreground = new SolidColorBrush(Color.FromRgb(
             (byte)rgb.Red, (byte)rgb.Green, (byte)rgb.Blue));
     }, DispatcherPriority.ContextIdle);
 }
 public override void ParseIDs()
 {
     base.ParseIDs();
     inactiveSource    = FindColorSource(inactiveColor);
     unavailableSource = FindColorSource(unavailableColor);
     lowSource         = FindColorSource(lowResourceColor);
     mediumSource      = FindColorSource(mediumResourceColor);
     highSource        = FindColorSource(highResourceColor);
 }
Beispiel #25
0
        /// <summary>
        /// Called when the module is starting up.
        /// </summary>
        /// <param name="state"></param>
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            highSource     = FindColorSource(highColor);
            mediumSource   = FindColorSource(mediumColor);
            lowSource      = FindColorSource(lowColor);
            criticalSource = FindColorSource(criticalColor);
            emptySource    = FindColorSource(emptyColor);
        }
Beispiel #26
0
        public override void ParseIDs()
        {
            base.ParseIDs();
            toggle = TryFindToggle(toggleName);

            colorSources = ParseColorSources();

            emptySource = FindColorSource(emptyColor);
            otherSource = colorSources[KERBAL_CLASS_UNKNOWN];
        }
Beispiel #27
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            StatusField.uiControlEditor.onFieldChanged = OnEditorToggleChanged;

            inputActive   = FindColorSource(activeColor);
            inputInactive = FindColorSource(inactiveColor);

            SetInputUIState();
        }
Beispiel #28
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            dataSource        = FindColorSource(dataColor);
            partialDataSource = string.IsNullOrEmpty(partialDataColor) ? null : FindColorSource(partialDataColor);
            lowDataSource     = string.IsNullOrEmpty(lowDataColor) ? null : FindColorSource(lowDataColor);
            emptySource       = FindColorSource(emptyColor);
            nextUpdate        = DateTime.MinValue;
            _subjectId        = GetData();
        }
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            inactiveSource    = FindColorSource(inactiveColor);
            unavailableSource = FindColorSource(unavailableColor);
            lowSource         = FindColorSource(lowResourceColor);
            mediumSource      = FindColorSource(mediumResourceColor);
            highSource        = FindColorSource(highResourceColor);

            tracker = new ResourceAbundanceTracker(SourceModule);
        }
Beispiel #30
0
            /// <summary>
            /// Try to get a dim color source from a ParsedParameters. The expected format is:
            ///
            /// dim(origin, multiplier)
            /// </summary>
            public static IColorSource TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (!TYPE_NAME.Equals(parsedParams.Identifier))
                {
                    return(null);
                }
                if (parsedParams.Count != 2)
                {
                    throw new ColorSourceException(
                              module,
                              TYPE_NAME + "() source specified " + parsedParams.Count + " parameters (2 required)");
                }

                IColorSource origin;

                try
                {
                    origin = FindPrivate(module, parsedParams[0]);
                }
                catch (ColorSourceException e)
                {
                    throw new ColorSourceException(module, TYPE_NAME + "() source has invalid origin", e);
                }

                float multiplier;

                try
                {
                    multiplier = float.Parse(parsedParams[1]);
                }
                catch (FormatException e)
                {
                    throw new ColorSourceException(module, TYPE_NAME + "(): Invalid multiplier value '" + parsedParams[1] + "' (must be a float)", e);
                }
                if ((multiplier < 0) || (multiplier > 1))
                {
                    throw new ColorSourceException(module, TYPE_NAME + "(): Invalid multiplier value '" + parsedParams[1] + "' (must be in range 0 - 1)");
                }
                if (multiplier >= 1)
                {
                    return(origin);
                }

                return(new DimColorSource(origin, multiplier));
            }
Beispiel #31
0
        /// <summary>
        /// Called when the module is starting up.
        /// </summary>
        /// <param name="state"></param>
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            activeSource   = FindColorSource(activeColor);
            inactiveSource = FindColorSource(inactiveColor);

            converter = FindConverter();
            if (converter == null)
            {
                // bad config!
                Logging.Warn("Can't find converter named '" + converterName + "' on " + part.GetTitle());
                return;
            }
        }
Beispiel #32
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            sourceOn  = FindColorSource(onColor);
            sourceOff = FindColorSource(offColor);
            blink     = Animations.Blink.of((long)onMillis, (long)offMillis, phase);

            BlinkEnabledField.uiControlEditor.onFieldChanged = OnBlinkEnabledChanged;
            OnMillisField.uiControlEditor.onFieldChanged     = OnMillisChanged;
            OffMillisField.uiControlEditor.onFieldChanged    = OnMillisChanged;
            PhaseField.uiControlEditor.onFieldChanged        = OnMillisChanged;

            SetUiState();
        }