Esempio n. 1
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as InventoryForm.InventoryItemPB;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src == dest || src.Slot == dest.Slot)
            {
                return(false);
            }

            if (src.Parent != dest.Parent)
            {
                return(false);
            }

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToEquipped(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            src.InventoryForm.InvokeRequestUseItem(src.Slot);

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_EquippedItemToInventory(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (EquippedForm.EquippedItemPB)srcDDP;

            _gps.EquippedForm_RequestUnequip(src.EquippedForm, EventArgsHelper.Create(src.Slot));

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Sends an event for a mouse button being pressed to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonPressed(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            var c = UnderCursor;

            if (c != null)
            {
                _lastPressedControl = c;
            }

            // Handle a left mouse button press
            if (e.Button == MouseButton.Left)
            {
                // Update the focus control
                var lastFocused = FocusedControl;
                FocusedControl = c;

                // If the focused control changed, send the corresponding events
                if (lastFocused != FocusedControl)
                {
                    // Tell the old control it lost focus
                    if (lastFocused != null)
                    {
                        lastFocused.SendLostFocusEvent(e);
                    }
                }

                // Tell the new control is acquired focus
                if (FocusedControl != null)
                {
                    FocusedControl.SendFocusedEvent(e);

                    // Check if the new focused control supports drag-and-drop
                    var ddp = _underCursor as IDragDropProvider;
                    if (ddp != null && ddp.CanDragContents && !_underCursor.CanDrag)
                    {
                        _draggedDragDropProvider = ddp;
                    }
                }
            }

            // Forward the event to the focused control, if any
            if (c != null)
            {
                c.SendMouseButtonPressedEvent(e);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
        /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
        /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        bool IDragDropProvider.CanDrop(IDragDropProvider source)
        {
            // Only allow drag-and-drop when trading
            if (!IsTradeActive)
            {
                return(false);
            }

            // Only allow drag-and-drop from an inventory item control
            if (!(source is InventoryForm.InventoryItemPB))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_ShopItemToInventory(srcDDP, destDDP))
            {
                return(false);
            }

            var src = (ShopForm.ShopItemPB)srcDDP;

            using (var pw = ClientPacket.BuyFromShop(src.Slot, 1))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as EquippedForm.EquippedItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.EquippedForm == null)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as ShopForm.ShopItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.ShopForm.ShopInfo == null)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
        /// <see cref="IDragDropProvider"/>.</param>
        void IDragDropProvider.Drop(IDragDropProvider source)
        {
            var ptih = PeerTradeInfoHandler;

            if (ptih == null)
            {
                return;
            }

            // Handle an inventory item control
            var asInvItem = source as InventoryForm.InventoryItemPB;

            if (asInvItem != null)
            {
                AddToTrade(asInvItem.Slot);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToInventoryItem(srcDDP, destDDP))
            {
                return(false);
            }

            var src  = (InventoryForm.InventoryItemPB)srcDDP;
            var dest = (InventoryForm.InventoryItemPB)destDDP;

            using (var pw = ClientPacket.SwapInventorySlots(src.Slot, dest.Slot))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return(true);
        }
Esempio n. 11
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToShop(srcDDP, destDDP))
            {
                return(false);
            }

            if (UserInventory == null)
            {
                return(false);
            }

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            UserInventory.SellToShop(src.Slot, _gps.GUIManager);

            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// Handles the drag-and-drop for the given <see cref="IDragDropProvider"/>s.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        public void Drop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return;
            }

            // Use the first method that successfully handles the given source and destination
            for (var i = 0; i < _dropCallbacks.Length; i++)
            {
                if (_dropCallbacks[i](src, dest))
                {
                    return;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        /// <returns>True if the <paramref name="src"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        public bool CanDrop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return(false);
            }

            // Check if any of our implementations are supported
            for (var i = 0; i < _canDropCallbacks.Length; i++)
            {
                if (_canDropCallbacks[i](src, dest))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
        /// <summary>
        /// Sends an event for the mouse moving to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseMoved(MouseMoveEventArgs e)
        {
            UpdateControlUnderCursor(e);

            var c = UnderCursor;

            // Update the DropOntoContorl
            if (DraggedDragDropProvider != null)
            {
                // Take the control we already found as being under the cursor. Then, create a loop that will check if
                // the control implements IDragDropProvider. If not, grab the parent. This will either give us the first
                // control to implement IDragDropProvider, or null.
                var tmpDropOntoControl = c;
                while (tmpDropOntoControl != null)
                {
                    var asDDP = tmpDropOntoControl as IDragDropProvider;

                    // If the control implements IDragDropProvider, and we can drop onto it, use that. Otherwise, move onto the parent.
                    if (asDDP != null && asDDP.CanDrop(DraggedDragDropProvider))
                    {
                        break;
                    }

                    tmpDropOntoControl = tmpDropOntoControl.Parent;
                }

                // Store the results of the above loop, which will be either a valid control we can drop on, or null
                _dropOntoControl = tmpDropOntoControl as IDragDropProvider;
            }
            else
            {
                // Nothing is being dragged, so don't take the time to calculate the control to drop onto
                _dropOntoControl = null;
            }

            // Send the mouse moved event
            if (c != null)
            {
                c.SendMouseMoveEvent(e);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as IQuickBarItemProvider;
            var dest = destDDP as QuickBarForm.QuickBarItemPB;

            if (src == null || dest == null)
            {
                return(false);
            }

            // Check if can be added to quick bar
            QuickBarItemType type;
            int value;

            if (!src.TryAddToQuickBar(out type, out value))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 16
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as ShopForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (dest.ShopInfo == null)
            {
                return(false);
            }

            if (!dest.ShopInfo.CanBuy)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 17
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src  = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as EquippedForm;

            if (src == null || dest == null)
            {
                return(false);
            }

            if (src.Item == null)
            {
                return(false);
            }

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 18
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool Drop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_IQuickBarItemProviderToQuickBar(srcDDP, destDDP))
            {
                return(false);
            }

            var src  = (IQuickBarItemProvider)srcDDP;
            var dest = (QuickBarForm.QuickBarItemPB)destDDP;

            // Get the quick bar values
            QuickBarItemType type;
            int value;

            if (!src.TryAddToQuickBar(out type, out value))
            {
                return(false);
            }

            var oldType  = dest.QuickBarItemType;
            var oldValue = dest.QuickBarItemValue;

            // Set the quick bar values
            dest.SetQuickBar(type, value);

            // If the source was a quick bar item, too, then set the source's item to the dest's item to give a "swap"
            // instead of just "copying" the value.
            var srcQBI = src as QuickBarForm.QuickBarItemPB;

            if (srcQBI != null)
            {
                srcQBI.SetQuickBar(oldType, oldValue);
            }

            return(true);
        }
Esempio n. 19
0
        /// <summary>
        /// Sends an event for a mouse button being released to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonReleased(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            // If it was the left mouse button that was released, then stop dragging the drag-and-drop provider
            // control (if we have one)
            if (e.Button == MouseButton.Left && DraggedDragDropProvider != null)
            {
                if (DropOntoControl != null && DropOntoControl.CanDrop(DraggedDragDropProvider))
                {
                    DropOntoControl.Drop(DraggedDragDropProvider);
                }

                _draggedDragDropProvider = null;
            }

            // Forward the event to the control under the cursor
            var c = UnderCursor;

            if (c != null)
            {
                c.SendMouseButtonReleasedEvent(e);
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(false);
 }
Esempio n. 21
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return _dragDropHandler.CanDrop(source, this);
 }
Esempio n. 22
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return false;
 }
Esempio n. 23
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(_dragDropHandler.CanDrop(source, this));
 }
Esempio n. 24
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as ShopForm;

            if (src == null || dest == null)
                return false;

            if (dest.ShopInfo == null)
                return false;

            if (!dest.ShopInfo.CanBuy)
                return false;

            return true;
        }
Esempio n. 25
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as InventoryForm.InventoryItemPB;

            if (src == null || dest == null)
                return false;

            if (src == dest || src.Slot == dest.Slot)
                return false;

            if (src.Parent != dest.Parent)
                return false;

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
                return false;

            return true;
        }
Esempio n. 26
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     QuickBarForm._gps.DragDropHandler.Drop(source, this);
 }
Esempio n. 27
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as ShopForm.ShopItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
                return false;

            if (src.ShopForm.ShopInfo == null)
                return false;

            return true;
        }
Esempio n. 28
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     QuickBarForm._gps.DragDropHandler.Drop(source, this);
 }
Esempio n. 29
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return InventoryForm._dragDropHandler.CanDrop(source, this);
 }
Esempio n. 30
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return QuickBarForm._gps.DragDropHandler.CanDrop(source, this);
 }
Esempio n. 31
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     InventoryForm._dragDropHandler.Drop(source, this);
 }
Esempio n. 32
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(InventoryForm._dragDropHandler.CanDrop(source, this));
 }
Esempio n. 33
0
        /// <summary>
        /// Sends an event for a mouse button being released to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonReleased(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            // If it was the left mouse button that was released, then stop dragging the drag-and-drop provider
            // control (if we have one)
            if (e.Button == MouseButton.Left && DraggedDragDropProvider != null)
            {
                if (DropOntoControl != null && DropOntoControl.CanDrop(DraggedDragDropProvider))
                    DropOntoControl.Drop(DraggedDragDropProvider);

                _draggedDragDropProvider = null;
            }

            // Forward the event to the control under the cursor
            var c = UnderCursor;
            if (c != null)
                c.SendMouseButtonReleasedEvent(e);
        }
