mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Rename attack, block to main, alt
This commit is contained in:
parent
838eab8637
commit
186db16707
@ -129,7 +129,7 @@ impl PlayState for SessionState {
|
|||||||
Event::Close => {
|
Event::Close => {
|
||||||
return PlayStateResult::Shutdown;
|
return PlayStateResult::Shutdown;
|
||||||
}
|
}
|
||||||
Event::InputUpdate(GameInput::Attack, state) => {
|
Event::InputUpdate(GameInput::Main, state) => {
|
||||||
self.controller.respawn = state; // TODO: Move this into separate GameInput
|
self.controller.respawn = state; // TODO: Move this into separate GameInput
|
||||||
|
|
||||||
// Check the existence of CanBuild component. If it's here, use LMB to
|
// Check the existence of CanBuild component. If it's here, use LMB to
|
||||||
@ -158,7 +158,7 @@ impl PlayState for SessionState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::InputUpdate(GameInput::Block, state) => {
|
Event::InputUpdate(GameInput::Alt, state) => {
|
||||||
let mut client = self.client.borrow_mut();
|
let mut client = self.client.borrow_mut();
|
||||||
if state
|
if state
|
||||||
&& client
|
&& client
|
||||||
|
@ -13,6 +13,8 @@ use std::{fs, io::prelude::*, path::PathBuf};
|
|||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ControlSettings {
|
pub struct ControlSettings {
|
||||||
|
pub main: KeyMouse,
|
||||||
|
pub alt: KeyMouse,
|
||||||
pub toggle_cursor: KeyMouse,
|
pub toggle_cursor: KeyMouse,
|
||||||
pub escape: KeyMouse,
|
pub escape: KeyMouse,
|
||||||
pub enter: KeyMouse,
|
pub enter: KeyMouse,
|
||||||
@ -36,8 +38,6 @@ pub struct ControlSettings {
|
|||||||
pub fullscreen: KeyMouse,
|
pub fullscreen: KeyMouse,
|
||||||
pub screenshot: KeyMouse,
|
pub screenshot: KeyMouse,
|
||||||
pub toggle_ingame_ui: KeyMouse,
|
pub toggle_ingame_ui: KeyMouse,
|
||||||
pub attack: KeyMouse,
|
|
||||||
pub block: KeyMouse,
|
|
||||||
pub roll: KeyMouse,
|
pub roll: KeyMouse,
|
||||||
pub interact: KeyMouse,
|
pub interact: KeyMouse,
|
||||||
}
|
}
|
||||||
@ -45,6 +45,8 @@ pub struct ControlSettings {
|
|||||||
impl Default for ControlSettings {
|
impl Default for ControlSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
main: KeyMouse::Mouse(MouseButton::Left),
|
||||||
|
alt: KeyMouse::Mouse(MouseButton::Right),
|
||||||
toggle_cursor: KeyMouse::Key(VirtualKeyCode::Tab),
|
toggle_cursor: KeyMouse::Key(VirtualKeyCode::Tab),
|
||||||
escape: KeyMouse::Key(VirtualKeyCode::Escape),
|
escape: KeyMouse::Key(VirtualKeyCode::Escape),
|
||||||
enter: KeyMouse::Key(VirtualKeyCode::Return),
|
enter: KeyMouse::Key(VirtualKeyCode::Return),
|
||||||
@ -68,8 +70,6 @@ impl Default for ControlSettings {
|
|||||||
fullscreen: KeyMouse::Key(VirtualKeyCode::F11),
|
fullscreen: KeyMouse::Key(VirtualKeyCode::F11),
|
||||||
screenshot: KeyMouse::Key(VirtualKeyCode::F4),
|
screenshot: KeyMouse::Key(VirtualKeyCode::F4),
|
||||||
toggle_ingame_ui: KeyMouse::Key(VirtualKeyCode::F6),
|
toggle_ingame_ui: KeyMouse::Key(VirtualKeyCode::F6),
|
||||||
attack: KeyMouse::Mouse(MouseButton::Left),
|
|
||||||
block: KeyMouse::Mouse(MouseButton::Right),
|
|
||||||
roll: KeyMouse::Mouse(MouseButton::Middle),
|
roll: KeyMouse::Mouse(MouseButton::Middle),
|
||||||
interact: KeyMouse::Key(VirtualKeyCode::E),
|
interact: KeyMouse::Key(VirtualKeyCode::E),
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ use vek::*;
|
|||||||
/// Represents a key that the game recognises after keyboard mapping.
|
/// Represents a key that the game recognises after keyboard mapping.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
|
||||||
pub enum GameInput {
|
pub enum GameInput {
|
||||||
|
Main,
|
||||||
|
Alt,
|
||||||
ToggleCursor,
|
ToggleCursor,
|
||||||
MoveForward,
|
MoveForward,
|
||||||
MoveBack,
|
MoveBack,
|
||||||
@ -34,8 +36,6 @@ pub enum GameInput {
|
|||||||
Fullscreen,
|
Fullscreen,
|
||||||
Screenshot,
|
Screenshot,
|
||||||
ToggleIngameUi,
|
ToggleIngameUi,
|
||||||
Attack,
|
|
||||||
Block,
|
|
||||||
Roll,
|
Roll,
|
||||||
Respawn,
|
Respawn,
|
||||||
Interact,
|
Interact,
|
||||||
@ -109,6 +109,8 @@ impl Window {
|
|||||||
.map_err(|err| Error::BackendError(Box::new(err)))?;
|
.map_err(|err| Error::BackendError(Box::new(err)))?;
|
||||||
|
|
||||||
let mut key_map = HashMap::new();
|
let mut key_map = HashMap::new();
|
||||||
|
key_map.insert(settings.controls.main, GameInput::Main);
|
||||||
|
key_map.insert(settings.controls.alt, GameInput::Alt);
|
||||||
key_map.insert(settings.controls.toggle_cursor, GameInput::ToggleCursor);
|
key_map.insert(settings.controls.toggle_cursor, GameInput::ToggleCursor);
|
||||||
key_map.insert(settings.controls.escape, GameInput::Escape);
|
key_map.insert(settings.controls.escape, GameInput::Escape);
|
||||||
key_map.insert(settings.controls.enter, GameInput::Enter);
|
key_map.insert(settings.controls.enter, GameInput::Enter);
|
||||||
@ -141,8 +143,6 @@ impl Window {
|
|||||||
settings.controls.toggle_ingame_ui,
|
settings.controls.toggle_ingame_ui,
|
||||||
GameInput::ToggleIngameUi,
|
GameInput::ToggleIngameUi,
|
||||||
);
|
);
|
||||||
key_map.insert(settings.controls.attack, GameInput::Attack);
|
|
||||||
key_map.insert(settings.controls.block, GameInput::Block);
|
|
||||||
key_map.insert(settings.controls.roll, GameInput::Roll);
|
key_map.insert(settings.controls.roll, GameInput::Roll);
|
||||||
key_map.insert(settings.controls.interact, GameInput::Interact);
|
key_map.insert(settings.controls.interact, GameInput::Interact);
|
||||||
|
|
||||||
@ -222,51 +222,21 @@ impl Window {
|
|||||||
Some(key) => match key_map.get(&KeyMouse::Key(key)) {
|
Some(key) => match key_map.get(&KeyMouse::Key(key)) {
|
||||||
Some(GameInput::Fullscreen) => {
|
Some(GameInput::Fullscreen) => {
|
||||||
if input.state == glutin::ElementState::Pressed
|
if input.state == glutin::ElementState::Pressed
|
||||||
&& !Self::is_event_key_held(keypress_map, GameInput::Fullscreen)
|
&& !Self::is_pressed(keypress_map, GameInput::Fullscreen)
|
||||||
{
|
{
|
||||||
toggle_fullscreen = !toggle_fullscreen;
|
toggle_fullscreen = !toggle_fullscreen;
|
||||||
}
|
}
|
||||||
Self::update_keypress_map(
|
Self::set_pressed(keypress_map, GameInput::Fullscreen, input.state);
|
||||||
keypress_map,
|
|
||||||
GameInput::Fullscreen,
|
|
||||||
input.state,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Some(GameInput::Screenshot) => {
|
Some(GameInput::Screenshot) => {
|
||||||
take_screenshot = input.state == glutin::ElementState::Pressed
|
take_screenshot = input.state == glutin::ElementState::Pressed
|
||||||
&& !Self::is_event_key_held(
|
&& !Self::is_pressed(keypress_map, GameInput::Screenshot);
|
||||||
keypress_map,
|
Self::set_pressed(keypress_map, GameInput::Screenshot, input.state);
|
||||||
GameInput::Screenshot,
|
|
||||||
);
|
|
||||||
Self::update_keypress_map(
|
|
||||||
keypress_map,
|
|
||||||
GameInput::Screenshot,
|
|
||||||
input.state,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Some(&game_input)
|
|
||||||
if game_input == GameInput::MoveForward
|
|
||||||
|| game_input == GameInput::MoveBack
|
|
||||||
|| game_input == GameInput::MoveLeft
|
|
||||||
|| game_input == GameInput::MoveRight
|
|
||||||
|| game_input == GameInput::Jump
|
|
||||||
|| game_input == GameInput::Glide
|
|
||||||
|| game_input == GameInput::Attack
|
|
||||||
|| game_input == GameInput::Roll =>
|
|
||||||
{
|
|
||||||
events.push(Event::InputUpdate(
|
|
||||||
game_input,
|
|
||||||
input.state == glutin::ElementState::Pressed,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Some(&game_input) => {
|
|
||||||
if input.state == glutin::ElementState::Pressed
|
|
||||||
&& !Self::is_event_key_held(keypress_map, game_input)
|
|
||||||
{
|
|
||||||
events.push(Event::InputUpdate(game_input, true));
|
|
||||||
}
|
|
||||||
Self::update_keypress_map(keypress_map, game_input, input.state);
|
|
||||||
}
|
}
|
||||||
|
Some(&game_input) => events.push(Event::InputUpdate(
|
||||||
|
game_input,
|
||||||
|
input.state == glutin::ElementState::Pressed,
|
||||||
|
)),
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -386,15 +356,12 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_event_key_held(
|
fn is_pressed(map: &mut HashMap<GameInput, glutin::ElementState>, input: GameInput) -> bool {
|
||||||
map: &mut HashMap<GameInput, glutin::ElementState>,
|
|
||||||
input: GameInput,
|
|
||||||
) -> bool {
|
|
||||||
*(map.entry(input).or_insert(glutin::ElementState::Released))
|
*(map.entry(input).or_insert(glutin::ElementState::Released))
|
||||||
== glutin::ElementState::Pressed
|
== glutin::ElementState::Pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_keypress_map(
|
fn set_pressed(
|
||||||
map: &mut HashMap<GameInput, glutin::ElementState>,
|
map: &mut HashMap<GameInput, glutin::ElementState>,
|
||||||
input: GameInput,
|
input: GameInput,
|
||||||
state: glutin::ElementState,
|
state: glutin::ElementState,
|
||||||
|
Loading…
Reference in New Issue
Block a user