private void ProfileModelOnOnProfileUpdatedEvent(object sender, EventArgs e) { foreach (var keybindModel in _keybindModels) { KeybindManager.AddOrUpdate(keybindModel); } }
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; }
public new void OnActivate() { base.OnActivate(); _loopManager.RenderCompleted += LoopManagerOnRenderCompleted; KeybindManager.AddOrUpdate(_copyKeybind); KeybindManager.AddOrUpdate(_pasteKeybind); }
/// <summary> /// Sets a keybind to call the provided function /// </summary> /// <param name="name">Name of the keybind</param> /// <param name="hotKey">Hotkey in string format, per example: ALT+CTRL+SHIFT+D</param> /// <param name="pressType">The key type, either key up or key down</param> /// <param name="function">LUA function to call</param> /// <param name="args">Optional arguments for the passed function</param> public void SetKeybind(string name, string hotKey, PressType pressType, DynValue function, params DynValue[] args) { if (pressType != PressType.Down && pressType != PressType.Up) { throw new ScriptRuntimeException("Key type must either be Down or Up."); } var modifierKeys = ModifierKeys.None; var key = Key.System; var hotKeyParts = hotKey.Split('+').Select(p => p.Trim()); foreach (var hotKeyPart in hotKeyParts) { if (hotKeyPart == "ALT") { modifierKeys |= ModifierKeys.Alt; } else if (hotKeyPart == "CTRL") { modifierKeys |= ModifierKeys.Control; } else if (hotKeyPart == "SHIFT") { modifierKeys |= ModifierKeys.Shift; } else { Enum.TryParse(hotKeyPart, true, out key); } } if (key == Key.System) { throw new ScriptRuntimeException($"Hotkey '{hotKey}' couldn't be parsed."); } var hk = new HotKey(key, modifierKeys); var model = args != null ? new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function, args)) : new KeybindModel("LUA-" + name, hk, pressType, () => LuaManager.Call(function)); KeybindManager.AddOrUpdate(model); var existing = _keybindModels.FirstOrDefault(k => k.Name == model.Name); if (existing != null) { _keybindModels.Remove(existing); } _keybindModels.Add(model); }
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); }
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); }