basic main menu (change this to generic overlay menu later?)
This commit is contained in:
parent
bc3421a371
commit
759ff410c2
6 changed files with 88 additions and 46 deletions
|
|
@ -6,10 +6,9 @@ use crate::tiles::{self, *};
|
||||||
pub mod player;
|
pub mod player;
|
||||||
pub mod wall;
|
pub mod wall;
|
||||||
|
|
||||||
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq)]
|
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq, Copy)]
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
|
||||||
Setup,
|
Setup,
|
||||||
// Deal,
|
// Deal,
|
||||||
Play,
|
Play,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
use bevy::input::keyboard::Key;
|
use bevy::input::keyboard::Key;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_ratatui::RatatuiContext;
|
use bevy_ratatui::RatatuiContext;
|
||||||
|
use bevy_ratatui::event::KeyMessage;
|
||||||
|
use ratatui::crossterm::event::KeyCode;
|
||||||
use ratatui::widgets::Block;
|
use ratatui::widgets::Block;
|
||||||
use tui_logger::TuiLoggerWidget;
|
use tui_logger::TuiLoggerWidget;
|
||||||
|
|
||||||
|
|
@ -23,12 +25,18 @@ impl std::ops::Not for ConsoleState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn toggle_console(
|
pub(crate) fn toggle_console(
|
||||||
input: Res<ButtonInput<Key>>,
|
// input: Res<ButtonInput<Key>>,
|
||||||
|
mut messages: MessageReader<KeyMessage>,
|
||||||
curr_state: Res<State<ConsoleState>>,
|
curr_state: Res<State<ConsoleState>>,
|
||||||
mut next_state: ResMut<NextState<ConsoleState>>,
|
mut next_state: ResMut<NextState<ConsoleState>>,
|
||||||
) {
|
) {
|
||||||
if input.just_pressed(Key::Character("`".into())) {
|
// if input.just_pressed(Key::Character("`".into())) {
|
||||||
next_state.set(!*curr_state.get());
|
// next_state.set(!*curr_state.get());
|
||||||
|
// }
|
||||||
|
for message in messages.read() {
|
||||||
|
if let KeyCode::Char('`') = message.code {
|
||||||
|
next_state.set(!*curr_state.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
// use bevy::ecs::message::MessageReader;
|
|
||||||
use bevy::app::AppExit;
|
|
||||||
use bevy::input::keyboard::{Key, KeyboardInput};
|
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
use crate::tui::console::ConsoleState;
|
|
||||||
|
|
||||||
pub(crate) fn keyboard_input_system(
|
|
||||||
// keycode_input: Option<Res<ButtonInput<KeyCode>>>,
|
|
||||||
// key_input: Option<Res<ButtonInput<Key>>>,
|
|
||||||
// mut next_state: ResMut<State<TuiState>>,
|
|
||||||
mut keyboard_events: MessageReader<KeyboardInput>,
|
|
||||||
) {
|
|
||||||
// if let Some(keycode_input) = keycode_input {
|
|
||||||
// if keycode_input.just_pressed(KeyCode::Backquote) {
|
|
||||||
// // console_state.set;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
for keyboard_input in keyboard_events.read() {
|
|
||||||
trace!("{:?}", keyboard_input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
50
src/tui/menu.rs
Normal file
50
src/tui/menu.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use bevy_ratatui::RatatuiContext;
|
||||||
|
use bevy_ratatui::event::KeyMessage;
|
||||||
|
use ratatui::crossterm::event::KeyCode;
|
||||||
|
use ratatui::layout::Constraint;
|
||||||
|
use ratatui::layout::Layout;
|
||||||
|
|
||||||
|
use jong::game::GameState;
|
||||||
|
|
||||||
|
use crate::tui::TuiState;
|
||||||
|
|
||||||
|
const MAINMENU_OPTIONS: [&str; 2] = ["(p)lay", "(q)uit"];
|
||||||
|
// const MAINMENU_INPUTS: [char;2] = ['p', 'q'];
|
||||||
|
|
||||||
|
pub(crate) fn draw_mainmenu(
|
||||||
|
mut tui_ctx: ResMut<RatatuiContext>,
|
||||||
|
// mut tui_state: ResMut<NextState<TuiState>>,
|
||||||
|
// mut game_state: ResMut<NextState<GameState>>,
|
||||||
|
) {
|
||||||
|
let options = MAINMENU_OPTIONS;
|
||||||
|
let layout = Layout::vertical(vec![Constraint::Min(1); options.len()]);
|
||||||
|
|
||||||
|
tui_ctx.draw(|frame| {
|
||||||
|
let areas = layout.split(frame.area());
|
||||||
|
for (opt, area) in options.into_iter().zip(areas.iter()) {
|
||||||
|
frame.render_widget(opt, *area)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn mainmenu_input(
|
||||||
|
// input: Res<ButtonInput<Key>>,
|
||||||
|
mut messages: MessageReader<KeyMessage>,
|
||||||
|
mut next_tuistate: ResMut<NextState<(TuiState)>>,
|
||||||
|
mut next_gamestate: ResMut<NextState<(GameState)>>,
|
||||||
|
mut exit: MessageWriter<AppExit>,
|
||||||
|
) {
|
||||||
|
for message in messages.read() {
|
||||||
|
match message.code {
|
||||||
|
KeyCode::Char('p') => {
|
||||||
|
next_tuistate.set(TuiState::InGame);
|
||||||
|
next_gamestate.set(GameState::default());
|
||||||
|
}
|
||||||
|
KeyCode::Char('q') => {
|
||||||
|
exit.write_default();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ use jong::game::GameState;
|
||||||
use jong::game::wall::InWall;
|
use jong::game::wall::InWall;
|
||||||
|
|
||||||
mod console;
|
mod console;
|
||||||
mod input;
|
mod menu;
|
||||||
mod render;
|
mod render;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
||||||
|
|
@ -31,27 +31,39 @@ impl Plugin for RiichiTui {
|
||||||
))),
|
))),
|
||||||
RatatuiPlugins {
|
RatatuiPlugins {
|
||||||
// enable_kitty_protocol: todo!(),
|
// enable_kitty_protocol: todo!(),
|
||||||
// enable_mouse_capture: todo!(),
|
enable_mouse_capture: true,
|
||||||
enable_input_forwarding: true,
|
// enable_input_forwarding: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
.add_plugins(StatesPlugin)
|
.add_plugins(StatesPlugin)
|
||||||
|
|
||||||
// setup console
|
// setup console
|
||||||
.init_state::<console::ConsoleState>()
|
.init_state::<console::ConsoleState>()
|
||||||
.add_systems(Update, console::toggle_console)
|
.add_systems(Update, console::toggle_console)
|
||||||
.add_systems(Update, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
|
.add_systems(Update, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
|
||||||
|
// other setup
|
||||||
.init_state::<TuiState>()
|
.init_state::<TuiState>()
|
||||||
.add_systems(Update, render::draw_mainmenu.run_if(in_state(TuiState::MainMenu)))
|
.add_computed_state::<InGame>()
|
||||||
// .add_systems(Update, input::keyboard_input_system)
|
// main menu
|
||||||
// .add_systems()
|
.add_systems(Update, (menu::draw_mainmenu,menu::mainmenu_input).run_if(in_state(TuiState::MainMenu)))
|
||||||
|
// gaming
|
||||||
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(TuiState::InGame)))
|
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(TuiState::InGame)))
|
||||||
.add_systems(Update, render::hand::render_changed_hand.run_if(in_state(GameState::Play)))
|
.add_systems(Update, render::hand::render_changed_hand.run_if(in_state(InGame).and(in_state(GameState::Play))))
|
||||||
// semicolon stopper
|
// semicolon stopper
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn prompt_names() {}
|
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
|
struct InGame;
|
||||||
|
|
||||||
|
impl ComputedStates for InGame {
|
||||||
|
type SourceStates = TuiState;
|
||||||
|
|
||||||
|
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||||
|
match sources {
|
||||||
|
TuiState::MainMenu => None,
|
||||||
|
TuiState::InGame => Some(Self),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
use bevy::ecs::system::SystemParam;
|
use bevy::ecs::system::SystemParam;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_ratatui::RatatuiContext;
|
use bevy_ratatui::RatatuiContext;
|
||||||
use ratatui::widgets::Paragraph;
|
use ratatui::{
|
||||||
|
layout::{},
|
||||||
|
widgets::Paragraph,
|
||||||
|
};
|
||||||
|
|
||||||
use jong::{
|
use jong::{
|
||||||
game::{
|
game::{
|
||||||
GameState,
|
|
||||||
player::Hand,
|
player::Hand,
|
||||||
wall::{Wall, WallTiles},
|
wall::{Wall, WallTiles},
|
||||||
},
|
},
|
||||||
|
|
@ -18,10 +20,3 @@ pub(crate) mod hand;
|
||||||
pub(crate) mod ingame;
|
pub(crate) mod ingame;
|
||||||
mod tiles;
|
mod tiles;
|
||||||
|
|
||||||
pub(crate) fn draw_mainmenu(
|
|
||||||
mut tui_ctx: ResMut<RatatuiContext>,
|
|
||||||
mut tui_state: ResMut<NextState<TuiState>>,
|
|
||||||
mut game_state: ResMut<NextState<GameState>>,
|
|
||||||
) {
|
|
||||||
tui_ctx.draw(|frame| {});
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue