From 311d1e1d2192c839ac86c2067ad9f009e56b38cb Mon Sep 17 00:00:00 2001 From: daleclack Date: Thu, 29 Feb 2024 20:28:56 +0800 Subject: [PATCH] Delete unused sources --- Gtk4/gtk158_minesweeper4/src/InputBox.cc | 99 ------------------------ Gtk4/gtk158_minesweeper4/src/InputBox.hh | 38 --------- 2 files changed, 137 deletions(-) delete mode 100644 Gtk4/gtk158_minesweeper4/src/InputBox.cc delete mode 100644 Gtk4/gtk158_minesweeper4/src/InputBox.hh diff --git a/Gtk4/gtk158_minesweeper4/src/InputBox.cc b/Gtk4/gtk158_minesweeper4/src/InputBox.cc deleted file mode 100644 index c46deeb..0000000 --- a/Gtk4/gtk158_minesweeper4/src/InputBox.cc +++ /dev/null @@ -1,99 +0,0 @@ -#include "InputBox.hh" - -InputBox::InputBox(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade) - : Gtk::Dialog(cobject), - ref_builder(ref_Glade) -{ - // Get Widgets - entry_name = ref_builder->get_widget("entry_name"); - check_scores = ref_builder->get_widget("check_scores"); - entry_name->signal_activate().connect(sigc::mem_fun(*this, &InputBox::entry_activated)); -} - -void InputBox::on_response(int response_id) -{ - // Open a file to save json data - std::fstream outfile; - outfile.open("scores.json", std::ios_base::out); - if (outfile.is_open()) - { - // Insert data to json - std::string name = std::string((entry_name->get_text()).c_str()); - names.push_back(name); - times.push_back(game_time); - data["name"] = names; - data["time"] = times; - - // Output data - outfile << data; - } - outfile.close(); - if (response_id == Gtk::ResponseType::OK) - { - read_scores(check_scores->get_active()); - } - hide(); -} - -void InputBox::read_scores(bool show_scores_win) -{ - // If show scores checkbutton is checked, show scores window - if (show_scores_win) - { - scores_win1->update_and_show(); - } -} - -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()) - { - data = json::parse(jsonfile); - std::vector names1 = data["name"]; - std::vector times1 = data["time"]; - names = names1; - times = times1; - } - else - { - // Otherwist, create json data - data = json::parse(R"( - { - "name":[" "], - "time":[0] - } - )"); - } - jsonfile.close(); - - // Initalize time - game_time = time; -} - -void InputBox::entry_activated() -{ - // Default response - response(Gtk::ResponseType::OK); -} - -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; - dialog = Gtk::Builder::get_widget_derived(builder, "dialog"); - - return dialog; -} diff --git a/Gtk4/gtk158_minesweeper4/src/InputBox.hh b/Gtk4/gtk158_minesweeper4/src/InputBox.hh deleted file mode 100644 index 228ddc7..0000000 --- a/Gtk4/gtk158_minesweeper4/src/InputBox.hh +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include -#include "jsonfile.hh" -#include "ScoresWin.hh" - -class InputBox : public Gtk::Dialog{ - public: - static InputBox *create(); - InputBox(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade); - void read_scores(bool show_scores_win = true); - void set_game_time(int time); - void set_scores_window(ScoresWin *win1); - - protected: - void on_response(int response_id) override; - - private: - int game_time; - - // Data to write to json file - json data; - std::vector names; - std::vector times; - - // Builder Object - Glib::RefPtr ref_builder; - - // Child widget - Gtk::Entry *entry_name; - Gtk::CheckButton *check_scores; - - // Scores Window - ScoresWin *scores_win1; - - // Signal Handlers - void entry_activated(); -}; \ No newline at end of file