@@ -197,7 +197,7 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
197
197
pickupableBlocks[pickedUpIndex]->setPosition (mousePositionWithOffset);
198
198
pickedUpPreviewCoords = Game::theTable->previewBlock (*pickupableBlocks[pickedUpIndex], mousePosition);
199
199
200
- if (theEvent.type == sf::Event::MouseButtonReleased && theEvent. mouseButton . button == sf::Mouse::Left ) {
200
+ if (theEvent.type == (Settings::Gameplay::holdToMove ? sf::Event::MouseButtonReleased : sf::Event::MouseButtonPressed) ) {
201
201
pickupableBlocks[pickedUpIndex]->setFloating (false );
202
202
203
203
if (pickedUpPreviewCoords.x != -1 || pickedUpPreviewCoords.y != -1 ) {
@@ -217,10 +217,20 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
217
217
}
218
218
219
219
pickedUpIndex = -1 ;
220
+
221
+ return ;
220
222
}
221
223
}
222
224
else {
223
- if (theEvent.type == sf::Event::MouseButtonPressed && theEvent.mouseButton .button == sf::Mouse::Left) {
225
+ if (Settings::Gameplay::paintMode)
226
+ paintModePreviewCoords = Game::theTable->previewBlock (paintModeBlock, mousePosition);
227
+ }
228
+
229
+ if (theEvent.type != sf::Event::MouseButtonPressed)
230
+ return ;
231
+
232
+ if (theEvent.mouseButton .button == sf::Mouse::Left) {
233
+ if (pickedUpIndex == -1 ) {
224
234
for (unsigned i = 0 ; i < 3 ; i++) { // check for every 3 blocks from the pickup area
225
235
if (pickupableBlocks[i] == nullptr ) // if they are picked up, if a block is nullptr, it means it was used
226
236
continue ;
@@ -233,31 +243,26 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
233
243
pickupableBlocks[i]->setScale (PICKUP_SCALE);
234
244
}
235
245
}
236
- }
237
246
238
- // if no pickupable blocks were picked up, process paintMode
239
- if (Settings::Gameplay::paintMode && pickedUpIndex == -1 ) {
240
- if (theEvent.type == sf::Event::MouseButtonPressed) {
241
- if (theEvent.mouseButton .button == sf::Mouse::Left) {
242
- paintModePreviewCoords = Game::theTable->previewBlock (paintModeBlock, mousePosition);
243
- if (paintModePreviewCoords.x != -1 && paintModePreviewCoords.y != -1 ) {
244
- Game::theTable->applyBlock (paintModeBlock, { static_cast <unsigned >(paintModePreviewCoords.x ), static_cast <unsigned >(paintModePreviewCoords.y ) });
245
-
246
- if (isBoardLost ())
247
- Game::theScore->setGameLost ();
248
- }
249
- }
250
- else if (theEvent.mouseButton .button == sf::Mouse::Right) {
251
- paintModePreviewCoords = Game::theTable->mousePositionToCellPosition (mousePosition);
252
- if (paintModePreviewCoords.x != -1 && paintModePreviewCoords.y != -1 ) {
253
- sf::Vector2u unsignedPreviewCoords = { static_cast <unsigned >(paintModePreviewCoords.x ), static_cast <unsigned >(paintModePreviewCoords.y ) };
254
- if (Game::theTable->getCellState (unsignedPreviewCoords) == cell::occupied)
255
- Game::theTable->applyBlock (paintModeBlock, unsignedPreviewCoords, cell::empty);
256
- }
247
+ // if no pickupable blocks were picked up, process paintMode
248
+ if (Settings::Gameplay::paintMode) {
249
+ if (paintModePreviewCoords.x != -1 && paintModePreviewCoords.y != -1 ) {
250
+ Game::theTable->applyBlock (paintModeBlock, { static_cast <unsigned >(paintModePreviewCoords.x ), static_cast <unsigned >(paintModePreviewCoords.y ) });
251
+
252
+ if (isBoardLost ())
253
+ Game::theScore->setGameLost ();
257
254
}
258
255
}
259
256
}
260
257
}
258
+ else if (theEvent.mouseButton .button == sf::Mouse::Right && pickedUpIndex == -1 ) {
259
+ paintModePreviewCoords = Game::theTable->mousePositionToCellPosition (mousePosition);
260
+ if (paintModePreviewCoords.x != -1 && paintModePreviewCoords.y != -1 ) {
261
+ sf::Vector2u unsignedPreviewCoords = { static_cast <unsigned >(paintModePreviewCoords.x ), static_cast <unsigned >(paintModePreviewCoords.y ) };
262
+ if (Game::theTable->getCellState (unsignedPreviewCoords) == cell::occupied)
263
+ Game::theTable->applyBlock (paintModeBlock, unsignedPreviewCoords, cell::empty);
264
+ }
265
+ }
261
266
}
262
267
263
268
void PickupBoard::update (sf::RenderWindow& window, sf::Time& dt) {
0 commit comments