Esempio n. 34
0
        /// <summary>
        /// Sends an event for a mouse button being pressed to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseButtonPressed(MouseButtonEventArgs e)
        {
            UpdateControlUnderCursor(e.X, e.Y);

            var c = UnderCursor;

            if (c != null)
                _lastPressedControl = c;

            // Handle a left mouse button press
            if (e.Button == MouseButton.Left)
            {
                // Update the focus control
                var lastFocused = FocusedControl;
                FocusedControl = c;

                // If the focused control changed, send the corresponding events
                if (lastFocused != FocusedControl)
                {
                    // Tell the old control it lost focus
                    if (lastFocused != null)
                        lastFocused.SendLostFocusEvent(e);
                }

                // Tell the new control is acquired focus
                if (FocusedControl != null)
                {
                    FocusedControl.SendFocusedEvent(e);

                    // Check if the new focused control supports drag-and-drop
                    var ddp = _underCursor as IDragDropProvider;
                    if (ddp != null && ddp.CanDragContents && !_underCursor.CanDrag)
                        _draggedDragDropProvider = ddp;
                }
            }

            // Forward the event to the focused control, if any
            if (c != null)
                c.SendMouseButtonPressedEvent(e);
        }
Esempio n. 35
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToEquipped(srcDDP, destDDP))
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            src.InventoryForm.InvokeRequestUseItem(src.Slot);

            return true;
        }
Esempio n. 36
0
        /// <summary>
        /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        /// <returns>True if the <paramref name="src"/> can be dropped on this <see cref="IDragDropProvider"/>;
        /// otherwise false.</returns>
        public bool CanDrop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return false;
            }

            // Check if any of our implementations are supported
            for (var i = 0; i < _canDropCallbacks.Length; i++)
            {
                if (_canDropCallbacks[i](src, dest))
                    return true;
            }

            return false;
        }
Esempio n. 37
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="ShopForm.ShopItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_ShopItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_ShopItemToInventory(srcDDP, destDDP))
                return false;

            var src = (ShopForm.ShopItemPB)srcDDP;

            using (var pw = ClientPacket.BuyFromShop(src.Slot, 1))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return true;
        }
Esempio n. 38
0
        /// <summary>
        /// Handles the drag-and-drop for the given <see cref="IDragDropProvider"/>s.
        /// </summary>
        /// <param name="src">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="dest">The <see cref="IDragDropProvider"/> that that <paramref name="src"/> was dropped onto.</param>
        public void Drop(IDragDropProvider src, IDragDropProvider dest)
        {
            // Check for valid parameters
            if (src == null || dest == null)
            {
                Debug.Fail("Shouldn't ever be passed a null argument.");
                return;
            }

            // Use the first method that successfully handles the given source and destination
            for (var i = 0; i < _dropCallbacks.Length; i++)
            {
                if (_dropCallbacks[i](src, dest))
                    return;
            }
        }
Esempio n. 39
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="ShopForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToShop(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToShop(srcDDP, destDDP))
                return false;

            if (UserInventory == null)
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;

            UserInventory.SellToShop(src.Slot, _gps.GUIManager);

            return true;
        }
Esempio n. 40
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as IQuickBarItemProvider;
            var dest = destDDP as QuickBarForm.QuickBarItemPB;

            if (src == null || dest == null)
                return false;

            // Check if can be added to quick bar
            QuickBarItemType type;
            int value;
            if (!src.TryAddToQuickBar(out type, out value))
                return false;

            return true;
        }
Esempio n. 41
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="InventoryForm.InventoryItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_InventoryItemToInventoryItem(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_InventoryItemToInventoryItem(srcDDP, destDDP))
                return false;

            var src = (InventoryForm.InventoryItemPB)srcDDP;
            var dest = (InventoryForm.InventoryItemPB)destDDP;

            using (var pw = ClientPacket.SwapInventorySlots(src.Slot, dest.Slot))
            {
                _gps.Socket.Send(pw, ClientMessageType.GUIItems);
            }

            return true;
        }
Esempio n. 42
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="IQuickBarItemProvider"/> onto an <see cref="QuickBarForm.QuickBarItemPB"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool Drop_IQuickBarItemProviderToQuickBar(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_IQuickBarItemProviderToQuickBar(srcDDP, destDDP))
                return false;

            var src = (IQuickBarItemProvider)srcDDP;
            var dest = (QuickBarForm.QuickBarItemPB)destDDP;

            // Get the quick bar values
            QuickBarItemType type;
            int value;
            if (!src.TryAddToQuickBar(out type, out value))
                return false;

            var oldType = dest.QuickBarItemType;
            var oldValue = dest.QuickBarItemValue;

            // Set the quick bar values
            dest.SetQuickBar(type, value);

            // If the source was a quick bar item, too, then set the source's item to the dest's item to give a "swap"
            // instead of just "copying" the value.
            var srcQBI = src as QuickBarForm.QuickBarItemPB;
            if (srcQBI != null)
                srcQBI.SetQuickBar(oldType, oldValue);

            return true;
        }
