X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Feditorwidget.cpp;fp=src%2Feditorwidget.cpp;h=40596326abe800ed1f6ea6bee42e31058dbe203b;hb=003638a66da61e2269e4ef398aa294c6ee02b171;hp=1431edc243c3db38397d694558e28d24f0d4f356;hpb=195a185d42504cbface8c29911467ce8cff27229;p=warehouse-man-deluxe diff --git a/src/editorwidget.cpp b/src/editorwidget.cpp index 1431edc..4059632 100644 --- a/src/editorwidget.cpp +++ b/src/editorwidget.cpp @@ -130,6 +130,21 @@ void EditorWidget::paintEvent(QPaintEvent * /*event*/) painter.setBrush(Qt::transparent); painter.setPen(Qt::darkGreen); painter.drawEllipse((x * GRIDSIZE) + 4, (y * GRIDSIZE) + 4, GRIDSIZE - 8, GRIDSIZE - 8); + + char s[256]; + int boxes, spots; + CountBoxesAndSpots(boxes, spots); + + if (boxes == spots) + sprintf(s, "Boxes = Spots"); + else if (boxes < spots) + sprintf(s, "Need %i more box%s", spots - boxes, (spots - boxes == 1 ? "" : "es")); + else if (spots < boxes) + sprintf(s, "Need %i more spot%s", boxes - spots, (boxes - spots == 1 ? "" : "s")); + + painter.setPen(Qt::blue); + painter.drawText(0, 0, clientArea.width(), clientArea.height(), + Qt::AlignRight | Qt::AlignBottom, QString(s)); } @@ -236,20 +251,25 @@ void EditorWidget::keyPressEvent(QKeyEvent * event) } else if (key == Qt::Key_Period) { - level.board[cursor.x][cursor.y] ^= GTBoxSpot; + if (!(level.board[cursor.x][cursor.y] & (GTWall | GTNull))) + level.board[cursor.x][cursor.y] ^= GTBoxSpot; } else if (key == Qt::Key_B) { - level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox); - level.board[cursor.x][cursor.y] |= GTBox; + level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTNull); + level.board[cursor.x][cursor.y] ^= GTBox; } else if (key == Qt::Key_W) { - level.board[cursor.x][cursor.y] = GTWall; + // If it's not a wall, just stick one in; otherwise, toggle it off + if (level.board[cursor.x][cursor.y] != GTWall) + level.board[cursor.x][cursor.y] = GTWall; + else + level.board[cursor.x][cursor.y] = GTSpace; } else if (key == Qt::Key_Space) { - level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox); + level.board[cursor.x][cursor.y] &= ~(GTSpace | GTWall | GTBox | GTNull); level.board[cursor.x][cursor.y] |= GTSpace; } else if (key == Qt::Key_O) @@ -265,7 +285,11 @@ void EditorWidget::keyPressEvent(QKeyEvent * event) } else if (key == Qt::Key_V) { - level.board[cursor.x][cursor.y] = GTNull; + // If it's not a void, just stick one in; otherwise, toggle it off + if (level.board[cursor.x][cursor.y] != GTNull) + level.board[cursor.x][cursor.y] = GTNull; + else + level.board[cursor.x][cursor.y] = GTSpace; } else return; // Only update screen if keypress was recognized @@ -451,6 +475,25 @@ void EditorWidget::AddNewLevelAtCurrentPosition(void) } +void EditorWidget::CountBoxesAndSpots(int & boxes, int & spots) +{ + Level & level = levelStorage[currentLevel]; + boxes = spots = 0; + + for(int x=0; x