MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / mousePressed

Method mousePressed

source/modes/GameMode.cpp:486–714  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484}
485
486bool GameMode::mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id)
487{
488 InputManager& inputManager = mModeManager->getInputManager();
489
490 CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(
491 Gui::convertButton(id));
492
493 if (!isConnected())
494 return true;
495
496 inputManager.mMouseDownOnCEGUIWindow = isMouseDownOnCEGUIWindow();
497 if (inputManager.mMouseDownOnCEGUIWindow)
498 return true;
499
500 if(mGameMap->getLocalPlayer() == nullptr)
501 {
502 static bool log = true;
503 if(log)
504 {
505 log = false;
506 OD_LOG_ERR("LOCAL PLAYER DOES NOT EXIST!!");
507 }
508 return true;
509 }
510
511 // There is a bug in OIS. When playing in windowed mode, if we clic outside the window
512 // and then we restore the window, we will receive a clic event on the last place where
513 // the mouse was.
514 Ogre::RenderWindow* mainWindows = static_cast<Ogre::RenderWindow*>(
515 Ogre::Root::getSingleton().getRenderTarget("OpenDungeons " + ODApplication::VERSION));
516 if((!mainWindows->isFullScreen()) &&
517 ((arg.state.X.abs == 0) || (arg.state.Y.abs == 0) ||
518 (static_cast<Ogre::uint32>(arg.state.X.abs) == mainWindows->getWidth()) ||
519 (static_cast<Ogre::uint32>(arg.state.Y.abs) == mainWindows->getHeight())))
520 {
521 return true;
522 }
523
524 if(mGameMap->getGamePaused())
525 return true;
526
527 if(!ODFrameListener::getSingleton().findWorldPositionFromMouse(arg, inputManager.mKeeperHandPos))
528 return true;
529
530 RenderManager::getSingleton().moveWorldCoords(inputManager.mKeeperHandPos.x, inputManager.mKeeperHandPos.y);
531
532 // The player should be able to move the mouse even if not clicking on a tile. Because of that, we set
533 // mMMouseDown before checking which tile is clicked
534 if (id == OIS::MB_Middle)
535 inputManager.mMMouseDown = true;
536
537 int tileX = Helper::round(inputManager.mKeeperHandPos.x);
538 int tileY = Helper::round(inputManager.mKeeperHandPos.y);
539 Tile* tileClicked = mGameMap->getTile(tileX, tileY);
540 if(tileClicked == nullptr)
541 return true;
542
543 if (id == OIS::MB_Middle)

Callers

nothing calls this directly

Calls 15

roundFunction · 0.85
squaredDistanceFunction · 0.85
getLocalPlayerMethod · 0.80
getGamePausedMethod · 0.80
moveWorldCoordsMethod · 0.80
fillWithEntitiesMethod · 0.80
setTextMethod · 0.80
getCurrentActionMethod · 0.80
setCurrentActionMethod · 0.80
numObjectsInHandMethod · 0.80
isDropHandPossibleMethod · 0.80

Tested by

no test coverage detected