fix: InputValue handling
This commit is contained in:
@@ -10,8 +10,9 @@ use bevy_controls::{
|
|||||||
contract::InputsContainer,
|
contract::InputsContainer,
|
||||||
plugin::ControlsPlugin,
|
plugin::ControlsPlugin,
|
||||||
resource::{
|
resource::{
|
||||||
ActivationMode, ActivationOptions, Binding, BindingCondition, BindingConfig, Bindings,
|
ActivationMode, ActivationOptions, AxisName, Binding, BindingCondition, BindingConfig,
|
||||||
ButtonCombination, Controls, InputType, InputValue, OptionsMode, PlayerActions,
|
Bindings, ButtonCombination, Controls, InputType, InputValue, MouseInput, OptionsMode,
|
||||||
|
PlayerActions,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use bevy_controls_derive::{Action, GameState};
|
use bevy_controls_derive::{Action, GameState};
|
||||||
@@ -25,6 +26,8 @@ enum MyAction {
|
|||||||
Right,
|
Right,
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
|
MouseHorizontal,
|
||||||
|
MouseVertical,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(States, PartialEq, Eq, Clone, Hash, Debug, Default, GameState)]
|
#[derive(States, PartialEq, Eq, Clone, Hash, Debug, Default, GameState)]
|
||||||
@@ -109,6 +112,18 @@ fn main() {
|
|||||||
MyAction::Up,
|
MyAction::Up,
|
||||||
BindingConfig::from_bind(Binding::from_single(InputType::Keyboard(KeyCode::Space))),
|
BindingConfig::from_bind(Binding::from_single(InputType::Keyboard(KeyCode::Space))),
|
||||||
)
|
)
|
||||||
|
.with(
|
||||||
|
MyAction::MouseHorizontal,
|
||||||
|
BindingConfig::from_bind(Binding::from_single(InputType::Mouse(MouseInput::Axis(
|
||||||
|
AxisName::Horizontal,
|
||||||
|
)))),
|
||||||
|
)
|
||||||
|
.with(
|
||||||
|
MyAction::MouseVertical,
|
||||||
|
BindingConfig::from_bind(Binding::from_single(InputType::Mouse(MouseInput::Axis(
|
||||||
|
AxisName::Vertical,
|
||||||
|
)))),
|
||||||
|
)
|
||||||
.with(
|
.with(
|
||||||
MyAction::Down,
|
MyAction::Down,
|
||||||
BindingConfig::from_bind(Binding::from_single(
|
BindingConfig::from_bind(Binding::from_single(
|
||||||
@@ -178,6 +193,20 @@ fn setup(mut commands: Commands) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
TextSection::new(
|
||||||
|
"(MouseDeltaX)",
|
||||||
|
TextStyle {
|
||||||
|
font_size: TEXT_SIZE,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSection::new(
|
||||||
|
"(MouseDeltaY)",
|
||||||
|
TextStyle {
|
||||||
|
font_size: TEXT_SIZE,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.with_background_color(Color::BLACK),
|
.with_background_color(Color::BLACK),
|
||||||
TextBlock,
|
TextBlock,
|
||||||
@@ -190,6 +219,8 @@ const MOVE_BACK_INDEX: usize = 2;
|
|||||||
const MOVE_FORWARD_INDEX: usize = 3;
|
const MOVE_FORWARD_INDEX: usize = 3;
|
||||||
const MOVE_RIGHT_INDEX: usize = 4;
|
const MOVE_RIGHT_INDEX: usize = 4;
|
||||||
const JUMP_INDEX: usize = 5;
|
const JUMP_INDEX: usize = 5;
|
||||||
|
const DELTA_X_INDEX: usize = 6;
|
||||||
|
const DELTA_Y_INDEX: usize = 7;
|
||||||
|
|
||||||
fn text_update_system(
|
fn text_update_system(
|
||||||
mut query: Query<&mut Text, With<TextBlock>>,
|
mut query: Query<&mut Text, With<TextBlock>>,
|
||||||
@@ -213,6 +244,7 @@ fn text_update_system(
|
|||||||
**jumps_count += 1;
|
**jumps_count += 1;
|
||||||
text.sections[JUMP_INDEX].value = format!("Up (Space) - {}", **jumps_count);
|
text.sections[JUMP_INDEX].value = format!("Up (Space) - {}", **jumps_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if player_inputs
|
if player_inputs
|
||||||
.get_just_pressed(MyAction::Down)
|
.get_just_pressed(MyAction::Down)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
@@ -220,6 +252,12 @@ fn text_update_system(
|
|||||||
**jumps_count -= 1;
|
**jumps_count -= 1;
|
||||||
text.sections[JUMP_INDEX].value = format!("Up (Space) - {}", **jumps_count);
|
text.sections[JUMP_INDEX].value = format!("Up (Space) - {}", **jumps_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let x = player_inputs.get(MyAction::MouseHorizontal).to_float();
|
||||||
|
text.sections[DELTA_X_INDEX].value = format!("(MouseDeltaX) - {}", x);
|
||||||
|
|
||||||
|
let y = player_inputs.get(MyAction::MouseVertical).to_float();
|
||||||
|
text.sections[DELTA_Y_INDEX].value = format!("(MouseDeltaY) - {}", y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,16 +153,16 @@ impl<A: Action, Ic: InputsContainer<A>, Gs: GameState> ControlsPlugin<A, Ic, Gs>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//log::info!("{:#?}", collected_inputs);
|
log::info!("{:#?}", collected_inputs);
|
||||||
//log::info!("{:#?}", action_binding_pairs[0]);
|
//log::info!("{:#?}", action_binding_pairs[0]);
|
||||||
|
|
||||||
match &binding.input {
|
match &binding.input {
|
||||||
ButtonCombination::Single(input_type) => {
|
ButtonCombination::Single(input_type) => {
|
||||||
// TODO: exclude if used
|
// TODO: exclude if used
|
||||||
if collected_inputs.contains_key(&*input_type) {
|
if let Some(value) = collected_inputs.get(&*input_type) {
|
||||||
inputs.forced_set(**action, true);
|
inputs.forced_set(**action, *value);
|
||||||
} else {
|
} else {
|
||||||
inputs.forced_set(**action, false);
|
inputs.forced_set(**action, InputValue::Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ impl<A: Action> PlayerActions<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add option on exlude or not exclude if used
|
||||||
common_traits_conditions! {
|
common_traits_conditions! {
|
||||||
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
|
||||||
pub enum InputType {
|
pub enum InputType {
|
||||||
|
|||||||
Reference in New Issue
Block a user