|
@@ -1,4 +1,6 @@
|
|
|
#include "window.hpp"
|
|
#include "window.hpp"
|
|
|
|
|
+#include "gdkmm/texture.h"
|
|
|
|
|
+#include "sigc++/functors/mem_fun.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
//}
|
|
@@ -19,7 +21,7 @@ void MainWindow::OnCellRightClick(int n_press, double n_x, double n_y, int index
|
|
|
field.toggleFlag(x, y);
|
|
field.toggleFlag(x, y);
|
|
|
if(field.isFlagged(x, y)) {
|
|
if(field.isFlagged(x, y)) {
|
|
|
auto imgflag = Gtk::make_managed<Gtk::Image>();
|
|
auto imgflag = Gtk::make_managed<Gtk::Image>();
|
|
|
- imgflag->set(m_pixbufFlag);
|
|
|
|
|
|
|
+ imgflag->set(m_textureFlag);
|
|
|
buttons.at(pos)->set_child(*imgflag);
|
|
buttons.at(pos)->set_child(*imgflag);
|
|
|
buttons.at(pos)->set_active(true);
|
|
buttons.at(pos)->set_active(true);
|
|
|
}
|
|
}
|
|
@@ -35,7 +37,6 @@ void MainWindow::updateFlagsLabel(int flags) {
|
|
|
Glib::ustring msg = Glib::ustring::compose("Remaining flags: %1", flags);
|
|
Glib::ustring msg = Glib::ustring::compose("Remaining flags: %1", flags);
|
|
|
flagLabel.set_label(msg);
|
|
flagLabel.set_label(msg);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// void MainWindow::OnNewButtonClick() {
|
|
// void MainWindow::OnNewButtonClick() {
|
|
|
// newGame = true;
|
|
// newGame = true;
|
|
|
// gameOver = false;
|
|
// gameOver = false;
|
|
@@ -67,14 +68,13 @@ void MainWindow::OnCellClick(int x, int y) {
|
|
|
if(field.isFlagged(x, y)) {
|
|
if(field.isFlagged(x, y)) {
|
|
|
buttons.at(x + y * field.getRows())->set_active(true);
|
|
buttons.at(x + y * field.getRows())->set_active(true);
|
|
|
}
|
|
}
|
|
|
- else if(field.isBomb(x, y)) {
|
|
|
|
|
- openBombs();
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
|
|
+ else {
|
|
|
field.openCell(x, y);
|
|
field.openCell(x, y);
|
|
|
|
|
+ if(field.isBomb(x, y)) {
|
|
|
|
|
+ openBombs();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
void MainWindow::openBombs() {
|
|
void MainWindow::openBombs() {
|
|
|
for(int i=0; i < field.getCols() * field.getRows(); i++) {
|
|
for(int i=0; i < field.getCols() * field.getRows(); i++) {
|
|
@@ -86,12 +86,12 @@ void MainWindow::openBombs() {
|
|
|
if(field.isBomb(x, y)) {
|
|
if(field.isBomb(x, y)) {
|
|
|
if(field.isFlagged(x, y)) {
|
|
if(field.isFlagged(x, y)) {
|
|
|
auto imgFlagBomb = std::make_shared<Gtk::Image>();
|
|
auto imgFlagBomb = std::make_shared<Gtk::Image>();
|
|
|
- imgFlagBomb->set(m_pixbufFlagBomb);
|
|
|
|
|
|
|
+ imgFlagBomb->set(m_textureFlagBomb);
|
|
|
buttons.at(i)->set_child(*imgFlagBomb);
|
|
buttons.at(i)->set_child(*imgFlagBomb);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
auto imgBomb = std::make_shared<Gtk::Image>();
|
|
auto imgBomb = std::make_shared<Gtk::Image>();
|
|
|
- imgBomb->set(m_pixbufBomb);
|
|
|
|
|
|
|
+ imgBomb->set(m_textureBomb);
|
|
|
buttons.at(i)->set_child(*imgBomb);
|
|
buttons.at(i)->set_child(*imgBomb);
|
|
|
}
|
|
}
|
|
|
buttons.at(i)->set_active(true);
|
|
buttons.at(i)->set_active(true);
|
|
@@ -158,31 +158,31 @@ void MainWindow::updateCell(int x, int y) {
|
|
|
// }
|
|
// }
|
|
|
// return true;
|
|
// return true;
|
|
|
// }
|
|
// }
|
|
|
|
|
+void MainWindow::gameOver() {
|
|
|
|
|
+ clockSignalConn.disconnect();
|
|
|
|
|
+ std::cout << "Signal gameOver emmited\n";
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-// bool MainWindow::UpdateClockLabel()
|
|
|
|
|
-// {
|
|
|
|
|
-// if(gameOver) return false;
|
|
|
|
|
-
|
|
|
|
|
-// elapsedTime++;
|
|
|
|
|
-
|
|
|
|
|
-// int deciseconds = elapsedTime % 10;
|
|
|
|
|
-// int seconds = (elapsedTime / 10) % 60;
|
|
|
|
|
-// int minutes = (elapsedTime /600) % 60;
|
|
|
|
|
-
|
|
|
|
|
-// Glib::ustring msg = Glib::ustring::compose("Elapsed time: %1:%2.%3", \
|
|
|
|
|
-// Glib::ustring::format(std::setfill(L'0'), std::setw(2), minutes), \
|
|
|
|
|
-// Glib::ustring::format(std::setfill(L'0'), std::setw(2), seconds), \
|
|
|
|
|
-// Glib::ustring::format(std::setfill(L'0'), std::setw(1), deciseconds));
|
|
|
|
|
-// clockLabel.set_label(msg);
|
|
|
|
|
-
|
|
|
|
|
-// return true;
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+bool MainWindow::updateClockLabel()
|
|
|
|
|
+{
|
|
|
|
|
+ ++m_elapsedTime;
|
|
|
|
|
+
|
|
|
|
|
+ int deciseconds = m_elapsedTime % 10;
|
|
|
|
|
+ int seconds = (m_elapsedTime / 10) % 60;
|
|
|
|
|
+ int minutes = (m_elapsedTime /600) % 60;
|
|
|
|
|
+
|
|
|
|
|
+ Glib::ustring msg = Glib::ustring::compose("Elapsed time: %1:%2.%3", \
|
|
|
|
|
+ Glib::ustring::format(std::setfill(L'0'), std::setw(2), minutes), \
|
|
|
|
|
+ Glib::ustring::format(std::setfill(L'0'), std::setw(2), seconds), \
|
|
|
|
|
+ Glib::ustring::format(std::setfill(L'0'), std::setw(1), deciseconds));
|
|
|
|
|
+ clockLabel.set_label(msg);
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
MainWindow::MainWindow()
|
|
MainWindow::MainWindow()
|
|
|
{
|
|
{
|
|
|
// ApplyStyles(); // Load the CSS file
|
|
// ApplyStyles(); // Load the CSS file
|
|
|
- elapsedTime = 0;
|
|
|
|
|
|
|
+ m_elapsedTime = 0;
|
|
|
newGame = true;
|
|
newGame = true;
|
|
|
set_title("MineSweeper");
|
|
set_title("MineSweeper");
|
|
|
set_default_size(400, 400);
|
|
set_default_size(400, 400);
|
|
@@ -222,9 +222,9 @@ MainWindow::MainWindow()
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO check if it's okay to mix std::shared_ptr with Gdk::ptr
|
|
//TODO check if it's okay to mix std::shared_ptr with Gdk::ptr
|
|
|
- m_pixbufBomb = Gdk::Pixbuf::create_from_resource("/minesweeper/bomb-solid");
|
|
|
|
|
- m_pixbufFlag = Gdk::Pixbuf::create_from_resource("/minesweeper/flag-solid");
|
|
|
|
|
- m_pixbufFlagBomb = Gdk::Pixbuf::create_from_resource("/minesweeper/flag-bomb");
|
|
|
|
|
|
|
+ m_textureBomb = Gdk::Texture::create_from_resource("/minesweeper/bomb-solid");
|
|
|
|
|
+ m_textureFlag = Gdk::Texture::create_from_resource("/minesweeper/flag-solid");
|
|
|
|
|
+ m_textureFlagBomb = Gdk::Texture::create_from_resource("/minesweeper/flag-bomb");
|
|
|
|
|
|
|
|
// bombPix.set_from_resource("/minesweeper/bomb-solid");
|
|
// bombPix.set_from_resource("/minesweeper/bomb-solid");
|
|
|
|
|
|
|
@@ -266,12 +266,17 @@ MainWindow::MainWindow()
|
|
|
|
|
|
|
|
field.openCellSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::updateCell)));
|
|
field.openCellSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::updateCell)));
|
|
|
field.remainingFlagsSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::updateFlagsLabel)));
|
|
field.remainingFlagsSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::updateFlagsLabel)));
|
|
|
|
|
+ field.gameOverSignal.connect(sigc::bind(sigc::mem_fun(*this, &MainWindow::gameOver)));
|
|
|
//newGameButton.set_label("New");
|
|
//newGameButton.set_label("New");
|
|
|
//newGameButton.add_css_class("suggested-action");
|
|
//newGameButton.add_css_class("suggested-action");
|
|
|
//newGameButton.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::OnNewButtonClick));
|
|
//newGameButton.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::OnNewButtonClick));
|
|
|
|
|
|
|
|
//optionButton.set_icon_name("open-menu");
|
|
//optionButton.set_icon_name("open-menu");
|
|
|
|
|
|
|
|
|
|
+ //if (clockSignalConn.connected()) clockSignalConn.disconnect();
|
|
|
|
|
+ //elapsedTime = 0;
|
|
|
|
|
+ clockSignalConn = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::updateClockLabel), 100);
|
|
|
|
|
+ //}
|
|
|
//create the minefield
|
|
//create the minefield
|
|
|
//field = new MineField(COLS, MINES);
|
|
//field = new MineField(COLS, MINES);
|
|
|
|
|
|