Update gtk141

This commit is contained in:
daleclack 2022-10-22 21:37:30 +08:00
parent 4bad490c0b
commit 496dd402d5
5 changed files with 42 additions and 6 deletions

View File

@ -47,7 +47,7 @@ set(RESOURCE_LIST
STRIPBLANKS minesweeper.ui
STRIPBLANKS win_input.ui
STRIPBLANKS scoreswin.ui
STRIPBLANKS mine_menu.ui)
STRIPBLANKS mine_menu.xml)
compile_gresources(RESOURCE_FILE
XML_OUT

View File

@ -14,7 +14,13 @@ void InputBox::on_response(int response_id)
{
if (response_id == Gtk::RESPONSE_OK)
{
// Open a file to save json data
read_scores(check_scores->get_active());
}
hide();
}
void InputBox::read_scores(bool show_scores_win){
// Open a file to save json data
std::fstream outfile;
outfile.open("scores.json", std::ios_base::out);
if (outfile.is_open())
@ -32,11 +38,9 @@ void InputBox::on_response(int response_id)
outfile.close();
// If show scores checkbutton is checked, show scores window
if(check_scores->get_active()){
if(show_scores_win){
scores_win1->show_with_vectors(names, times);
}
}
hide();
}
void InputBox::set_game_time(int time)

View File

@ -8,6 +8,7 @@ class InputBox : public Gtk::Dialog{
public:
static InputBox *create();
InputBox(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade);
void read_scores(bool show_scores_win = true);
void set_game_time(int time);
void set_scores_window(ScoresWin *win1);

View File

@ -8,9 +8,26 @@ MineSweeper::MineSweeper()
cell(nullptr)
{
// Initalize Window
set_title("Gtkmm MineSweeper");
header.set_title("Gtkmm MineSweeper");
set_titlebar(header);
header.set_show_close_button();
header.set_decoration_layout("close,minimize,maximize:menu");
header.pack_end(menu_btn);
set_icon_name("org.gtk.daleclack");
// Initalize Menu
menu_builder = Gtk::Builder::create_from_resource("/org/gtk/daleclack/mine_menu.xml");
auto object = menu_builder->get_object("mine_menu");
auto gmenu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
popover1.bind_model(gmenu);
menu_btn.set_popover(popover1);
// Add Actions
add_action("new_game", sigc::mem_fun(*this, &MineSweeper::reset_game));
add_action("scores", sigc::mem_fun(*this, &MineSweeper::show_scores));
add_action("show_mines", sigc::mem_fun(*this, &MineSweeper::show_mines));
add_action("quit", sigc::mem_fun(*this, &MineSweeper::hide));
// Default setting
reset_game();
@ -157,6 +174,11 @@ void MineSweeper::show_mines()
}
}
void MineSweeper::show_scores(){
// Show Scores Window
input_dialog->read_scores();
}
void MineSweeper::game_lost(int explode_index){
// When a cell with mine is clicked, show other mines
for (int i = 0; i < 49; i++)

View File

@ -25,6 +25,11 @@ public:
~MineSweeper();
private:
// HeaderBar
Gtk::HeaderBar header;
Gtk::MenuButton menu_btn;
Gtk::Popover popover1;
// Child widgets
Gtk::Grid mine_grid;
Gtk::Label status_label;
@ -34,6 +39,9 @@ private:
bool winned, game_ended;
int mines_clear, mine_count;
// Menu
Glib::RefPtr<Gtk::Builder> menu_builder;
// Timer
int timer_count;
sigc::connection mytimer;
@ -48,6 +56,7 @@ private:
void reset_game();
void calc_mines();
void show_mines();
void show_scores();
void game_lost(int explode_index);
void cell_clicked(MineCell *cell1);
bool timer_func();