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

Method mouseMoved

source/modes/GameMode.cpp:342–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340}
341
342bool GameMode::mouseMoved(const OIS::MouseEvent &arg)
343{
344 AbstractApplicationMode::mouseMoved(arg);
345
346 if (!isConnected())
347 return true;
348
349 InputManager& inputManager = mModeManager->getInputManager();
350 inputManager.mCommandState = (inputManager.mLMouseDown ? InputCommandState::building : InputCommandState::infoOnly);
351
352 // TODO: Here we should check whether the terminal is active...
353 if(inputManager.mMMouseDown)
354 {
355 ODFrameListener::getSingleton().moveCamera(CameraManager::randomRotateX,arg.state.X.rel);
356 ODFrameListener::getSingleton().moveCamera(CameraManager::randomRotateY,arg.state.Y.rel);
357 }
358
359 // If we have a room/trap/spell selected, show it
360 // TODO: This should be changed, or combined with an icon or something later.
361 TextRenderer& textRenderer = TextRenderer::getSingleton();
362 textRenderer.moveText(ODApplication::POINTER_INFO_STRING,
363 static_cast<Ogre::Real>(arg.state.X.abs + 30), static_cast<Ogre::Real>(arg.state.Y.abs));
364
365 // We notify current selection input
366 checkInputCommand();
367
368 handleMouseWheel(arg);
369
370 // Since this is a tile selection query we loop over the result set
371 // and look for the first object which is actually a tile.
372 ODFrameListener::getSingleton().findWorldPositionFromMouse(arg, inputManager.mKeeperHandPos);
373 RenderManager::getSingleton().moveWorldCoords(inputManager.mKeeperHandPos.x, inputManager.mKeeperHandPos.y);
374
375 int tileX = Helper::round(inputManager.mKeeperHandPos.x);
376 int tileY = Helper::round(inputManager.mKeeperHandPos.y);
377 Tile* tileClicked = mGameMap->getTile(tileX, tileY);
378 if(tileClicked == nullptr)
379 return true;
380
381 std::vector<GameEntity*> entities;
382 tileClicked->fillWithEntities(entities, SelectionEntityWanted::creatureAliveOrDead, mGameMap->getLocalPlayer());
383 // We search the closest creature alive
384 Creature* closestCreature = nullptr;
385 double closestDist = 0;
386 for(GameEntity* entity : entities)
387 {
388 if(entity->getObjectType() != GameEntityType::creature)
389 {
390 OD_LOG_ERR("entityName=" + entity->getName() + ", entityType=" + Helper::toString(static_cast<uint32_t>(entity->getObjectType())));
391 continue;
392 }
393
394 const Ogre::Vector3& entityPos = entity->getPosition();
395 double dist = Pathfinding::squaredDistance(entityPos.x, inputManager.mKeeperHandPos.x, entityPos.y, inputManager.mKeeperHandPos.y);
396 if(closestCreature == nullptr)
397 {
398 closestDist = dist;
399 closestCreature = static_cast<Creature*>(entity);

Callers 1

updateMethod · 0.45

Calls 14

roundFunction · 0.85
squaredDistanceFunction · 0.85
moveCameraMethod · 0.80
moveTextMethod · 0.80
moveWorldCoordsMethod · 0.80
fillWithEntitiesMethod · 0.80
getLocalPlayerMethod · 0.80
toStringFunction · 0.50
getTileMethod · 0.45
getObjectTypeMethod · 0.45

Tested by

no test coverage detected