diff --git a/Gtkmm3/gtk141_minesweeper2/CMakeLists.txt b/Gtkmm3/gtk141_minesweeper2/CMakeLists.txt
index edf6d51..b6cfb6d 100644
--- a/Gtkmm3/gtk141_minesweeper2/CMakeLists.txt
+++ b/Gtkmm3/gtk141_minesweeper2/CMakeLists.txt
@@ -26,7 +26,7 @@ find_package (Gettext REQUIRED)
set(PO_DIR ${CMAKE_BINARY_DIR}/po/zh_CN/LC_MESSAGES)
#Source files
-set(SOURCE_FILE src/main.cc src/MineSweeper.cc src/InputBox.cc)
+set(SOURCE_FILE src/main.cc src/MineSweeper.cc src/InputBox.cc src/ScoresWin.cc)
#Compile Resource
@@ -45,7 +45,8 @@ set(RESOURCE_LIST
icons/scalable/status/maybe.svg
icons/scalable/status/mine.svg
STRIPBLANKS minesweeper.ui
- STRIPBLANKS win_input.ui)
+ STRIPBLANKS win_input.ui
+ STRIPBLANKS scoreswin.ui)
compile_gresources(RESOURCE_FILE
XML_OUT
diff --git a/Gtkmm3/gtk141_minesweeper2/res/minesweeper.cmb b/Gtkmm3/gtk141_minesweeper2/res/cambalache/minesweeper.cmb
similarity index 54%
rename from Gtkmm3/gtk141_minesweeper2/res/minesweeper.cmb
rename to Gtkmm3/gtk141_minesweeper2/res/cambalache/minesweeper.cmb
index 73b54c4..6e75fcc 100644
--- a/Gtkmm3/gtk141_minesweeper2/res/minesweeper.cmb
+++ b/Gtkmm3/gtk141_minesweeper2/res/cambalache/minesweeper.cmb
@@ -3,7 +3,8 @@
(1,None,"minesweeper.ui","minesweeper.ui",None,None,None,None,None,None,None),
- (2,None,None,"win_input.ui",None,None,None,None,None,None,None)
+ (2,None,None,"win_input.ui",None,None,None,None,None,None,None),
+ (3,None,None,"scoreswin.ui",None,None,None,None,None,None,None)
(1,1,"GtkContainer","resize-mode","queue",None,None,None,None,None),
@@ -30,6 +37,22 @@
(2,1,"GtkWidget","height-request","200",None,None,None,None,None),
(2,1,"GtkWidget","margin-start","3",None,None,None,None,None),
(2,1,"GtkWidget","width-request","400",None,None,None,None,None),
- (2,1,"GtkWindow","gravity","center",None,None,None,None,None)
+ (2,1,"GtkWindow","gravity","center",None,None,None,None,None),
+ (3,2,"GtkOrientable","orientation","vertical",None,None,None,None,None),
+ (3,3,"GtkWidget","height-request","3",None,None,None,None,None),
+ (3,4,"GtkWidget","height-request","300",None,None,None,None,None),
+ (3,4,"GtkWidget","valign","start",None,None,None,None,None),
+ (3,4,"GtkWidget","width-request","400",None,None,None,None,None),
+ (3,5,"GtkButton","label","Close",None,None,None,None,None),
+ (3,6,"GtkLabel","label"," ",None,None,None,None,None),
+ (3,6,"GtkWidget","hexpand","True",None,None,None,None,None)
+
+ (3,2,3,"GtkBoxLayoutChild","fill","False",None,None,None,None),
+ (3,2,3,"GtkBoxLayoutChild","position","2",None,None,None,None),
+ (3,2,4,"GtkBoxLayoutChild","position","1",None,None,None,None),
+ (3,3,5,"GtkBoxLayoutChild","position","2",None,None,None,None),
+ (3,3,6,"GtkBoxLayoutChild","fill","False",None,None,None,None),
+ (3,3,6,"GtkBoxLayoutChild","position","1",None,None,None,None)
+
diff --git a/Gtkmm3/gtk141_minesweeper2/res/scoreswin.ui b/Gtkmm3/gtk141_minesweeper2/res/scoreswin.ui
new file mode 100644
index 0000000..957c57b
--- /dev/null
+++ b/Gtkmm3/gtk141_minesweeper2/res/scoreswin.ui
@@ -0,0 +1,49 @@
+
+
+
+
+
+
diff --git a/Gtkmm3/gtk141_minesweeper2/res/win_input.ui b/Gtkmm3/gtk141_minesweeper2/res/win_input.ui
index 9560854..646d156 100644
--- a/Gtkmm3/gtk141_minesweeper2/res/win_input.ui
+++ b/Gtkmm3/gtk141_minesweeper2/res/win_input.ui
@@ -55,20 +55,49 @@
-
+
True
False
center
center
True
True
+ vertical
-
+
True
False
center
center
- Input Name:
+ True
+ True
+
+
+ True
+ False
+ center
+ center
+ Input Name:
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ True
+ center
+ center
+
+
+ False
+ True
+ 1
+
+
False
@@ -77,11 +106,12 @@
-
+
+ Show Scores Window
True
True
- center
- center
+ False
+ True
False
diff --git a/Gtkmm3/gtk141_minesweeper2/src/InputBox.cc b/Gtkmm3/gtk141_minesweeper2/src/InputBox.cc
index d32b6b0..4192eca 100644
--- a/Gtkmm3/gtk141_minesweeper2/src/InputBox.cc
+++ b/Gtkmm3/gtk141_minesweeper2/src/InputBox.cc
@@ -7,15 +7,19 @@ InputBox::InputBox(BaseObjectType *cobject, const Glib::RefPtr &re
{
// Get Widgets
ref_builder->get_widget("entry_name", entry_name);
+ ref_builder->get_widget("check_scores", check_scores);
entry_name->signal_activate().connect(sigc::mem_fun(*this, &InputBox::entry_activated));
}
-void InputBox::on_response(int response_id){
- if(response_id == Gtk::RESPONSE_OK){
+void InputBox::on_response(int response_id)
+{
+ if (response_id == Gtk::RESPONSE_OK)
+ {
// Open a file to save json data
std::fstream outfile;
outfile.open("scores.json", std::ios_base::out);
- if(outfile.is_open()){
+ if (outfile.is_open())
+ {
// Insert data to json
std::string name = std::string((entry_name->get_text()).c_str());
names.push_back(name);
@@ -24,26 +28,35 @@ void InputBox::on_response(int response_id){
data["time"] = times;
// Output data
- outfile<get_active()){
+ scores_win1->show_all();
+ }
}
hide();
}
-void InputBox::set_game_time(int time){
+void InputBox::set_game_time(int time)
+{
// Try to open json file
std::fstream jsonfile;
jsonfile.open("scores.json", std::ios_base::in);
-
+
// If json file opened, read the data
- if(jsonfile.is_open()){
+ if (jsonfile.is_open())
+ {
data = json::parse(jsonfile);
std::vector names1 = data["name"];
std::vector times1 = data["time"];
names = names1;
times = times1;
- }else{
+ }
+ else
+ {
// Otherwist, create json data
data = json::parse(R"(
{
@@ -58,19 +71,25 @@ void InputBox::set_game_time(int time){
game_time = time;
}
-void InputBox::entry_activated(){
+void InputBox::entry_activated()
+{
// Default response
response(Gtk::RESPONSE_OK);
}
-InputBox *InputBox::create(Gtk::Window &parent)
+void InputBox::set_scores_window(ScoresWin *win1)
+{
+ // Bind Scores Window
+ scores_win1 = win1;
+}
+
+InputBox *InputBox::create()
{
// Create a inputbox object
auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/win_input.ui");
InputBox *dialog;
builder->get_widget_derived("dialog", dialog);
- dialog->set_transient_for(parent);
return dialog;
}
diff --git a/Gtkmm3/gtk141_minesweeper2/src/InputBox.hh b/Gtkmm3/gtk141_minesweeper2/src/InputBox.hh
index fd5cbbf..800d501 100644
--- a/Gtkmm3/gtk141_minesweeper2/src/InputBox.hh
+++ b/Gtkmm3/gtk141_minesweeper2/src/InputBox.hh
@@ -2,15 +2,15 @@
#include
#include
-#include "../json_nlohmann/json.hpp"
-
-using json = nlohmann::json;
+#include "jsonfile.hh"
+#include "ScoresWin.hh"
class InputBox : public Gtk::Dialog{
public:
- static InputBox *create(Gtk::Window &parent);
+ static InputBox *create();
InputBox(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade);
void set_game_time(int time);
+ void set_scores_window(ScoresWin *win1);
protected:
void on_response(int response_id) override;
@@ -28,6 +28,10 @@ class InputBox : public Gtk::Dialog{
// Child widget
Gtk::Entry *entry_name;
+ Gtk::CheckButton *check_scores;
+
+ // Scores Window
+ ScoresWin *scores_win1;
// Signal Handlers
void entry_activated();
diff --git a/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.cc b/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.cc
index 081ae29..0a05078 100644
--- a/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.cc
+++ b/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.cc
@@ -34,13 +34,23 @@ MineSweeper::MineSweeper()
main_box.pack_start(btn_box, Gtk::PACK_SHRINK);
// Create a dialog
- input_dialog = InputBox::create(*this);
+ input_dialog = InputBox::create();
+
+ // Create Scores Window
+ scores_win = ScoresWin::create();
// Show everything
add(main_box);
show_all_children();
}
+MineSweeper::~MineSweeper(){
+ delete input_dialog;
+ if(cell != nullptr){
+ delete[] cell;
+ }
+}
+
void MineSweeper::reset_game()
{
if(cell != nullptr){
@@ -241,6 +251,9 @@ void MineSweeper::check_mines(int pos_x, int pos_y)
mytimer.disconnect();
// Save the time of game
+ input_dialog->set_transient_for(*this);
+ scores_win->set_transient_for(*this);
+ input_dialog->set_scores_window(scores_win);
input_dialog->set_game_time(timer_count);
input_dialog->show_all();
}
diff --git a/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.hh b/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.hh
index 9c8d4bc..bb5767b 100644
--- a/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.hh
+++ b/Gtkmm3/gtk141_minesweeper2/src/MineSweeper.hh
@@ -2,6 +2,7 @@
#include
#include "InputBox.hh"
+#include "ScoresWin.hh"
class MineCell : public Gtk::Button
{
@@ -21,6 +22,7 @@ class MineSweeper : public Gtk::ApplicationWindow
{
public:
MineSweeper();
+ ~MineSweeper();
private:
// Child widgets
@@ -39,6 +41,9 @@ private:
// Input dialog
InputBox *input_dialog;
+ // Scores Window
+ ScoresWin *scores_win;
+
// Signal Handlers
void reset_game();
void calc_mines();
diff --git a/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.cc b/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.cc
new file mode 100644
index 0000000..ad8abf3
--- /dev/null
+++ b/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.cc
@@ -0,0 +1,19 @@
+#include "ScoresWin.hh"
+
+ScoresWin::ScoresWin(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade)
+ : Gtk::Window(cobject),
+ ref_builder(ref_Glade)
+{
+
+}
+
+ScoresWin *ScoresWin::create()
+{
+ // Create a window
+ auto builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/scoreswin.ui");
+ ScoresWin *main_win;
+
+ builder->get_widget_derived("scores_win", main_win);
+
+ return main_win;
+}
diff --git a/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.hh b/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.hh
new file mode 100644
index 0000000..458b6a9
--- /dev/null
+++ b/Gtkmm3/gtk141_minesweeper2/src/ScoresWin.hh
@@ -0,0 +1,13 @@
+#pragma once
+
+#include
+#include "jsonfile.hh"
+
+class ScoresWin : public Gtk::Window{
+ public:
+ static ScoresWin *create();
+ ScoresWin(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade);
+
+ private:
+ Glib::RefPtr ref_builder;
+};
diff --git a/Gtkmm3/gtk141_minesweeper2/src/jsonfile.hh b/Gtkmm3/gtk141_minesweeper2/src/jsonfile.hh
new file mode 100644
index 0000000..2fe7821
--- /dev/null
+++ b/Gtkmm3/gtk141_minesweeper2/src/jsonfile.hh
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "../json_nlohmann/json.hpp"
+
+using json = nlohmann::json;