diff --git a/Gtkmm3/gtk140_minesweeper/CMakeLists.txt b/Gtkmm3/gtk140_minesweeper/CMakeLists.txt index 1a0f380..b04821a 100644 --- a/Gtkmm3/gtk140_minesweeper/CMakeLists.txt +++ b/Gtkmm3/gtk140_minesweeper/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/TimesWin.cc) +set(SOURCE_FILE src/main.cc src/MineSweeper.cc src/TimesWin.cc src/InputBox.cc) #Compile Resource diff --git a/Gtkmm3/gtk140_minesweeper/src/InputBox.cc b/Gtkmm3/gtk140_minesweeper/src/InputBox.cc index 61c20ce..2726939 100644 --- a/Gtkmm3/gtk140_minesweeper/src/InputBox.cc +++ b/Gtkmm3/gtk140_minesweeper/src/InputBox.cc @@ -1 +1,19 @@ -#include "InputBox.hh" \ No newline at end of file +#include +#include "InputBox.hh" +#include "jsonfile.hh" + +InputBox::InputBox(){ + +} + +void InputBox::on_response(int response_id){ + // Read the original json file + std::fstream json_file; + json_file.open("score.json"); + // Append data to the json file + if(json_file.is_open()){ + + }else{ + + } +} diff --git a/Gtkmm3/gtk140_minesweeper/src/InputBox.hh b/Gtkmm3/gtk140_minesweeper/src/InputBox.hh index 3954307..d840aea 100644 --- a/Gtkmm3/gtk140_minesweeper/src/InputBox.hh +++ b/Gtkmm3/gtk140_minesweeper/src/InputBox.hh @@ -2,4 +2,14 @@ #include -class InputBox : public Gtk::Dialog{}; \ No newline at end of file +class InputBox : public Gtk::Dialog +{ +public: + InputBox(); + +protected: + void on_response(int response_id); + +private: + Gtk::Entry entry_name; +}; \ No newline at end of file diff --git a/Gtkmm3/gtk140_minesweeper/src/MineSweeper.cc b/Gtkmm3/gtk140_minesweeper/src/MineSweeper.cc index df01092..e4fcacc 100644 --- a/Gtkmm3/gtk140_minesweeper/src/MineSweeper.cc +++ b/Gtkmm3/gtk140_minesweeper/src/MineSweeper.cc @@ -1,9 +1,8 @@ #include "MineSweeper.hh" -#include "../json_nlohmann/json.hpp" +#include "TimesWin.hh" +#include "InputBox.hh" #include -using json = nlohmann::json; - MineSweeper::MineSweeper() : main_box(Gtk::ORIENTATION_VERTICAL, 5), btn_box(Gtk::ORIENTATION_HORIZONTAL, 5) diff --git a/Gtkmm3/gtk140_minesweeper/src/MineSweeper.hh b/Gtkmm3/gtk140_minesweeper/src/MineSweeper.hh index f688877..5cf0d5a 100644 --- a/Gtkmm3/gtk140_minesweeper/src/MineSweeper.hh +++ b/Gtkmm3/gtk140_minesweeper/src/MineSweeper.hh @@ -1,6 +1,7 @@ #pragma once #include +#include "InputBox.hh" class MineCell : public Gtk::Button { @@ -34,6 +35,9 @@ private: int timer_count; sigc::connection mytimer; + // When winned, show a input box + InputBox win_input; + // Signal Handlers void reset_game(); void calc_mines(); diff --git a/Gtkmm3/gtk140_minesweeper/src/TimesWin.cc b/Gtkmm3/gtk140_minesweeper/src/TimesWin.cc index 522b38a..eed47ea 100644 --- a/Gtkmm3/gtk140_minesweeper/src/TimesWin.cc +++ b/Gtkmm3/gtk140_minesweeper/src/TimesWin.cc @@ -1 +1,14 @@ -#include "TimesWin.hh" \ No newline at end of file +#include "TimesWin.hh" + +TimesWin::TimesWin() +{ +} + +void TimesWin::insert_data(int time, std::string& name){ + // Insert data to map + data[name] = std::to_string(time); +} + +void TimesWin::on_response(int response_id) +{ +} \ No newline at end of file diff --git a/Gtkmm3/gtk140_minesweeper/src/TimesWin.hh b/Gtkmm3/gtk140_minesweeper/src/TimesWin.hh index f66fd8f..9cc49dc 100644 --- a/Gtkmm3/gtk140_minesweeper/src/TimesWin.hh +++ b/Gtkmm3/gtk140_minesweeper/src/TimesWin.hh @@ -1,7 +1,16 @@ #pragma once #include +#include +#include "jsonfile.hh" -class TimesWin : public Gtk::Window{ +class TimesWin : public Gtk::Dialog +{ +public: + TimesWin(); + void insert_data(int time, std::string& name); + times_map data; -}; \ No newline at end of file +protected: + void on_response(int response_id) override; +}; diff --git a/Gtkmm3/gtk140_minesweeper/src/jsonfile.hh b/Gtkmm3/gtk140_minesweeper/src/jsonfile.hh new file mode 100644 index 0000000..b7c0a73 --- /dev/null +++ b/Gtkmm3/gtk140_minesweeper/src/jsonfile.hh @@ -0,0 +1,6 @@ +#pragma once +#include "../json_nlohmann/json.hpp" +#include + +using json = nlohmann::json; +typedef std::map times_map;