diff --git a/Cargo.toml b/Cargo.toml index 3d726e9..4f8500e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +dirs = "5.0.1" gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] } rand = "0.8.5" + +[build-dependencies] +glib-build-tools = "0.19.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2fb52ed --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +fn main() { + glib_build_tools::compile_resources( + &["resources"], + "resources/resources.gresource.xml", + "compiled.gresource", + ); +} diff --git a/resources/guessing.ui.xml b/resources/guessing.ui.xml new file mode 100644 index 0000000..4b9e8ec --- /dev/null +++ b/resources/guessing.ui.xml @@ -0,0 +1,26 @@ + + + + diff --git a/resources/memory_cards_settings.ui.xml b/resources/memory_cards_settings.ui.xml new file mode 100644 index 0000000..3af6073 --- /dev/null +++ b/resources/memory_cards_settings.ui.xml @@ -0,0 +1,21 @@ + + + + diff --git a/resources/menu.ui.xml b/resources/menu.ui.xml new file mode 100644 index 0000000..b1cf1ff --- /dev/null +++ b/resources/menu.ui.xml @@ -0,0 +1,21 @@ + + + + diff --git a/resources/resources.gresource.xml b/resources/resources.gresource.xml new file mode 100644 index 0000000..a27b575 --- /dev/null +++ b/resources/resources.gresource.xml @@ -0,0 +1,9 @@ + + + + menu.ui.xml + guessing.ui.xml + settings.gschema.xml + memory_cards_settings.ui.xml + + diff --git a/resources/settings.gschema.xml b/resources/settings.gschema.xml new file mode 100644 index 0000000..cc56617 --- /dev/null +++ b/resources/settings.gschema.xml @@ -0,0 +1,21 @@ + + + + + false + Enable romaji to kana + + + true + Enable kana to romaji + + + true + Enable hiragana + + + false + Enable katakana + + + diff --git a/src/game.rs b/src/game.rs index 3110460..f7fe3fa 100644 --- a/src/game.rs +++ b/src/game.rs @@ -32,12 +32,8 @@ pub struct Hieroglyph { column: usize, } -pub trait Useful { - fn get_kana(&self) -> Kanas; -} - -impl Useful for Hieroglyph { - fn get_kana(&self) -> Kanas { +impl Hieroglyph { + pub fn get_kana(&self) -> Kanas { for row in ROMAJI { if row.contains(&(self.syllable).as_str()) { return Kanas::Romaji; @@ -107,7 +103,7 @@ const KATAKANA: KanaCharacters = [ ["サ", "シ", "ス", "セ", "ソ"], ["タ", "チ", "ツ", "テ", "ト"], ["ナ", "ニ", "ヌ", "ネ", "ノ"], - ["ハ", "ヒ", "フ", "ヘ", "ホ"], + ["ハ", "ヒ", "フ", "ヘ", "ホ"], ["マ", "ミ", "ム", "メ", "モ"], ["ヤ", OBS, "ユ", OBS, "ヨ"], ["ラ", "リ", "ル", "レ", "ロ"], @@ -146,3 +142,61 @@ pub fn generate_random_hieroglyph(k: Kanas) -> Hieroglyph { column, } } + +pub fn random_kana(hiragana: bool, katakana: bool) -> Hieroglyph { + if hiragana && katakana { + generate_random_hieroglyph(if rand::thread_rng().gen_bool(0.5) { + Kanas::Katakana + } else { + Kanas::Hiragana + }) + } else { + generate_random_hieroglyph(if hiragana { + Kanas::Hiragana + } else { + Kanas::Katakana + }) + } +} + +pub fn ask(ktr: bool, rtk: bool, hiragana: bool, katakana: bool) -> Hieroglyph { + if ktr && rtk { + return if rand::thread_rng().gen_bool(0.5) { + random_kana(hiragana, katakana) + } else { + generate_random_hieroglyph(Kanas::Romaji) + }; + } else if ktr { + return random_kana(hiragana, katakana); + } else { + return generate_random_hieroglyph(Kanas::Romaji); + } +} + +pub fn generate_question_text(question: &Hieroglyph, exact_kana: &Kanas) -> String { + return String::from(match question.get_kana() { + Kanas::Romaji => match exact_kana { + Kanas::Hiragana => { + format!("Name corresponding hiragana for {}", question.to_string()) + } + Kanas::Katakana => { + format!("Name corresponding katakana for {}", question.to_string()) + } + _ => { + panic!("HOW DID YOU GET HERE!?"); + } + }, + Kanas::Hiragana => { + format!( + "Name corresponding romaji for hiragana {}", + question.to_string() + ) + } + Kanas::Katakana => { + format!( + "Name corresponding romaji for katakana {}", + question.to_string() + ) + } + }); +} \ No newline at end of file diff --git a/src/labled_switch/imp.rs b/src/labled_switch/imp.rs new file mode 100644 index 0000000..3528085 --- /dev/null +++ b/src/labled_switch/imp.rs @@ -0,0 +1,22 @@ +use gtk::glib; +use gtk::subclass::prelude::*; + +// Object holding the state +#[derive(Default)] +pub struct LabledSwitch; + +// The central trait for subclassing a GObject +#[glib::object_subclass] +impl ObjectSubclass for LabledSwitch { + const NAME: &'static str = "LabledSwitch"; + type Type = super::LabledSwitch; + type ParentType = gtk::Widget; +} + +impl ObjectImpl for LabledSwitch {} + +impl WidgetImpl for LabledSwitch {} + +impl ButtonImpl for LabledSwitch {} + +// impl IsSubclassable for LabledSwitch {} \ No newline at end of file diff --git a/src/labled_switch/mod.rs b/src/labled_switch/mod.rs index 88bd76b..4f1639d 100644 --- a/src/labled_switch/mod.rs +++ b/src/labled_switch/mod.rs @@ -1,23 +1,45 @@ -use gtk::{prelude::*, Box, Label, Switch}; +// mod imp; -pub fn build(text: &str) -> (Box, Switch, Label) { - let switch: Switch = Switch::builder() - .valign(gtk::Align::Start) - .halign(gtk::Align::Center) - .build(); +// use glib::Object; +// use gtk::glib; - let label: Label = Label::builder() - .valign(gtk::Align::End) - .halign(gtk::Align::BaselineCenter) - .label(text) - .build(); +// glib::wrapper! { +// pub struct LabledSwitch(ObjectSubclass) +// @extends gtk::Widget, +// @implements gtk::Accessible, gtk::Actionable, gtk::Buildable, gtk::ConstraintTarget; +// } - let container = Box::builder() - .orientation(gtk::Orientation::Horizontal) - .build(); +// impl LabledSwitch { +// pub fn new() -> Self { +// Object::builder().build() +// } - container.append(&switch); - container.append(&label); +// pub fn with_label(label: &str) -> Self { +// Object::builder().property("label", label).build() +// } +// } - (container, switch, label) -} + +// // use gtk::{prelude::*, Box, Label, Switch}; + +// // pub fn build(text: &str) -> (Box, Switch, Label) { +// // let switch: Switch = Switch::builder() +// // .valign(gtk::Align::Start) +// // .halign(gtk::Align::Center) +// // .build(); + +// // let label: Label = Label::builder() +// // .valign(gtk::Align::End) +// // .halign(gtk::Align::BaselineCenter) +// // .label(text) +// // .build(); + +// // let container = Box::builder() +// // .orientation(gtk::Orientation::Horizontal) +// // .build(); + +// // container.append(&switch); +// // container.append(&label); + +// // (container, switch, label) +// // } diff --git a/src/main.rs b/src/main.rs index c1ba412..f69a43f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,17 +2,34 @@ mod game; mod labled_switch; mod ui; -use crate::ui::build_ui; +use crate::ui::menu::MenuScene; -use gtk::prelude::*; -use gtk::{glib, Application}; +use gtk::{prelude::*, ApplicationWindow}; +use gtk::{glib, Application, gio}; const APP_ID: &str = "org.foxarmy.learn-hieroglyph"; - +// const APP: Option> = None;//RefCell::new(Application::builder().application_id(APP_ID).build()); +// pub const S: Stack = Stack::new(); fn main() -> glib::ExitCode { - let app = Application::builder().application_id(APP_ID).build(); + gio::resources_register_include!("compiled.gresource") + .expect("Cannot include gresources"); + + // APP = Option::from(RefCell::new(Application::builder().application_id(APP_ID).build())); + // *APP.unwrap().borrow_mut() = Application::builder().application_id(APP_ID).build(); + + let app: Application = Application::builder().application_id(APP_ID).build(); + + app.connect_activate(test_ui); - app.connect_activate(build_ui); app.run() } + +fn test_ui (app: &Application) { + let window: ApplicationWindow = MenuScene::new(app).into(); + + window.present(); + + println!("{}", app.windows().len()); + +} diff --git a/src/ui/cards/imp.rs b/src/ui/cards/imp.rs new file mode 100644 index 0000000..d508c83 --- /dev/null +++ b/src/ui/cards/imp.rs @@ -0,0 +1,42 @@ +use glib::subclass::InitializingObject; +use gtk::subclass::prelude::*; +use gtk::{glib, Button, CompositeTemplate}; + + +#[derive(CompositeTemplate, Default)] +#[template(resource = "/org/foxarmy/learn-hieroglyph/memory_cards_settings.ui.xml")] +pub struct MemoryCardsSetupScene { + #[template_child] + pub edit_button: TemplateChild