Fix panic with dragging into the same loadout slot

This commit is contained in:
Imbris 2020-04-24 00:50:16 -04:00
parent 78f3f2cc32
commit 8aa88b22a5
3 changed files with 14 additions and 2 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

@ -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