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