MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / handleMouseDown

Method handleMouseDown

game/ui/tileview/cityview.cpp:3318–3618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3316}
3317
3318bool CityView::handleMouseDown(Event *e)
3319{
3320 static const std::set<TileObject::Type> sceneryPortalVehicleSet = {
3321 TileObject::Type::Scenery, TileObject::Type::Doodad, TileObject::Type::Vehicle};
3322 static const std::set<TileObject::Type> projectileSet = {TileObject::Type::Projectile};
3323 static const std::set<TileObject::Type> vehicleSet = {TileObject::Type::Vehicle};
3324
3325 if (Event::isPressed(e->mouse().Button, Event::MouseButton::Middle) ||
3326 (Event::isPressed(e->mouse().Button, Event::MouseButton::Right) && vanillaControls))
3327 {
3328 Vec2<float> screenOffset = {this->getScreenOffset().x, this->getScreenOffset().y};
3329 auto clickTile =
3330 this->screenToTileCoords(Vec2<float>{e->mouse().X, e->mouse().Y} - screenOffset, 0.0f);
3331 this->setScreenCenterTile(Vec2<float>{clickTile.x, clickTile.y});
3332 return true;
3333 }
3334 if (Event::isPressed(e->mouse().Button, Event::MouseButton::Left) ||
3335 Event::isPressed(e->mouse().Button, Event::MouseButton::Right))
3336 {
3337 auto buttonPressed = Event::isPressed(e->mouse().Button, Event::MouseButton::Left)
3338 ? Event::MouseButton::Left
3339 : Event::MouseButton::Right;
3340
3341 if (vanillaControls)
3342 {
3343 if (buttonPressed == Event::MouseButton::Left)
3344 {
3345 if (modifierLAlt || modifierRAlt)
3346 {
3347 setSelectionState(CitySelectionState::AttackVehicle);
3348 }
3349 else if (modifierLShift || modifierRShift)
3350 {
3351 setSelectionState(CitySelectionState::GotoBuilding);
3352 }
3353 }
3354 }
3355
3356 // If a click has not been handled by a form it's in the map. See if we intersect with
3357 // anything
3358 Vec2<float> screenOffset = {this->getScreenOffset().x, this->getScreenOffset().y};
3359 auto clickTop = this->screenToTileCoords(
3360 Vec2<float>{e->mouse().X, e->mouse().Y} - screenOffset, 12.99f);
3361 auto clickBottom =
3362 this->screenToTileCoords(Vec2<float>{e->mouse().X, e->mouse().Y} - screenOffset, 0.0f);
3363 auto collision = state->current_city->map->findCollision(
3364 clickTop, clickBottom, sceneryPortalVehicleSet, nullptr, true);
3365
3366 auto position = collision.position;
3367 bool portal = false;
3368 sp<Scenery> scenery;
3369 StateRef<Building> building;
3370 sp<Vehicle> vehicle;
3371 sp<Projectile> projectile;
3372 if (collision)
3373 {
3374 switch (collision.obj->getType())
3375 {

Callers

nothing calls this directly

Calls 15

formatFunction · 0.85
getScreenOffsetMethod · 0.80
screenToTileCoordsMethod · 0.80
findCollisionMethod · 0.80
getTileMethod · 0.80
getVehicleMethod · 0.80
crashMethod · 0.80
getProjectileMethod · 0.80
setScreenCenterTileMethod · 0.45
getTypeMethod · 0.45
getOwnerMethod · 0.45
willCollapseMethod · 0.45

Tested by

no test coverage detected