From 03396eb77ea5ea1f8d8366eaab79e9c436488286 Mon Sep 17 00:00:00 2001 From: Capucho Date: Thu, 26 Mar 2020 21:22:21 +0000 Subject: [PATCH] Implement #505 --- CHANGELOG.md | 1 + assets/voxygen/i18n/en.ron | 2 ++ voxygen/src/hud/mod.rs | 25 +++++++++++++++++++++++++ voxygen/src/session.rs | 14 +++++++++++--- voxygen/src/settings.rs | 2 ++ voxygen/src/window.rs | 4 ++++ 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f8bc8c16..a579276f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added authentication system (to play on the official server register on https://account.veloren.net) - Added gamepad/controller support - Added player feedback when attempting to pickup an item with a full inventory +- Added free look ### Changed diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index a9ab34bd68..57ef0300db 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -327,6 +327,8 @@ Chat commands: "hud.social.play_online_fmt": "{nb_player} player(s) online", "hud.spell": "Spell", + + "hud.free_look_indicator": "Free look active", /// End HUD section diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index f5a0a89ad8..9a45e82156 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -56,6 +56,7 @@ use vek::*; const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); const TEXT_COLOR: Color = Color::Rgba(1.0, 1.0, 1.0, 1.0); +const TEXT_BG: Color = Color::Rgba(0.0, 0.0, 0.0, 1.0); //const TEXT_COLOR_GREY: Color = Color::Rgba(1.0, 1.0, 1.0, 0.5); const MENU_BG: Color = Color::Rgba(0.0, 0.0, 0.0, 0.4); //const TEXT_COLOR_2: Color = Color::Rgba(0.0, 0.0, 0.0, 1.0); @@ -175,6 +176,10 @@ widget_ids! { small_window, social_window, settings_window, + + // Free look indicator + free_look_txt, + free_look_bg, } } @@ -285,6 +290,7 @@ pub struct Show { settings_tab: SettingsTab, social_tab: SocialTab, want_grab: bool, + free_look: bool, } impl Show { fn bag(&mut self, open: bool) { @@ -507,6 +513,7 @@ impl Hud { social_tab: SocialTab::Online, want_grab: true, ingame: true, + free_look: false, }, to_focus: None, never_show: false, @@ -1961,6 +1968,22 @@ impl Hud { } } + // Free look indicator + if self.show.free_look { + Text::new(&self.voxygen_i18n.get("hud.free_look_indicator")) + .color(TEXT_BG) + .mid_top_with_margin_on(ui_widgets.window, 100.0) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(20)) + .set(self.ids.free_look_bg, ui_widgets); + Text::new(&self.voxygen_i18n.get("hud.free_look_indicator")) + .color(KILL_COLOR) + .top_left_with_margins_on(self.ids.free_look_bg, -1.0, -1.0) + .font_id(self.fonts.cyri.conrod_id) + .font_size(self.fonts.cyri.scale(20)) + .set(self.ids.free_look_txt, ui_widgets); + } + events } @@ -2132,4 +2155,6 @@ impl Hud { self.ui.render(renderer, Some(globals)); } } + + pub fn free_look(&mut self, free_look: bool) { self.show.free_look = free_look; } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 7f8ecd2370..5e9d46b6fb 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -154,6 +154,9 @@ impl PlayState for SessionState { ) .unwrap(); + let mut ori = self.scene.camera().get_orientation(); + let mut free_look = false; + // Game loop let mut current_client_state = self.client.borrow().get_client_state(); while let ClientState::Pending | ClientState::Character = current_client_state { @@ -399,6 +402,10 @@ impl PlayState for SessionState { Event::InputUpdate(GameInput::Charge, state) => { self.inputs.charge.set_state(state); }, + Event::InputUpdate(GameInput::FreeLook, true) => { + free_look = !free_look; + self.hud.free_look(free_look); + }, Event::AnalogGameInput(input) => match input { AnalogGameInput::MovementX(v) => { self.key_state.analog_matrix.x = v; @@ -418,9 +425,12 @@ impl PlayState for SessionState { } } + if !free_look { + ori = self.scene.camera().get_orientation(); + self.inputs.look_dir = cam_dir; + } // Calculate the movement input vector of the player from the current key // presses and the camera direction. - let ori = self.scene.camera().get_orientation(); let unit_vecs = ( Vec2::new(ori[0].cos(), -ori[0].sin()), Vec2::new(ori[0].sin(), ori[0].cos()), @@ -428,8 +438,6 @@ impl PlayState for SessionState { let dir_vec = self.key_state.dir_vec(); self.inputs.move_dir = unit_vecs.0 * dir_vec[0] + unit_vecs.1 * dir_vec[1]; - self.inputs.look_dir = cam_dir; - // Runs if either in a multiplayer server or the singleplayer server is unpaused if global_state.singleplayer.is_none() || !global_state.singleplayer.as_ref().unwrap().is_paused() diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 78431b2dd1..5f47300544 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -51,6 +51,7 @@ pub struct ControlSettings { pub interact: KeyMouse, pub toggle_wield: KeyMouse, pub charge: KeyMouse, + pub free_look: KeyMouse, } /// Since Macbook trackpads lack middle click, on OS X we default to LShift @@ -101,6 +102,7 @@ impl Default for ControlSettings { interact: KeyMouse::Mouse(MouseButton::Right), toggle_wield: KeyMouse::Key(VirtualKeyCode::T), charge: KeyMouse::Key(VirtualKeyCode::Key1), + free_look: KeyMouse::Key(VirtualKeyCode::LAlt), } } } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index f052ec73a2..9d24999eb6 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -49,6 +49,7 @@ pub enum GameInput { Interact, ToggleWield, Charge, + FreeLook, } /// Represents a key that the game menus recognise after input mapping @@ -458,6 +459,9 @@ impl Window { map.entry(settings.controls.charge) .or_default() .push(GameInput::Charge); + map.entry(settings.controls.free_look) + .or_default() + .push(GameInput::FreeLook); let keypress_map = HashMap::new();