Merge branch 'imbris/small-fixes' into 'master'

Fix leaning bug and dragging panic

Closes #534 and #547

See merge request veloren/veloren!974
This commit is contained in:
Imbris 2020-05-11 05:25:32 +00:00
commit 2b4de3730d
8 changed files with 53 additions and 15 deletions

View File

@ -1,5 +1,6 @@
use crate::{comp, comp::item};
use comp::{Inventory, Loadout};
use log::warn;
#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
pub enum Slot {
@ -169,6 +170,13 @@ fn swap_inventory_loadout(
}
fn swap_loadout(slot_a: EquipSlot, slot_b: EquipSlot, loadout: &mut Loadout) {
// Ensure that the slots are not the same (somehow the voxygen does this
// occasionsally)
if slot_a == slot_b {
warn!("Tried to swap equip slot with itself");
return;
}
// Get items from the slots
let item_a = loadout_remove(slot_a, loadout);
let item_b = loadout_remove(slot_b, loadout);

View File

@ -28,7 +28,7 @@ impl CharacterBehavior for Data {
* ROLL_SPEED;
// Smooth orientation
update.ori.0 = Dir::slerp_to_vec3(update.ori.0, update.vel.0, 9.0 * data.dt.0);
update.ori.0 = Dir::slerp_to_vec3(update.ori.0, update.vel.0.xy().into(), 9.0 * data.dt.0);
if self.remaining_duration == Duration::default() {
// Roll duration has expired

View File

@ -63,9 +63,11 @@ fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate, strength: f32) {
// Set direction based on move direction
let ori_dir = if update.character.is_attack() || update.character.is_block() {
Vec2::from(*data.inputs.look_dir)
data.inputs.look_dir.xy()
} else if !data.inputs.move_dir.is_approx_zero() {
data.inputs.move_dir
} else {
Vec2::from(data.inputs.move_dir)
update.ori.0.xy()
};
// Smooth orientation

View File

@ -22,18 +22,18 @@ pub trait CompPacket: Clone + Debug + Send + 'static {
/// Useful for implementing CompPacket trait
pub fn handle_insert<C: Component>(comp: C, entity: Entity, world: &World) {
if let Err(err) = world.write_storage::<C>().insert(entity, comp) {
error!("Error inserting component: {:?}", err);
error!("Error inserting : {:?}", err);
}
}
/// Useful for implementing CompPacket trait
pub fn handle_modify<C: Component>(comp: C, entity: Entity, world: &World) {
if world
.write_storage::<C>()
.get_mut(entity)
.map(|c| *c = comp)
.is_none()
{
error!("Error modifying synced component, it doesn't seem to exist");
pub fn handle_modify<C: Component + Debug>(comp: C, entity: Entity, world: &World) {
if let Some(c) = world.write_storage::<C>().get_mut(entity) {
*c = comp
} else {
error!(
"Error modifying synced component: {:?}, it doesn't seem to exist",
comp
);
}
}
/// Useful for implementing CompPacket trait

View File

@ -143,6 +143,7 @@ widget_ids! {
ping,
coordinates,
velocity,
orientation,
loaded_distance,
time,
entity_count,
@ -196,6 +197,7 @@ pub struct DebugInfo {
pub ping_ms: f64,
pub coordinates: Option<comp::Pos>,
pub velocity: Option<comp::Vel>,
pub ori: Option<comp::Ori>,
pub num_chunks: u32,
pub num_visible_chunks: u32,
pub num_figures: u32,
@ -1449,6 +1451,20 @@ impl Hud {
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(14))
.set(self.ids.velocity, ui_widgets);
// Player's orientation vector
let orientation_text = match debug_info.ori {
Some(ori) => format!(
"Orientation: ({:.1}, {:.1}, {:.1})",
ori.0.x, ori.0.y, ori.0.z,
),
None => "Player has no Ori component".to_owned(),
};
Text::new(&orientation_text)
.color(TEXT_COLOR)
.down_from(self.ids.velocity, 5.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(14))
.set(self.ids.orientation, ui_widgets);
// Loaded distance
Text::new(&format!(
"View distance: {:.2} blocks ({:.2} chunks)",
@ -1456,7 +1472,7 @@ impl Hud {
client.loaded_distance() / TerrainChunk::RECT_SIZE.x as f32,
))
.color(TEXT_COLOR)
.down_from(self.ids.velocity, 5.0)
.down_from(self.ids.orientation, 5.0)
.font_id(self.fonts.cyri.conrod_id)
.font_size(self.fonts.cyri.scale(14))
.set(self.ids.loaded_distance, ui_widgets);

View File

@ -497,6 +497,14 @@ impl PlayState for SessionState {
.read_storage::<Vel>()
.get(self.client.borrow().entity())
.cloned(),
ori: self
.client
.borrow()
.state()
.ecs()
.read_storage::<comp::Ori>()
.get(self.client.borrow().entity())
.cloned(),
num_chunks: self.scene.terrain().chunk_count() as u32,
num_visible_chunks: self.scene.terrain().visible_chunk_count() as u32,
num_figures: self.scene.figure_mgr().figure_count() as u32,

View File

@ -8,7 +8,7 @@ use conrod_core::{
};
/// This widget is like conrod's `Image` widget except it always returns false
/// for is_over
/// for is_over so widgets under it are still interactable
#[derive(WidgetCommon)]
pub struct GhostImage {
#[conrod(common_builder)]

View File

@ -166,7 +166,11 @@ where
self.events.push(Event::Dropped(*slot));
} else if let Some(idx) = slot_ids.iter().position(|slot_id| *slot_id == id) {
// If widget is a slot widget swap with it
self.events.push(Event::Dragged(*slot, slots[idx]));
let (from, to) = (*slot, slots[idx]);
// Don't drag if it is the same slot
if from != to {
self.events.push(Event::Dragged(from, to));
}
}
}
// Mouse released stop dragging