Skip to main content

traaains/editor/
viewing.rs

1use bevy::{
2    app::{Plugin, Update},
3    ecs::{
4        query::With,
5        schedule::IntoScheduleConfigs,
6        system::{Res, ResMut, Single},
7    },
8    input::{ButtonInput, keyboard::KeyCode},
9    state::{
10        condition::in_state,
11        state::{NextState, OnEnter},
12    },
13    ui::widget::Text,
14};
15
16use crate::editor::{EditorState, StateText};
17
18pub fn on_enter_viewing(mut text: Single<&mut Text, With<StateText>>) {
19    text.0 = "Viewing\n[0] Edit tracks".to_string();
20}
21
22pub fn input_handler(
23    input: Res<ButtonInput<KeyCode>>,
24    mut next_editor_state: ResMut<NextState<EditorState>>,
25) {
26    if input.just_pressed(KeyCode::Digit0) {
27        next_editor_state.set(EditorState::Track);
28    }
29}
30
31pub struct ViewingEditorPlugin;
32
33impl Plugin for ViewingEditorPlugin {
34    fn build(&self, app: &mut bevy::app::App) {
35        app.add_systems(OnEnter(EditorState::Viewing), on_enter_viewing)
36            .add_systems(Update, input_handler.run_if(in_state(EditorState::Viewing)));
37    }
38}