void InputManager::handleInput() { // Events SDL_Event event; while (SDL_PollEvent(&event)) { bool used = false; // Key press events if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) used = handleKeyboardInput(event); if (event.type == SDL_JOYAXISMOTION || event.type == SDL_JOYBALLMOTION || event.type == SDL_JOYHATMOTION || event.type == SDL_JOYBUTTONDOWN || event.type == SDL_JOYBUTTONUP) handleJoystickInput(event); // Quit event else if (event.type == SDL_QUIT) stateManager->setState(QUIT_STATE); // Push input to GUI when not used if (!used) forwardInput(event); } }
int takeInput(motorGroup *group, bool setMotors=true) { int power = 0; if (group->controlActive) { switch (group->controlType) { case BUTTON: power = handleButtonInput(group); break; case JOYSTICK: power = handleJoystickInput(group); break; } } if (setMotors) setPower(group, power); return power; }
void InputOptionsState::step_impl() { IMGUI& imgui = IMGUI::getSingleton(); imgui.doCursor(); imgui.doImage(GEN_ID, Vector2(400.0, 300.0), "background"); imgui.doOverlay(GEN_ID, Vector2(0.0, 0.0), Vector2(800.0, 600.0)); std::string lastActionKey = InputManager::getSingleton()->getLastActionKey(); // left player side: imgui.doText(GEN_ID, Vector2(34.0, 10.0), TextManager::OP_LEFT_PLAYER); if (imgui.doButton(GEN_ID, Vector2(80.0, 60.0), getDeviceName(mLeftBlobbyDevice))) { if (mLeftBlobbyDevice == "mouse") { mLeftBlobbyDevice = "keyboard"; } else if (mLeftBlobbyDevice == "keyboard") { mLeftBlobbyDevice = "joystick"; } else if (mLeftBlobbyDevice == "joystick") { if (mRightBlobbyDevice != "mouse") { mLeftBlobbyDevice = "mouse"; } else { mLeftBlobbyDevice = "keyboard"; } } } //if mouse device is selected: if (mLeftBlobbyDevice == "mouse") { handleMouseInput(0, mLeftBlobbyMouseJumpbutton); } if ((mLeftBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1)) mLeftBlobbyMouseJumpbutton = -1; //if keyboard device is selected: if (mLeftBlobbyDevice == "keyboard") { handleKeyboardInput(0, lastActionKey, mLeftBlobbyKeyboard); } //if joystick device is selected: if (mLeftBlobbyDevice == "joystick") { handleJoystickInput(0, mLeftBlobbyJoystick); } //right player side: imgui.doText(GEN_ID, Vector2(434.0, 10.0), TextManager::OP_RIGHT_PLAYER); if (imgui.doButton(GEN_ID, Vector2(480.0, 60.0), getDeviceName(mRightBlobbyDevice))) { if (mRightBlobbyDevice == "mouse") { mRightBlobbyDevice = "keyboard"; } else if (mRightBlobbyDevice == "keyboard") { mRightBlobbyDevice = "joystick"; } else if (mRightBlobbyDevice == "joystick") { if (mLeftBlobbyDevice != "mouse") { mRightBlobbyDevice = "mouse"; } else { mRightBlobbyDevice = "keyboard"; } } } //if mouse device is selected: if (mRightBlobbyDevice == "mouse") { handleMouseInput(400, mRightBlobbyMouseJumpbutton); } if ((mRightBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1)) mRightBlobbyMouseJumpbutton = -1; //if keyboard device is selected: if (mRightBlobbyDevice == "keyboard") { handleKeyboardInput(400, lastActionKey, mRightBlobbyKeyboard); } //if joystick device is selected: if (mRightBlobbyDevice == "joystick") { handleJoystickInput(400, mRightBlobbyJoystick); } //check if a capture window is open, to set all widgets inactive: if (mLeftBlobbyKeyboard[IA_LEFT] != "" && mLeftBlobbyKeyboard[IA_RIGHT] != "" && mLeftBlobbyKeyboard[IA_JUMP] != "" && mLeftBlobbyJoystick[IA_LEFT] != "" && mLeftBlobbyJoystick[IA_RIGHT] != "" && mLeftBlobbyJoystick[IA_JUMP] != "" && mLeftBlobbyMouseJumpbutton != -1 && mRightBlobbyKeyboard[IA_LEFT] != "" && mRightBlobbyKeyboard[IA_RIGHT] != "" && mRightBlobbyKeyboard[IA_JUMP] != "" && mRightBlobbyJoystick[IA_LEFT] != "" && mRightBlobbyJoystick[IA_RIGHT] != "" && mRightBlobbyJoystick[IA_JUMP] != "" && mRightBlobbyMouseJumpbutton != -1) { imgui.doCursor(true); imgui.doInactiveMode(false); } else { imgui.doInactiveMode(true); imgui.doCursor(false); } //Capture dialogs: getMouseInput(mLeftBlobbyMouseJumpbutton, TextManager::OP_JUMPING); getKeyboardInput(mLeftBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey); getKeyboardInput(mLeftBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey); getKeyboardInput(mLeftBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey); getJoystickInput(mLeftBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT); getJoystickInput(mLeftBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT); getJoystickInput(mLeftBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING); getMouseInput(mRightBlobbyMouseJumpbutton, TextManager::OP_JUMPING); getKeyboardInput(mRightBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey); getKeyboardInput(mRightBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey); getKeyboardInput(mRightBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey); getJoystickInput(mRightBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT); getJoystickInput(mRightBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT); getJoystickInput(mRightBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING); if (imgui.doButton(GEN_ID, Vector2(224.0, 530.0), TextManager::LBL_OK)) { save(); switchState(new OptionState()); } if (imgui.doButton(GEN_ID, Vector2(424.0, 530.0), TextManager::LBL_CANCEL)) { switchState(new OptionState()); } }