learn-hieroglyphs/src/main.rs

188 lines
4.9 KiB
Rust
Raw Normal View History

2024-04-10 20:25:02 +03:00
mod db;
2024-03-22 15:59:42 +03:00
mod game;
2024-03-27 11:27:15 +03:00
mod ui;
mod widgets;
2024-03-22 15:59:42 +03:00
2024-04-01 15:42:50 +03:00
use crate::ui::menu::MenuScene;
2024-03-27 11:27:15 +03:00
2024-04-10 20:25:02 +03:00
use gtk::glib::closure_local;
use gtk::prelude::*;
use gtk::{gio, glib, Application, Button};
use ui::cards::edit::MemoryCardsEditScene;
use ui::cards::game::MemoryCardsGameScene;
use ui::cards::new::MemoryCardsNewScene;
use ui::cards::setup::MemoryCardsSetupScene;
use ui::guessing::game::GuessingScene;
use ui::guessing::setup::GuessingSetupScene;
enum AppWindow {
MenuScene = 1,
GuessingSetupScene = 2,
GuessingScene = 3,
MemoryCardsSetupScene = 4,
MemoryCardsEditScene = 5,
MemoryCardsGameScene = 6,
// MemoryCardsNewScene = 7,
}
2024-03-22 15:59:42 +03:00
2024-03-25 05:20:18 +03:00
const APP_ID: &str = "org.foxarmy.learn-hieroglyph";
2024-04-01 23:46:13 +03:00
2024-03-22 15:59:42 +03:00
fn main() -> glib::ExitCode {
2024-04-02 15:32:43 +03:00
gio::resources_register_include!("compiled.gresource").expect("Cannot include gresources");
2024-04-01 15:42:50 +03:00
2024-04-05 15:01:24 +03:00
db::init();
2024-04-01 15:42:50 +03:00
let app: Application = Application::builder().application_id(APP_ID).build();
2024-04-10 20:25:02 +03:00
app.connect_activate(build_ui);
2024-03-22 15:59:42 +03:00
app.run()
}
2024-04-01 15:42:50 +03:00
2024-04-10 20:25:02 +03:00
fn hide_all_windows(app: &Application) {
for window in app.windows() {
window.set_visible(false);
}
}
fn switch_to(app: &Application, win: AppWindow) {
hide_all_windows(app);
app.window_by_id(win as u32).unwrap().set_visible(true);
}
fn build_ui(app: &Application) {
let menu: MenuScene = MenuScene::new(app); // 1
let guessing_setup: GuessingSetupScene = GuessingSetupScene::new(app); // 2
let guessing_scene: GuessingScene = GuessingScene::new(app); // 3
let memory_cards_setup: MemoryCardsSetupScene = MemoryCardsSetupScene::new(app); // 4
let memory_cards_edit: MemoryCardsEditScene = MemoryCardsEditScene::new(app); // 5
let memory_cards_game: MemoryCardsGameScene = MemoryCardsGameScene::new(app); // 6
let _memory_cards_new: MemoryCardsNewScene = MemoryCardsNewScene::new(app); //7
menu.get_guessing_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::GuessingSetupScene);
}
),
);
menu.get_memory_cards_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsSetupScene);
}
),
);
guessing_setup.get_start_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app, @strong guessing_scene => move |_b: &Button| {
switch_to(&app, AppWindow::GuessingScene);
guessing_scene.read_settings();
guessing_scene.init();
}
),
);
guessing_setup.get_back_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MenuScene);
}
),
);
memory_cards_setup.get_edit_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsEditScene);
}
),
);
memory_cards_setup.get_back_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MenuScene);
}
),
);
memory_cards_setup.get_start_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app, @strong memory_cards_game => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsGameScene);
memory_cards_game.update_card_list();
}
),
);
memory_cards_edit.get_back_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsSetupScene);
}
),
);
memory_cards_game.get_back_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::MemoryCardsSetupScene);
}
),
);
guessing_scene.get_back_button().connect_closure(
"clicked",
false,
closure_local!(
@strong app => move |_b: &Button| {
switch_to(&app, AppWindow::GuessingSetupScene);
}
),
);
// memory_cards_edit.get_add_button().connect_closure(
// "clicked",
// false,
// closure_local!(
// @strong app => move |_b: &Button| {
// switch_to(&app, AppWindow::MemoryCardsNewScene);
// hide_all_windows(&app);
// app.window_by_id(7).unwrap().set_visible(true); // to memory card new scene
// }
// ),
// );
2024-04-01 15:42:50 +03:00
2024-04-10 20:25:02 +03:00
menu.present();
2024-04-01 15:42:50 +03:00
}