This commit is contained in:
Capucho 2020-03-26 21:22:21 +00:00 committed by Imbris
parent 9cb8dc1df1
commit 03396eb77e
6 changed files with 45 additions and 3 deletions

View File

@ -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 authentication system (to play on the official server register on https://account.veloren.net)
- Added gamepad/controller support - Added gamepad/controller support
- Added player feedback when attempting to pickup an item with a full inventory - Added player feedback when attempting to pickup an item with a full inventory
- Added free look
### Changed ### Changed

View File

@ -327,6 +327,8 @@ Chat commands:
"hud.social.play_online_fmt": "{nb_player} player(s) online", "hud.social.play_online_fmt": "{nb_player} player(s) online",
"hud.spell": "Spell", "hud.spell": "Spell",
"hud.free_look_indicator": "Free look active",
/// End HUD section /// End HUD section

View File

@ -56,6 +56,7 @@ use vek::*;
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0); 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_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 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 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); //const TEXT_COLOR_2: Color = Color::Rgba(0.0, 0.0, 0.0, 1.0);
@ -175,6 +176,10 @@ widget_ids! {
small_window, small_window,
social_window, social_window,
settings_window, settings_window,
// Free look indicator
free_look_txt,
free_look_bg,
} }
} }
@ -285,6 +290,7 @@ pub struct Show {
settings_tab: SettingsTab, settings_tab: SettingsTab,
social_tab: SocialTab, social_tab: SocialTab,
want_grab: bool, want_grab: bool,
free_look: bool,
} }
impl Show { impl Show {
fn bag(&mut self, open: bool) { fn bag(&mut self, open: bool) {
@ -507,6 +513,7 @@ impl Hud {
social_tab: SocialTab::Online, social_tab: SocialTab::Online,
want_grab: true, want_grab: true,
ingame: true, ingame: true,
free_look: false,
}, },
to_focus: None, to_focus: None,
never_show: false, 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 events
} }
@ -2132,4 +2155,6 @@ impl Hud {
self.ui.render(renderer, Some(globals)); self.ui.render(renderer, Some(globals));
} }
} }
pub fn free_look(&mut self, free_look: bool) { self.show.free_look = free_look; }
} }

View File

@ -154,6 +154,9 @@ impl PlayState for SessionState {
) )
.unwrap(); .unwrap();
let mut ori = self.scene.camera().get_orientation();
let mut free_look = false;
// Game loop // Game loop
let mut current_client_state = self.client.borrow().get_client_state(); let mut current_client_state = self.client.borrow().get_client_state();
while let ClientState::Pending | ClientState::Character = current_client_state { while let ClientState::Pending | ClientState::Character = current_client_state {
@ -399,6 +402,10 @@ impl PlayState for SessionState {
Event::InputUpdate(GameInput::Charge, state) => { Event::InputUpdate(GameInput::Charge, state) => {
self.inputs.charge.set_state(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 { Event::AnalogGameInput(input) => match input {
AnalogGameInput::MovementX(v) => { AnalogGameInput::MovementX(v) => {
self.key_state.analog_matrix.x = 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 // Calculate the movement input vector of the player from the current key
// presses and the camera direction. // presses and the camera direction.
let ori = self.scene.camera().get_orientation();
let unit_vecs = ( let unit_vecs = (
Vec2::new(ori[0].cos(), -ori[0].sin()), Vec2::new(ori[0].cos(), -ori[0].sin()),
Vec2::new(ori[0].sin(), ori[0].cos()), Vec2::new(ori[0].sin(), ori[0].cos()),
@ -428,8 +438,6 @@ impl PlayState for SessionState {
let dir_vec = self.key_state.dir_vec(); 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.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 // Runs if either in a multiplayer server or the singleplayer server is unpaused
if global_state.singleplayer.is_none() if global_state.singleplayer.is_none()
|| !global_state.singleplayer.as_ref().unwrap().is_paused() || !global_state.singleplayer.as_ref().unwrap().is_paused()

View File

@ -51,6 +51,7 @@ pub struct ControlSettings {
pub interact: KeyMouse, pub interact: KeyMouse,
pub toggle_wield: KeyMouse, pub toggle_wield: KeyMouse,
pub charge: KeyMouse, pub charge: KeyMouse,
pub free_look: KeyMouse,
} }
/// Since Macbook trackpads lack middle click, on OS X we default to LShift /// 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), interact: KeyMouse::Mouse(MouseButton::Right),
toggle_wield: KeyMouse::Key(VirtualKeyCode::T), toggle_wield: KeyMouse::Key(VirtualKeyCode::T),
charge: KeyMouse::Key(VirtualKeyCode::Key1), charge: KeyMouse::Key(VirtualKeyCode::Key1),
free_look: KeyMouse::Key(VirtualKeyCode::LAlt),
} }
} }
} }

View File

@ -49,6 +49,7 @@ pub enum GameInput {
Interact, Interact,
ToggleWield, ToggleWield,
Charge, Charge,
FreeLook,
} }
/// Represents a key that the game menus recognise after input mapping /// Represents a key that the game menus recognise after input mapping
@ -458,6 +459,9 @@ impl Window {
map.entry(settings.controls.charge) map.entry(settings.controls.charge)
.or_default() .or_default()
.push(GameInput::Charge); .push(GameInput::Charge);
map.entry(settings.controls.free_look)
.or_default()
.push(GameInput::FreeLook);
let keypress_map = HashMap::new(); let keypress_map = HashMap::new();