示例#1
0
 public static void Remove(KeybindModel keybindModel)
 {
     if (KeybindModels.Contains(keybindModel))
     {
         KeybindModels.Remove(keybindModel);
     }
 }
示例#2
0
        private void RegisterToggle(LayerModel layerModel, int index)
        {
            Action downAction = null;
            Action upAction   = null;

            switch (ToggleType)
            {
            case ToggleType.EnableHeldDown:
                layerModel.RenderAllowed = false;
                downAction = () => layerModel.RenderAllowed = true;
                upAction   = () => layerModel.RenderAllowed = false;
                break;

            case ToggleType.DisableHeldDown:
                downAction = () => layerModel.RenderAllowed = false;
                upAction   = () => layerModel.RenderAllowed = true;
                break;
            }

            // Either bind HotKey or mouse buttons depending on what isn't null
            if (HotKey != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", HotKey, PressType.Down, downAction);
                _upKeybind   = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-up", HotKey, PressType.Up, upAction);
            }
            else if (MouseButtons != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", MouseButtons.Value, PressType.Down, downAction);
                _upKeybind   = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-up", MouseButtons.Value, PressType.Up, upAction);
            }
            KeybindManager.AddOrUpdate(_downKeybind);
            KeybindManager.AddOrUpdate(_upKeybind);
            return;
        }
示例#3
0
 public void Unregister()
 {
     if (_downKeybind != null)
     {
         KeybindManager.Remove(_downKeybind);
         _downKeybind = null;
     }
     if (_upKeybind != null)
     {
         KeybindManager.Remove(_upKeybind);
         _upKeybind = null;
     }
 }
示例#4
0
        public static void AddOrUpdate(KeybindModel keybindModel)
        {
            if (keybindModel == null)
            {
                return;
            }

            var existing = KeybindModels.FirstOrDefault(k => k.Name == keybindModel.Name);

            if (existing != null)
            {
                KeybindModels.Remove(existing);
            }

            KeybindModels.Add(keybindModel);
        }
示例#5
0
        private void RegisterEvent(LayerModel layerModel, int index)
        {
            Action action = () =>
            {
                layerModel.EventProperties.TriggerEvent(layerModel);
            };

            // Either bind HotKey or mouse buttons depending on what isn't null
            if (HotKey != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", HotKey, PressType.Down, action);
            }
            else if (MouseButtons != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", MouseButtons.Value, PressType.Down, action);
            }
            KeybindManager.AddOrUpdate(_downKeybind);
        }
示例#6
0
        private void RegisterRegular(LayerModel layerModel, int index)
        {
            // Bind Enable, Disable or Toggle
            Action action = null;

            switch (ToggleType)
            {
            case ToggleType.Enable:
                // Apply RenderAllowed only if this is the first keybind
                if (index == 0)
                {
                    layerModel.RenderAllowed = false;
                }
                action = () => layerModel.RenderAllowed = true;
                break;

            case ToggleType.Disable:
                // Apply RenderAllowed only if this is the first keybind
                if (index == 0)
                {
                    layerModel.RenderAllowed = false;
                }
                action = () => layerModel.RenderAllowed = false;
                break;

            case ToggleType.Toggle:
                action = () => layerModel.RenderAllowed = !layerModel.RenderAllowed;
                break;
            }

            // Either bind HotKey or mouse buttons depending on what isn't null
            if (HotKey != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", HotKey, PressType.Down, action);
            }
            else if (MouseButtons != null)
            {
                _downKeybind = new KeybindModel($"{layerModel.GetHashCode()}-{layerModel.Name}-{index}-down", MouseButtons.Value, PressType.Down, action);
            }
            KeybindManager.AddOrUpdate(_downKeybind);
        }
        public ProfileEditorViewModel(ProfileEditorModel profileEditorModel, DeviceManager deviceManager, LoopManager loopManager, LuaManager luaManager, ModuleModel moduleModel, MetroDialogService dialogService)
        {
            _deviceManager       = deviceManager;
            _loopManager         = loopManager;
            _moduleModel         = moduleModel;
            _dialogService       = dialogService;
            _copyKeybind         = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), PressType.Down, LayerToClipboard);
            _pasteKeybind        = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), PressType.Up, ClipboardToLayer);
            _placeholderKeyboard = KeyboardPreview = ImageUtilities.BitmapToBitmapImage(Resources.none);
            ProfileNames         = new ObservableCollection <string>();
            Layers             = new ObservableCollection <LayerModel>();
            ProfileEditorModel = profileEditorModel;
            LuaManager         = luaManager;
            ShowAll            = true;

            PropertyChanged += EditorStateHandler;
            _deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
            _moduleModel.ProfileChanged      += ModuleModelOnProfileChanged;

            LoadProfiles();
        }