Delete unused sources
This commit is contained in:
parent
78f9f20407
commit
311d1e1d21
|
@ -1,99 +0,0 @@
|
|||
#include "InputBox.hh"
|
||||
|
||||
InputBox::InputBox(BaseObjectType *cobject, const Glib::RefPtr<Gtk::Builder> &ref_Glade)
|
||||
: Gtk::Dialog(cobject),
|
||||
ref_builder(ref_Glade)
|
||||
{
|
||||
// Get Widgets
|
||||
entry_name = ref_builder->get_widget<Gtk::Entry>("entry_name");
|
||||
check_scores = ref_builder->get_widget<Gtk::CheckButton>("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<std::string> names1 = data["name"];
|
||||
std::vector<int> 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<InputBox>(builder, "dialog");
|
||||
|
||||
return dialog;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
#include "jsonfile.hh"
|
||||
#include "ScoresWin.hh"
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
void on_response(int response_id) override;
|
||||
|
||||
private:
|
||||
int game_time;
|
||||
|
||||
// Data to write to json file
|
||||
json data;
|
||||
std::vector<std::string> names;
|
||||
std::vector<int> times;
|
||||
|
||||
// Builder Object
|
||||
Glib::RefPtr<Gtk::Builder> ref_builder;
|
||||
|
||||
// Child widget
|
||||
Gtk::Entry *entry_name;
|
||||
Gtk::CheckButton *check_scores;
|
||||
|
||||
// Scores Window
|
||||
ScoresWin *scores_win1;
|
||||
|
||||
// Signal Handlers
|
||||
void entry_activated();
|
||||
};
|
Loading…
Reference in New Issue