#include "InputBox.hh" #include InputBox::InputBox(BaseObjectType *cobject, const Glib::RefPtr &ref_Glade) : Gtk::Dialog(cobject), ref_builder(ref_Glade) { // Get Widgets ref_builder->get_widget("entry_name", entry_name); 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){ // 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< 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::RESPONSE_OK); } InputBox *InputBox::create(Gtk::Window &parent) { // 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; }