private void pollForButtonClicks(ButtonAssignment ba) { if (ba != null && ba.buttonIndex != -1) { if (ba.joystick != null) { try { if (ba.joystick != null) { JoystickState state = ba.joystick.GetCurrentState(); if (state != null) { Boolean click = state.Buttons[ba.buttonIndex]; if (click) { ba.hasUnprocessedClick = true; } } } } catch (Exception) { } } else if (ba.controller.guid == UDP_NETWORK_CONTROLLER_GUID) { if (PCarsUDPreader.getButtonState(ba.buttonIndex)) { ba.hasUnprocessedClick = true; } } } }
public Boolean isChannelOpen() { ButtonAssignment ba = buttonAssignments[buttonAssignmentIndexes[CHANNEL_OPEN_FUNCTION]]; if (ba != null && ba.buttonIndex != -1) { if (ba.joystick != null) { try { return(ba.joystick.GetCurrentState().Buttons[ba.buttonIndex]); } catch (Exception) { // ignore this exception } } else if (ba.controller.guid == UDP_NETWORK_CONTROLLER_GUID && CrewChief.gameDefinition.gameEnum == GameEnum.PCARS_NETWORK) { return(PCarsUDPreader.getButtonState(ba.buttonIndex)); } else if (ba.controller.guid == UDP_NETWORK_CONTROLLER_GUID && CrewChief.gameDefinition.gameEnum == GameEnum.PCARS2_NETWORK) { return(PCars2UDPreader.getButtonState(ba.buttonIndex)); } } return(false); }
/// <summary> /// Creates the content for an item that shall be inserted into the Control, Command listbox. /// </summary> /// <param name="control">The control.</param> /// <param name="assignment">The assignment for the control.</param> /// <returns>The created AssignmentListBoxItemContent.</returns> private AssignmentListBoxItemContent CreateContent(ClawControl control, Assignment assignment) { if (assignment == null) { return(new AssignmentListBoxItemContent(control, null)); } ButtonAssignment buttonAssignment = assignment as ButtonAssignment; if (buttonAssignment == null) { throw new InvalidOperationException("An assignment to a ButtonControl is not allowed to be something else than a ButtonAssignment! Got: " + assignment.GetType()); } if (buttonAssignment.Bands.Count == 0) { return(new AssignmentListBoxItemContent(control, null)); } // Currently there is alway only one node bound so looking at the first item is sufficient. Band band = buttonAssignment.Bands.First(); Command command = activeProfile.Commands.GetCommandForBand(band); return(new AssignmentListBoxItemContent(control, command)); }
public Boolean hasOutstandingClick(String action) { ButtonAssignment ba = buttonAssignments[buttonAssignmentIndexes[action]]; if (ba.hasUnprocessedClick) { ba.hasUnprocessedClick = false; return(true); } return(false); }
/// <summary> /// Gets the button assignment for the given control in the given shift, creates a new one if none exists. /// </summary> /// <param name="shift">The parent shift of the control.</param> /// <param name="control">The control to get a button assignment for.</param> /// <returns>The new or existing button assignment.</returns> private static ButtonAssignment GetButtonAssignment(Shift shift, Control control) { Assignment assignment = shift.Assignments.GetAssignmentForControl(control); if (assignment == null) { var buttonAssignment = new ButtonAssignment(control); shift.Assignments.Add(buttonAssignment); return(buttonAssignment); } ButtonAssignment button = assignment as ButtonAssignment; if (button == null) { throw new InvalidOperationException("Profile structure is corrupted! A button control also needs a button assignment!"); } return(button); }
public void AssociateCommand(MadCatzProfile profile, Shift shift, Control control, Command command) { if (profile == null) { throw new ArgumentNullException("profile"); } if (shift == null) { throw new ArgumentNullException("shift"); } if (!(control is ButtonControl)) { throw new InvalidOperationException("Can't associate a command to a non-button control."); } if (command != null && !profile.Commands.Contains(command)) { throw new ArgumentException("The given command needs to be in the same profile as the given control."); } profileInfos[profile].Edited = true; if (command == null) { shift.Assignments.RemoveAssignmentForControl(control); return; } var band = new Band(command); ButtonAssignment buttonAssignment = GetButtonAssignment(shift, control); buttonAssignment.Bands.Clear(); buttonAssignment.Bands.Add(band); }
private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment) { Boolean gotAssignment = false; if (controllerData.guid == UDP_NETWORK_CONTROLLER_GUID) { PCarsUDPreader gameDataReader = (PCarsUDPreader)GameStateReaderFactory.getInstance().getGameStateReader(GameDefinition.pCarsNetwork); int assignedButton = gameDataReader.getButtonIndexForAssignment(); if (assignedButton != -1) { removeAssignmentsForControllerAndButton(controllerData.guid, assignedButton); buttonAssignment.controller = controllerData; buttonAssignment.buttonIndex = assignedButton; listenForAssignment = false; gotAssignment = true; } } else { listenForAssignment = true; // Instantiate the joystick var joystick = new Joystick(directInput, controllerData.guid); // Acquire the joystick joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background)); joystick.Properties.BufferSize = 128; joystick.Acquire(); while (listenForAssignment) { Boolean[] buttons = joystick.GetCurrentState().Buttons; for (int i = 0; i < buttons.Count(); i++) { if (buttons[i]) { Console.WriteLine("Got button at index " + i); removeAssignmentsForControllerAndButton(controllerData.guid, i); buttonAssignment.controller = controllerData; buttonAssignment.joystick = joystick; buttonAssignment.buttonIndex = i; listenForAssignment = false; gotAssignment = true; } } } if (!gotAssignment) { joystick.Unacquire(); } } return(gotAssignment); }
public static void BindKey(Feature feature, ToolStripMenuItem menuItem) { BindKey(feature, (Keys keys) => { menuItem.ShortcutKeys = keys; menuItem.ShortcutKeyDisplayString = keys == System.Windows.Forms.Keys.None ? "" : ButtonAssignment.GetString(keys); }); }
private void pollForButtonClicks(ButtonAssignment ba) { if (ba != null && ba.buttonIndex != -1 && ba.joystick != null) { Boolean click = ba.joystick.GetCurrentState().Buttons[ba.buttonIndex]; if (click) { ba.hasUnprocessedClick = true; } } }
private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment) { listenForAssignment = true; // Instantiate the joystick var joystick = new Joystick(directInput, controllerData.guid); // Acquire the joystick joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background)); joystick.Properties.BufferSize = 128; joystick.Acquire(); Boolean gotAssignment = false; while (listenForAssignment) { Boolean[] buttons = joystick.GetCurrentState().Buttons; for (int i = 0; i < buttons.Count(); i++) { if (buttons[i]) { Console.WriteLine("Got button at index " + i); removeAssignmentsForControllerAndButton(controllerData.guid, i); buttonAssignment.controller = controllerData; buttonAssignment.joystick = joystick; buttonAssignment.buttonIndex = i; listenForAssignment = false; gotAssignment = true; } } } if (!gotAssignment) { joystick.Unacquire(); } return gotAssignment; }
private void pollForButtonClicks(ButtonAssignment ba) { if (ba != null && ba.buttonIndex != -1) { if (ba.joystick != null) { try { if (ba.joystick != null) { JoystickState state = ba.joystick.GetCurrentState(); if (state != null) { Boolean click = state.Buttons[ba.buttonIndex]; if (click) { ba.hasUnprocessedClick = true; } } } } catch (Exception) { } } else if (ba.controller.guid == NETWORK_CONSOLE_CONTROLLER_GUID) { if (PCarsUDPreader.getButtonState(ba.buttonIndex)) { ba.hasUnprocessedClick = true; } } } }
private Boolean getFirstPressedButton(System.Windows.Forms.Form parent, ControllerData controllerData, ButtonAssignment buttonAssignment) { Boolean gotAssignment = false; if (controllerData.guid == NETWORK_CONSOLE_CONTROLLER_GUID) { PCarsUDPreader gameDataReader = (PCarsUDPreader)GameStateReaderFactory.getInstance().getGameStateReader(GameDefinition.pCarsNetwork); int assignedButton = gameDataReader.getButtonIndexForAssignment(); if (assignedButton != -1) { removeAssignmentsForControllerAndButton(controllerData.guid, assignedButton); buttonAssignment.controller = controllerData; buttonAssignment.buttonIndex = assignedButton; listenForAssignment = false; gotAssignment = true; } } else { listenForAssignment = true; // Instantiate the joystick var joystick = new Joystick(directInput, controllerData.guid); // Acquire the joystick joystick.SetCooperativeLevel(parent, (CooperativeLevel.NonExclusive | CooperativeLevel.Background)); joystick.Properties.BufferSize = 128; joystick.Acquire(); while (listenForAssignment) { Boolean[] buttons = joystick.GetCurrentState().Buttons; for (int i = 0; i < buttons.Count(); i++) { if (buttons[i]) { Console.WriteLine("Got button at index " + i); removeAssignmentsForControllerAndButton(controllerData.guid, i); buttonAssignment.controller = controllerData; buttonAssignment.joystick = joystick; buttonAssignment.buttonIndex = i; listenForAssignment = false; gotAssignment = true; } } } if (!gotAssignment) { joystick.Unacquire(); } } return gotAssignment; }