Allow using stack splitting into or out of a trade.

This commit is contained in:
Avi Weinstock 2021-03-03 18:19:10 -05:00
parent dd2097ac75
commit 0472956b5c
2 changed files with 24 additions and 63 deletions

View File

@ -2825,6 +2825,28 @@ impl Hud {
} else if let (Hotbar(a), Hotbar(b)) = (a, b) {
self.hotbar.swap(a, b);
events.push(Event::ChangeHotbarState(Box::new(self.hotbar.to_owned())));
} else if let (Inventory(i), Trade(t)) = (a, b) {
if i.ours == t.ours {
if let Some(inventory) = inventories.get(t.entity) {
events.push(Event::TradeAction(TradeAction::AddItem {
item: i.slot,
quantity: i.amount(inventory).unwrap_or(1) / 2,
ours: i.ours,
}));
}
}
} else if let (Trade(t), Inventory(i)) = (a, b) {
if i.ours == t.ours {
if let Some(inventory) = inventories.get(t.entity) {
if let Some(invslot) = t.invslot {
events.push(Event::TradeAction(TradeAction::RemoveItem {
item: invslot,
quantity: t.amount(inventory).unwrap_or(1) / 2,
ours: t.ours,
}));
}
}
}
}
},
slot::Event::Used(from) => {

View File

@ -186,69 +186,8 @@ impl Default for ControlSettings {
keybindings: HashMap::new(),
inverse_keybindings: HashMap::new(),
};
// Sets the initial keybindings for those GameInputs. If a new one is created in
// future, you'll have to update default_binding, and you should update this vec
// too.
let game_inputs = vec![
GameInput::Primary,
GameInput::Secondary,
GameInput::ToggleCursor,
GameInput::MoveForward,
GameInput::MoveBack,
GameInput::MoveLeft,
GameInput::MoveRight,
GameInput::Jump,
GameInput::Sit,
GameInput::Dance,
GameInput::Glide,
GameInput::Climb,
GameInput::ClimbDown,
GameInput::SwimUp,
GameInput::SwimDown,
GameInput::Fly,
GameInput::Sneak,
//GameInput::WallLeap,
GameInput::ToggleLantern,
GameInput::Mount,
GameInput::Chat,
GameInput::Command,
GameInput::Escape,
GameInput::Map,
GameInput::Bag,
GameInput::Social,
GameInput::Crafting,
GameInput::Spellbook,
GameInput::Settings,
GameInput::ToggleInterface,
GameInput::Help,
GameInput::ToggleDebug,
GameInput::Fullscreen,
GameInput::Screenshot,
GameInput::ToggleIngameUi,
GameInput::Roll,
GameInput::Respawn,
GameInput::Interact,
GameInput::ToggleWield,
//GameInput::Charge,
GameInput::FreeLook,
GameInput::AutoWalk,
GameInput::CycleCamera,
GameInput::Slot1,
GameInput::Slot2,
GameInput::Slot3,
GameInput::Slot4,
GameInput::Slot5,
GameInput::Slot6,
GameInput::Slot7,
GameInput::Slot8,
GameInput::Slot9,
GameInput::Slot10,
GameInput::SwapLoadout,
GameInput::Select,
GameInput::AcceptGroupInvite,
GameInput::DeclineGroupInvite,
];
for game_input in game_inputs {
// Sets the initial keybindings for those GameInputs.
for game_input in GameInput::iterator() {
new_settings.insert_binding(game_input, ControlSettings::default_binding(game_input));
}
new_settings