Compare commits

..

No commits in common. "07b73515013ec92eab3bdd57b8a9d330ad722600" and "5478d388cb99b1bb696a957f6dc87cffaf88df25" have entirely different histories.

11 changed files with 22 additions and 186 deletions

2
Cargo.lock generated
View File

@ -910,7 +910,7 @@ dependencies = [
"gdk4", "gdk4",
"gio", "gio",
"glib", "glib",
"glib-build-tools 0.16.3", "glib-build-tools",
"gtk4", "gtk4",
"libadwaita", "libadwaita",
"serde", "serde",

View File

@ -30,7 +30,6 @@ macro_rules! define_config {
} }
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum ConfigOption { pub enum ConfigOption {
$($name($struct)),+ $($name($struct)),+
} }

View File

@ -71,10 +71,8 @@ impl CoreApp {
pub fn new(config_path: std::path::PathBuf) -> Self { pub fn new(config_path: std::path::PathBuf) -> Self {
println!("config_path: {:?}", config_path); println!("config_path: {:?}", config_path);
let config = Config::from_path(config_path).expect("configuration to open"); let config = Config::from_path(config_path).expect("configuration to open");
println!("config: {:?}", config);
let db_path: DatabasePath = config.get().unwrap(); let db_path: DatabasePath = config.get().unwrap();
println!("db_path: {:?}", db_path);
let state = Arc::new(RwLock::new(AppState::new(db_path))); let state = Arc::new(RwLock::new(AppState::new(db_path)));
println!("config: {:?}", config); println!("config: {:?}", config);

View File

@ -1,18 +1,14 @@
use crate::ui::{home, library_view, HomeView, LibraryView}; use crate::{
ui::types;
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use typeshare::typeshare; use typeshare::typeshare;
#[typeshare]
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LaunchScreenView { pub enum LaunchScreenView {
home: HomeView, CreateGame(CreateGameView)
library: LibraryView,
} }
// This will be called when the Kifu application starts. // This will be called when the Kifu application starts.
pub fn launch_screen_view() -> LaunchScreenView { pub fn launch_screen() -> LaunchScreenView {
LaunchScreenView {
home: home(vec![].into_iter()),
library: library_view(),
}
} }

View File

@ -1,10 +0,0 @@
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
#[typeshare]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LibraryView;
pub fn library_view() -> LibraryView {
LibraryView
}

View File

@ -4,11 +4,8 @@ pub use elements::{action::Action, game_preview::GamePreviewElement, menu::Menu}
mod playing_field; mod playing_field;
pub use playing_field::{playing_field, PlayingFieldView}; pub use playing_field::{playing_field, PlayingFieldView};
mod launch_screen; // mod launch_screen;
pub use launch_screen::{launch_screen_view, LaunchScreenView}; // pub use launch_screen::{launch_screen, LaunchScreenView};
mod library_view;
pub use library_view::{library_view, LibraryView};
mod home; mod home;
pub use home::{home, HomeView, HotseatPlayerElement, PlayerElement}; pub use home::{home, HomeView, HotseatPlayerElement, PlayerElement};

View File

@ -12,7 +12,7 @@ screenplay = []
cairo-rs = { version = "0.17" } cairo-rs = { version = "0.17" }
gio = { version = "0.17" } gio = { version = "0.17" }
glib = { version = "0.17" } glib = { version = "0.17" }
gtk = { version = "0.6", package = "gtk4", features = ["v4_8"] } gtk = { version = "0.6", package = "gtk4" }
image = { version = "0.24" } image = { version = "0.24" }
kifu-core = { path = "../core" } kifu-core = { path = "../core" }
tokio = { version = "1.26", features = [ "full" ] } tokio = { version = "1.26", features = [ "full" ] }

View File

@ -1,7 +1 @@
{ {"Me":{"name":"Savanni","rank":{"Kyu":10}},"DatabasePath":"../core/fixtures/five_games"}
"Me":{
"name":"Savanni",
"rank":{"Kyu":10}
},
"DatabasePath": "kifu/core/fixtures/five_games"
}

View File

@ -1,96 +0,0 @@
use glib::{Object, Properties};
use gtk::{glib, prelude::*, subclass::prelude::*};
use std::{cell::RefCell, rc::Rc};
#[derive(Default)]
pub struct IntegerObjectPrivate {
number: Rc<RefCell<i32>>,
}
#[glib::object_subclass]
impl ObjectSubclass for IntegerObjectPrivate {
const NAME: &'static str = "IntegerObject";
type Type = IntegerObject;
}
impl ObjectImpl for IntegerObjectPrivate {}
glib::wrapper! {
pub struct IntegerObject(ObjectSubclass<IntegerObjectPrivate>);
}
impl IntegerObject {
pub fn new(number: i32) -> Self {
let s: Self = Object::builder().build();
*s.imp().number.borrow_mut() = number;
s
}
pub fn number(&self) -> i32 {
self.imp().number.borrow().clone()
}
}
pub struct GameDatabasePrivate {
list_view: gtk::ListView,
}
impl Default for GameDatabasePrivate {
fn default() -> Self {
let vector: Vec<IntegerObject> = (0..=500).map(IntegerObject::new).collect();
let model = gio::ListStore::new(glib::types::Type::OBJECT);
model.extend_from_slice(&vector);
let factory = gtk::SignalListItemFactory::new();
factory.connect_setup(move |_, list_item| {
let label = gtk::Label::new(None);
list_item
.downcast_ref::<gtk::ListItem>()
.expect("Needs to be a ListItem")
.set_child(Some(&label));
});
factory.connect_bind(move |_, list_item| {
let integer_object = list_item
.downcast_ref::<gtk::ListItem>()
.expect("Needs to be ListItem")
.item()
.and_downcast::<IntegerObject>()
.expect("The item has to be an IntegerObject.");
let label = list_item
.downcast_ref::<gtk::ListItem>()
.expect("Needs to be ListItem")
.child()
.and_downcast::<gtk::Label>()
.expect("The child has to be an Label.");
label.set_label(&integer_object.number().to_string());
});
let selection_model = gtk::SingleSelection::new(Some(model));
let list_view = gtk::ListView::new(Some(selection_model), Some(factory));
Self { list_view }
}
}
#[glib::object_subclass]
impl ObjectSubclass for GameDatabasePrivate {
const NAME: &'static str = "GameDatabase";
type Type = GameDatabase;
type ParentType = gtk::Box;
}
impl ObjectImpl for GameDatabasePrivate {}
impl WidgetImpl for GameDatabasePrivate {}
impl BoxImpl for GameDatabasePrivate {}
glib::wrapper! {
pub struct GameDatabase(ObjectSubclass<GameDatabasePrivate>) @extends gtk::Widget, gtk::Box;
}
impl GameDatabase {
pub fn new() -> Self {
let s: Self = Object::builder().build();
s.append(&s.imp().list_view);
s
}
}

View File

@ -1,16 +1,12 @@
use crate::{ui::GamePreview, CoreApi}; use crate::ui::GamePreview;
use glib::{Object, Properties}; use crate::CoreApi;
use glib::Object;
use gtk::{glib, prelude::*, subclass::prelude::*}; use gtk::{glib, prelude::*, subclass::prelude::*};
use kifu_core::{ use kifu_core::{
ui::{GamePreviewElement, HomeView, PlayerElement}, ui::{HomeView, PlayerElement},
CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest, CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
}; };
use std::{ use std::{cell::RefCell, rc::Rc};
cell::{Cell, RefCell},
rc::Rc,
};
use super::GameDatabase;
struct PlayerDataEntryPrivate { struct PlayerDataEntryPrivate {
name: gtk::Text, name: gtk::Text,
@ -87,44 +83,6 @@ impl PlayerDataEntry {
} }
} }
pub struct DatabaseGamePrivate {
game: Rc<RefCell<GamePreviewElement>>,
}
impl Default for DatabaseGamePrivate {
fn default() -> Self {
Self {
game: Rc::new(RefCell::new(GamePreviewElement {
date: vec![],
black_player: "".to_owned(),
black_rank: None,
white_player: "".to_owned(),
white_rank: None,
})),
}
}
}
#[glib::object_subclass]
impl ObjectSubclass for DatabaseGamePrivate {
const NAME: &'static str = "DatabaseGame";
type Type = DatabaseGame;
}
impl ObjectImpl for DatabaseGamePrivate {}
glib::wrapper! {
pub struct DatabaseGame(ObjectSubclass<DatabaseGamePrivate>);
}
impl DatabaseGame {
pub fn new(preview: GamePreviewElement) -> Self {
let s: Self = Object::builder().build();
*s.imp().game.borrow_mut() = preview;
s
}
}
pub struct HomePrivate { pub struct HomePrivate {
black_player: Rc<RefCell<Option<PlayerDataEntry>>>, black_player: Rc<RefCell<Option<PlayerDataEntry>>>,
white_player: Rc<RefCell<Option<PlayerDataEntry>>>, white_player: Rc<RefCell<Option<PlayerDataEntry>>>,
@ -169,9 +127,6 @@ impl Home {
let new_game_button = gtk::Button::builder().label(&view.start_game.label).build(); let new_game_button = gtk::Button::builder().label(&view.start_game.label).build();
s.attach(&new_game_button, 2, 2, 1, 1); s.attach(&new_game_button, 2, 2, 1, 1);
let database = GameDatabase::new();
s.attach(&database, 0, 3, 2, 2);
new_game_button.connect_clicked({ new_game_button.connect_clicked({
move |_| { move |_| {
let black_player = black_player.clone(); let black_player = black_player.clone();
@ -184,6 +139,12 @@ impl Home {
} }
}); });
let game_list = gtk::Box::new(gtk::Orientation::Vertical, 0);
s.attach(&game_list, 1, 3, 2, 1);
view.games
.iter()
.for_each(|game_preview| game_list.append(&GamePreview::new(game_preview.clone())));
s s
} }
} }

View File

@ -1,9 +1,6 @@
mod chat; mod chat;
pub use chat::Chat; pub use chat::Chat;
mod game_database;
pub use game_database::GameDatabase;
mod game_preview; mod game_preview;
pub use game_preview::GamePreview; pub use game_preview::GamePreview;