Exemple #1
0
        public void Draw(SpriteBatch spriteBatch, Color textColor)
        {
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);

            //draw underlying alpha box
            playerNameBox.Draw(spriteBatch);
            //calculate the size of the players name
            Vector2 nameSize = textFont.MeasureString(playerName);
            //calculate the position where the name needs to be drawn to be central
            //  to the player name box.
            Vector2 namePos = playerNameBox.GetCentrePos() - 0.5f * nameSize;

            //draw the player name
            spriteBatch.DrawString(textFont, playerName, namePos, textColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            characterSpriteBox.Draw(spriteBatch);
            characterInfoBox.Draw(spriteBatch);

            //draw dividing lines
            divisorA.Draw(spriteBatch);
            divisorB.Draw(spriteBatch);

            //draw respective information about character if a character is selected
            if (characterType != null)
            {
                //draw selected character sprite
                Vector2 spritePos = characterSpriteBox.GetCentrePos() - 0.5f * spriteScale * UiTools.BoundsToVector(characterSprite.Bounds);
                spriteBatch.Draw(characterSprite, position: spritePos, scale: spriteScaleVector);

                //draw character name
                string  chrName = characterType.Name;
                Vector2 basePos = characterInfoBox.GetPos() + new Vector2(characterInfoBox.DestinationRect.Width / 2, textPadding + textFont.MeasureString(chrName).Y / 2);
                namePos = basePos - textFont.MeasureString(chrName) / 2;
                spriteBatch.DrawString(textFont, chrName, namePos, textColor);

                string  ability     = $"Ability:";
                Vector2 abilitySize = textFont.MeasureString(ability);
                Vector2 abilityPos  = basePos
                                      + new Vector2(0, 5 * lineSpacing + textFont.MeasureString(chrName).Y / 2);
                spriteBatch.DrawString(textFont, ability, abilityPos - abilitySize / 2, Color.Red);

                //draw the ability description.
                // this is a long string being drawn to a small box, so
                // the text is wrapped according to the width of the box.
                // (See uitools for how text wrapping works).
                float   drawGap     = lineSpacing + textFont.MeasureString(abilityDescription).Y / 2;
                Vector2 linesOrigin = abilityPos + new Vector2(0, abilitySize.Y / 2 + lineSpacing);
                for (int i = 0; i < descriptionLines.Length; i++)
                {
                    spriteBatch.DrawString(textFont,
                                           descriptionLines[i],
                                           linesOrigin + new Vector2(0, i * drawGap) - textFont.MeasureString(descriptionLines[i]) / 2,
                                           Color.White);
                }
            }

            spriteBatch.End();
        }
