예제 #1
0
 internal void VerticalScroll(IMGUIPass pass, int scrollValue)
 {
     ScrollAreaStartPosition = Position;
     Position.X  += ScrollWidth;
     IsScrollArea = true;
     ScrollValue  = scrollValue;
 }
예제 #2
0
        internal void DoText(IMGUIPass cardCreationPass, string text, Color textColor)
        {
            switch (cardCreationPass)
            {
            case IMGUIPass.Draw:
            {
                Renderer.DrawString(Font, text, Position, textColor);
                Position.X += Font.MeasureString(text).X;
            }
            break;

            case IMGUIPass.Update:
            {
            }
            break;
            }
        }
예제 #3
0
        internal bool DoClickableText(IMGUIPass cardCreationPass, Input input, string text, Color textColor)
        {
            bool result            = false;
            int  horisontalPadding = 5;
            int  buttonWidth       = (int)Font.MeasureString(text).X + 2 * horisontalPadding;

            Rectangle buttonRectangle = new Rectangle((int)Position.X, (int)Position.Y + ScrollValue, buttonWidth, Font.LineSpacing);

            int rightmostX = buttonRectangle.Right;

            if (IsScrollArea && rightmostX >= RightmostScrollX)
            {
                RightmostScrollX = rightmostX;
            }
            switch (cardCreationPass)
            {
            case IMGUIPass.Draw:
            {
                Vector2 textPosition = new Vector2(buttonRectangle.Left + horisontalPadding, buttonRectangle.Top);
                Renderer.DrawString(Font, text, textPosition, textColor);
                if (Game1.PointInRectangle(input.MousePosition, buttonRectangle))
                {
                    Renderer.DrawRectangleOutline(2, Game1.flareHighlightColor, buttonRectangle);
                }
                if (!IsScrollArea)
                {
                    Renderer.DrawRectangle(buttonRectangle, Game1.tileColor);
                }
            }
            break;

            case IMGUIPass.Update:
            {
                if (input.LeftMouseDisengaged() && Game1.PointInRectangle(input.MousePosition, buttonRectangle))
                {
                    result = true;
                }
            }
            break;
            }

            Position.X += buttonWidth;

            return(result);
        }
예제 #4
0
 internal bool DoClickableText(IMGUIPass cardCreationPass, Input input, string text)
 {
     return(DoClickableText(cardCreationPass, input, text, Color.White));
 }
예제 #5
0
        internal int EndScroll(IMGUIPass pass, Input input, int scrollValue)
        {
            IsScrollArea = false;

            if (pass == IMGUIPass.Draw)
            {
                // Draw Scroll Bar
                float x            = ScrollAreaStartPosition.X + ScrollWidth / 2;
                float scrollYStart = ScrollAreaStartPosition.Y;
                float scrollYEnd   = Math.Min(Position.Y, Game1.Graphics.PreferredBackBufferHeight);
                float scrollLength = scrollYEnd - scrollYStart;

                float firstItemY            = ScrollAreaStartPosition.Y + scrollValue;
                float lastItemY             = Position.Y + scrollValue;
                float totalLength           = lastItemY - firstItemY;
                float distanceBeforeScreen  = -scrollValue;
                float distanceAfterScreen   = (Position.Y + scrollValue) - Game1.Graphics.PreferredBackBufferHeight;
                float highlightStartPercent = 0f;
                float highlightEndPercent   = 1f;
                if (totalLength != 0f)
                {
                    highlightStartPercent = distanceBeforeScreen / totalLength;
                    if (distanceAfterScreen > 0f)
                    {
                        highlightEndPercent = 1 - (distanceAfterScreen / totalLength);
                    }
                }

                float highlightYStart = scrollYStart + (highlightStartPercent * scrollLength);
                float highlightYEnd   = scrollYStart + (highlightEndPercent * scrollLength);
                if (highlightStartPercent != 0f || highlightEndPercent != 1f)
                {
                    Renderer.DrawLine(2, Game1.flareHighlightColor, new Vector2(x, highlightYStart), new Vector2(x, highlightYEnd));
                }
                Renderer.DrawLine(2, Game1.backgroundColor, new Vector2(x, scrollYStart), new Vector2(x, scrollYEnd));

                // Draw Background
                Rectangle outputScrollArea = new Rectangle((int)ScrollAreaStartPosition.X, (int)ScrollAreaStartPosition.Y,
                                                           (int)(RightmostScrollX - ScrollAreaStartPosition.X), (int)(Position.Y - ScrollAreaStartPosition.Y));
                Renderer.DrawRectangle(outputScrollArea, Game1.tileColor);
            }

            // Get new scroll value.
            int newScrollValue = scrollValue;

            if (pass == IMGUIPass.Update)
            {
                Vector2 mousePosition = input.MousePosition;
                if (ScrollAreaStartPosition.X <= input.MousePosition.X &&
                    input.MousePosition.X <= RightmostScrollX &&
                    ScrollAreaStartPosition.Y <= input.MousePosition.Y &&
                    input.MousePosition.Y <= Position.Y)
                {
                    newScrollValue += (input.MouseState.ScrollWheelValue - input.LastMouseState.ScrollWheelValue) / 20;
                    int maxScroll = (int)-(Position.Y - Game1.Graphics.PreferredBackBufferHeight);
                    if (newScrollValue < maxScroll)
                    {
                        newScrollValue = maxScroll;
                    }
                    if (newScrollValue > 0)
                    {
                        newScrollValue = 0;
                    }
                }
            }
            return(newScrollValue);
        }
