/// <summary> /// Handles the binding if the corresponding binding button has been pressed. /// </summary> /// <param name="bind">The binding that should be handled. Depends on the button.</param> /// <param name="listener">The listener that should be binded. Depends on the button. </param> private void HandleRebind(Binding bind, BindInputListener listener) { // stops the double pressing of keybinds if (currentRebind != null && currentRebind == bind) { currentRebind = null; return; } bind.ReKeybinding = (bind.ReKeybinding == BindInputListener.NONE) ? listener : BindInputListener.NONE; currentRebind = bind; }
/// <summary> /// Gets the label of a bind for the OnGUI buttons. /// </summary> /// <param name="bind">The bind that is being displayed.</param> /// <param name="listener">The listener label that corresponds to the button.</param> /// <returns></returns> private string GetBindingLabel(Binding bind, BindInputListener listener) { // if the key is being rekeybound to the tested listener key then return the waiting message if (currentRebind == bind && bind.ReKeybinding == listener) return "..."; // if the key does not have the listener that's being checked then return the "no keybind" message if(!bind.HasListener(listener)) return NoKeybindLabel; switch (listener) { case BindInputListener.MOUSE: return bind.MouseButton.ToString(); case BindInputListener.KEYBOARD: return bind.Key.ToString(); case BindInputListener.CONTROLLER: return bind.ControllerButton.ToString(); } return null; }
/// <summary> /// Checks if the Binding has a specific binding input listener flag. /// </summary> public bool HasListener(BindInputListener listener) { return (Bindings & listener) != 0; }
/// <summary> /// Adds a input listener to the listeners already defined. /// </summary> public void AddListener(BindInputListener listener) { Bindings = Bindings |= listener; }
/// <summary> /// Creates a binding that expects the given inputs, use a object initializer to define the appropiate buttons. /// </summary> public Binding(BindInputListener bindings) { Bindings = bindings; }
/// <summary> /// Removes a input listener from the bindings listener, if it has already been defined. /// </summary> public void RemoveListener(BindInputListener listener) { if(HasListener(listener)) Bindings = Bindings &= ~listener; }