public ToggleService(ICoreButton client, ICoreButton altButton, KState.Special toggle_key = KState.Special.Shift) : base(client) { _serviceType = Enum.GetName(typeof(TIH), client.Action) + Enum.GetName(typeof(TIH), altButton.Action) + "Toggle"; _altButton = altButton; toggleKey = toggle_key; }
/// <summary> /// Set up key-event-subscribers that will toggle between the 2 contexts /// when the player holds or releases the button. /// </summary> /// <param name="key">Key (ctrl | shift | alt) on which to toggle content</param> /// <param name="context1">Default button displayed</param> /// <param name="context2">Button displayed while <paramref name="key "/> is held down.</param> public void RegisterKeyToggle(KState.Special key, T context1, T context2) { // have to initialize (rather than just declare) this to prevent compile-time // error in kw1 declaration var kw2 = new KeyWatcher(key, KeyEventProvider.Event.Released, null); var kw1 = new KeyWatcher(key, KeyEventProvider.Event.Pressed, () => { ChangeContent(context2); kw2.Subscribe(); }); // assign kw2 onkeyevent kw2.OnKeyEvent = () => { ChangeContent(context1); kw1.Subscribe(); }; // subscribe to default watcher // FIXME: it occurs to me that there might currently be no // way to Un-register this key-toggle. But I've never really // needed to do that yet, sooo.... kw1.Subscribe(); }
/// <summary> /// register a key toggle for this slot's default context /// </summary> /// <param name="key">Activation key, e.g. Shift</param> /// <param name="context2">Button to swap with</param> public void RegisterKeyToggle(KState.Special key, T context2) { RegisterKeyToggle(key, DefaultContent, context2); }
/// <summary> /// Set up key-event-subscribers that will toggle between the /// 2 contexts when the player holds or releases the button. /// </summary> /// <param name="key">Key (ctrl | shift | alt) on which to toggle content</param> /// <param name="button_a_id">ID of default button to display</param> /// <param name="button_b_id">ID of button displayed while /// <paramref name="key "/> is held down.</param> public void RegisterKeyToggle(KState.Special key, string button_a_id, string button_b_id) { RegisterKeyToggle(key, AssociatedButtons[button_a_id], AssociatedButtons[button_b_id]); }
/// <summary> /// register a key toggle for this slot's default context /// </summary> /// <param name="key">Activation key, e.g. Shift</param> /// <param name="button_id">ID of button to swap with</param> public void RegisterKeyToggle(KState.Special key, string button_id) { RegisterKeyToggle(key, DefaultContent, AssociatedButtons[button_id]); }
/// Specialized version of AddToggle for connecting sort/reverse-sort buttons public static T AddSortToggle <T>(this T button, T reverse_button, KState.Special toggle_key = KState.Special.Shift) where T : ICoreButton { return(button.AddNewService(new SortingToggleService(button, reverse_button, toggle_key))); }
/// Allow this button to toggle to another button public static T AddToggle <T>(this T button, T toggle_to_button, KState.Special toggle_key = KState.Special.Shift) where T : ICoreButton { return(button.AddNewService(new ToggleService(button, toggle_to_button, toggle_key))); }
// add new Providers // public void AddProvider(Keys key) // { // activeProviders.TryAdd(key, new Notifier()); // } public void AddProvider(KState.Special key) { specialProviders.TryAdd(key, new Notifier()); }
//indexers // public Provider this[Keys key] // { // get { return activeProviders.GetOrAdd(key, new KeysProvider(key)); } // } public Notifier this[KState.Special key] { get { return(specialProviders.GetOrAdd(key, new Notifier())); } }
public KeyWatcher(KState.Special k, KeyEventProvider.Event e, Action h) { key = k; evType = e; onKeyEvent = h; }
public SortingToggleService(ICoreButton forward, ICoreButton reverse, KState.Special toggle_key) : base(forward, reverse, toggle_key) { sortAction = () => IHPlayer.Sort(); revSortAction = () => IHPlayer.Sort(true); }