Exemple #2
0
        public void Draw(SpriteBatch spriteBatch, Texture2D vsAiIcon, Texture2D vsPlayerIcon)
        {
            //draw underlying alpha box
            textBox.Draw(spriteBatch);
            //calculate the size of the text
            Vector2 textSize = textFont.MeasureString(text);
            //calculate the position where the text needs to be drawn to be central
            //  to the text box.
            Vector2 textPos = textBox.GetCentrePos() - 0.5f * new Vector2(textSize.X, textSize.Y);

            //draw the text
            spriteBatch.DrawString(textFont, text, textPos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            //draw the underlying alpha boxes for each round.
            foreach (RectBox box in stageIconBoxes)
            {
                box.Draw(spriteBatch);
            }


            //draw dividing line
            divisorA.Draw(spriteBatch);

            //draw respective information about each round.
            for (int i = 0; i < stage.Length; i++)
            {
                if (stage.Rounds[i] == Stage.RoundTypes.vsAi)
                {
                    spriteBatch.Draw(vsAiIcon,
                                     position: stageIconBoxes[i].GetCentrePos() - 0.5f * spriteScale * UiTools.BoundsToVector(vsAiIcon.Bounds),
                                     scale: spriteScaleVector,
                                     color: (i < stageIndex - 1)? Color.Gray : Color.White
                                     );
                }
                else
                {
                    spriteBatch.Draw(vsPlayerIcon,
                                     position: stageIconBoxes[i].GetCentrePos() - 0.5f * spriteScale * UiTools.BoundsToVector(vsPlayerIcon.Bounds),
                                     scale: spriteScaleVector,
                                     color: (i < stageIndex - 1) ? Color.DarkRed : Color.Red
                                     );
                }
            }
        }
Exemple #3
0
        public void Draw(SpriteBatch spriteBatch, BattleTurn.ActionArgs[] actions, Player[] players, DrawParams textures)
        {
            //pass in the information about actions -- draw for each one. This information does not need to be stored here too.


            //draw underlying alpha box for the box containing text.
            textBox.Draw(spriteBatch);
            //calculate the size of the text
            Vector2 nameSize = textFont.MeasureString(text);
            //calculate the position where the text needs to be drawn to be central
            //  to the text box.
            Vector2 namePos = textBox.GetCentrePos() - 0.5f * new Vector2(nameSize.X, nameSize.Y);

            //draw the text
            spriteBatch.DrawString(textFont, text, namePos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            foreach (RectBox box in actionBoxes)
            {
                box.Draw(spriteBatch);
            }

            //draw respective information about each action
            for (int i = 0; i < actions.Length; i++)
            {
                BattleTurn.ActionArgs action = actions[i];
                RectBox boxDrawingTo         = actionBoxes[i];
                Vector2 boxPos = boxDrawingTo.GetPos();

                Color boxColor = (action.ActingUnit.OwnerId == 3) ?
                                 Color.Gray :
                                 players.Where(player => player.Id == action.ActingUnit.OwnerId).First().Colour; //set the color to Ai color/player color


                //draw a coloured block to specify which player the acting unit belongs to.
                //Using a single pixel texture instead of a non-disposable object (say my RectBox class for instance)
                // eliminates memory leak issues.
                spriteBatch.Draw(emptyRect, new Rectangle(boxDrawingTo.GetPos().ToPoint(), new Point(10, actionBoxHeight)), color: boxColor);

                Texture2D actingUnitSprite = action.ActingUnit.GetSprite(textures.unitSprites);


                //draw the units involved in each action, and the icons displaying the type of action.
                if (action.IsAttack)
                {
                    //draw the attacking unit
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw the attack icon
                    spriteBatch.Draw(textures.attackIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );

                    //draw the target unit
                    Texture2D targetUnitSprite = action.TargetUnit.GetSprite(textures.unitSprites);
                    spriteBatch.Draw(targetUnitSprite,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(targetUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw the defense icon
                    spriteBatch.Draw(textures.defenseIcon,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale * new Vector2(textures.defenseIcon.Width, 0),
                                     scale: iconScaleVector
                                     );

                    //draw the skull icon if the target unit died as a result of the action.
                    if (action.TargetFainted)
                    {
                        spriteBatch.Draw(textures.skullIcon,
                                         position: boxPos + new Vector2(3.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale / 2 * UiTools.BoundsToVector(textures.skullIcon.Bounds),
                                         scale: iconScaleVector * 2
                                         );
                    }
                }
                else if (action.IsMove)
                {
                    //draw acting unit
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw move icon
                    spriteBatch.Draw(textures.moveIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );

                    //draw target unit
                    Texture2D targetUnitSprite = action.TargetUnit.GetSprite(textures.unitSprites);
                    spriteBatch.Draw(targetUnitSprite,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(targetUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //draw targetting icon
                    spriteBatch.Draw(textures.targetIcon,
                                     position: boxPos + new Vector2(2.5f * width / 5, boxDrawingTo.GetHeight() / 2) - iconScale * new Vector2(textures.targetIcon.Width, 0),
                                     scale: iconScaleVector
                                     );
                }
                else //(No move)
                {
                    //Draw the unit trying to act
                    spriteBatch.Draw(actingUnitSprite,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(actingUnitSprite.Bounds),
                                     scale: spriteScaleVector
                                     );

                    //Draw no act icon (cant move)
                    spriteBatch.Draw(textures.noMoveIcon,
                                     position: boxPos + new Vector2(width / 5, boxDrawingTo.GetHeight() / 2),
                                     scale: iconScaleVector
                                     );
                }
            }

            //draw dividing line
            divisorA.Draw(spriteBatch);
        }
Exemple #4
0
        public void Draw(SpriteBatch spriteBatch, Player owner, UnitShop.ShopEntry[] entries, Dictionary <Type, Texture2D> unitSprites, Texture2D moneyIcon, SpriteFont textFont)
        {
            //pass in the information about shop entries -- draw for each one.

            //draw underlying alpha box for the box containing text.
            textBox.Draw(spriteBatch);
            //calculate the size of the text
            Vector2 textSize = textFont.MeasureString(text);
            //calculate the position where the text needs to be drawn to be central
            //  to the text box.
            Vector2 textPos = textBox.GetCentrePos() - 0.5f * textSize;

            //draw the text
            spriteBatch.DrawString(textFont, text, textPos, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);

            foreach (UnitShopButton box in unitBoxes)
            {
                box.Draw(spriteBatch, owner, entries);
            }

            //draw respective information about each entry
            for (int i = 0; i < entries.Length; i++)
            {
                UnitShop.ShopEntry entry        = entries[i];
                UnitShopButton     boxDrawingTo = unitBoxes[i];
                Vector2            boxPos       = boxDrawingTo.GetPos();
                Texture2D          unitSprite   = unitSprites[entry.unitType];

                spriteBatch.Draw(unitSprite,
                                 position: boxPos + new Vector2(width / 6, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(unitSprite.Bounds),
                                 scale: spriteScaleVector
                                 );

                if (entry.Sold)
                {
                    Vector2 size = textFont.MeasureString(soldText);
                    Vector2 pos  = boxPos + new Vector2(width / 3, (boxDrawingTo.GetHeight() - size.Y) / 2);
                    spriteBatch.DrawString(textFont, soldText, pos, Color.White);
                }
                else if (owner.IsBenchFull())
                {
                    Vector2 size = textFont.MeasureString(fullText);
                    Vector2 pos  = boxPos + new Vector2(width / 3, (boxDrawingTo.GetHeight() - size.Y) / 2);
                    spriteBatch.DrawString(textFont, fullText, pos, Color.White);
                }
                else
                {
                    string  text = $"Buy: {entry.cost}";
                    Vector2 size = textFont.MeasureString(text);
                    Vector2 pos  = boxPos + new Vector2(width / 3, (boxDrawingTo.GetHeight() - size.Y) / 2);
                    spriteBatch.DrawString(textFont, text, pos, Color.White);
                    spriteBatch.Draw(moneyIcon,
                                     position: boxPos + new Vector2(width / 3 + width / 15 + size.X, boxDrawingTo.GetHeight() / 2) - spriteScale / 2 * UiTools.BoundsToVector(moneyIcon.Bounds),
                                     scale: spriteScaleVector
                                     );
                }
            }

            //draw dividing line
            divisorA.Draw(spriteBatch);
        }