예제 #6
0
        public void UpdateAndDraw(GameTime gameTime, IMGUIPass pass)
        {
            // RESET
            List <Keys> keysConsumed = new List <Keys>();

            if (input.KeyPressed(Keys.R) && (input.KeyboardState.IsKeyDown(Keys.LeftControl) || input.KeyboardState.IsKeyDown(Keys.RightControl)))
            {
                keysConsumed.Add(Keys.R);
                network.SendResetMessage();
                Reset();
            }

            // CARD CREATION
            bool  mouseActionConsumed = false;
            Panel panel = new Panel(new Vector2(5, 0), renderer);

            panel.Font = font;
            int start = (int)'A';
            int end   = (int)'Z';

            for (int i = start; i <= end; i++)
            {
                if (panel.DoClickableText(pass, input, ((char)i).ToString()))
                {
                    shownLetter         = (char)i;
                    mouseActionConsumed = true;
                }
            }
            if (panel.DoClickableText(pass, input, "*"))
            {
                shownLetter         = '*';
                mouseActionConsumed = true;
            }
            if (panel.DoClickableText(pass, input, "C"))
            {
                SpawnCounterAndSendNetworkMessage();
                mouseActionConsumed = true;
            }

            // TYPED CARD RETREIVAL
            if (pass == IMGUIPass.Update)
            {
                if (lastKeyboardState != null)
                {
                    for (int i = 65; i <= 90; i++)
                    {
                        Keys key = (Keys)i;
                        if (!keysConsumed.Contains(key) && keyboardState.IsKeyDown(key) && lastKeyboardState.IsKeyUp(key))
                        {
                            int keyInt = i;
                            if (!keyboardState.IsKeyDown(Keys.LeftShift) && !keyboardState.IsKeyDown(Keys.RightShift))
                            {
                                keyInt += 32;
                            }
                            searchText     += (char)keyInt;
                            searchTextColor = textColor;
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Space) && lastKeyboardState.IsKeyUp(Keys.Space))
                    {
                        searchText += " ";
                    }
                    if (keyboardState.IsKeyDown(Keys.OemComma) && lastKeyboardState.IsKeyUp(Keys.OemComma))
                    {
                        searchText += ",";
                    }
                    if (keyboardState.IsKeyDown(Keys.OemMinus) && lastKeyboardState.IsKeyUp(Keys.OemMinus))
                    {
                        searchText += "-";
                    }
                    if (keyboardState.IsKeyDown(Keys.OemQuotes) && lastKeyboardState.IsKeyUp(Keys.OemQuotes))
                    {
                        searchText += "'";
                    }
                    if (searchText.Length > 0 && keyboardState.IsKeyDown(Keys.Back) && lastKeyboardState.IsKeyUp(Keys.Back))
                    {
                        searchText = searchText.Substring(0, searchText.Length - 1);
                    }
                    if (keyboardState.IsKeyDown(Keys.Enter) && lastKeyboardState.IsKeyUp(Keys.Enter))
                    {
                        if (!TryGetFile(searchText))
                        {
                            searchTextColor = Color.Red;
                        }
                        else
                        {
                            searchText = "";
                        }
                    }
                }
            }
            panel.DoText(pass, searchText, searchTextColor);
            panel.Row();

            if (input.RightMouseEngaged() && shownLetter != (char)0)
            {
                shownLetter         = (char)0;
                mouseActionConsumed = true;
            }

            if (shownLetter != (char)0)
            {
                List <CardData> cardsToShow;
                if (shownLetter == '*')
                {
                    cardsToShow = cardData.Where(x => x.Starred).ToList();
                }
                else
                {
                    cardsToShow = cardData.Where(x => x.Name.ToUpper()[0] == shownLetter).ToList();
                }

                panel.VerticalScroll(pass, cardSelectScrollValue);
                foreach (CardData card in cardsToShow)
                {
                    Color starColor = Color.White;
                    if (!card.Starred)
                    {
                        starColor = Color.Black;
                    }
                    if (panel.DoClickableText(pass, input, "*", starColor))
                    {
                        card.Starred = !card.Starred;
                        SaveStarredCards();
                    }
                    if (panel.DoClickableText(pass, input, card.Name))
                    {
                        SpawnCardAndSendNetworkMessage(card.Name, card.TexturePath);
                        shownLetter           = (char)0;
                        mouseActionConsumed   = true;
                        cardSelectScrollValue = 0;
                    }
                    panel.Row();
                }
                cardSelectScrollValue = panel.EndScroll(pass, input, cardSelectScrollValue);
            }

            // MANA BOXES
            if (!mouseActionConsumed || pass == IMGUIPass.Draw)
            {
                int manaBoxIndex_TopAvaliable    = 0;
                int manaBoxIndex_TopUsed         = 1;
                int manaBoxIndex_BottomAvaliable = 2;
                int manaBoxIndex_BottomUsed      = 3;

                int manaBoxWidth       = manaBoxWidthInMana * manaTextureSize;
                int totalManaBoxWidth  = 2 * manaBoxWidth + manaTextureSize;
                int totalManaBoxHeight = manaTextureSize * manaBoxHeightInMana;

                float     startX = Graphics.PreferredBackBufferWidth - totalManaBoxWidth - manaTextureSize;
                Vector2[] refreshButtonPositions = new Vector2[2] {
                    new Vector2(startX, 0), new Vector2(startX, Graphics.PreferredBackBufferHeight - totalManaBoxHeight)
                };
                int[] avaliableManaIndex = new int[2] {
                    manaBoxIndex_TopAvaliable, manaBoxIndex_BottomAvaliable
                };
                int[] usedManaIndex = new int[2] {
                    manaBoxIndex_TopUsed, manaBoxIndex_BottomUsed
                };
                for (int i = 0; i <= 1; i++)
                {
                    // Refresh Button
                    Rectangle refreshButtonTextureRectangle = new Rectangle((int)refreshButtonPositions[i].X, (int)refreshButtonPositions[i].Y, (int)manaTextureSize, (int)manaTextureSize);
                    switch (pass)
                    {
                    case IMGUIPass.Draw:
                        Texture2D refreshManaTexture = Content.Load <Texture2D>("Mana\\refresh.png");
                        renderer.Draw(refreshManaTexture, refreshButtonTextureRectangle, Color.White);
                        break;

                    case IMGUIPass.Update:
                        if (input.LeftMouseDisengaged() && Game1.PointInRectangle(input.MousePosition, refreshButtonTextureRectangle))
                        {
                            RefreshMana(avaliableManaIndex[i]);
                            mouseActionConsumed = true;
                            network.SendRefreshMana(avaliableManaIndex[i]);
                        }
                        break;
                    }

                    Vector2 availiableManaBoxPosition = refreshButtonPositions[i] + new Vector2(manaTextureSize, 0);
                    Vector2 usedManaBoxPosition       = availiableManaBoxPosition + new Vector2(manaBoxWidth, 0);

                    Vector2[] manaBoxPosition = new Vector2[2] {
                        availiableManaBoxPosition, usedManaBoxPosition
                    };
                    int[] myManaIndex = new int[2] {
                        avaliableManaIndex[i], usedManaIndex[i]
                    };
                    int[] swapManaIndex = new int[2] {
                        usedManaIndex[i], avaliableManaIndex[i]
                    };
                    Color[] textureColor = new Color[2] {
                        Color.White, Color.Gray
                    };
                    for (int j = 0; j <= 1; j++)
                    {
                        Vector2 currentPosition = new Vector2(manaBoxPosition[j].X, manaBoxPosition[j].Y);
                        int     column          = 0;
                        for (int manaType = 0; manaType < 5; manaType++)
                        {
                            Texture2D manaTexture = Content.Load <Texture2D>(manaTextures[manaType]);
                            for (int mana = 0; mana < manaBoxes[myManaIndex[j], manaType]; mana++)
                            {
                                Rectangle manaTextureRectangle = new Rectangle((int)currentPosition.X, (int)currentPosition.Y, (int)manaTextureSize, (int)manaTextureSize);
                                switch (pass)
                                {
                                case IMGUIPass.Draw:
                                    renderer.Draw(manaTexture, manaTextureRectangle, textureColor[j]);
                                    break;

                                case IMGUIPass.Update:
                                    if (Game1.PointInRectangle(input.MousePosition, manaTextureRectangle))
                                    {
                                        if (input.LeftMouseDisengaged())
                                        {
                                            manaBoxes[myManaIndex[j], manaType]--;
                                            manaBoxes[swapManaIndex[j], manaType]++;
                                            mouseActionConsumed = true;
                                            network.SendTransferMana(myManaIndex[j], swapManaIndex[j], manaType);
                                        }
                                        else if (input.RightMouseDisengaged())
                                        {
                                            manaBoxes[myManaIndex[j], manaType]--;
                                            mouseActionConsumed = true;
                                            network.SendRemoveMana(myManaIndex[j], manaType);
                                        }
                                    }
                                    break;
                                }
                                currentPosition.X += manaTextureSize;
                                column++;
                                if (column >= manaBoxWidthInMana)
                                {
                                    column             = 0;
                                    currentPosition.X  = manaBoxPosition[j].X;
                                    currentPosition.Y += manaTextureSize;
                                }
                            }
                        }
                    }

                    // Add Mana Buttons
                    Vector2 addManaBoxPosition = usedManaBoxPosition + new Vector2(manaBoxWidth, 0);
                    for (int manaType = 0; manaType < manaTextures.Count; manaType++)
                    {
                        Rectangle manaTextureRectangle = new Rectangle((int)addManaBoxPosition.X,
                                                                       (int)addManaBoxPosition.Y + manaType * manaTextureSize,
                                                                       (int)manaTextureSize,
                                                                       (int)manaTextureSize);
                        switch (pass)
                        {
                        case IMGUIPass.Draw:
                            Texture2D manaTexture = Content.Load <Texture2D>(manaTextures[manaType]);
                            renderer.Draw(manaTexture, manaTextureRectangle, Color.White);
                            break;

                        case IMGUIPass.Update:
                            if (input.LeftMouseDisengaged() && Game1.PointInRectangle(input.MousePosition, manaTextureRectangle))
                            {
                                manaBoxes[avaliableManaIndex[i], manaType]++;
                                mouseActionConsumed = true;
                                network.SendCreateMana(avaliableManaIndex[i], manaType);
                            }
                            break;
                        }
                    }

                    // Blue Lines
                    if (pass == IMGUIPass.Draw)
                    {
                        Rectangle manaBoxRectangle = new Rectangle((int)availiableManaBoxPosition.X, (int)availiableManaBoxPosition.Y, totalManaBoxWidth, totalManaBoxHeight);
                        renderer.DrawRectangleOutline(2, flareColor, manaBoxRectangle);
                        renderer.DrawLine(2, flareColor, usedManaBoxPosition, usedManaBoxPosition + new Vector2(0, totalManaBoxHeight));
                        renderer.DrawLine(2, flareColor, addManaBoxPosition, addManaBoxPosition + new Vector2(0, totalManaBoxHeight));
                        renderer.DrawRectangle(manaBoxRectangle, tileColor);
                    }
                }
            }

            // CARDS AND COUNTERS
            // Move And Drop Drag Target
            if (pass == IMGUIPass.Update && !mouseActionConsumed)
            {
                if (dragTarget != null)
                {
                    dragTarget.Position += input.MousePosition - input.LastMousePosition;

                    if (lastDragMessageSentSeconds > 0.2)
                    {
                        network.SendEntityMovedMessage(dragTarget.NetworkID, dragTarget.Position);
                        lastDragMessageSentSeconds = 0;
                    }

                    if (input.LeftMouseDisengaged())
                    {
                        network.SendEntityMovedMessage(dragTarget.NetworkID, dragTarget.Position);
                        lastDragMessageSentSeconds = 0;
                        dragTarget          = null;
                        mouseActionConsumed = true;
                    }
                }
            }

            Entities.Sort(new EntityComparerReverse());
            foreach (Entity entity in Entities)
            {
                switch (entity.Type)
                {
                case EntityType.Card:
                    if (pass == IMGUIPass.Draw)
                    {
                        Card  card     = (Card)entity.TypeSpecificClass;
                        float rotation = 0;
                        if (card.Tapped)
                        {
                            rotation = (float)Math.PI / 2f;
                        }
                        renderer.Draw(card.Texture, entity.Position, Color.White, rotation, card.GetHalf());
                    }
                    else     // Update Pass
                    {
                        // Start Drag
                        if (input.LeftMouseEngaged() && dragTarget == null && !mouseActionConsumed)
                        {
                            if (PointInRectangle(input.MousePosition, entity.GetBounds()))
                            {
                                dragTarget          = entity;
                                dragTarget.Depth    = GetNextHeighestDepth();
                                mouseActionConsumed = true;
                            }
                        }

                        // Tap
                        if (input.RightMouseDisengaged() && !mouseActionConsumed)
                        {
                            if (PointInRectangle(input.MousePosition, entity.GetBounds()))
                            {
                                Card card = (Card)entity.TypeSpecificClass;
                                card.Tapped = !card.Tapped;
                                network.SendEntityTappedMessage(entity.NetworkID);
                                mouseActionConsumed = true;
                            }
                        }
                    }
                    break;

                case EntityType.Counter:
                    Counter counter = (Counter)entity.TypeSpecificClass;
                    if (pass == IMGUIPass.Draw)
                    {
                        Vector2   topArrowPoint     = entity.Position + new Vector2(Counter.TextAreaWidth / 2f, 0);
                        Vector2   bottomArrowPoint  = topArrowPoint + new Vector2(0, 2 * Counter.Buttonheight + Counter.TextAreaHeight);
                        Rectangle textAreaRectangle = new Rectangle((int)entity.Position.X,
                                                                    (int)entity.Position.Y + Counter.Buttonheight,
                                                                    Counter.TextAreaWidth,
                                                                    Counter.TextAreaHeight);

                        // Top arrow
                        renderer.DrawLine(1, flareColor, new Vector2(textAreaRectangle.Left, textAreaRectangle.Top), topArrowPoint);
                        renderer.DrawLine(1, flareColor, topArrowPoint, new Vector2(textAreaRectangle.Right, textAreaRectangle.Top));

                        // Bottom arrow
                        renderer.DrawLine(1, flareColor, new Vector2(textAreaRectangle.Left, textAreaRectangle.Bottom), bottomArrowPoint);
                        renderer.DrawLine(1, flareColor, bottomArrowPoint, new Vector2(textAreaRectangle.Right, textAreaRectangle.Bottom));

                        string     text         = counter.Value.ToString();
                        SpriteFont fontToUse    = font;
                        Vector2    centerOffset = (new Vector2(Counter.TextAreaWidth, Counter.TextAreaHeight) - fontToUse.MeasureString(text)) / 2f;
                        renderer.DrawString(fontToUse, text, new Vector2(textAreaRectangle.Left, textAreaRectangle.Top) + centerOffset, textColor);

                        renderer.DrawRectangle(textAreaRectangle, Game1.tileColor);
                    }
                    else     // Update Pass
                    {
                        if (dragTarget == null && !mouseActionConsumed)
                        {
                            if (input.LeftMouseEngaged())
                            {
                                if (PointInRectangle(input.MousePosition,
                                                     new Rectangle((int)entity.Position.X, (int)entity.Position.Y + Counter.Buttonheight,
                                                                   Counter.TextAreaHeight, Counter.TextAreaHeight)))
                                {
                                    dragTarget          = entity;
                                    dragTarget.Depth    = GetNextHeighestDepth();
                                    mouseActionConsumed = true;
                                }
                            }
                            else if (input.LeftMouseDisengaged())
                            {
                                Vector2 startOfBottomTriangle = entity.Position + new Vector2(0, Counter.Buttonheight + Counter.TextAreaHeight);
                                int     counterChange         = 0;
                                if (PointInTriangle(input.MousePosition,
                                                    entity.Position + new Vector2(0, Counter.Buttonheight),
                                                    entity.Position + new Vector2(Counter.TextAreaWidth / 2, 0),
                                                    entity.Position + new Vector2(Counter.TextAreaWidth, Counter.Buttonheight)))
                                {
                                    counterChange = 1;
                                }
                                else if (PointInTriangle(input.MousePosition,
                                                         startOfBottomTriangle + new Vector2(0, 0),
                                                         startOfBottomTriangle + new Vector2(Counter.TextAreaWidth / 2, Counter.Buttonheight),
                                                         startOfBottomTriangle + new Vector2(Counter.TextAreaWidth, 0)))
                                {
                                    counterChange = -1;
                                }

                                if (counterChange != 0)
                                {
                                    counter.Value += counterChange;
                                    network.SendCounterChangeMessage(entity.NetworkID, counter.Value);
                                    mouseActionConsumed = true;
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }