diff --git a/voxygen/src/menu/main/ui/connecting.rs b/voxygen/src/menu/main/ui/connecting.rs index 29cd0caacc..6778d52918 100644 --- a/voxygen/src/menu/main/ui/connecting.rs +++ b/voxygen/src/menu/main/ui/connecting.rs @@ -103,7 +103,10 @@ impl Screen { let key = |code| match controls.keybindings.get(&code) { Some(Some(key_mouse)) => key_mouse.display_string(key_layout), Some(None) => i18n.get_msg("main-unbound_key_tip").into_owned(), - None => ControlSettings::default_binding(code).display_string(key_layout), + None => match ControlSettings::default_binding(code) { + Some(key_mouse) => key_mouse.display_string(key_layout), + None => i18n.get_msg("main-unbound_key_tip").into_owned(), + }, }; let keys = i18n::fluent_args! { "gameinput-togglelantern" => key(GameInput::ToggleLantern), diff --git a/voxygen/src/settings/control.rs b/voxygen/src/settings/control.rs index 2e844c3cf6..28c5a96309 100644 --- a/voxygen/src/settings/control.rs +++ b/voxygen/src/settings/control.rs @@ -17,7 +17,7 @@ impl From for ControlSettingsSerde { // Do a delta between default() ControlSettings and the argument, and let // keybindings be only the custom keybindings chosen by the user. for (k, v) in control_settings.keybindings { - if Some(ControlSettings::default_binding(k)) != v { + if ControlSettings::default_binding(k) != v { // Keybinding chosen by the user user_bindings.insert(k, v); } @@ -121,77 +121,77 @@ impl ControlSettings { false } - pub fn default_binding(game_input: GameInput) -> KeyMouse { + pub fn default_binding(game_input: GameInput) -> Option { // If a new GameInput is added, be sure to update GameInput::iterator() too! match game_input { - GameInput::Primary => KeyMouse::Mouse(MouseButton::Left), - GameInput::Secondary => KeyMouse::Mouse(MouseButton::Right), - GameInput::Block => KeyMouse::Key(VirtualKeyCode::LAlt), - GameInput::ToggleCursor => KeyMouse::Key(VirtualKeyCode::Comma), - GameInput::Escape => KeyMouse::Key(VirtualKeyCode::Escape), - GameInput::Chat => KeyMouse::Key(VirtualKeyCode::Return), - GameInput::Command => KeyMouse::Key(VirtualKeyCode::Slash), - GameInput::MoveForward => KeyMouse::Key(VirtualKeyCode::W), - GameInput::MoveLeft => KeyMouse::Key(VirtualKeyCode::A), - GameInput::MoveBack => KeyMouse::Key(VirtualKeyCode::S), - GameInput::MoveRight => KeyMouse::Key(VirtualKeyCode::D), - GameInput::Jump => KeyMouse::Key(VirtualKeyCode::Space), - GameInput::Sit => KeyMouse::Key(VirtualKeyCode::K), - GameInput::Dance => KeyMouse::Key(VirtualKeyCode::J), - GameInput::Greet => KeyMouse::Key(VirtualKeyCode::H), - GameInput::Glide => KeyMouse::Key(VirtualKeyCode::LControl), - GameInput::Climb => KeyMouse::Key(VirtualKeyCode::Space), - GameInput::ClimbDown => KeyMouse::Key(VirtualKeyCode::LShift), - GameInput::SwimUp => KeyMouse::Key(VirtualKeyCode::Space), - GameInput::SwimDown => KeyMouse::Key(VirtualKeyCode::LShift), - GameInput::Fly => KeyMouse::Key(VirtualKeyCode::H), - GameInput::Sneak => KeyMouse::Key(VirtualKeyCode::LShift), - GameInput::ToggleLantern => KeyMouse::Key(VirtualKeyCode::G), - GameInput::Mount => KeyMouse::Key(VirtualKeyCode::F), - GameInput::Map => KeyMouse::Key(VirtualKeyCode::M), - GameInput::Bag => KeyMouse::Key(VirtualKeyCode::B), - GameInput::Trade => KeyMouse::Key(VirtualKeyCode::T), - GameInput::Social => KeyMouse::Key(VirtualKeyCode::O), - GameInput::Crafting => KeyMouse::Key(VirtualKeyCode::C), - GameInput::Spellbook => KeyMouse::Key(VirtualKeyCode::P), - GameInput::Settings => KeyMouse::Key(VirtualKeyCode::F10), - GameInput::Help => KeyMouse::Key(VirtualKeyCode::F1), - GameInput::ToggleInterface => KeyMouse::Key(VirtualKeyCode::F2), - GameInput::ToggleDebug => KeyMouse::Key(VirtualKeyCode::F3), + GameInput::Primary => Some(KeyMouse::Mouse(MouseButton::Left)), + GameInput::Secondary => Some(KeyMouse::Mouse(MouseButton::Right)), + GameInput::Block => Some(KeyMouse::Key(VirtualKeyCode::LAlt)), + GameInput::ToggleCursor => Some(KeyMouse::Key(VirtualKeyCode::Comma)), + GameInput::Escape => Some(KeyMouse::Key(VirtualKeyCode::Escape)), + GameInput::Chat => Some(KeyMouse::Key(VirtualKeyCode::Return)), + GameInput::Command => Some(KeyMouse::Key(VirtualKeyCode::Slash)), + GameInput::MoveForward => Some(KeyMouse::Key(VirtualKeyCode::W)), + GameInput::MoveLeft => Some(KeyMouse::Key(VirtualKeyCode::A)), + GameInput::MoveBack => Some(KeyMouse::Key(VirtualKeyCode::S)), + GameInput::MoveRight => Some(KeyMouse::Key(VirtualKeyCode::D)), + GameInput::Jump => Some(KeyMouse::Key(VirtualKeyCode::Space)), + GameInput::Sit => Some(KeyMouse::Key(VirtualKeyCode::K)), + GameInput::Dance => Some(KeyMouse::Key(VirtualKeyCode::J)), + GameInput::Greet => Some(KeyMouse::Key(VirtualKeyCode::H)), + GameInput::Glide => Some(KeyMouse::Key(VirtualKeyCode::LControl)), + GameInput::Climb => Some(KeyMouse::Key(VirtualKeyCode::Space)), + GameInput::ClimbDown => Some(KeyMouse::Key(VirtualKeyCode::LShift)), + GameInput::SwimUp => Some(KeyMouse::Key(VirtualKeyCode::Space)), + GameInput::SwimDown => Some(KeyMouse::Key(VirtualKeyCode::LShift)), + GameInput::Fly => Some(KeyMouse::Key(VirtualKeyCode::H)), + GameInput::Sneak => Some(KeyMouse::Key(VirtualKeyCode::LShift)), + GameInput::ToggleLantern => Some(KeyMouse::Key(VirtualKeyCode::G)), + GameInput::Mount => Some(KeyMouse::Key(VirtualKeyCode::F)), + GameInput::Map => Some(KeyMouse::Key(VirtualKeyCode::M)), + GameInput::Bag => Some(KeyMouse::Key(VirtualKeyCode::B)), + GameInput::Trade => Some(KeyMouse::Key(VirtualKeyCode::T)), + GameInput::Social => Some(KeyMouse::Key(VirtualKeyCode::O)), + GameInput::Crafting => Some(KeyMouse::Key(VirtualKeyCode::C)), + GameInput::Spellbook => Some(KeyMouse::Key(VirtualKeyCode::P)), + GameInput::Settings => Some(KeyMouse::Key(VirtualKeyCode::F10)), + GameInput::Help => Some(KeyMouse::Key(VirtualKeyCode::F1)), + GameInput::ToggleInterface => Some(KeyMouse::Key(VirtualKeyCode::F2)), + GameInput::ToggleDebug => Some(KeyMouse::Key(VirtualKeyCode::F3)), #[cfg(feature = "egui-ui")] - GameInput::ToggleEguiDebug => KeyMouse::Key(VirtualKeyCode::F7), - GameInput::ToggleChat => KeyMouse::Key(VirtualKeyCode::F5), - GameInput::Fullscreen => KeyMouse::Key(VirtualKeyCode::F11), - GameInput::Screenshot => KeyMouse::Key(VirtualKeyCode::F4), - GameInput::ToggleIngameUi => KeyMouse::Key(VirtualKeyCode::F6), - GameInput::Roll => MIDDLE_CLICK_KEY, - GameInput::Respawn => KeyMouse::Key(VirtualKeyCode::Space), - GameInput::Interact => KeyMouse::Key(VirtualKeyCode::E), - GameInput::ToggleWield => KeyMouse::Key(VirtualKeyCode::R), - GameInput::FreeLook => KeyMouse::Key(VirtualKeyCode::L), - GameInput::AutoWalk => KeyMouse::Key(VirtualKeyCode::Period), - GameInput::CameraClamp => KeyMouse::Key(VirtualKeyCode::Apostrophe), - GameInput::CycleCamera => KeyMouse::Key(VirtualKeyCode::Key0), - GameInput::Slot1 => KeyMouse::Key(VirtualKeyCode::Key1), - GameInput::Slot2 => KeyMouse::Key(VirtualKeyCode::Key2), - GameInput::Slot3 => KeyMouse::Key(VirtualKeyCode::Key3), - GameInput::Slot4 => KeyMouse::Key(VirtualKeyCode::Key4), - GameInput::Slot5 => KeyMouse::Key(VirtualKeyCode::Key5), - GameInput::Slot6 => KeyMouse::Key(VirtualKeyCode::Key6), - GameInput::Slot7 => KeyMouse::Key(VirtualKeyCode::Key7), - GameInput::Slot8 => KeyMouse::Key(VirtualKeyCode::Key8), - GameInput::Slot9 => KeyMouse::Key(VirtualKeyCode::Key9), - GameInput::Slot10 => KeyMouse::Key(VirtualKeyCode::Q), - GameInput::SwapLoadout => KeyMouse::Key(VirtualKeyCode::Tab), - GameInput::Select => KeyMouse::Key(VirtualKeyCode::X), - GameInput::AcceptGroupInvite => KeyMouse::Key(VirtualKeyCode::Y), - GameInput::DeclineGroupInvite => KeyMouse::Key(VirtualKeyCode::N), - GameInput::MapZoomIn => KeyMouse::Key(VirtualKeyCode::Plus), - GameInput::MapZoomOut => KeyMouse::Key(VirtualKeyCode::Minus), - GameInput::MapSetMarker => KeyMouse::Mouse(MouseButton::Middle), - GameInput::SpectateSpeedBoost => KeyMouse::Key(VirtualKeyCode::LControl), - GameInput::SpectateViewpoint => KeyMouse::Mouse(MouseButton::Middle), - GameInput::MuteMusic => KeyMouse::Key(VirtualKeyCode::F8), + GameInput::ToggleEguiDebug => Some(KeyMouse::Key(VirtualKeyCode::F7)), + GameInput::ToggleChat => Some(KeyMouse::Key(VirtualKeyCode::F5)), + GameInput::Fullscreen => Some(KeyMouse::Key(VirtualKeyCode::F11)), + GameInput::Screenshot => Some(KeyMouse::Key(VirtualKeyCode::F4)), + GameInput::ToggleIngameUi => Some(KeyMouse::Key(VirtualKeyCode::F6)), + GameInput::Roll => Some(MIDDLE_CLICK_KEY), + GameInput::Respawn => Some(KeyMouse::Key(VirtualKeyCode::Space)), + GameInput::Interact => Some(KeyMouse::Key(VirtualKeyCode::E)), + GameInput::ToggleWield => Some(KeyMouse::Key(VirtualKeyCode::R)), + GameInput::FreeLook => Some(KeyMouse::Key(VirtualKeyCode::L)), + GameInput::AutoWalk => Some(KeyMouse::Key(VirtualKeyCode::Period)), + GameInput::CameraClamp => Some(KeyMouse::Key(VirtualKeyCode::Apostrophe)), + GameInput::CycleCamera => Some(KeyMouse::Key(VirtualKeyCode::Key0)), + GameInput::Slot1 => Some(KeyMouse::Key(VirtualKeyCode::Key1)), + GameInput::Slot2 => Some(KeyMouse::Key(VirtualKeyCode::Key2)), + GameInput::Slot3 => Some(KeyMouse::Key(VirtualKeyCode::Key3)), + GameInput::Slot4 => Some(KeyMouse::Key(VirtualKeyCode::Key4)), + GameInput::Slot5 => Some(KeyMouse::Key(VirtualKeyCode::Key5)), + GameInput::Slot6 => Some(KeyMouse::Key(VirtualKeyCode::Key6)), + GameInput::Slot7 => Some(KeyMouse::Key(VirtualKeyCode::Key7)), + GameInput::Slot8 => Some(KeyMouse::Key(VirtualKeyCode::Key8)), + GameInput::Slot9 => Some(KeyMouse::Key(VirtualKeyCode::Key9)), + GameInput::Slot10 => Some(KeyMouse::Key(VirtualKeyCode::Q)), + GameInput::SwapLoadout => Some(KeyMouse::Key(VirtualKeyCode::Tab)), + GameInput::Select => Some(KeyMouse::Key(VirtualKeyCode::X)), + GameInput::AcceptGroupInvite => Some(KeyMouse::Key(VirtualKeyCode::Y)), + GameInput::DeclineGroupInvite => Some(KeyMouse::Key(VirtualKeyCode::N)), + GameInput::MapZoomIn => Some(KeyMouse::Key(VirtualKeyCode::Plus)), + GameInput::MapZoomOut => Some(KeyMouse::Key(VirtualKeyCode::Minus)), + GameInput::MapSetMarker => Some(KeyMouse::Mouse(MouseButton::Middle)), + GameInput::SpectateSpeedBoost => Some(KeyMouse::Key(VirtualKeyCode::LControl)), + GameInput::SpectateViewpoint => Some(KeyMouse::Mouse(MouseButton::Middle)), + GameInput::MuteMusic => Some(KeyMouse::Key(VirtualKeyCode::F8)), } } } @@ -204,7 +204,10 @@ impl Default for ControlSettings { }; // Sets the initial keybindings for those GameInputs. for game_input in GameInput::iter() { - new_settings.insert_binding(game_input, ControlSettings::default_binding(game_input)); + match ControlSettings::default_binding(game_input) { + None => {}, + Some(default) => new_settings.insert_binding(game_input, default), + }; } new_settings }