Exemplo n.º 1
0
        protected override bool OnMouseUp(EMouseButtons button)
        {
            if (Active)
            {
                foreach (Control c in Parent.Parent.Controls)
                {
                    SlotHolder receiver = c as SlotHolder;

                    if (receiver != null && receiver.CursorIsInArea())
                    {
                        SlotHolder sender = Parent as SlotHolder;
                        if (sender != null && sender != receiver)
                        {
                            SetSlot(sender, receiver);
                        }

                        break;
                    }
                }

                GetControlManager().PlaySound("VB\\Sounds\\InventoryPutDown.ogg");
                GetControlManager().DefaultCursor = "VB\\GUI\\Cursors\\GUIDefault.tga";
                Active = false;
            }

            return(base.OnMouseUp(button));
        }
Exemplo n.º 2
0
        protected override void OnAttach()
        {
            base.OnAttach();

            window = ControlDeclarationManager.Instance.CreateControl("VB\\GUI\\HUD\\playerInventory.gui");
            (window.Controls["inv"] as Inventory).FillItems(owner);

            //set owners for any slots
            foreach (Control c in window.Controls)
            {
                SlotHolder tmpHolder = c as SlotHolder;

                if (tmpHolder != null && tmpHolder.holderType > SlotHolder.HolderType.Inventory)
                {
                    tmpHolder.owner = owner;

                    VBCharacter rtsOwner = owner as VBCharacter;
                    if (rtsOwner != null)
                    {
                        switch (tmpHolder.holderType)
                        {
                        case SlotHolder.HolderType.Slot1:
                            if (rtsOwner.ActiveItems[0] > 0)
                            {
                                tmpHolder.Controls.Add(new TestSlot(owner.Inventory[rtsOwner.ActiveItems[0] - 1]));
                            }
                            break;

                        case SlotHolder.HolderType.Slot2:
                            if (rtsOwner.ActiveItems[1] > 0)
                            {
                                tmpHolder.Controls.Add(new TestSlot(owner.Inventory[rtsOwner.ActiveItems[1] - 1]));
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }

            Controls.Add(window);
        }
Exemplo n.º 3
0
        void SetSlot(SlotHolder _sender, SlotHolder _receiver)
        {
            if (_receiver.holderType > SlotHolder.HolderType.Inventory)
            {
                //TODO: SWAP ITEMS IN INVENTORY
                if (_receiver.Controls.Count != 0)
                {
                    return;
                }

                //TODO: MAKE RECEIVER CHECK FOR ITEM TYPE

                VBCharacter chSnd = _sender.owner as VBCharacter;
                switch (_receiver.holderType)
                {
                case SlotHolder.HolderType.Armor:
                    //set player armor
                    break;

                case SlotHolder.HolderType.Slot1:
                    if (chSnd != null)
                    {
                        chSnd.SetItem(assignedItem, true);
                    }
                    break;

                case SlotHolder.HolderType.Slot2:
                    if (chSnd != null)
                    {
                        chSnd.SetItem(assignedItem, false);
                    }
                    break;

                case SlotHolder.HolderType.Drop:
                    _sender.owner.DropItem(assignedItem);
                    break;
                }
            }
            else
            {
                if (_sender.holderType == SlotHolder.HolderType.Inventory)
                {
                    if (_receiver.owner.CanHoldItem(assignedItem.ItemType))
                    {
                        _sender.owner.Inventory.Remove(assignedItem);
                        _receiver.owner.Inventory.Add(assignedItem);
                    }
                    else
                    {
                        return;  //full stop
                    }
                }
            }

            //TODO: THE PROBLEM WITH THIS SYSTEM IS THAT OBJECTS CANNOT BE SWAPPED BETWEEN SLOTS, INSTEAD OF NOT ACCEPTING THE NEW HOLDER REMOVE THE PREVIOUS ONE

            //if my sender is on primary or secondary reset its slot
            VBCharacter chRec = _receiver.owner as VBCharacter;

            if (chRec != null)
            {
                if (_sender.holderType == SlotHolder.HolderType.Slot1)
                {
                    chRec.ResetSlot(true);
                }

                if (_sender.holderType == SlotHolder.HolderType.Slot2)
                {
                    chRec.ResetSlot(false);
                }
            }

            //if my quantity is > 1, then instead of swapping the slot, add a new identical one to the receiver
            //and decrease the quntity to the initial one while strring the new one to 0

            if (quantity > 1 && (assignedItem.ItemType as AmmoItemType) == null)
            {
                if (_receiver.holderType != SlotHolder.HolderType.Drop)
                {
                    //create a new and identical slot but with the assigned item of the other object
                    TestSlot stmp = new TestSlot(_sender.GetFirstOfTypeUnassignedItem(assignedItem.ItemType));
                    _receiver.Controls.Add(stmp);
                }

                SetQuantity(quantity - 1);
            }
            else
            {
                Position = new ScaleValue(ScaleType.ScaleByResolution, Vec2.Zero);
                Parent.Controls.Remove(this);

                if (_receiver.holderType != SlotHolder.HolderType.Drop && !_receiver.FoundAndUpdatedEntry(assignedItem))
                {
                    _receiver.Controls.Add(this);
                }
            }
        }