コード例 #1
0
        void charInventory_CellMouseDown(object sender, InventoryWindowEventArgs e)
        {
            var keyboard = _inputManager.KeyboardManager.CurKeyboardState;

            if (_dragControl.Slot == null)
            {
                // taking item
                var slot = e.Container.PeekSlot(e.SlotPosition);

                if (slot != null)
                {
                    if (ContainerInventoryWindow != null && e.MouseState.RightButton == S33M3CoreComponents.Inputs.MouseHandler.ButtonState.Pressed && !keyboard.IsKeyDown(Keys.ShiftKey))
                    {
                        var targetContainer = e.Container != PlayerInventoryWindow.Content ? PlayerInventoryWindow.Content : ContainerInventoryWindow.Content;

                        // quick transfer
                        if (targetContainer == null)
                        {
                            targetContainer = PlayerManager.PlayerCharacter.Equipment;
                        }

                        if (targetContainer.CanPut(slot.Item, slot.ItemsCount) && e.Container.TakeItem(slot.GridPosition, slot.ItemsCount))
                        {
                            OnSlotTaken(slot);
                            targetContainer.PutItem(slot.Item, slot.ItemsCount);
                            OnSlotPut(slot);
                        }

                        return;
                    }

                    var itemsCount = slot.ItemsCount;

                    if (e.MouseState.RightButton == S33M3CoreComponents.Inputs.MouseHandler.ButtonState.Pressed)
                    {
                        itemsCount = 1;
                    }

                    if (keyboard.IsKeyDown(Keys.ShiftKey) && itemsCount > 1)
                    {
                        itemsCount = slot.ItemsCount / 2;
                    }

                    if (!e.Container.TakeItem(slot.GridPosition, itemsCount))
                    {
                        throw new InvalidOperationException();
                    }

                    slot.ItemsCount = itemsCount;

                    BeginDrag(slot);

                    _sourceContainer = e.Container;

                    OnSlotTaken(slot);
                }
            }
        }
コード例 #2
0
        private void OnMouseDown(InventoryWindowEventArgs e)
        {
            var handler = CellMouseDown;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #3
0
        protected void OnSlotClicked(InventoryWindowEventArgs e)
        {
            var handler = InventorySlotClicked;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #4
0
        void charInventory_CellMouseUp(object sender, InventoryWindowEventArgs e)
        {
            var keyboard = _inputManager.KeyboardManager.CurKeyboardState;

            if (_dragControl.Slot != null)
            {
                if (_hoverSlot == null)
                {
                    CancelDrag();
                    return;
                }

                if (_hoverSlot.Parent == _toolBar)
                {
                    ToolBarSlotClicked(sender, new InventoryWindowCellMouseEventArgs {
                        Cell = _hoverSlot
                    });
                    CancelDrag();
                    return;
                }

                e = ((InventoryWindow)_hoverSlot.Parent).CreateEventArgs(_hoverSlot);

                // put item

                // check slot we want to put to
                var slot = e.Container.PeekSlot(e.SlotPosition);

                if (slot != null && !slot.CanStackWith(_dragControl.Slot))
                {
                    // exchange

                    // first check if we can perform exchange here, we can't if we took not the whole pack
                    var srcSlot = _sourceContainer.PeekSlot(_dragControl.Slot.GridPosition);
                    if (srcSlot != null)
                    {
                        CancelDrag();
                    }
                    else
                    {
                        var prevPosition = _dragControl.Slot.GridPosition;
                        _dragControl.Slot.GridPosition = e.SlotPosition;
                        ContainedSlot slotTaken;
                        if (!e.Container.PutItemExchange(_dragControl.Slot.Item, _dragControl.Slot.GridPosition, _dragControl.Slot.ItemsCount, out slotTaken))
                        {
                            throw new InvalidOperationException();
                        }

                        OnSlotPut(_dragControl.Slot);

                        slotTaken.GridPosition = prevPosition;
                        UpdateDrag(slotTaken);
                        CancelDrag();
                    }
                }
                else
                {
                    // just put, gonna be okay, da da doo-doo-mmm
                    _dragControl.Slot.GridPosition = e.SlotPosition;

                    var itemsCount = _dragControl.Slot.ItemsCount;

                    if (e.MouseState.RightButton == S33M3CoreComponents.Inputs.MouseHandler.ButtonState.Pressed)
                    {
                        if (keyboard.IsKeyDown(Keys.ShiftKey) && itemsCount > 1)
                        {
                            itemsCount = itemsCount / 2;
                        }
                        else
                        {
                            itemsCount = 1;
                        }
                    }

                    if (!e.Container.PutItem(_dragControl.Slot.Item, _dragControl.Slot.GridPosition, itemsCount))
                    {
                        throw new InvalidOperationException();
                    }

                    OnSlotPut(_dragControl.Slot);

                    _dragControl.Slot.ItemsCount -= itemsCount;
                    if (_dragControl.Slot.ItemsCount == 0)
                    {
                        EndDrag();
                    }
                    else
                    {
                        _dragControl.BringToFront();
                    }
                }
            }
        }