public ControlToggle(IToggle toggle)
     : base(toggle)
 {
     toggle.OnToggled    += (sender, args) => Toggled(sender, args);
     toggle.OnToggledOn  += (sender, args) => ToggledOn(sender, args);
     toggle.OnToggledOff += (sender, args) => ToggledOff(sender, args);
 }
Example #2
0
 void Refresh(IToggle toggle)
 {
     if (toggle.Enabled)
     {
         if (toggle.HasCursorOver(GuiManager.Cursor))
         {
             HandleRollOn(toggle);
         }
         else
         {
             HandleRollOff(toggle);
         }
     }
     else
     {
         if (toggle.IsOn)
         {
             toggle.SetState(DisabledOn);
         }
         else
         {
             toggle.SetState(DisabledOff);
         }
     }
 }
            /// <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));
            }
Example #4
0
 /// <summary>
 /// Add a Toggle (Ad-Hoc)
 /// </summary>
 /// <param name="toggle">the Toggle to add</param>
 public void AddToggle(IToggle toggle)
 {
     if (!ToggleDictionary.ContainsKey(toggle.Key))
     {
         ToggleDictionary.TryAdd(toggle.Key, toggle);
     }
 }
            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);
                }
            }
Example #6
0
 public Record(IToggle toggle, SandboxControl control, IPrim hostPrim, IPrimFactory factory, IConfig controlConfig)
     : base(toggle)
 {
     _control = control;
     _save = new SaveDialog(hostPrim, factory, "sequence", control.DefaultRecordingName, name => control.Record.GetUserFolder(name));
     _save.OnSave += (name, id, file) => control.Record.SaveRecording(name, file);
 }
Example #7
0
 public Record(IToggle toggle, SandboxControl control, IPrim hostPrim, IPrimFactory factory, IConfig controlConfig)
     : base(toggle)
 {
     _control      = control;
     _save         = new SaveDialog(hostPrim, factory, "sequence", control.DefaultRecordingName, name => control.Record.GetFolder(name));
     _save.OnSave += (name, id, file) => control.Record.SaveRecording(name, file);
 }
 public ControlToggle(IToggle toggle)
     : base(toggle)
 {
     toggle.OnToggled += (sender, args) => Toggled(sender, args);
     toggle.OnToggledOn += (sender, args) => ToggledOn(sender, args);
     toggle.OnToggledOff += (sender, args) => ToggledOff(sender, args);
 }
Example #9
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);
        }
 /// <summary>
 /// For Ad-hoc toggle adding to the provider
 /// </summary>
 /// <param name="toggle">the toggle to add</param>
 /// <returns>true is successfully added</returns>
 public void AddToggle(IToggle toggle)
 {
     toggle.ThrowIfNull();
     if (!ToggleRepository.HasToggleByKey(toggle.Key))
     {
         ToggleRepository.AddToggle(toggle);
     }
 }
 public VolumeHandler(ref MediaElement mediaElement, ref Slider volumeSlider, ref Image pic,
                      ImageSource otherImage)
 {
     _mediaElement = mediaElement;
     _volumeImageToggle = new ImageToggle(otherImage,ref pic);
     LastOnVolumeValue = Globals.MaxVolume;
     LastOnVolumeSliderValue = Globals.MaxSliderValue;
     _volumeSlider = volumeSlider;
     forceOn();
 }
Example #12
0
        public override void ParseIDs()
        {
            base.ParseIDs();
            toggle = TryFindToggle(toggleName);

            colorSources = ParseColorSources();

            emptySource = FindColorSource(emptyColor);
            otherSource = colorSources[KERBAL_CLASS_UNKNOWN];
        }
Example #13
0
        public bool TryGetToggle(string key, out IToggle toggle)
        {
            if (dict.TryGetValue(key, out var x))
            {
                toggle = x.toggle;
                return(true);
            }

            toggle = default;
            return(false);
        }
