protected EffectViewModel(MainManager mainManager, EffectModel effectModel) { MainManager = mainManager; EffectModel = effectModel; EffectSettings = effectModel.Settings; MainManager.OnEnabledChangedEvent += MainManagerOnOnEnabledChangedEvent; MainManager.EffectManager.OnEffectChangedEvent += EffectManagerOnOnEffectChangedEvent; }
/// <summary> /// Get all profiles matching the provided game /// </summary> /// <param name="game">The game to match</param> /// <param name="keyboard">The keyboard to match</param> /// <returns>All profiles matching the provided game</returns> public static List<ProfileModel> GetAll(EffectModel game, KeyboardProvider keyboard) { if (game == null) throw new ArgumentNullException(nameof(game)); if (keyboard == null) throw new ArgumentNullException(nameof(keyboard)); return GetAll().Where(g => g.GameName.Equals(game.Name) && g.KeyboardSlug.Equals(keyboard.Slug)).ToList(); }
public ProfileEditorViewModel(MainManager mainManager, EffectModel gameModel, ProfileViewModel profileViewModel, MetroDialogService dialogService, string lastProfile, ILayerEditorVmFactory layerEditorVmFactory) { _mainManager = mainManager; _gameModel = gameModel; _layerEditorVmFactory = layerEditorVmFactory; Profiles = new BindableCollection<ProfileModel>(); Layers = new BindableCollection<LayerModel>(); ProfileViewModel = profileViewModel; DialogService = dialogService; LastProfile = lastProfile; PropertyChanged += EditorStateHandler; ProfileViewModel.PropertyChanged += LayerSelectedHandler; mainManager.DeviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent; _saveTimer = new Timer(5000); _saveTimer.Elapsed += ProfileSaveHandler; LoadProfiles(); }
public EffectChangedEventArgs(EffectModel effect) { Effect = effect; }
/// <summary> /// Disables the current effect and changes it to the provided effect. /// </summary> /// <param name="effectModel">The effect to activate</param> /// <param name="loopManager">Optionally pass the LoopManager to automatically start it, if it's not running.</param> public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null) { if (_waitEffect != null) { _logger.Debug("Stopping effect because a change is already queued"); return; } if (effectModel == null) throw new ArgumentNullException(nameof(effectModel)); if (effectModel is OverlayModel) throw new ArgumentException("Can't set an Overlay effect as the active effect"); if (_deviceManager.ActiveKeyboard == null) { _logger.Debug("Stopping effect change until keyboard is enabled"); _waitEffect = effectModel; _waitLoopManager = loopManager; _deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent; _deviceManager.EnableLastKeyboard(); return; } // Game models are only used if they are enabled var gameModel = effectModel as GameModel; if (gameModel != null) if (!gameModel.Enabled) { _logger.Debug("Cancelling effect change, provided game not enabled"); return; } var wasNull = false; if (ActiveEffect == null) { wasNull = true; ActiveEffect = effectModel; } lock (ActiveEffect) { if (!wasNull) ActiveEffect.Dispose(); ActiveEffect = effectModel; ActiveEffect.Enable(); if (!ActiveEffect.Initialized) { _logger.Debug("Cancelling effect change, couldn't initialize the effect ({0})", effectModel.Name); ActiveEffect = null; return; } } if (loopManager != null && !loopManager.Running) { _logger.Debug("Starting LoopManager for effect change"); loopManager.StartAsync(); } _logger.Debug("Changed active effect to: {0}", effectModel.Name); if (ActiveEffect is GameModel || ActiveEffect is ProfilePreviewModel) return; // Non-game effects are stored as the new LastEffect. _generalSettings.LastEffect = ActiveEffect?.Name; _generalSettings.Save(); }
/// <summary> /// Disables the given game /// </summary> /// <param name="activeEffect"></param> public void DisableGame(EffectModel activeEffect) { _logger.Debug("Disabling game: {0}", activeEffect?.Name); if (GetLastEffect() == null) ClearEffect(); else ChangeEffect(GetLastEffect()); }
private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs e) { _deviceManager.OnKeyboardChangedEvent -= DeviceManagerOnOnKeyboardChangedEvent; _logger.Debug("Resuming effect change"); var effect = _waitEffect; _waitEffect = null; var loopManager = _waitLoopManager; _waitLoopManager = null; ChangeEffect(effect, loopManager); }