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

Method mouseMoved

source/modes/EditorMode.cpp:201–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201bool EditorMode::mouseMoved(const OIS::MouseEvent &arg)
202{
203 AbstractApplicationMode::mouseMoved(arg);
204
205 if (!isConnected())
206 return true;
207
208 InputManager& inputManager = mModeManager->getInputManager();
209 inputManager.mCommandState = (inputManager.mLMouseDown ? InputCommandState::building : InputCommandState::infoOnly);
210
211 // If we have a room/trap/spell selected, show it
212 // TODO: This should be changed, or combined with an icon or something later.
213 TextRenderer& textRenderer = TextRenderer::getSingleton();
214 textRenderer.moveText(ODApplication::POINTER_INFO_STRING,
215 static_cast<Ogre::Real>(arg.state.X.abs + 30), static_cast<Ogre::Real>(arg.state.Y.abs));
216
217 // We notify current selection input
218 checkInputCommand();
219
220 handleMouseWheel(arg);
221
222 // Since this is a tile selection query we loop over the result set
223 // and look for the first object which is actually a tile.
224 Ogre::Vector3 keeperHandPos;
225 if(!ODFrameListener::getSingleton().findWorldPositionFromMouse(arg, keeperHandPos))
226 return true;
227
228 RenderManager::getSingleton().moveWorldCoords(keeperHandPos.x, keeperHandPos.y);
229
230 int tileX = Helper::round(keeperHandPos.x);
231 int tileY = Helper::round(keeperHandPos.y);
232 Tile* tileClicked = mGameMap->getTile(tileX, tileY);
233 if(tileClicked == nullptr)
234 return true;
235
236 std::vector<GameEntity*> entities;
237 tileClicked->fillWithEntities(entities, SelectionEntityWanted::creatureAlive, mGameMap->getLocalPlayer());
238 // We search the closest creature alive
239 Creature* closestCreature = nullptr;
240 double closestDist = 0;
241 for(GameEntity* entity : entities)
242 {
243 if(entity->getObjectType() != GameEntityType::creature)
244 {
245 OD_LOG_ERR("entityName=" + entity->getName() + ", entityType=" + Helper::toString(static_cast<uint32_t>(entity->getObjectType())));
246 continue;
247 }
248
249 const Ogre::Vector3& entityPos = entity->getPosition();
250 double dist = Pathfinding::squaredDistance(entityPos.x, keeperHandPos.x, entityPos.y, keeperHandPos.y);
251 if(closestCreature == nullptr)
252 {
253 closestDist = dist;
254 closestCreature = static_cast<Creature*>(entity);
255 continue;
256 }
257
258 if(dist >= closestDist)

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected