Go back to creating a new game
This commit is contained in:
parent
d0db274110
commit
ebb7062041
|
@ -28,8 +28,8 @@ pub struct PlayStoneRequest {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub struct CreateGameRequest {
|
||||
black_player: PlayerInfoRequest,
|
||||
white_player: PlayerInfoRequest,
|
||||
pub black_player: PlayerInfoRequest,
|
||||
pub white_player: PlayerInfoRequest,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
|
@ -41,8 +41,8 @@ pub enum PlayerInfoRequest {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub struct HotseatPlayerRequest {
|
||||
name: Option<String>,
|
||||
rank: Option<Rank>,
|
||||
pub name: Option<String>,
|
||||
pub rank: Option<Rank>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
mod api;
|
||||
pub use api::{CoreApp, CoreRequest, CoreResponse};
|
||||
pub use api::{
|
||||
CoreApp, CoreRequest, CoreResponse, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
|
||||
};
|
||||
|
||||
mod types;
|
||||
pub use types::{BoardError, Color, Rank, Size};
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub struct Action<A> {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub action: A,
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub struct Menu<T: PartialEq + Eq> {
|
||||
current: Option<T>,
|
||||
options: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: PartialEq + Eq> Menu<T> {
|
||||
pub fn new(options: Vec<T>, current: Option<T>) -> Menu<T> {
|
||||
if let Some(ref current) = current {
|
||||
assert!(options.contains(current));
|
||||
}
|
||||
Menu { current, options }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
pub mod action;
|
||||
pub mod menu;
|
|
@ -1,3 +1,6 @@
|
|||
mod elements;
|
||||
pub use elements::{action::Action, menu::Menu};
|
||||
|
||||
mod playing_field;
|
||||
pub use playing_field::{playing_field, PlayingFieldView};
|
||||
|
||||
|
@ -5,7 +8,7 @@ pub use playing_field::{playing_field, PlayingFieldView};
|
|||
// pub use launch_screen::{launch_screen, LaunchScreenView};
|
||||
|
||||
mod new_game;
|
||||
pub use new_game::{new_game, HotseatPlayerElement, Menu, NewGameView, PlayerElement};
|
||||
pub use new_game::{new_game, HotseatPlayerElement, NewGameView, PlayerElement};
|
||||
|
||||
mod types;
|
||||
pub use types::{
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::ui::Action;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
|
||||
|
@ -15,22 +16,6 @@ fn rank_strings() -> Vec<String> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub struct Menu<T: PartialEq + Eq> {
|
||||
current: Option<T>,
|
||||
options: Vec<T>,
|
||||
}
|
||||
|
||||
impl<T: PartialEq + Eq> Menu<T> {
|
||||
pub fn new(options: Vec<T>, current: Option<T>) -> Menu<T> {
|
||||
if let Some(ref current) = current {
|
||||
assert!(options.contains(current));
|
||||
}
|
||||
Menu { current, options }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[typeshare]
|
||||
pub enum PlayerElement {
|
||||
|
@ -66,6 +51,7 @@ pub struct BotPlayerElement {}
|
|||
pub struct NewGameView {
|
||||
pub black_player: PlayerElement,
|
||||
pub white_player: PlayerElement,
|
||||
pub start_game: Action<()>,
|
||||
}
|
||||
|
||||
pub fn new_game() -> NewGameView {
|
||||
|
@ -82,5 +68,10 @@ pub fn new_game() -> NewGameView {
|
|||
NewGameView {
|
||||
black_player,
|
||||
white_player,
|
||||
start_game: Action {
|
||||
id: "start-game-action".to_owned(),
|
||||
label: "New Game".to_owned(),
|
||||
action: (),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::CoreApi;
|
||||
use glib::{subclass, Object, ParamSpec, Properties, Value};
|
||||
use gtk::{glib, prelude::*, subclass::prelude::*};
|
||||
use kifu_core::ui::{NewGameView, PlayerElement};
|
||||
use kifu_core::{
|
||||
ui::{NewGameView, PlayerElement},
|
||||
CoreRequest, CreateGameRequest, HotseatPlayerRequest, PlayerInfoRequest,
|
||||
};
|
||||
use std::{cell::Cell, cell::RefCell, rc::Rc};
|
||||
|
||||
struct PlayerDataEntryPrivate {
|
||||
|
@ -100,15 +103,21 @@ impl NewGame {
|
|||
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();
|
||||
let new_game_button = gtk::Button::builder().label(&view.start_game.label).build();
|
||||
s.attach(&new_game_button, 2, 2, 1, 1);
|
||||
|
||||
/*
|
||||
new_game_button.connect_clicked(move |_| {
|
||||
api.dispatch(CoreRequest::CreatGameRequest(CreateGameRequest {
|
||||
api.dispatch(CoreRequest::CreateGame(CreateGameRequest {
|
||||
black_player: PlayerInfoRequest::Hotseat(HotseatPlayerRequest {
|
||||
name: None,
|
||||
rank: None,
|
||||
}),
|
||||
white_player: PlayerInfoRequest::Hotseat(HotseatPlayerRequest {
|
||||
name: None,
|
||||
rank: None,
|
||||
}),
|
||||
}));
|
||||
});
|
||||
*/
|
||||
|
||||
s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue