mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
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:
commit
ad2fadf8bc
@ -140,15 +140,20 @@ pub struct Show {
|
||||
want_grab: bool,
|
||||
}
|
||||
impl Show {
|
||||
fn toggle_bag(&mut self) {
|
||||
self.bag = !self.bag;
|
||||
self.want_grab = !self.bag;
|
||||
fn bag(&mut self, open: bool) {
|
||||
self.bag = open;
|
||||
self.want_grab = !open;
|
||||
}
|
||||
|
||||
fn toggle_map(&mut self) {
|
||||
self.map = !self.map;
|
||||
fn toggle_bag(&mut self) {
|
||||
self.bag(!self.bag);
|
||||
}
|
||||
fn map(&mut self, open: bool) {
|
||||
self.map = open;
|
||||
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) {
|
||||
@ -179,13 +184,20 @@ impl Show {
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_settings(&mut self) {
|
||||
self.open_windows = match self.open_windows {
|
||||
Windows::Settings => Windows::None,
|
||||
_ => Windows::Settings,
|
||||
fn settings(&mut self, open: bool) {
|
||||
self.open_windows = if open {
|
||||
Windows::Settings
|
||||
} else {
|
||||
Windows::None
|
||||
};
|
||||
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) {
|
||||
@ -287,20 +299,29 @@ impl Hud {
|
||||
let actor = ecs.read_storage::<comp::Actor>();
|
||||
let pos = ecs.read_storage::<comp::phys::Pos>();
|
||||
let stats = ecs.read_storage::<comp::Stats>();
|
||||
let player = ecs.read_storage::<comp::Player>();
|
||||
let entities = ecs.entities();
|
||||
let player = client.entity();
|
||||
let me = client.entity();
|
||||
let mut name_id_walker = self.ids.name_tags.walk();
|
||||
let mut health_id_walker = self.ids.health_bars.walk();
|
||||
let mut health_back_id_walker = self.ids.health_bar_backs.walk();
|
||||
for (pos, name) in
|
||||
(&entities, &pos, &actor)
|
||||
.join()
|
||||
.filter_map(|(entity, pos, actor)| match actor {
|
||||
comp::Actor::Character { name, .. } if entity != player => {
|
||||
Some((pos.0, name))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
for (pos, name) in (&entities, &pos, &actor, player.maybe())
|
||||
.join()
|
||||
.filter(|(entity, _, _, _)| *entity != me)
|
||||
.map(|(entity, pos, actor, player)| match actor {
|
||||
comp::Actor::Character {
|
||||
name: char_name, ..
|
||||
} => {
|
||||
// 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(
|
||||
&mut self.ids.name_tags,
|
||||
@ -317,7 +338,7 @@ impl Hud {
|
||||
for (pos, hp) in (&entities, &pos, &stats)
|
||||
.join()
|
||||
.filter_map(|(entity, pos, stats)| {
|
||||
if entity != player {
|
||||
if entity != me {
|
||||
Some((pos.0, stats.hp))
|
||||
} else {
|
||||
None
|
||||
@ -444,7 +465,10 @@ impl Hud {
|
||||
match Bag::new(self.inventory_space, &self.imgs, &self.fonts)
|
||||
.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 => {}
|
||||
}
|
||||
}
|
||||
@ -490,7 +514,10 @@ impl Hud {
|
||||
self.show.inventory_test_button = !self.show.inventory_test_button
|
||||
}
|
||||
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) => {
|
||||
events.push(Event::AdjustViewDistance(view_distance));
|
||||
}
|
||||
@ -538,7 +565,10 @@ impl Hud {
|
||||
// Map
|
||||
if self.show.map {
|
||||
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 => {}
|
||||
}
|
||||
}
|
||||
@ -550,7 +580,11 @@ impl Hud {
|
||||
self.show.esc_menu = false;
|
||||
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::Quit) => events.push(Event::Quit),
|
||||
None => {}
|
||||
|
@ -41,6 +41,8 @@ pub struct ControlSettings {
|
||||
pub fullscreen: VirtualKeyCode,
|
||||
pub screenshot: VirtualKeyCode,
|
||||
pub toggle_ingame_ui: VirtualKeyCode,
|
||||
pub pan_sensitivity: f32,
|
||||
pub zoom_sensitivity: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@ -97,6 +99,8 @@ impl Default for Settings {
|
||||
fullscreen: VirtualKeyCode::F11,
|
||||
screenshot: VirtualKeyCode::F4,
|
||||
toggle_ingame_ui: VirtualKeyCode::F6,
|
||||
pan_sensitivity: 1.0,
|
||||
zoom_sensitivity: 1.0,
|
||||
},
|
||||
networking: NetworkingSettings {
|
||||
username: "Username".to_string(),
|
||||
|
@ -11,10 +11,13 @@ pub struct Window {
|
||||
renderer: Renderer,
|
||||
window: glutin::GlWindow,
|
||||
cursor_grabbed: bool,
|
||||
pub pan_sensitivity: f32,
|
||||
pub zoom_sensitivity: f32,
|
||||
fullscreen: bool,
|
||||
needs_refresh_resize: bool,
|
||||
key_map: HashMap<glutin::VirtualKeyCode, Key>,
|
||||
supplement_events: Vec<Event>,
|
||||
focused: bool,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
@ -62,17 +65,19 @@ impl Window {
|
||||
key_map.insert(settings.controls.screenshot, Key::Screenshot);
|
||||
key_map.insert(settings.controls.toggle_ingame_ui, Key::ToggleIngameUi);
|
||||
|
||||
let tmp = Ok(Self {
|
||||
Ok(Self {
|
||||
events_loop,
|
||||
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
|
||||
window,
|
||||
cursor_grabbed: false,
|
||||
pan_sensitivity: settings.controls.pan_sensitivity,
|
||||
zoom_sensitivity: settings.controls.zoom_sensitivity,
|
||||
fullscreen: false,
|
||||
needs_refresh_resize: false,
|
||||
key_map,
|
||||
supplement_events: vec![],
|
||||
});
|
||||
tmp
|
||||
focused: true,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn renderer(&self) -> &Renderer {
|
||||
@ -96,7 +101,10 @@ impl Window {
|
||||
let cursor_grabbed = self.cursor_grabbed;
|
||||
let renderer = &mut self.renderer;
|
||||
let window = &mut self.window;
|
||||
let focused = &mut self.focused;
|
||||
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 take_screenshot = false;
|
||||
|
||||
@ -138,18 +146,22 @@ impl Window {
|
||||
},
|
||||
_ => {}
|
||||
},
|
||||
glutin::WindowEvent::Focused(new_focus) => *focused = new_focus,
|
||||
_ => {}
|
||||
},
|
||||
glutin::Event::DeviceEvent { event, .. } => match event {
|
||||
glutin::DeviceEvent::MouseMotion {
|
||||
delta: (dx, dy), ..
|
||||
} if cursor_grabbed => {
|
||||
events.push(Event::CursorPan(Vec2::new(dx as f32, dy as f32)))
|
||||
}
|
||||
} if cursor_grabbed && *focused => events.push(Event::CursorPan(Vec2::new(
|
||||
dx as f32 * pan_sensitivity,
|
||||
dy as f32 * pan_sensitivity,
|
||||
))),
|
||||
glutin::DeviceEvent::MouseWheel {
|
||||
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))
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
|
Loading…
Reference in New Issue
Block a user