void MyGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) { emit clickedPosition(Coordonnee(round((mouseEvent->scenePos().x()/100)*2.0)/2.0,round((mouseEvent->scenePos().y()/100)*2.0)/2.0),new T_sol_mono("i_t_tSolMono1",2,100,2,1,0.75,25)); }
void MapEditor::handleEditorViewEvents() { mapView->handleEvents(); validateMapButton->handleEvents(); saveMapButton->handleEvents(); if (mapView->isClicked()) { Position clickedPosition(mapView->getMouseClickedColumn(), mapView->getMouseClickedRow()); CellState nextState; switch (map->getCellState(clickedPosition)) { case CellState::EMPTY: if (clickedPosition == map->getEndPosition()) nextState = CellState::CHARACTER; else nextState = CellState::WALL; break; case CellState::WALL: nextState = CellState::OPPONENT; break; case CellState:: CHARACTER: nextState = CellState::CHARACTER; break; case CellState::OPPONENT: nextState = CellState::CHEST; break; case CellState::CHEST: nextState = CellState::EMPTY; break; } if (nextState == CellState::CHARACTER) { map->setCharacterPosition(clickedPosition); map->setBeginPosition(clickedPosition); } else { if (nextState == CellState::EMPTY) map->setEndPosition(clickedPosition); map->setCellState(clickedPosition, nextState); } mapView->resetClicked(); } if (validateMapButton->isClicked()) { if (map->validate()) { validityLbl->getParameters()->setId("validLbl"); } else { validityLbl->getParameters()->setId("invalidLbl"); } validateMapButton->resetClicked(); } if (saveMapButton->isClicked()) { // Saving the map woooooooooooooohoooooooooooo!!! saveMapButton->resetClicked(); } }