Place a stone onto the drawing area #38
|
@ -1,5 +1,3 @@
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
pub use api::{CoreApp, Request, Response};
|
pub use api::{CoreApp, Request, Response};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::types::{Color, Size};
|
use crate::types::Color;
|
||||||
use crate::{types::GameState, ui::types};
|
use crate::{types::GameState, ui::types};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
use gio::resources_lookup_data;
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use kifu_core::{CoreApp, Request, Response};
|
use kifu_core::{CoreApp, Request, Response};
|
||||||
use kifu_gtk::{ui::PlayingField, CoreApi};
|
use kifu_gtk::{ui::PlayingField, CoreApi};
|
||||||
use std::{
|
use std::sync::{Arc, RwLock};
|
||||||
sync::{Arc, Mutex, RwLock},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
use tokio::{
|
|
||||||
runtime::Runtime,
|
|
||||||
sync::mpsc::{Receiver, Sender},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource")
|
gio::resources_register_include!("com.luminescent-dreams.kifu-gtk.gresource")
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct BoardPrivate {
|
||||||
|
|
||||||
current_player: Rc<RefCell<Color>>,
|
current_player: Rc<RefCell<Color>>,
|
||||||
board: Rc<RefCell<BoardElement>>,
|
board: Rc<RefCell<BoardElement>>,
|
||||||
cursor_location: Rc<RefCell<Addr>>,
|
cursor_location: Rc<RefCell<Option<Addr>>>,
|
||||||
|
|
||||||
api: Rc<RefCell<Option<CoreApi>>>,
|
api: Rc<RefCell<Option<CoreApi>>>,
|
||||||
}
|
}
|
||||||
|
@ -135,14 +135,17 @@ impl ObjectImpl for BoardPrivate {
|
||||||
});
|
});
|
||||||
|
|
||||||
let cursor = cursor_location.borrow();
|
let cursor = cursor_location.borrow();
|
||||||
match board.stone(cursor.row, cursor.column) {
|
match *cursor {
|
||||||
IntersectionElement::Empty(_) => pen.ghost_stone(
|
None => {}
|
||||||
context,
|
Some(ref cursor) => match board.stone(cursor.row, cursor.column) {
|
||||||
cursor.row,
|
IntersectionElement::Empty(_) => pen.ghost_stone(
|
||||||
cursor.column,
|
context,
|
||||||
*current_player.borrow(),
|
cursor.row,
|
||||||
),
|
cursor.column,
|
||||||
_ => {}
|
*current_player.borrow(),
|
||||||
|
),
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
let render_end = std::time::Instant::now();
|
let render_end = std::time::Instant::now();
|
||||||
println!("board rendering time: {:?}", render_end - render_start);
|
println!("board rendering time: {:?}", render_end - render_start);
|
||||||
|
@ -159,12 +162,17 @@ impl ObjectImpl for BoardPrivate {
|
||||||
let hspace_between = ((WIDTH - 40) as f64) / ((board.size.width - 1) as f64);
|
let hspace_between = ((WIDTH - 40) as f64) / ((board.size.width - 1) as f64);
|
||||||
let vspace_between = ((HEIGHT - 40) as f64) / ((board.size.height - 1) as f64);
|
let vspace_between = ((HEIGHT - 40) as f64) / ((board.size.height - 1) as f64);
|
||||||
|
|
||||||
let addr = Addr {
|
let addr =
|
||||||
column: ((x.round() - 20.) / hspace_between).round() as u8,
|
if x.round() < 20. || x.round() > 780. || y.round() < 20. || y.round() > 780. {
|
||||||
row: ((y.round() - 20.) / vspace_between).round() as u8,
|
None
|
||||||
};
|
} else {
|
||||||
|
Some(Addr {
|
||||||
|
column: ((x.round() - 20.) / hspace_between).round() as u8,
|
||||||
|
row: ((y.round() - 20.) / vspace_between).round() as u8,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
if *cursor != addr {
|
if *cursor != addr.clone() {
|
||||||
*cursor = addr;
|
*cursor = addr;
|
||||||
drawing_area.queue_draw();
|
drawing_area.queue_draw();
|
||||||
}
|
}
|
||||||
|
@ -179,15 +187,18 @@ impl ObjectImpl for BoardPrivate {
|
||||||
gesture.connect_released(move |_, _, _, _| {
|
gesture.connect_released(move |_, _, _, _| {
|
||||||
let board = board.borrow();
|
let board = board.borrow();
|
||||||
let cursor = cursor.borrow();
|
let cursor = cursor.borrow();
|
||||||
match board.stone(cursor.row, cursor.column) {
|
match *cursor {
|
||||||
IntersectionElement::Empty(request) => {
|
None => {}
|
||||||
println!("need to send request: {:?}", request);
|
Some(ref cursor) => match board.stone(cursor.row, cursor.column) {
|
||||||
api.borrow()
|
IntersectionElement::Empty(request) => {
|
||||||
.as_ref()
|
println!("need to send request: {:?}", request);
|
||||||
.expect("API must exist")
|
api.borrow()
|
||||||
.dispatch(request);
|
.as_ref()
|
||||||
}
|
.expect("API must exist")
|
||||||
_ => {}
|
.dispatch(request);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use kifu_core::{ui::PlayerCardElement, Color};
|
use kifu_core::ui::PlayerCardElement;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PlayerCardPrivate {
|
pub struct PlayerCardPrivate {
|
||||||
|
|
|
@ -2,27 +2,9 @@ use crate::ui::{Board, Chat, PlayerCard};
|
||||||
use crate::CoreApi;
|
use crate::CoreApi;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use kifu_core::{
|
use kifu_core::ui::PlayingFieldView;
|
||||||
ui::{
|
|
||||||
BoardElement, ChatElement, IntersectionElement, PlayerCardElement, PlayingFieldView,
|
|
||||||
StoneElement, TextFieldElement,
|
|
||||||
},
|
|
||||||
Color, Size,
|
|
||||||
};
|
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
/*
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct PlayingFieldView {
|
|
||||||
pub board: types::GobanElement,
|
|
||||||
pub player_card_black: types::PlayerCardElement,
|
|
||||||
pub player_card_white: types::PlayerCardElement,
|
|
||||||
pub chat: types::ChatElement,
|
|
||||||
pub message: types::TextFieldElement,
|
|
||||||
pub current_player: Color,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct PlayingFieldPrivate {
|
pub struct PlayingFieldPrivate {
|
||||||
board: Rc<RefCell<Option<Board>>>,
|
board: Rc<RefCell<Option<Board>>>,
|
||||||
player_card_white: Rc<RefCell<Option<PlayerCard>>>,
|
player_card_white: Rc<RefCell<Option<PlayerCard>>>,
|
||||||
|
|
Loading…
Reference in New Issue