7dac46ec3c
A carried bundle clicked on a stack took its place instead of taking it in (#1456): Horizon's menus had no BundleItem click overrides. The PICKUP click now runs them first, as AbstractContainerMenu.tryItemClickBehaviourOverride: - a carried bundle takes as much of a clicked stack as its weight allows (tryTransfer), and a right click on an empty slot puts its first stack there (removeOne, the rest going back in); - a stack clicked onto a bundle in a slot goes in as far as it fits, and a right click with an empty hand takes the bundle's first stack out. BundleContents.Mutable is in horizon_client::bundle (exact Fraction weights: 1/max stack, 1 for a beehive with bees, a nested bundle's contents plus 1/16; shulker boxes don't fit), used by the menu engine and the LAN/server-thread container engine. The insert, insert-fail and remove-one sounds play at the player. In single player the inventory screen's empty-hand press went to an older click path instead of the menu engine; it now goes to the engine, as on a server, so the right click on a bundle works there too. The menu click harness now has bundles (empty, loaded, nested; often in hand) and compares the player's sounds: 3000/3000 bundle-heavy cases match, 2796/3000 without the overrides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.8 KiB
Rust
96 lines
3.8 KiB
Rust
//! `BundleItem`'s click overrides in a PICKUP click
|
|
//! (`tryItemClickBehaviourOverride`).
|
|
use super::{Env, Menu, tidy};
|
|
use crate::bundle::{Contents, INSERT, INSERT_FAIL, REMOVE_ONE, can_be_in_bundle};
|
|
|
|
impl Menu {
|
|
/// The carried stack's `overrideStackedOnOther`, then the clicked
|
|
/// one's `overrideOtherStackedOnMe`. True when a bundle took the click.
|
|
pub(super) fn bundle_click(&mut self, env: &Env, s: usize, primary: bool) -> bool {
|
|
self.carried_bundle_click(env, s, primary) || self.clicked_bundle_click(env, s, primary)
|
|
}
|
|
|
|
/// `BundleItem.overrideStackedOnOther`: the carried bundle on a slot.
|
|
fn carried_bundle_click(&mut self, env: &Env, s: usize, primary: bool) -> bool {
|
|
let Some(mut contents) = self
|
|
.carried
|
|
.as_ref()
|
|
.and_then(|c| Contents::of(env.items, c))
|
|
else {
|
|
return false;
|
|
};
|
|
match (self.slot(s).cloned(), primary) {
|
|
(Some(other), true) => {
|
|
// tryTransfer: what fits, taken by the slot's rules.
|
|
let mut moved = 0;
|
|
if can_be_in_bundle(&other) {
|
|
let room = contents.room_for(env.items, &other);
|
|
if let Some(mut taken) = self.safe_take(env, s, other.count, room) {
|
|
moved = contents.try_insert(env.items, &mut taken);
|
|
}
|
|
}
|
|
self.player_sounds
|
|
.push(if moved > 0 { INSERT } else { INSERT_FAIL });
|
|
}
|
|
(None, false) => {
|
|
if let Some(stack) = contents.remove_one(env.items) {
|
|
let count = stack.count;
|
|
let mut remainder = Some(stack);
|
|
self.safe_insert(env, s, &mut remainder, count);
|
|
match remainder {
|
|
Some(mut rest) => {
|
|
contents.try_insert(env.items, &mut rest);
|
|
}
|
|
None => self.player_sounds.push(REMOVE_ONE),
|
|
}
|
|
}
|
|
}
|
|
_ => return false,
|
|
}
|
|
if let Some(carried) = self.carried.as_mut() {
|
|
contents.store(carried);
|
|
}
|
|
true
|
|
}
|
|
|
|
/// `BundleItem.overrideOtherStackedOnMe`: a click on a bundle in a slot.
|
|
fn clicked_bundle_click(&mut self, env: &Env, s: usize, primary: bool) -> bool {
|
|
let Some(mut bundle) = self.slot(s).cloned() else {
|
|
return false;
|
|
};
|
|
let Some(mut contents) = Contents::of(env.items, &bundle) else {
|
|
return false;
|
|
};
|
|
let allowed = self.allow_modification(env, s);
|
|
match (self.carried.take(), primary) {
|
|
(Some(mut other), true) => {
|
|
let moved = if allowed {
|
|
contents.try_insert(env.items, &mut other)
|
|
} else {
|
|
0
|
|
};
|
|
self.player_sounds
|
|
.push(if moved > 0 { INSERT } else { INSERT_FAIL });
|
|
self.carried = Some(other);
|
|
tidy(&mut self.carried);
|
|
}
|
|
(None, false) => {
|
|
if allowed && let Some(removed) = contents.remove_one(env.items) {
|
|
self.player_sounds.push(REMOVE_ONE);
|
|
self.carried = Some(removed);
|
|
}
|
|
}
|
|
(carried, _) => {
|
|
// toggleSelectedItem(-1): Horizon keeps no selected item.
|
|
self.carried = carried;
|
|
return false;
|
|
}
|
|
}
|
|
// `self.set(BUNDLE_CONTENTS, ...)` changes the slot's stack in place.
|
|
contents.store(&mut bundle);
|
|
let slot = self.slots[s];
|
|
self.containers[slot.container][slot.index] = Some(bundle);
|
|
true
|
|
}
|
|
}
|