2023-03-24 14:14:01 +00:00
|
|
|
use crate::ui::{Chat, Goban, PlayerCard};
|
2023-03-24 13:59:04 +00:00
|
|
|
use glib::Object;
|
|
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
|
|
|
use kifu_core::{
|
|
|
|
ui::{ChatElement, GameBoardElement, PlayerCardElement, PlayingFieldView, TextFieldElement},
|
|
|
|
Color, Size,
|
|
|
|
};
|
|
|
|
use std::{cell::RefCell, rc::Rc};
|
|
|
|
|
|
|
|
/*
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct PlayingFieldView {
|
|
|
|
pub board: types::GameBoardElement,
|
|
|
|
pub player_card_black: types::PlayerCardElement,
|
|
|
|
pub player_card_white: types::PlayerCardElement,
|
|
|
|
pub chat: types::ChatElement,
|
|
|
|
pub message: types::TextFieldElement,
|
|
|
|
pub current_player: Color,
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct PlayingFieldPrivate {
|
|
|
|
player_card_white: Rc<RefCell<Option<PlayerCard>>>,
|
|
|
|
player_card_black: Rc<RefCell<Option<PlayerCard>>>,
|
|
|
|
chat: Rc<RefCell<Option<Chat>>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for PlayingFieldPrivate {
|
|
|
|
const NAME: &'static str = "PlayingField";
|
|
|
|
type Type = PlayingField;
|
|
|
|
type ParentType = gtk::Grid;
|
|
|
|
|
|
|
|
fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
player_card_white: Rc::new(RefCell::new(None)),
|
|
|
|
player_card_black: Rc::new(RefCell::new(None)),
|
|
|
|
chat: Rc::new(RefCell::new(None)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for PlayingFieldPrivate {}
|
|
|
|
impl WidgetImpl for PlayingFieldPrivate {}
|
|
|
|
impl GridImpl for PlayingFieldPrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
pub struct PlayingField(ObjectSubclass<PlayingFieldPrivate>) @extends gtk::Grid, gtk::Widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PlayingField {
|
|
|
|
pub fn new(view: PlayingFieldView) -> PlayingField {
|
|
|
|
let s: Self = Object::builder().build();
|
|
|
|
|
2023-03-24 14:14:01 +00:00
|
|
|
let goban = Goban::new();
|
2023-03-24 13:59:04 +00:00
|
|
|
let player_card_white = PlayerCard::new(view.player_card_white);
|
|
|
|
let player_card_black = PlayerCard::new(view.player_card_black);
|
|
|
|
let chat = Chat::new(view.chat);
|
|
|
|
|
2023-03-24 14:14:01 +00:00
|
|
|
s.attach(&goban, 1, 1, 1, 2);
|
2023-03-24 13:59:04 +00:00
|
|
|
s.attach(&player_card_black, 2, 1, 1, 1);
|
|
|
|
s.attach(&player_card_white, 3, 1, 1, 1);
|
|
|
|
s.attach(&chat, 2, 2, 2, 1);
|
|
|
|
|
|
|
|
*s.imp().player_card_white.borrow_mut() = Some(player_card_white);
|
|
|
|
*s.imp().player_card_black.borrow_mut() = Some(player_card_black);
|
|
|
|
*s.imp().chat.borrow_mut() = Some(chat);
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn playing_field() -> PlayingFieldView {
|
|
|
|
let mut spaces = Vec::new();
|
|
|
|
(0..19).for_each(|_| spaces.push(Vec::new()));
|
|
|
|
|
|
|
|
let board = GameBoardElement {
|
|
|
|
size: Size {
|
|
|
|
width: 19,
|
|
|
|
height: 19,
|
|
|
|
},
|
|
|
|
spaces,
|
|
|
|
};
|
|
|
|
|
|
|
|
let player_card_black = PlayerCardElement {
|
|
|
|
color: Color::Black,
|
|
|
|
name: "Savanni".to_owned(),
|
|
|
|
rank: "10k".to_owned(),
|
|
|
|
clock: "24:53".to_owned(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let player_card_white = PlayerCardElement {
|
|
|
|
color: Color::White,
|
|
|
|
name: "Opal".to_owned(),
|
|
|
|
rank: "10k".to_owned(),
|
|
|
|
clock: "25:00".to_owned(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let chat = ChatElement {
|
|
|
|
messages: vec![
|
|
|
|
"[22:05] Savanni: oops".to_owned(),
|
|
|
|
"[22:06] Opal: you know I'll take advantage of that, right?".to_owned(),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
let message = TextFieldElement {};
|
|
|
|
|
|
|
|
PlayingFieldView {
|
|
|
|
board,
|
|
|
|
player_card_black,
|
|
|
|
player_card_white,
|
|
|
|
chat,
|
|
|
|
message,
|
|
|
|
current_player: Color::White,
|
|
|
|
}
|
|
|
|
}
|