Merge branch 'fixes_and_tweaks' into 'master'

Fixes and tweaks

Closes #104

See merge request veloren/veloren!175

Former-commit-id: a0dee8b70c9b2a0dffa287d1fda371b0f216287a
This commit is contained in:
Imbris 2019-05-25 14:05:10 +00:00
commit ad2fadf8bc
3 changed files with 84 additions and 34 deletions

View File

@ -140,15 +140,20 @@ pub struct Show {
want_grab: bool, want_grab: bool,
} }
impl Show { impl Show {
fn toggle_bag(&mut self) { fn bag(&mut self, open: bool) {
self.bag = !self.bag; self.bag = open;
self.want_grab = !self.bag; self.want_grab = !open;
} }
fn toggle_bag(&mut self) {
fn toggle_map(&mut self) { self.bag(!self.bag);
self.map = !self.map; }
fn map(&mut self, open: bool) {
self.map = open;
self.bag = false; self.bag = false;
self.want_grab = !self.map; self.want_grab = !open;
}
fn toggle_map(&mut self) {
self.map(!self.map)
} }
fn toggle_mini_map(&mut self) { fn toggle_mini_map(&mut self) {
@ -179,13 +184,20 @@ impl Show {
} }
} }
fn toggle_settings(&mut self) { fn settings(&mut self, open: bool) {
self.open_windows = match self.open_windows { self.open_windows = if open {
Windows::Settings => Windows::None, Windows::Settings
_ => Windows::Settings, } else {
Windows::None
}; };
self.bag = false; self.bag = false;
self.want_grab = self.open_windows != Windows::Settings; self.want_grab = !open;
}
fn toggle_settings(&mut self) {
match self.open_windows {
Windows::Settings => self.settings(false),
_ => self.settings(true),
};
} }
fn toggle_help(&mut self) { fn toggle_help(&mut self) {
@ -287,20 +299,29 @@ impl Hud {
let actor = ecs.read_storage::<comp::Actor>(); let actor = ecs.read_storage::<comp::Actor>();
let pos = ecs.read_storage::<comp::phys::Pos>(); let pos = ecs.read_storage::<comp::phys::Pos>();
let stats = ecs.read_storage::<comp::Stats>(); let stats = ecs.read_storage::<comp::Stats>();
let player = ecs.read_storage::<comp::Player>();
let entities = ecs.entities(); let entities = ecs.entities();
let player = client.entity(); let me = client.entity();
let mut name_id_walker = self.ids.name_tags.walk(); let mut name_id_walker = self.ids.name_tags.walk();
let mut health_id_walker = self.ids.health_bars.walk(); let mut health_id_walker = self.ids.health_bars.walk();
let mut health_back_id_walker = self.ids.health_bar_backs.walk(); let mut health_back_id_walker = self.ids.health_bar_backs.walk();
for (pos, name) in for (pos, name) in (&entities, &pos, &actor, player.maybe())
(&entities, &pos, &actor) .join()
.join() .filter(|(entity, _, _, _)| *entity != me)
.filter_map(|(entity, pos, actor)| match actor { .map(|(entity, pos, actor, player)| match actor {
comp::Actor::Character { name, .. } if entity != player => { comp::Actor::Character {
Some((pos.0, name)) name: char_name, ..
} } => {
_ => None, // Temporary
}) // If the player used the default character name display thier name instead
let name = if char_name == "Character Name" {
player.map_or(char_name, |p| &p.alias)
} else {
char_name
};
(pos.0, name)
}
})
{ {
let id = name_id_walker.next( let id = name_id_walker.next(
&mut self.ids.name_tags, &mut self.ids.name_tags,
@ -317,7 +338,7 @@ impl Hud {
for (pos, hp) in (&entities, &pos, &stats) for (pos, hp) in (&entities, &pos, &stats)
.join() .join()
.filter_map(|(entity, pos, stats)| { .filter_map(|(entity, pos, stats)| {
if entity != player { if entity != me {
Some((pos.0, stats.hp)) Some((pos.0, stats.hp))
} else { } else {
None None
@ -444,7 +465,10 @@ impl Hud {
match Bag::new(self.inventory_space, &self.imgs, &self.fonts) match Bag::new(self.inventory_space, &self.imgs, &self.fonts)
.set(self.ids.bag, ui_widgets) .set(self.ids.bag, ui_widgets)
{ {
Some(bag::Event::Close) => self.show.bag = false, Some(bag::Event::Close) => {
self.show.bag(false);
self.force_ungrab = true;
}
None => {} None => {}
} }
} }
@ -490,7 +514,10 @@ impl Hud {
self.show.inventory_test_button = !self.show.inventory_test_button self.show.inventory_test_button = !self.show.inventory_test_button
} }
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug, settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
settings_window::Event::Close => self.show.open_windows = Windows::None, settings_window::Event::Close => {
self.show.settings(false);
self.force_ungrab = true;
}
settings_window::Event::AdjustViewDistance(view_distance) => { settings_window::Event::AdjustViewDistance(view_distance) => {
events.push(Event::AdjustViewDistance(view_distance)); events.push(Event::AdjustViewDistance(view_distance));
} }
@ -538,7 +565,10 @@ impl Hud {
// Map // Map
if self.show.map { if self.show.map {
match Map::new(&self.imgs, &self.fonts).set(self.ids.map, ui_widgets) { match Map::new(&self.imgs, &self.fonts).set(self.ids.map, ui_widgets) {
Some(map::Event::Close) => self.show.map = false, Some(map::Event::Close) => {
self.show.map(false);
self.force_ungrab = true;
}
None => {} None => {}
} }
} }
@ -550,7 +580,11 @@ impl Hud {
self.show.esc_menu = false; self.show.esc_menu = false;
self.show.open_windows = Windows::Settings; self.show.open_windows = Windows::Settings;
} }
Some(esc_menu::Event::Close) => self.show.esc_menu = false, Some(esc_menu::Event::Close) => {
self.show.esc_menu = false;
self.show.want_grab = false;
self.force_ungrab = true;
}
Some(esc_menu::Event::Logout) => events.push(Event::Logout), Some(esc_menu::Event::Logout) => events.push(Event::Logout),
Some(esc_menu::Event::Quit) => events.push(Event::Quit), Some(esc_menu::Event::Quit) => events.push(Event::Quit),
None => {} None => {}

View File

@ -41,6 +41,8 @@ pub struct ControlSettings {
pub fullscreen: VirtualKeyCode, pub fullscreen: VirtualKeyCode,
pub screenshot: VirtualKeyCode, pub screenshot: VirtualKeyCode,
pub toggle_ingame_ui: VirtualKeyCode, pub toggle_ingame_ui: VirtualKeyCode,
pub pan_sensitivity: f32,
pub zoom_sensitivity: f32,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
@ -97,6 +99,8 @@ impl Default for Settings {
fullscreen: VirtualKeyCode::F11, fullscreen: VirtualKeyCode::F11,
screenshot: VirtualKeyCode::F4, screenshot: VirtualKeyCode::F4,
toggle_ingame_ui: VirtualKeyCode::F6, toggle_ingame_ui: VirtualKeyCode::F6,
pan_sensitivity: 1.0,
zoom_sensitivity: 1.0,
}, },
networking: NetworkingSettings { networking: NetworkingSettings {
username: "Username".to_string(), username: "Username".to_string(),

View File

@ -11,10 +11,13 @@ pub struct Window {
renderer: Renderer, renderer: Renderer,
window: glutin::GlWindow, window: glutin::GlWindow,
cursor_grabbed: bool, cursor_grabbed: bool,
pub pan_sensitivity: f32,
pub zoom_sensitivity: f32,
fullscreen: bool, fullscreen: bool,
needs_refresh_resize: bool, needs_refresh_resize: bool,
key_map: HashMap<glutin::VirtualKeyCode, Key>, key_map: HashMap<glutin::VirtualKeyCode, Key>,
supplement_events: Vec<Event>, supplement_events: Vec<Event>,
focused: bool,
} }
impl Window { impl Window {
@ -62,17 +65,19 @@ impl Window {
key_map.insert(settings.controls.screenshot, Key::Screenshot); key_map.insert(settings.controls.screenshot, Key::Screenshot);
key_map.insert(settings.controls.toggle_ingame_ui, Key::ToggleIngameUi); key_map.insert(settings.controls.toggle_ingame_ui, Key::ToggleIngameUi);
let tmp = Ok(Self { Ok(Self {
events_loop, events_loop,
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?, renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
window, window,
cursor_grabbed: false, cursor_grabbed: false,
pan_sensitivity: settings.controls.pan_sensitivity,
zoom_sensitivity: settings.controls.zoom_sensitivity,
fullscreen: false, fullscreen: false,
needs_refresh_resize: false, needs_refresh_resize: false,
key_map, key_map,
supplement_events: vec![], supplement_events: vec![],
}); focused: true,
tmp })
} }
pub fn renderer(&self) -> &Renderer { pub fn renderer(&self) -> &Renderer {
@ -96,7 +101,10 @@ impl Window {
let cursor_grabbed = self.cursor_grabbed; let cursor_grabbed = self.cursor_grabbed;
let renderer = &mut self.renderer; let renderer = &mut self.renderer;
let window = &mut self.window; let window = &mut self.window;
let focused = &mut self.focused;
let key_map = &self.key_map; let key_map = &self.key_map;
let pan_sensitivity = self.pan_sensitivity;
let zoom_sensitivity = self.zoom_sensitivity;
let mut toggle_fullscreen = false; let mut toggle_fullscreen = false;
let mut take_screenshot = false; let mut take_screenshot = false;
@ -138,18 +146,22 @@ impl Window {
}, },
_ => {} _ => {}
}, },
glutin::WindowEvent::Focused(new_focus) => *focused = new_focus,
_ => {} _ => {}
}, },
glutin::Event::DeviceEvent { event, .. } => match event { glutin::Event::DeviceEvent { event, .. } => match event {
glutin::DeviceEvent::MouseMotion { glutin::DeviceEvent::MouseMotion {
delta: (dx, dy), .. delta: (dx, dy), ..
} if cursor_grabbed => { } if cursor_grabbed && *focused => events.push(Event::CursorPan(Vec2::new(
events.push(Event::CursorPan(Vec2::new(dx as f32, dy as f32))) dx as f32 * pan_sensitivity,
} dy as f32 * pan_sensitivity,
))),
glutin::DeviceEvent::MouseWheel { glutin::DeviceEvent::MouseWheel {
delta: glutin::MouseScrollDelta::LineDelta(_x, y), delta: glutin::MouseScrollDelta::LineDelta(_x, y),
.. ..
} if cursor_grabbed => events.push(Event::Zoom(y as f32)), } if cursor_grabbed && *focused => {
events.push(Event::Zoom(y as f32 * zoom_sensitivity))
}
_ => {} _ => {}
}, },
_ => {} _ => {}