mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'timo-keybinds' into 'master'
Timo keybinds See merge request veloren/veloren!464
This commit is contained in:
commit
1bd3f0ab28
@ -217,11 +217,14 @@ impl<'a> Widget for Skillbar<'a> {
|
|||||||
.font_size(40)
|
.font_size(40)
|
||||||
.color(CRITICAL_HP_COLOR)
|
.color(CRITICAL_HP_COLOR)
|
||||||
.set(state.ids.death_message_1, ui);
|
.set(state.ids.death_message_1, ui);
|
||||||
Text::new("Press L-Mouse to respawn.")
|
Text::new(&format!(
|
||||||
.mid_bottom_with_margin_on(state.ids.death_message_1, -30.0)
|
"Press {:?} to respawn.",
|
||||||
.font_size(15)
|
self.global_state.settings.controls.respawn
|
||||||
.color(CRITICAL_HP_COLOR)
|
))
|
||||||
.set(state.ids.death_message_2, ui);
|
.mid_bottom_with_margin_on(state.ids.death_message_1, -30.0)
|
||||||
|
.font_size(15)
|
||||||
|
.color(CRITICAL_HP_COLOR)
|
||||||
|
.set(state.ids.death_message_2, ui);
|
||||||
}
|
}
|
||||||
// Experience-Bar
|
// Experience-Bar
|
||||||
match self.global_state.settings.gameplay.xp_bar {
|
match self.global_state.settings.gameplay.xp_bar {
|
||||||
|
@ -129,9 +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
|
|
||||||
|
|
||||||
// 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
|
||||||
// place blocks, if not, use it to attack
|
// place blocks, if not, use it to attack
|
||||||
let mut client = self.client.borrow_mut();
|
let mut client = self.client.borrow_mut();
|
||||||
@ -158,7 +156,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
|
||||||
@ -204,6 +202,9 @@ impl PlayState for SessionState {
|
|||||||
self.controller.roll = state;
|
self.controller.roll = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Event::InputUpdate(GameInput::Respawn, state) => {
|
||||||
|
self.controller.respawn = state;
|
||||||
|
}
|
||||||
Event::InputUpdate(GameInput::Jump, state) => {
|
Event::InputUpdate(GameInput::Jump, state) => {
|
||||||
self.controller.jump = state;
|
self.controller.jump = state;
|
||||||
}
|
}
|
||||||
|
@ -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,15 +38,16 @@ 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 respawn: KeyMouse,
|
||||||
pub interact: KeyMouse,
|
pub interact: KeyMouse,
|
||||||
}
|
}
|
||||||
|
|
||||||
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,9 +71,8 @@ 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),
|
||||||
|
respawn: KeyMouse::Mouse(MouseButton::Left),
|
||||||
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,
|
||||||
@ -81,7 +81,7 @@ pub struct Window {
|
|||||||
pub zoom_sensitivity: u32,
|
pub zoom_sensitivity: u32,
|
||||||
fullscreen: bool,
|
fullscreen: bool,
|
||||||
needs_refresh_resize: bool,
|
needs_refresh_resize: bool,
|
||||||
key_map: HashMap<KeyMouse, GameInput>,
|
key_map: HashMap<KeyMouse, Vec<GameInput>>,
|
||||||
keypress_map: HashMap<GameInput, glutin::ElementState>,
|
keypress_map: HashMap<GameInput, glutin::ElementState>,
|
||||||
supplement_events: Vec<Event>,
|
supplement_events: Vec<Event>,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
@ -108,43 +108,91 @@ 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 map: HashMap<_, Vec<_>> = HashMap::new();
|
||||||
key_map.insert(settings.controls.toggle_cursor, GameInput::ToggleCursor);
|
map.entry(settings.controls.main)
|
||||||
key_map.insert(settings.controls.escape, GameInput::Escape);
|
.or_default()
|
||||||
key_map.insert(settings.controls.enter, GameInput::Enter);
|
.push(GameInput::Main);
|
||||||
key_map.insert(settings.controls.command, GameInput::Command);
|
map.entry(settings.controls.alt)
|
||||||
key_map.insert(settings.controls.move_forward, GameInput::MoveForward);
|
.or_default()
|
||||||
key_map.insert(settings.controls.move_left, GameInput::MoveLeft);
|
.push(GameInput::Alt);
|
||||||
key_map.insert(settings.controls.move_back, GameInput::MoveBack);
|
map.entry(settings.controls.toggle_cursor)
|
||||||
key_map.insert(settings.controls.move_right, GameInput::MoveRight);
|
.or_default()
|
||||||
key_map.insert(settings.controls.jump, GameInput::Jump);
|
.push(GameInput::ToggleCursor);
|
||||||
key_map.insert(settings.controls.glide, GameInput::Glide);
|
map.entry(settings.controls.escape)
|
||||||
key_map.insert(settings.controls.map, GameInput::Map);
|
.or_default()
|
||||||
key_map.insert(settings.controls.bag, GameInput::Bag);
|
.push(GameInput::Escape);
|
||||||
key_map.insert(settings.controls.quest_log, GameInput::QuestLog);
|
map.entry(settings.controls.enter)
|
||||||
key_map.insert(
|
.or_default()
|
||||||
settings.controls.character_window,
|
.push(GameInput::Enter);
|
||||||
GameInput::CharacterWindow,
|
map.entry(settings.controls.command)
|
||||||
);
|
.or_default()
|
||||||
key_map.insert(settings.controls.social, GameInput::Social);
|
.push(GameInput::Command);
|
||||||
key_map.insert(settings.controls.spellbook, GameInput::Spellbook);
|
map.entry(settings.controls.move_forward)
|
||||||
key_map.insert(settings.controls.settings, GameInput::Settings);
|
.or_default()
|
||||||
key_map.insert(settings.controls.help, GameInput::Help);
|
.push(GameInput::MoveForward);
|
||||||
key_map.insert(
|
map.entry(settings.controls.move_left)
|
||||||
settings.controls.toggle_interface,
|
.or_default()
|
||||||
GameInput::ToggleInterface,
|
.push(GameInput::MoveLeft);
|
||||||
);
|
map.entry(settings.controls.move_back)
|
||||||
key_map.insert(settings.controls.toggle_debug, GameInput::ToggleDebug);
|
.or_default()
|
||||||
key_map.insert(settings.controls.fullscreen, GameInput::Fullscreen);
|
.push(GameInput::MoveBack);
|
||||||
key_map.insert(settings.controls.screenshot, GameInput::Screenshot);
|
map.entry(settings.controls.move_right)
|
||||||
key_map.insert(
|
.or_default()
|
||||||
settings.controls.toggle_ingame_ui,
|
.push(GameInput::MoveRight);
|
||||||
GameInput::ToggleIngameUi,
|
map.entry(settings.controls.jump)
|
||||||
);
|
.or_default()
|
||||||
key_map.insert(settings.controls.attack, GameInput::Attack);
|
.push(GameInput::Jump);
|
||||||
key_map.insert(settings.controls.block, GameInput::Block);
|
map.entry(settings.controls.glide)
|
||||||
key_map.insert(settings.controls.roll, GameInput::Roll);
|
.or_default()
|
||||||
key_map.insert(settings.controls.interact, GameInput::Interact);
|
.push(GameInput::Glide);
|
||||||
|
map.entry(settings.controls.map)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Map);
|
||||||
|
map.entry(settings.controls.bag)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Bag);
|
||||||
|
map.entry(settings.controls.quest_log)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::QuestLog);
|
||||||
|
map.entry(settings.controls.character_window)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::CharacterWindow);
|
||||||
|
map.entry(settings.controls.social)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Social);
|
||||||
|
map.entry(settings.controls.spellbook)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Spellbook);
|
||||||
|
map.entry(settings.controls.settings)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Settings);
|
||||||
|
map.entry(settings.controls.help)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Help);
|
||||||
|
map.entry(settings.controls.toggle_interface)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::ToggleInterface);
|
||||||
|
map.entry(settings.controls.toggle_debug)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::ToggleDebug);
|
||||||
|
map.entry(settings.controls.fullscreen)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Fullscreen);
|
||||||
|
map.entry(settings.controls.screenshot)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Screenshot);
|
||||||
|
map.entry(settings.controls.toggle_ingame_ui)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::ToggleIngameUi);
|
||||||
|
map.entry(settings.controls.roll)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Roll);
|
||||||
|
map.entry(settings.controls.respawn)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Respawn);
|
||||||
|
map.entry(settings.controls.interact)
|
||||||
|
.or_default()
|
||||||
|
.push(GameInput::Interact);
|
||||||
|
|
||||||
let keypress_map = HashMap::new();
|
let keypress_map = HashMap::new();
|
||||||
|
|
||||||
@ -157,7 +205,7 @@ impl Window {
|
|||||||
zoom_sensitivity: settings.gameplay.zoom_sensitivity,
|
zoom_sensitivity: settings.gameplay.zoom_sensitivity,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
needs_refresh_resize: false,
|
needs_refresh_resize: false,
|
||||||
key_map,
|
key_map: map,
|
||||||
keypress_map,
|
keypress_map,
|
||||||
supplement_events: vec![],
|
supplement_events: vec![],
|
||||||
focused: true,
|
focused: true,
|
||||||
@ -210,65 +258,58 @@ impl Window {
|
|||||||
}
|
}
|
||||||
glutin::WindowEvent::ReceivedCharacter(c) => events.push(Event::Char(c)),
|
glutin::WindowEvent::ReceivedCharacter(c) => events.push(Event::Char(c)),
|
||||||
glutin::WindowEvent::MouseInput { button, state, .. } if cursor_grabbed => {
|
glutin::WindowEvent::MouseInput { button, state, .. } if cursor_grabbed => {
|
||||||
if let Some(&game_input) = key_map.get(&KeyMouse::Mouse(button)) {
|
if let Some(game_inputs) = key_map.get(&KeyMouse::Mouse(button)) {
|
||||||
events.push(Event::InputUpdate(
|
for game_input in game_inputs {
|
||||||
game_input,
|
events.push(Event::InputUpdate(
|
||||||
state == glutin::ElementState::Pressed,
|
*game_input,
|
||||||
))
|
state == glutin::ElementState::Pressed,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glutin::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode
|
glutin::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode
|
||||||
{
|
{
|
||||||
Some(key) => match key_map.get(&KeyMouse::Key(key)) {
|
Some(key) => {
|
||||||
Some(GameInput::Fullscreen) => {
|
let game_inputs = key_map.get(&KeyMouse::Key(key));
|
||||||
if input.state == glutin::ElementState::Pressed
|
if let Some(game_inputs) = game_inputs {
|
||||||
&& !Self::is_event_key_held(keypress_map, GameInput::Fullscreen)
|
for game_input in game_inputs {
|
||||||
{
|
match game_input {
|
||||||
toggle_fullscreen = !toggle_fullscreen;
|
GameInput::Fullscreen => {
|
||||||
|
if input.state == glutin::ElementState::Pressed
|
||||||
|
&& !Self::is_pressed(
|
||||||
|
keypress_map,
|
||||||
|
GameInput::Fullscreen,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
toggle_fullscreen = !toggle_fullscreen;
|
||||||
|
}
|
||||||
|
Self::set_pressed(
|
||||||
|
keypress_map,
|
||||||
|
GameInput::Fullscreen,
|
||||||
|
input.state,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
GameInput::Screenshot => {
|
||||||
|
take_screenshot = input.state
|
||||||
|
== glutin::ElementState::Pressed
|
||||||
|
&& !Self::is_pressed(
|
||||||
|
keypress_map,
|
||||||
|
GameInput::Screenshot,
|
||||||
|
);
|
||||||
|
Self::set_pressed(
|
||||||
|
keypress_map,
|
||||||
|
GameInput::Screenshot,
|
||||||
|
input.state,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => events.push(Event::InputUpdate(
|
||||||
|
*game_input,
|
||||||
|
input.state == glutin::ElementState::Pressed,
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Self::update_keypress_map(
|
|
||||||
keypress_map,
|
|
||||||
GameInput::Fullscreen,
|
|
||||||
input.state,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Some(GameInput::Screenshot) => {
|
}
|
||||||
take_screenshot = input.state == glutin::ElementState::Pressed
|
|
||||||
&& !Self::is_event_key_held(
|
|
||||||
keypress_map,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
glutin::WindowEvent::Focused(state) => {
|
glutin::WindowEvent::Focused(state) => {
|
||||||
@ -386,15 +427,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