complete cards/game
This commit is contained in:
@@ -82,7 +82,7 @@ impl MemoryCardsEditScene {
|
||||
let cards_iter = stmt
|
||||
.query_map([], |row| {
|
||||
let image_path: String = row.get(0).unwrap();
|
||||
let image_path = get_images_store_path() + &image_path;
|
||||
let image_path: String = get_images_store_path() + &image_path;
|
||||
let hieroglyph: String = row.get(1).unwrap();
|
||||
let reading: String = row.get(2).unwrap();
|
||||
let entry = CardEntry::new(&image_path, &hieroglyph, &reading);
|
||||
@@ -94,9 +94,6 @@ impl MemoryCardsEditScene {
|
||||
let card_binding = card.unwrap();
|
||||
let self_binding = self.obj();
|
||||
c.append(&card_binding);
|
||||
card_binding.connect_closure("created", false, closure_local!(move | | {
|
||||
println!("New card created");
|
||||
}));
|
||||
|
||||
card_binding.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_binding, @strong self_binding => move |_b: &Button| {
|
||||
let connection = Connection::open(get_db_path()).unwrap();
|
||||
|
||||
@@ -1 +1,65 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use crate::widgets::card_display::*;
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::clone;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{prelude::*, Entry};
|
||||
use gtk::{glib, CompositeTemplate, Label};
|
||||
|
||||
#[derive(CompositeTemplate, Default)]
|
||||
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/game/ui.xml")]
|
||||
pub struct MemoryCardsGameScene {
|
||||
#[template_child]
|
||||
pub card_display: TemplateChild<CardDisplay>,
|
||||
#[template_child]
|
||||
pub stats_label: TemplateChild<Label>,
|
||||
|
||||
pub correct: RefCell<usize>,
|
||||
pub incorrect: RefCell<usize>
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MemoryCardsGameScene {
|
||||
const NAME: &'static str = "MemoryCardsGameScene";
|
||||
type Type = super::MemoryCardsGameScene;
|
||||
type ParentType = gtk::ApplicationWindow;
|
||||
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
klass.bind_template();
|
||||
}
|
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) {
|
||||
obj.init_template();
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectImpl for MemoryCardsGameScene {
|
||||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
let card_display_binding = self.card_display.imp().obj();
|
||||
let self_binding = self.obj();
|
||||
|
||||
card_display_binding.generate_card();
|
||||
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(), card_display_binding.get_hieroglyph(), e.text().to_string() == *card_display_binding.get_hieroglyph());
|
||||
if e.text() == *card_display_binding.get_hieroglyph() {
|
||||
*self_binding.imp().correct.borrow_mut() += 1;
|
||||
} else {
|
||||
*self_binding.imp().incorrect.borrow_mut() +=1;
|
||||
}
|
||||
self_binding.update_stats();
|
||||
card_display_binding.generate_card();
|
||||
e.set_text("");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl WidgetImpl for MemoryCardsGameScene {}
|
||||
|
||||
impl WindowImpl for MemoryCardsGameScene {}
|
||||
|
||||
impl ApplicationWindowImpl for MemoryCardsGameScene {}
|
||||
|
||||
@@ -1 +1,35 @@
|
||||
|
||||
mod imp;
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MemoryCardsGameScene(ObjectSubclass<imp::MemoryCardsGameScene>)
|
||||
@extends gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
}
|
||||
|
||||
impl MemoryCardsGameScene {
|
||||
pub fn new(app: &Application) -> Self {
|
||||
Object::builder().property("application", app).build()
|
||||
}
|
||||
|
||||
// pub fn set_stats(&self, correct: usize, incorrect: usize) {
|
||||
// self.imp().stats_label.set_text(&format!("Correct|Incorrect: {correct}|{incorrect}"));
|
||||
// }
|
||||
|
||||
pub fn update_stats(&self) {
|
||||
self.imp().stats_label.set_text(&format!("Correct|Incorrect: {}|{}", self.imp().correct.borrow(), self.imp().incorrect.borrow()));
|
||||
}
|
||||
|
||||
// pub fn get_stats(&self) -> (usize, usize) {
|
||||
// (self.imp().correct, self.imp().incorrect)
|
||||
// }
|
||||
|
||||
// pub fn set_stats(&self, correct: usize, incorrect: usize) {
|
||||
// self.imp().correct = correct;
|
||||
// self.imp().incorrect = incorrect;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::ui::cards::edit::*;
|
||||
use crate::ui::cards::{edit::MemoryCardsEditScene, game::MemoryCardsGameScene};
|
||||
|
||||
use glib::subclass::InitializingObject;
|
||||
use gtk::glib::closure_local;
|
||||
@@ -35,13 +35,17 @@ impl ObjectImpl for MemoryCardsSetupScene {
|
||||
|
||||
let binding = self.obj();
|
||||
|
||||
self.edit_button.connect_closure("clicked",
|
||||
false,
|
||||
closure_local!(@strong binding => move |_b: &Button| {
|
||||
self.edit_button.connect_closure("clicked",false, closure_local!(@strong binding => move |_b: &Button| {
|
||||
let new_win: MemoryCardsEditScene = MemoryCardsEditScene::new(&binding.application().unwrap());
|
||||
new_win.present();
|
||||
})
|
||||
);
|
||||
|
||||
self.start_button.connect_closure("clicked", false, closure_local!(@strong binding => move |_b: &Button| {
|
||||
let new_win: MemoryCardsGameScene = MemoryCardsGameScene::new(&binding.application().unwrap());
|
||||
new_win.present();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user