예제 #1
0
        /// <summary>
        /// Tries to set new content to this socket.
        /// If <paramref name="content"/>'s key matches one of keys in this socket,
        /// returns true and set content. If not, returns false.
        /// If <paramref name="force"/> is true, set this content no matter what key it has.
        /// </summary>
        /// <returns><c>true</c>, if content was set, <c>false</c> otherwise.</returns>
        /// <param name="content">Content.</param>
        /// <param name="force">If set to <c>true</c> force.</param>
        public bool SetContent(IDragable content, bool force = false)
        {
            bool passed = MatchKey(content);

            if (passed || force)
            {
                DragSocket otherSocket = content.GetSocket();
                if (otherSocket != null)
                {
                    otherSocket.ResetContent();
                    // If this socket already have content, exchange content with given content's socket.
                    if (this.content != null)
                    {
                        if (!otherSocket.SetContent((IDragable)this.content))
                        {
                            otherSocket.SetContent(content, true);
                            return(false); // If setting socket is failed, return false.
                        }
                        components.Clear();
                    }
                }
                if (components.Count > 0)
                {
                    return(false);
                }
                components.Add((GUIComponent)content);
                content.ChangeSocket(this);
                return(true);
            }

            return(false);
        }
예제 #2
0
        public void ChangeSocket(DragSocket socket)
        {
            relativeX = 0;
            relativeY = 0;

            if (this.socket != null && socket is ItemSocket)
            {
                player.MoveItem(this.socket.column, this.socket.row, ((ItemSocket)socket).column, ((ItemSocket)socket).row);
            }

            parent = socket;
        }
예제 #3
0
        public void ChangeSocket(DragSocket socket)
        {
            relativeX = 0;
            relativeY = 0;
            parent    = socket;

            switch (((DragSocket)parent).name)
            {
            case "HeroFront": hero.ChangeDefaultState(FighterState.Front); break;

            case "HeroBehind": hero.ChangeDefaultState(FighterState.Behind); break;

            case "HeroStored": hero.ChangeDefaultState(FighterState.Stored); break;
            }
        }
예제 #4
0
        public bool AddSocket(int index, DragSocket socket)
        {
            if (index >= size || index < 0)
            {
                return(false);
            }
            if (!(components[index] is NullGUIComponent))
            {
                return(false);
            }

            components[index] = socket;
            socket.ChangeParent(this);
            return(true);
        }
예제 #5
0
 private void SetItems()
 {
     for (int row = 0; row < Player.ITEM_HEIGHT; row++)
     {
         for (int col = 0; col < Player.ITEM_WIDTH; col++)
         {
             Item       item   = player.items[row, col];
             DragSocket socket = itemGroup.GetSocket(col + row * Player.ITEM_WIDTH);
             if (item != null && socket.content == null)
             {
                 socket.SetContent(new ItemIcon(item.name, socket, 0, 0, item));
             }
             if (item == null && socket.content != null)
             {
                 socket.ResetContent();
             }
         }
     }
 }
예제 #6
0
        public override void Update(GameTime gameTime)
        {
            KeyCheck();

            #region Set hero sockets.
            for (int i = 0; i < Player.HEROFRONT_MAX; i++)
            {
                DragSocket socket = heroFrontGroup.GetSocket(i);
                if (socket == null)
                {
                    selector.SetItemToMatrix("HeroSockets", null, 0, i);
                    continue;
                }
                selector.SetItemToMatrix("HeroSockets", (ISelectable)socket, 0, i);
            }
            for (int i = 0; i < Player.HEROBEHIND_MAX; i++)
            {
                DragSocket socket = heroBehindGroup.GetSocket(i);
                if (socket == null)
                {
                    selector.SetItemToMatrix("HeroSockets", null, 1, i);
                    continue;
                }
                selector.SetItemToMatrix("HeroSockets", (ISelectable)socket, 1, i);
            }
            for (int i = 0; i < Player.HEROSTORED_MAX; i++)
            {
                DragSocket socket = heroStoredGroup.GetSocket(i);
                if (socket == null)
                {
                    selector.SetItemToMatrix("HeroSockets", null, 2, i);
                    continue;
                }
                selector.SetItemToMatrix("HeroSockets", (ISelectable)socket, 2, i);
            }
            #endregion


            #region Drag
            MouseState mouse = Mouse.GetState();
            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (dragging)
                {
                    dragEffect.x = mouse.X;
                    dragEffect.y = mouse.Y;

                    // Socket effect.
                    bool selected = false;
                    foreach (GUIComponent element in guiLayer.MainGroup)
                    {
                        if (element is DragSocket)
                        {
                            if (((DragSocket)element).IsInside(mouse.X, mouse.Y) && ((DragSocket)element).MatchKey(dragGUI))
                            {
                                selected = true;
                                if (element != selectedSocket)
                                {
                                    selectedSocket = (DragSocket)element;
                                    if (socketEffect is Effect)
                                    {
                                        socketEffect.Finish();
                                    }
                                    socketEffect = new EffectTexture(selectedSocket.emphasis, selectedSocket.x, selectedSocket.y, -1);
                                    topEffectLayer.elements.Add(socketEffect);
                                }
                            }
                        }
                    }
                    if (!selected)
                    {
                        if (socketEffect is Effect)
                        {
                            socketEffect.Finish();
                        }
                        selectedSocket = null;
                    }
                }
                else
                {
                    foreach (GUIComponent element in guiLayer.MainGroup)
                    {
                        if (element is IDragable)
                        {
                            IDragable dragable = (IDragable)element;
                            if (dragable.IsInside(mouse.X, mouse.Y))
                            {
                                dragGUI = dragable;
                                Texture2D dragTexture = dragable.GetTexture();
                                Vector2   dragOrigin  = dragable.GetOrigin(mouse.X, mouse.Y);
                                Sprite    dragSprite  = new Sprite(dragTexture, dragOrigin);
                                dragEffect = new EffectSprite(dragSprite, mouse.X, mouse.Y);
                                topEffectLayer.elements.Add(dragEffect);
                                dragging = true;
                                break;
                            }
                        }
                    }
                }
            }
            else if (mouse.LeftButton == ButtonState.Released)
            {
                if (dragging)
                {
                    foreach (GUIComponent element in guiLayer.MainGroup)
                    {
                        if (element is DragSocket)
                        {
                            DragSocket newSocket = (DragSocket)element;
                            if (newSocket.IsInside(mouse.X, mouse.Y))
                            {
                                if (newSocket.SetContent(dragGUI))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    dragging = false;
                    dragEffect?.Finish();
                    socketEffect?.Finish();
                }
            }
            #endregion

            base.Update(gameTime);
        }