Do some cleanups and allow the cursor to move off the board
This commit is contained in:
parent
59a8f252da
commit
26db170c79
|
@ -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,7 +135,9 @@ impl ObjectImpl for BoardPrivate {
|
||||||
});
|
});
|
||||||
|
|
||||||
let cursor = cursor_location.borrow();
|
let cursor = cursor_location.borrow();
|
||||||
match board.stone(cursor.row, cursor.column) {
|
match *cursor {
|
||||||
|
None => {}
|
||||||
|
Some(ref cursor) => match board.stone(cursor.row, cursor.column) {
|
||||||
IntersectionElement::Empty(_) => pen.ghost_stone(
|
IntersectionElement::Empty(_) => pen.ghost_stone(
|
||||||
context,
|
context,
|
||||||
cursor.row,
|
cursor.row,
|
||||||
|
@ -143,6 +145,7 @@ impl ObjectImpl for BoardPrivate {
|
||||||
*current_player.borrow(),
|
*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 =
|
||||||
|
if x.round() < 20. || x.round() > 780. || y.round() < 20. || y.round() > 780. {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Addr {
|
||||||
column: ((x.round() - 20.) / hspace_between).round() as u8,
|
column: ((x.round() - 20.) / hspace_between).round() as u8,
|
||||||
row: ((y.round() - 20.) / vspace_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,7 +187,9 @@ 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 {
|
||||||
|
None => {}
|
||||||
|
Some(ref cursor) => match board.stone(cursor.row, cursor.column) {
|
||||||
IntersectionElement::Empty(request) => {
|
IntersectionElement::Empty(request) => {
|
||||||
println!("need to send request: {:?}", request);
|
println!("need to send request: {:?}", request);
|
||||||
api.borrow()
|
api.borrow()
|
||||||
|
@ -188,6 +198,7 @@ impl ObjectImpl for BoardPrivate {
|
||||||
.dispatch(request);
|
.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