Example #14
0
 void HandleIsOnChange(IToggle toggle)
 {
     if (toggle.HasCursorOver(GuiManager.Cursor))
     {
         HandleRollOn(toggle);
     }
     else
     {
         HandleRollOff(toggle);
     }
 }
        public MainWindow()
        {
            #if DEBUG
            Environment.SetEnvironmentVariable("SQLite_ForceLogPrepare","True");
            #endif
            InitializeComponent();
            _pausePlayToggle = new FunctionImageToggle(new BitmapImage(new Uri("pack://application:,,,/Icons/Symbols_Play_16xLG.png")),
                                               ref ImageMainWindowPausePlayButton,
                () =>
                {
                    if (MediaElementMainWindow.IsLoaded &&
                        MediaElementMainWindow.LoadedBehavior == MediaState.Manual &&
                        MediaElementMainWindow.Clock == null)
                    {
                        MediaElementMainWindow.Play();
                        //MessageBox.Show("Play");
                    }
                },
                () =>
                {
                    if (MediaElementMainWindow.IsLoaded &&
                        MediaElementMainWindow.LoadedBehavior == MediaState.Manual &&
                        MediaElementMainWindow.Clock == null)
                    {
                        MediaElementMainWindow.Pause();
                        //MessageBox.Show("Pause");
                    }
                });

            _volumeHandler = new VolumeHandler(ref MediaElementMainWindow,
                ref SliderMainWindowSoundSlider,
                ref ImageMainWindowVolumePic,
                new BitmapImage(new Uri("pack://application:,,,/Icons/SoundfileNoSound_461.png")));

            IList<MediaEntry> mediaEntries = searchForFilesAndGetInfo();

            _databaseHandler = new DatabaseHandler(mediaEntries);
            _mediaDict = new Dictionary<string, MediaEntry>();
            initListBoxValues(mediaEntries,ListBoxMainWindowRecentlyPlayed);
            _defaultPlaylist = new Playlist(ListBoxMainWindowRecentlyPlayed.Items);
            _currentPlaylist = new Playlist(ListBoxMainWindowRecentlyPlayed.Items);
            _timeSliderHandler = new TimeSliderHandler(ref MediaElementMainWindow,
                ref SliderMainWindowTimeSlider,
                ref LabelMainWindowTimer);

            _timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _timer.Tick += (source, e) => { _timeSliderHandler.updateSliderPosition(source,e);};
            _timer.Start();
        }
        public override void ParseIDs()
        {
            base.ParseIDs();

            try
            {
                inputToggle = RequireToggle(input);
                isValid     = true;
            }
            catch (ArgumentException e)
            {
                Logging.Warn("Invalid input for " + Identifier + " on " + part.GetTitle() + ": " + e.Message);
            }
            activeSource   = FindColorSource(activeColor);
            inactiveSource = FindColorSource(inactiveColor);
        }
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     toggle       = Identifiers.FindFirst <IToggle>(part, toggleID);
     activeSource = ColorSourceArray.of(activeColor);
     if (toggle == null)
     {
         if (!string.IsNullOrEmpty(inactiveColor))
         {
             Logging.Warn("Ignoring inactiveColor on " + GetType() + " of " + part.GetTitle() + " (no toggle was specified)");
         }
     }
     else
     {
         inactiveSource = ColorSourceArray.of(inactiveColor);
     }
 }
        public LockedPermissions(IPrimFactory factory, IConfigSource config, IPrim host, Control.Impl.Module.Control control)
        {
            _ownerID = UUID.Zero;
            _host = host;
            IConfig controlConfig = config.Configs["Control"];
            double fade = controlConfig.GetDouble("LockFade", control.Fade);
            double glow = controlConfig.GetDouble("LockGlow", control.ToggleGlow);
            _lockWait = controlConfig.GetInt("ControlsLockTimeout", 300000);
            _lockToggle = new Toggle(factory.MakeButton("Lock", new LockPermissions(this)), fade, glow);

            _lockToggle.OnToggledOn += (source, args) => SetCurrentOwner(args.ID, args.Name);
            _lockToggle.OnToggledOff += (source, args) => {
                _ownerID = UUID.Zero;
                _host.Say(_ownerName + " relinquished control of sandbox.");
                JM726.Lib.Static.Util.Wake(this);
            };
            _lockToggle.OnTouched += (source, args) => {
                if (_Locked && !args.AvatarID.Equals(_ownerID))
                    _host.Say("Unable to take control of sandbox. Sandbox is currently locked to '" + _ownerName + "'.");
            };
        }
Example #19
0
 /// <summary>
 /// Try to get a "logical AND" toggle from a ParsedParameters. The expected format is:
 ///
 /// and(toggle1, toggle2, ... toggleN)
 /// </summary>
 /// <param name="module"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public static IToggle TryParse(PartModule module, ParsedParameters parsedParams)
 {
     if (parsedParams == null)
     {
         return(null);
     }
     if (!TYPE_NAME.Equals(parsedParams.Identifier))
     {
         return(null);
     }
     parsedParams.RequireCount(module, 1, -1);
     if (parsedParams.Count == 1)
     {
         return(Require(module, parsedParams[0]));
     }
     IToggle[] inputs = new IToggle[parsedParams.Count];
     for (int i = 0; i < inputs.Length; ++i)
     {
         inputs[i] = Require(module, parsedParams[i]);
     }
     return(new LogicalOr(inputs));
 }
