mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix panic with dragging into the same loadout slot
This commit is contained in:
parent
78f3f2cc32
commit
8aa88b22a5
@ -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);
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user