public static bool Execute(ItemSlotControl slotControl, IItem itemInHand, bool isLeftMouseButton, bool isDown) { var itemInSlot = slotControl.Item; if (itemInSlot is null && itemInHand is null) { return(false); } var context = new Context(slotControl, itemInHand, isLeftMouseButton); if (!isDown && (context.IsShiftHeld || context.IsControlHeld)) { // we don't allow modifier actions on button up // no operation executed return(false); } // try execute operations one by one foreach (var operation in Cases) { if (operation(context)) { return(true); } } // no operation executed return(false); }
public GameObject SetItemButton(Transform position) { var newButton = Instantiate(itemButton, position); _itemSlotControl = newButton.GetComponent <ItemSlotControl>(); return(newButton); }
public GameObject SetItemImage(Transform position) { var newImage = Instantiate(itemImage, position); _itemSlotControl = newImage.GetComponent <ItemSlotControl>(); return(newImage); }
public Context(ItemSlotControl slotControl, IItem itemInHand, bool isLeftMouseButton) { var itemInSlot = slotControl.Item; this.ItemInSlot = itemInSlot; this.ItemInHand = itemInHand; this.IsLeftMouseButton = isLeftMouseButton; this.SlotContainer = slotControl.Container; this.SlotContainerSlotId = slotControl.SlotId; this.CanStackItems = itemInHand is not null && itemInHand.ProtoItem.IsStackable && itemInSlot is not null && itemInHand.Container.CanStackItems(itemInHand, itemInSlot); this.TargetContainers = itemInSlot is not null ? ClientContainersExchangeManager.GetTargetContainers(itemInSlot.Container) : null; this.IsShiftHeld = Input.IsKeyHeld(InputKey.Shift, evenIfHandled: true); this.IsControlHeld = Input.IsKeyHeld(InputKey.Control, evenIfHandled: true); this.IsAltHeld = Input.IsKeyHeld(InputKey.Alt, evenIfHandled: true); }
protected override void InitControl() { this.itemSlotControl = this.GetByName <ItemSlotControl>("ItemSlotControl"); }