Add no cards notification

This commit is contained in:
leca 2024-04-09 16:51:49 +03:00
parent c376dbc01a
commit d51aaed23d
2 changed files with 14 additions and 5 deletions

View File

@ -174,7 +174,6 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
_ => panic!("Could not create directory for storing images!"), _ => panic!("Could not create directory for storing images!"),
}, },
}; };
println!("Setting handler");
w.get_done_button().connect_closure( w.get_done_button().connect_closure(
"clicked", "clicked",
false, false,
@ -189,8 +188,6 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
let reading = w.get_reading_input(); let reading = w.get_reading_input();
let conn = Connection::open(get_db_path()).unwrap(); let conn = Connection::open(get_db_path()).unwrap();
println!("INSERTING NEW IMAGE");
let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)"; let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)";
conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap(); conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();
w.close(); w.close();

View File

@ -6,7 +6,7 @@ use glib::subclass::InitializingObject;
use gtk::glib::clone; use gtk::glib::clone;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use gtk::{prelude::*, Entry}; use gtk::{prelude::*, Entry};
use gtk::{glib, CompositeTemplate, Label}; use gtk::{glib, CompositeTemplate, Label, Box};
#[derive(CompositeTemplate, Default)] #[derive(CompositeTemplate, Default)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/game/ui.xml")] #[template(resource = "/org/foxarmy/learn-hieroglyph/cards/game/ui.xml")]
@ -15,6 +15,8 @@ pub struct MemoryCardsGameScene {
pub card_display: TemplateChild<CardDisplay>, pub card_display: TemplateChild<CardDisplay>,
#[template_child] #[template_child]
pub stats_label: TemplateChild<Label>, pub stats_label: TemplateChild<Label>,
#[template_child]
pub content: TemplateChild<Box>,
pub correct: RefCell<usize>, pub correct: RefCell<usize>,
pub incorrect: RefCell<usize> pub incorrect: RefCell<usize>
@ -42,7 +44,17 @@ impl ObjectImpl for MemoryCardsGameScene {
let card_display_binding = self.card_display.imp().obj(); let card_display_binding = self.card_display.imp().obj();
let self_binding = self.obj(); let self_binding = self.obj();
card_display_binding.generate_card(); match card_display_binding.generate_card() {
Some(_) => (),
None => {
while self.content.first_child() != None {
self.content.remove(&self.content.first_child().unwrap());
}
self.content.append(&Label::builder().label("No cards found. Please, add some.").build());
return
}
};
card_display_binding.get_answer_entry().connect_activate(clone!(@strong card_display_binding, @strong self_binding => move |e: &Entry| { card_display_binding.get_answer_entry().connect_activate(clone!(@strong card_display_binding, @strong self_binding => move |e: &Entry| {
println!("{}", e.text()); println!("{}", e.text());
println!("{} = {}? -> {}", e.text(), card_display_binding.get_hieroglyph(), e.text().to_string() == *card_display_binding.get_hieroglyph()); println!("{} = {}? -> {}", e.text(), card_display_binding.get_hieroglyph(), e.text().to_string() == *card_display_binding.get_hieroglyph());