Skip to content

Commit bb6cdf3

Browse files
committed
Implemented click to move
hold to move is still the default option tho
1 parent 14bd250 commit bb6cdf3

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

include/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace Settings
5353
inline static unsigned customBlockSizeHeight, customBlockSizeWidth;
5454
inline static bool customBlockStructure[5][5];
5555

56+
inline static bool holdToMove;
57+
5658
static void defaultValues();
5759
static void save(std::stringstream& sstream);
5860
static void load(std::stringstream& sstream);

src/imguiInterface.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ void ImguiInterface::draw(sf::RenderWindow& window) {
132132

133133
if (ImGui::TreeNode("Pickup board"))
134134
{
135+
ImGui::Checkbox("Hold to move block.", &Settings::Gameplay::holdToMove);
136+
ImGui::Separator();
137+
135138
ImGui::Text("Type:");
136139
ImGui::SameLine();
137140
if (ImGui::Button("Random")) {

src/pickupBoard.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
197197
pickupableBlocks[pickedUpIndex]->setPosition(mousePositionWithOffset);
198198
pickedUpPreviewCoords = Game::theTable->previewBlock(*pickupableBlocks[pickedUpIndex], mousePosition);
199199

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)) {
201201
pickupableBlocks[pickedUpIndex]->setFloating(false);
202202

203203
if (pickedUpPreviewCoords.x != -1 || pickedUpPreviewCoords.y != -1) {
@@ -217,10 +217,20 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
217217
}
218218

219219
pickedUpIndex = -1;
220+
221+
return;
220222
}
221223
}
222224
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) {
224234
for (unsigned i = 0; i < 3; i++) { //check for every 3 blocks from the pickup area
225235
if (pickupableBlocks[i] == nullptr) //if they are picked up, if a block is nullptr, it means it was used
226236
continue;
@@ -233,31 +243,26 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
233243
pickupableBlocks[i]->setScale(PICKUP_SCALE);
234244
}
235245
}
236-
}
237246

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();
257254
}
258255
}
259256
}
260257
}
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+
}
261266
}
262267

263268
void PickupBoard::update(sf::RenderWindow& window, sf::Time& dt) {

src/settings.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,13 @@ namespace Settings
112112
customBlockStructure[i][j] = 0;
113113
}
114114

115+
holdToMove = true;
116+
115117
Gameplay::apply();
116118
}
117119

118120
void Gameplay::save(std::stringstream& sstream) {
119-
sstream << checkGameInAdvance << " " << continousGenerate << " " << blockModel << " ";
121+
sstream << holdToMove << " " << checkGameInAdvance << " " << continousGenerate << " " << blockModel << " ";
120122
sstream << customBlockSizeHeight << " " << customBlockSizeWidth << " ";
121123
for (unsigned i = 0; i < 5; i++) {
122124
for (unsigned j = 0; j < 5; j++)
@@ -126,7 +128,7 @@ namespace Settings
126128
}
127129

128130
void Gameplay::load(std::stringstream& sstream) {
129-
sstream >> checkGameInAdvance >> continousGenerate >> blockModel;
131+
sstream >> holdToMove >> checkGameInAdvance >> continousGenerate >> blockModel;
130132
sstream >> customBlockSizeHeight >> customBlockSizeWidth;
131133
for (unsigned i = 0; i < 5; i++) {
132134
for (unsigned j = 0; j < 5; j++)

0 commit comments

Comments
 (0)