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

Method handleMouseDown

game/ui/tileview/battleview.cpp:3557–4044  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3555}
3556
3557bool BattleView::handleMouseDown(Event *e)
3558{
3559 if (activeTab == notMyTurnTab)
3560 {
3561 return true;
3562 }
3563
3564 if (!debugHotkeyMode && Event::isPressed(e->mouse().Button, Event::MouseButton::Middle))
3565 {
3566 Vec2<float> screenOffset = {getScreenOffset().x, getScreenOffset().y};
3567 auto clickTile =
3568 screenToTileCoords(Vec2<float>{e->mouse().X, e->mouse().Y} - screenOffset, 0.0f);
3569 setScreenCenterTile(Vec2<float>{clickTile.x, clickTile.y});
3570 return true;
3571 }
3572 // CHEAT - move unit to mouse
3573 if (Event::isPressed(e->mouse().Button, Event::MouseButton::Middle) && debugHotkeyMode)
3574 {
3575 if (!battle.battleViewSelectedUnits.empty())
3576 {
3577 selectionState = BattleSelectionState::TeleportLeft;
3578 }
3579 return true;
3580 }
3581 if (Event::isPressed(e->mouse().Button, Event::MouseButton::Left) ||
3582 Event::isPressed(e->mouse().Button, Event::MouseButton::Right))
3583 {
3584 auto buttonPressed = Event::isPressed(e->mouse().Button, Event::MouseButton::Left)
3585 ? Event::MouseButton::Left
3586 : Event::MouseButton::Right;
3587
3588 auto player = state->current_battle->currentPlayer;
3589 // If a click has not been handled by a form it's in the map.
3590 auto t = getSelectedTilePosition();
3591 auto objsPresent = map.getTile(t.x, t.y, t.z)->getUnits(true);
3592 auto unitPresent = objsPresent.empty() ? nullptr : objsPresent.front();
3593 auto objsOccupying = map.getTile(t.x, t.y, t.z)->getUnits(true, true);
3594 auto unitOccupying = objsOccupying.empty() ? nullptr : objsOccupying.front();
3595 if (unitOccupying)
3596 {
3597 unitPresent = unitOccupying;
3598 }
3599 // Determine attack target
3600 sp<BattleUnit> attackTarget = nullptr;
3601 if (!attackTarget)
3602 {
3603 for (auto &u : objsOccupying)
3604 {
3605 if (player->isRelatedTo(u->owner) == Organisation::Relation::Hostile &&
3606 battle.visibleUnits[player].find({&*state, u->id}) !=
3607 battle.visibleUnits[player].end())
3608 {
3609 attackTarget = u;
3610 break;
3611 }
3612 }
3613 }
3614 if (!attackTarget)

Callers

nothing calls this directly

Calls 15

formatFunction · 0.85
emptyMethod · 0.80
getUnitsMethod · 0.80
getTileMethod · 0.80
isRelatedToMethod · 0.80
endMethod · 0.80
stageQueueCommandMethod · 0.80
isConsciousMethod · 0.80
getLosBlockIDMethod · 0.80
getPassableMethod · 0.80
getHazardMethod · 0.80

Tested by

no test coverage detected