Write an initial Playing Field

This commit is contained in:
Savanni D'Gerinel 2023-03-24 09:59:04 -04:00
parent ea02e614dd
commit b8493b7fe7
9 changed files with 143 additions and 24 deletions

View File

@ -1,11 +1,6 @@
use crate::types::AppState;
use crate::ui::playing_field::{playing_field, PlayingFieldView};
use std::{
sync::{Arc, RwLock},
thread,
time::Duration,
};
use tokio::sync::mpsc::{channel, Receiver, Sender};
use crate::ui::{playing_field, PlayingFieldView};
use std::sync::{Arc, RwLock};
pub enum Request {
PlayingField,

View File

@ -4,5 +4,5 @@ mod api;
pub use api::{CoreApp, Request, Response};
mod types;
pub use types::Color;
pub use types::{Color, Size};
pub mod ui;

View File

@ -6,6 +6,12 @@ pub enum Color {
White,
}
#[derive(Clone, Debug)]
pub struct Size {
pub width: u8,
pub height: u8,
}
pub(crate) struct AppState {
game: Option<GameState>,
}

View File

@ -1,4 +1,5 @@
pub mod playing_field;
mod playing_field;
pub use playing_field::{playing_field, PlayingFieldView};
mod types;
pub use types::{ChatElement, PlayerCardElement};
pub use types::{ChatElement, GameBoardElement, PlayerCardElement, TextFieldElement};

View File

@ -1,4 +1,4 @@
use crate::types::Color;
use crate::types::{Color, Size};
use crate::ui::types;
#[derive(Clone, Debug)]
@ -16,7 +16,7 @@ pub fn playing_field() -> PlayingFieldView {
(0..19).for_each(|_| spaces.push(Vec::new()));
let board = types::GameBoardElement {
size: types::Size {
size: Size {
width: 19,
height: 19,
},

View File

@ -1,4 +1,4 @@
use crate::types::Color;
use crate::types::{Color, Size};
#[derive(Clone, Debug)]
pub struct Jitter {
@ -6,12 +6,6 @@ pub struct Jitter {
pub y: i8,
}
#[derive(Clone, Debug)]
pub struct Size {
pub width: u8,
pub height: u8,
}
#[derive(Clone, Debug)]
pub struct StoneElement {
pub color: Color,

View File

@ -1,9 +1,10 @@
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use kifu_core::{ui::ChatElement, ui::PlayerCardElement, Color};
use kifu_gtk::ui::{Chat, PlayerCard};
use kifu_core::{
ui::{ChatElement, PlayerCardElement, PlayingFieldView},
Color,
};
use kifu_gtk::ui::{playing_field, Chat, PlayerCard, PlayingField};
use screenplay::{Screen, Screenplay};
use std::{cell::RefCell, rc::Rc};
fn main() {
let app = gtk::Application::builder()
@ -35,8 +36,13 @@ fn main() {
.upcast::<gtk::Widget>(),
adjustments: vec![],
},
Screen {
title: "PlayingField".to_owned(),
widget: PlayingField::new(playing_field()).upcast::<gtk::Widget>(),
adjustments: vec![],
},
];
let screenplay = Screenplay::new(&app, screens).unwrap();
Screenplay::new(&app, screens).unwrap();
});
app.run();

View File

@ -3,3 +3,6 @@ pub use player_card::PlayerCard;
mod chat;
pub use chat::Chat;
mod playing_field;
pub use playing_field::{playing_field, PlayingField};

View File

@ -0,0 +1,114 @@
use crate::ui::{Chat, PlayerCard};
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();
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);
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,
}
}