2023-05-26 04:16:40 +00:00
|
|
|
use crate::CoreApi;
|
2023-06-15 03:49:03 +00:00
|
|
|
use glib::{subclass, Object, ParamSpec, Properties, Value};
|
|
|
|
use gtk::{glib, prelude::*, subclass::prelude::*};
|
|
|
|
use kifu_core::ui::{NewGameView, PlayerElement};
|
|
|
|
use std::{cell::Cell, cell::RefCell, rc::Rc};
|
|
|
|
|
|
|
|
struct PlayerDataEntryPrivate {
|
|
|
|
placeholder: gtk::Text,
|
|
|
|
rank: gtk::DropDown,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PlayerDataEntryPrivate {
|
|
|
|
fn default() -> Self {
|
|
|
|
let rank = gtk::DropDown::builder().build();
|
|
|
|
Self {
|
|
|
|
placeholder: gtk::Text::builder().build(),
|
|
|
|
rank,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for PlayerDataEntryPrivate {
|
|
|
|
const NAME: &'static str = "PlayerDataEntry";
|
|
|
|
type Type = PlayerDataEntry;
|
|
|
|
type ParentType = gtk::Box;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for PlayerDataEntryPrivate {}
|
|
|
|
impl WidgetImpl for PlayerDataEntryPrivate {}
|
|
|
|
impl BoxImpl for PlayerDataEntryPrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
struct PlayerDataEntry(ObjectSubclass<PlayerDataEntryPrivate>) @extends gtk::Box, gtk::Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PlayerDataEntry {
|
|
|
|
pub fn new(element: PlayerElement) -> PlayerDataEntry {
|
|
|
|
let s: Self = Object::builder().build();
|
|
|
|
|
|
|
|
let rank_model = gio::ListStore::new(gtk::StringObject::static_type());
|
|
|
|
s.imp().rank.set_model(Some(&rank_model));
|
|
|
|
|
|
|
|
match element {
|
|
|
|
PlayerElement::Hotseat(player) => {
|
|
|
|
if let Some(placeholder) = player.placeholder {
|
|
|
|
s.imp().placeholder.set_placeholder_text(Some(&placeholder));
|
|
|
|
}
|
|
|
|
player.ranks.iter().for_each(|rank| rank_model.append(>k::StringObject::new(rank)));
|
|
|
|
}
|
|
|
|
// PlayerElement::Remote(_) => s.imp().placeholder.set_text("remote player"),
|
|
|
|
// PlayerElement::Bot(_) => s.imp().placeholder.set_text("bot player"),
|
|
|
|
}
|
|
|
|
|
|
|
|
s.append(&s.imp().placeholder);
|
|
|
|
s.append(&s.imp().rank);
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 04:16:40 +00:00
|
|
|
|
|
|
|
pub struct NewGamePrivate {
|
2023-06-15 03:49:03 +00:00
|
|
|
black_player: Rc<RefCell<Option<PlayerDataEntry>>>,
|
|
|
|
white_player: Rc<RefCell<Option<PlayerDataEntry>>>,
|
2023-05-26 04:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for NewGamePrivate {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2023-06-15 03:49:03 +00:00
|
|
|
black_player: Rc::new(RefCell::new(None)),
|
|
|
|
white_player: Rc::new(RefCell::new(None)),
|
2023-05-26 04:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for NewGamePrivate {
|
|
|
|
const NAME: &'static str = "NewGame";
|
|
|
|
type Type = NewGame;
|
|
|
|
type ParentType = gtk::Grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for NewGamePrivate {}
|
|
|
|
impl WidgetImpl for NewGamePrivate {}
|
|
|
|
impl GridImpl for NewGamePrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
pub struct NewGame(ObjectSubclass<NewGamePrivate>) @extends gtk::Grid, gtk::Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NewGame {
|
2023-06-15 03:49:03 +00:00
|
|
|
pub fn new(api: CoreApi, view: NewGameView) -> NewGame {
|
2023-05-26 04:16:40 +00:00
|
|
|
let s: Self = Object::builder().build();
|
|
|
|
|
2023-06-15 03:49:03 +00:00
|
|
|
let black_player = PlayerDataEntry::new(view.black_player);
|
|
|
|
s.attach(&black_player, 1, 1, 1, 1);
|
|
|
|
*s.imp().black_player.borrow_mut() = Some(black_player);
|
2023-05-26 04:16:40 +00:00
|
|
|
|
2023-06-15 03:49:03 +00:00
|
|
|
let white_player = PlayerDataEntry::new(view.white_player);
|
|
|
|
s.attach(&white_player, 2, 1, 1, 1);
|
|
|
|
*s.imp().white_player.borrow_mut() = Some(white_player);
|
|
|
|
|
|
|
|
let new_game_button = gtk::Button::builder().label("Start Game").build();
|
|
|
|
s.attach(&new_game_button, 2, 2, 1, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
new_game_button.connect_clicked(move |_| {
|
|
|
|
api.dispatch(CoreRequest::CreatGameRequest(CreateGameRequest {
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
*/
|
2023-05-26 04:16:40 +00:00
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|