Esempio n. 43
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
 }
Esempio n. 44
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        static bool CanDrop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as EquippedForm.EquippedItemPB;
            var dest = destDDP as InventoryForm;

            if (src == null || dest == null)
                return false;

            if (src.EquippedForm == null)
                return false;

            return true;
        }
Esempio n. 45
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     _dragDropHandler.Drop(source, this);
 }
Esempio n. 46
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="EquippedForm.EquippedItemPB"/> onto an <see cref="InventoryForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool Drop_EquippedItemToInventory(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            if (!CanDrop_EquippedItemToInventory(srcDDP, destDDP))
                return false;

            var src = (EquippedForm.EquippedItemPB)srcDDP;

            _gps.EquippedForm_RequestUnequip(src.EquippedForm, EventArgsHelper.Create(src.Slot));

            return true;
        }
Esempio n. 47
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
 }
Esempio n. 48
0
        /// <summary>
        /// Adds support for dragging a
        /// <see cref="InventoryForm.InventoryItemPB"/> onto an <see cref="EquippedForm"/>.
        /// </summary>
        /// <param name="srcDDP">The <see cref="IDragDropProvider"/> that was dragged.</param>
        /// <param name="destDDP">The <see cref="IDragDropProvider"/> that that <paramref name="srcDDP"/>
        /// was dropped onto.</param>
        /// <returns>True if the drag-and-drop can be or was successful; otherwise false.</returns>
        bool CanDrop_InventoryItemToEquipped(IDragDropProvider srcDDP, IDragDropProvider destDDP)
        {
            var src = srcDDP as InventoryForm.InventoryItemPB;
            var dest = destDDP as EquippedForm;

            if (src == null || dest == null)
                return false;

            if (src.Item == null)
                return false;

            if (src.InventoryForm.Inventory != _gps.UserInfo.Inventory)
                return false;

            return true;
        }
Esempio n. 49
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     _dragDropHandler.Drop(source, this);
 }
Esempio n. 50
0
        /// <summary>
        /// Sends an event for the mouse moving to this <see cref="IGUIManager"/>.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        public void SendEventMouseMoved(MouseMoveEventArgs e)
        {
            UpdateControlUnderCursor(e);

            var c = UnderCursor;

            // Update the DropOntoContorl
            if (DraggedDragDropProvider != null)
            {
                // Take the control we already found as being under the cursor. Then, create a loop that will check if
                // the control implements IDragDropProvider. If not, grab the parent. This will either give us the first
                // control to implement IDragDropProvider, or null.
                var tmpDropOntoControl = c;
                while (tmpDropOntoControl != null)
                {
                    var asDDP = tmpDropOntoControl as IDragDropProvider;

                    // If the control implements IDragDropProvider, and we can drop onto it, use that. Otherwise, move onto the parent.
                    if (asDDP != null && asDDP.CanDrop(DraggedDragDropProvider))
                        break;

                    tmpDropOntoControl = tmpDropOntoControl.Parent;
                }

                // Store the results of the above loop, which will be either a valid control we can drop on, or null
                _dropOntoControl = tmpDropOntoControl as IDragDropProvider;
            }
            else
            {
                // Nothing is being dragged, so don't take the time to calculate the control to drop onto
                _dropOntoControl = null;
            }

            // Send the mouse moved event
            if (c != null)
                c.SendMouseMoveEvent(e);
        }
Esempio n. 51
0
 /// <summary>
 /// Handles when the specified <see cref="IDragDropProvider"/> is dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> that is being dropped on this
 /// <see cref="IDragDropProvider"/>.</param>
 void IDragDropProvider.Drop(IDragDropProvider source)
 {
     InventoryForm._dragDropHandler.Drop(source, this);
 }
Esempio n. 52
0
 /// <summary>
 /// Gets if the specified <see cref="IDragDropProvider"/> can be dropped on this <see cref="IDragDropProvider"/>.
 /// </summary>
 /// <param name="source">The <see cref="IDragDropProvider"/> to check if can be dropped on this
 /// <see cref="IDragDropProvider"/>. This value will never be null.</param>
 /// <returns>True if the <paramref name="source"/> can be dropped on this <see cref="IDragDropProvider"/>;
 /// otherwise false.</returns>
 bool IDragDropProvider.CanDrop(IDragDropProvider source)
 {
     return(QuickBarForm._gps.DragDropHandler.CanDrop(source, this));
 }