bool MyEventReceiver::OnEvent(const SEvent &event) { /* React to nothing here if a menu is active */ if (isMenuActive()) { #ifdef HAVE_TOUCHSCREENGUI if (m_touchscreengui) { m_touchscreengui->Toggle(false); } #endif return g_menumgr.preprocessEvent(event); } // Remember whether each key is down or up if (event.EventType == irr::EET_KEY_INPUT_EVENT) { const KeyPress &keyCode = event.KeyInput; if (keysListenedFor[keyCode]) { if (event.KeyInput.PressedDown) { keyIsDown.set(keyCode); keyWasDown.set(keyCode); } else { keyIsDown.unset(keyCode); } return true; } } #ifdef HAVE_TOUCHSCREENGUI // case of touchscreengui we have to handle different events if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) { m_touchscreengui->translateEvent(event); return true; } #endif #ifdef __IOS__ if (event.EventType == irr::EET_APPLICATION_EVENT) { if (event.ApplicationEvent.EventType == irr::EAET_WILL_PAUSE) external_exit_game(); return true; } #endif if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) { /* TODO add a check like: if (event.JoystickEvent != joystick_we_listen_for) return false; */ return joystick->handleEvent(event.JoystickEvent); } // handle mouse events if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) { if (isMenuActive()) { left_active = false; middle_active = false; right_active = false; } else { left_active = event.MouseInput.isLeftPressed(); middle_active = event.MouseInput.isMiddlePressed(); right_active = event.MouseInput.isRightPressed(); if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { leftclicked = true; } if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) { rightclicked = true; } if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) { leftreleased = true; } if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) { rightreleased = true; } if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) { mouse_wheel += event.MouseInput.Wheel; } } } else if (event.EventType == irr::EET_LOG_TEXT_EVENT) { static const LogLevel irr_loglev_conv[] = { LL_VERBOSE, // ELL_DEBUG LL_INFO, // ELL_INFORMATION LL_WARNING, // ELL_WARNING LL_ERROR, // ELL_ERROR LL_NONE, // ELL_NONE }; assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv)); #if !defined(__ANDROID__) && !defined(__IOS__) g_logger.log(irr_loglev_conv[event.LogEvent.Level], std::string("Irrlicht: ") + (const char *)event.LogEvent.Text); #endif return true; } /* always return false in order to continue processing events */ return false; }
void SubMenu::addEvents() { auto listener = cocos2d::EventListenerTouchOneByOne::create(); listener->setSwallowTouches(false); listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event) { if (!isMenuActive()) { return false; } cocos2d::Vec2 p = touch->getLocation(); cocos2d::Rect btnRect = m_restartBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_restartBtn->setScale(1.1); } btnRect = m_newGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_newGameBtn->setScale(1.1); } btnRect = m_backBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_backBtn->setScale(1.1); } btnRect = m_resultRestartGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_resultRestartGameBtn->setScale(1.1); } btnRect = m_resultNewGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_resultNewGameBtn->setScale(1.1); } return true; }; listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event) { if (!isMenuActive()) { return ; } cocos2d::Vec2 p = touch->getLocation(); cocos2d::Rect btnRect = m_restartBtn->getBoundingBox(); m_restartBtn->setScale(1.0); m_newGameBtn->setScale(1.0); m_backBtn->setScale(1.0); if (btnRect.containsPoint(p)) { m_board->restartGame(); return; } btnRect = m_newGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_board->newGame(); return; } btnRect = m_backBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { showMenu(OPTIONS_MENU, false); } btnRect = m_resultRestartGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_board->restartGame(); } btnRect = m_resultNewGameBtn->getBoundingBox(); if (btnRect.containsPoint(p)) { m_layerNotification->setVisible(false); m_board->newGame(); } if (m_layerNotification->isVisible()) { showMenu(ALL_MENU, false); } //showMenu(ALL_MENU, false); //return false; }; listener->onTouchMoved = [=](cocos2d::Touch* touch, cocos2d::Event* event) { }; cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, m_layerOption); }