Example #20
0
        public LockedPermissions(IPrimFactory factory, IConfigSource config, IPrim host, Control.Impl.Module.Control control)
        {
            _ownerID = UUID.Zero;
            _host    = host;
            IConfig controlConfig = config.Configs["Control"];
            double  fade          = controlConfig.GetDouble("LockFade", control.Fade);
            double  glow          = controlConfig.GetDouble("LockGlow", control.ToggleGlow);

            _lockWait   = controlConfig.GetInt("ControlsLockTimeout", 300000);
            _lockToggle = new Toggle(factory.MakeButton("Lock", new LockPermissions(this)), fade, glow);

            _lockToggle.OnToggledOn  += (source, args) => SetCurrentOwner(args.ID, args.Name);
            _lockToggle.OnToggledOff += (source, args) => {
                _ownerID = UUID.Zero;
                _host.Say(_ownerName + " relinquished control of sandbox.");
                JM726.Lib.Static.Util.Wake(this);
            };
            _lockToggle.OnTouched += (source, args) => {
                if (_Locked && !args.AvatarID.Equals(_ownerID))
                {
                    _host.Say("Unable to take control of sandbox. Sandbox is currently locked to '" + _ownerName + "'.");
                }
            };
        }
Example #21
0
        /// <summary>
        /// Get a descriptive string for a ModuleEmissiveControllerBase.
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        private string DescribeController(ModuleEmissiveControllerBase controller)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(controller.ClassName);
            ModuleEmissiveController simpleController = controller as ModuleEmissiveController;

            if ((simpleController != null) && !string.IsNullOrEmpty(simpleController.controllerName))
            {
                builder.AppendFormat(" \"{0}\"", simpleController.controllerName);
            }
            builder.Append(", ");
            if (string.IsNullOrEmpty(controller.emissiveName))
            {
                builder.Append("no emissive");
            }
            else
            {
                builder.AppendFormat("emissive \"{0}\"", controller.emissiveName);
            }
            string description = controller.DebugDescription;

            if (string.IsNullOrEmpty(description))
            {
                IToggle toggle = controller as IToggle;
                if (toggle != null)
                {
                    description = string.Format("status = {0}", toggle.ToggleStatus);
                }
            }
            if (!string.IsNullOrEmpty(description))
            {
                builder.AppendFormat(": {0}", description);
            }
            return(builder.ToString());
        }
Example #22
0
 void Refresh(IToggle toggle)
 {
     if (toggle.Enabled)
     {
         if (toggle.HasCursorOver(GuiManager.Cursor))
         {
             HandleRollOn(toggle);
         }
         else
         {
             HandleRollOff(toggle);
         }
     }
     else
     {
         if(toggle.IsOn)
         {
             toggle.SetState(DisabledOn);
         }
         else
         {
             toggle.SetState(DisabledOff);
         }
     }
 }
Example #23
0
 void HandleIsOnChange(IToggle toggle)
 {
     if (toggle.HasCursorOver(GuiManager.Cursor))
     {
         HandleRollOn(toggle);
     }
     else
     {
         HandleRollOff(toggle);
     }
 }
Example #24
0
 private ToggleAsScalar(IToggle input, double activeValue, double inactiveValue)
 {
     this.input         = input;
     this.activeValue   = activeValue;
     this.inactiveValue = inactiveValue;
 }
Example #25
0
 void Initialize()
 {
     this._togglePattern = new ToggleImplementation(uiObject: this);
 }
Example #26
0
 /// <summary>
 /// Gets an inverter of the specified toggle.
 /// </summary>
 /// <param name="source"></param>
 /// <returns></returns>
 public static IToggle of(IToggle source)
 {
     return((source is Inverter) ? ((Inverter)source).source : new Inverter(source));
 }
Example #27
0
 public Pause(IToggle toggle, IModule control, IPrim hostPrim, IPrimFactory factory, IConfig controlConfig)
     : base(toggle)
 {
     _control = control;
 }
        /// <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);

            emptySource     = FindColorSource(emptyColor);
            pilotSource     = FindColorSource(pilotColor);
            engineerSource  = FindColorSource(engineerColor);
            scientistSource = FindColorSource(scientistColor);
            touristSource   = FindColorSource(touristColor);

            // The default value for slot is NO_SLOT. When we start up, we scan for all ModuleCrewIndicators
            // on the part, and assign them sequentially to slots, if available.
            if (part == null)
            {
                return;
            }
            if (part.CrewCapacity < 1)
            {
                return;
            }
            // First, go through and note which slots already have a ModuleCrewIndicator assigned to them.
            bool[] slotAssignments = new bool[part.CrewCapacity];
            for (int moduleIndex = 0; moduleIndex < part.Modules.Count; ++moduleIndex)
            {
                ModuleCrewIndicator indicator = part.Modules[moduleIndex] as ModuleCrewIndicator;
                if (indicator == null)
                {
                    continue;
                }
                if ((indicator.slot < 0) || (indicator.slot >= part.CrewCapacity))
                {
                    indicator.slot = NO_SLOT;
                }
                else
                {
                    slotAssignments[indicator.slot] = true;
                }
            }
            // Next, go through and assign any unassigned ModuleCrewIndicators to any open slots.
            int slotIndex = 0;

            for (int moduleIndex = 0; moduleIndex < part.Modules.Count; ++moduleIndex)
            {
                ModuleCrewIndicator indicator = part.Modules[moduleIndex] as ModuleCrewIndicator;
                if (indicator == null)
                {
                    continue;
                }
                if (indicator.slot != NO_SLOT)
                {
                    continue;                            // explicitly specifies a slot
                }
                while (slotAssignments[slotIndex])
                {
                    ++slotIndex;
                    if (slotIndex >= part.CrewCapacity)
                    {
                        return;
                    }
                }
                indicator.slot             = slotIndex;
                slotAssignments[slotIndex] = true;
            }
        }
Example #29
0
 public TogglePair(IToggle toggle)
 {
     this.toggle     = toggle;
     prevToggleValue = toggle.IsOn;
 }
Example #30
0
 public static IScalar Of(IToggle input, double activeValue, double inactiveValue)
 {
     return(new ToggleAsScalar(input, activeValue, inactiveValue));
 }
Example #31
0
 public void Add(string key, IToggle toggle)
 {
     dict.Add(key, new TogglePair(toggle));
 }
Example #32
0
 private Inverter(IToggle source)
 {
     this.source = source;
 }
Example #33
0
 public ToggleGroup(IToggle masterToggle, IEnumerable <IToggle> slaveToggles)
 {
     this.masterToggle = masterToggle;
     this.slaveToggles = slaveToggles;
 }
Example #34
0
        /// <summary>
        /// Parse an IToggle from the specified text. Throws ArgumentException if there's a problem.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static IToggle Require(PartModule module, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("must supply a value");
            }
            text = text.Trim();

            // Check for constants.
            if (text == "true")
            {
                return(Constant.TRUE);
            }
            if (text == "false")
            {
                return(Constant.FALSE);
            }

            // Perhaps it's an inverted toggle?
            if (text.StartsWith(NOT_OPERATOR))
            {
                return(Inverter.of(Require(module, text.Substring(NOT_OPERATOR.Length))));
            }

            // Maybe it's an identifier for a toggle.
            IToggle found = Identifiers.FindFirst <IToggle>(module.part, text);

            if (found != null)
            {
                return(found);
            }

            // Could it be a named-field reference?
            Identifiers.IFieldEvaluator field = Identifiers.FindKSPField(module.part, text);
            if (field != null)
            {
                if (!typeof(bool).IsAssignableFrom(field.FieldType))
                {
                    throw new ArgumentException("Can't use " + text + " as a boolean field (it's of type " + field.FieldType.Name + ")");
                }
                return(new NamedField(field));
            }

            // Perhaps it's a parameterized expression?
            ParsedParameters parsedParams = ParsedParameters.TryParse(text);

            if (parsedParams != null)
            {
                for (int i = 0; i < PARSEABLE_TOGGLES.Length; ++i)
                {
                    IToggle parsed = PARSEABLE_TOGGLES[i](module, parsedParams);
                    if (parsed != null)
                    {
                        return(parsed);
                    }
                }
            }

            // Nope, not parseable.
            throw new ArgumentException("Invalid toggle syntax \"" + text + "\"");
        }
Example #35
0
 public Pause(IToggle toggle, IModule control, IPrim hostPrim, IPrimFactory factory, IConfig controlConfig)
     : base(toggle)
 {
     _control = control;
 }