Exemple #1
0
        private void LoadContent_Ui(ContentManager Content)
        {
            augmentIcon = Content.Load <Texture2D>("PreparationTurn/StatAugmentIcon");

            moneyBox = new RectBox(graphicsDevice,
                                   characterDrawPos + new Vector2(uiScale * turnPlayer.CharacterSprite.Width / 2, winBarDimensions.Y + unitBarDimensions.Y),
                                   (int)moneyBoxDimensions.X, (int)moneyBoxDimensions.Y);

            emptyRect         = UiTools.GeneratePixelTexture(graphicsDevice);
            characterBoundary = Content.Load <Texture2D>("CharacterSelect/Buttons/ButtonBoundaryLR");
            vsAiIcon          = Content.Load <Texture2D>("PreparationTurn/vsPlayerIcon");
            vsPlayerIcon      = Content.Load <Texture2D>("PreparationTurn/vsPlayerIcon");
            moneyIcon         = Content.Load <Texture2D>("PreparationTurn/MoneyIcon");
            //information used by the stage box:
            stageInfo = new StageViewBox(graphicsDevice,
                                         currentStage,
                                         bebasSmall,
                                         stageNumber + 1,
                                         stageIndex + 1,
                                         WindowTools.PaddingToPixelCoordinate(0f, 0.25f, 10, 10)
                                         );

            //Buttons
            Texture2D buttonTexture = Content.Load <Texture2D>("PreparationTurn/EndTurnButton");
            Texture2D hoverTexture  = Content.Load <Texture2D>("PreparationTurn/EndTurnButtonHovered");

            bool[,] mask  = UiTools.CreateBoolMask(buttonTexture);
            endTurnButton = new SinglePressSpriteButton(WindowTools.PaddingToPixelCoordinate(0f, 0.17f, 10, 10),
                                                        buttonTexture,
                                                        hoverTexture,
                                                        mask, uiScale);

            //assign the end turn function to the button's event handler.
            endTurnButton.buttonPressed += HandleEndTurnButtonPress;

            levelUnitCapButton = new LevelUnitCapButton(graphicsDevice,
                                                        moneyBox.GetPos() + new Vector2(moneyBoxDimensions.X, 0f),
                                                        (int)WindowTools.GetUpscaledValue(225f), (int)moneyBoxDimensions.Y);

            //and so on with all used buttons
            levelUnitCapButton.buttonPressed += HandleLevelUpCapPress;

            useAbilityButton = new UseAbilityButton(graphicsDevice,
                                                    WindowTools.PaddingToPixelCoordinate(0.1f, 0.17f, 10, 10),
                                                    (int)WindowTools.GetUpscaledValue(225f),
                                                    (int)(buttonTexture.Height * uiScale)
                                                    );

            useAbilityButton.buttonPressed += HandleAbilityButtonPress;

            //divisor line to distinguish between money box/level up button.
            divisorLine = new Line(graphicsDevice, levelUnitCapButton.GetPos(), levelUnitCapButton.GetPos() + new Vector2(0, levelUnitCapButton.GetHeight()), 5, Color.White);


            //help button
            helpButton = new TutorialButton(graphicsDevice, this,
                                            WindowTools.PaddingToPixelCoordinate(0.90f, 0f, 0, 10),
                                            (int)(20 * uiScale),
                                            (int)(10 * uiScale));
        }
Exemple #2
0
        private void Draw_TopLeftUI(SpriteBatch spriteBatch)
        {
            //Draw the win progress bar
            Vector2 barPos = characterDrawPos + new Vector2(uiScale * turnPlayer.CharacterSprite.Width / 2, 0f);

            PercentageBar.Draw(spriteBatch, emptyRect, barPos, winBarDimensions, turnPlayer.Colour, Color.Gray, turnPlayer.WinThreshold, turnPlayer.WinProgress);
            string text = $"{turnPlayer.WinProgress}/{turnPlayer.WinThreshold} Wins";

            spriteBatch.DrawString(bebasSmall, text, barPos + (winBarDimensions - 0.6f * bebasSmall.MeasureString(text)) / 2, Color.White, 0f, Vector2.Zero, 0.6f, SpriteEffects.None, 0f);

            //Draw the unit cap bar.
            Vector2 unitBarPos = barPos + new Vector2(0, winBarDimensions.Y);
            int     unitCount  = grid.CountPlayerUnitsOnGrid(turnPlayer.Id);

            PercentageBar.Draw(spriteBatch, emptyRect, unitBarPos, unitBarDimensions, Color.DarkRed, Color.YellowGreen, turnPlayer.UnitCap, unitCount);
            text = $"{unitCount}/{turnPlayer.UnitCap} Units";
            spriteBatch.DrawString(bebasSmall, text, unitBarPos + (unitBarDimensions - 0.5f * bebasSmall.MeasureString(text)) / 2, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);

            //Draw the players money amount.
            moneyBox.Draw(spriteBatch);
            string  moneyText = $"{turnPlayer.Money}";
            Vector2 textSize  = bebasSmall.MeasureString(moneyText);
            Vector2 basePos   = moneyBox.GetPos() + moneyBoxDimensions / 2;

            spriteBatch.DrawString(bebasSmall, moneyText, basePos - new Vector2(0, textSize.Y / 2), Color.White);
            spriteBatch.Draw(moneyIcon,
                             position: basePos + new Vector2(textSize.X + moneyBoxDimensions.X / 35, 0) - uiScale / 2 * new Vector2(0, moneyIcon.Height),
                             scale: uiScaleVector
                             );

            //Draw the player's character.
            spriteBatch.Draw(texture: characterBoundary, position: characterDrawPos - new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: turnPlayer.Colour);
            spriteBatch.Draw(texture: turnPlayer.CharacterSprite, position: characterDrawPos, scale: uiScaleVector);

            //draw end turn button
            if (endTurnButton.IsHovered)
            {
                spriteBatch.Draw(texture: endTurnButton.HoverTexture, position: endTurnButton.Position, scale: uiScaleVector);
            }
            else
            {
                spriteBatch.Draw(texture: endTurnButton.ButtonTexture, position: endTurnButton.Position, scale: uiScaleVector);
            }
            spriteBatch.DrawString(bebasSmall, "End Turn", endTurnButton.MidPoint - 0.6f * bebasSmall.MeasureString("End Turn") / 2 + new Vector2(0, 1), Color.White, 0f, Vector2.Zero, 0.6f, SpriteEffects.None, 0);

            //draw the level up unit cap button.
            levelUnitCapButton.Draw(spriteBatch, turnPlayer, moneyIcon, WindowTools.GetUpscaledValue(2f), bebasSmall, 0.6f);

            //and the ability button
            useAbilityButton.Draw(spriteBatch, turnPlayer, bebasSmall, 0.6f);

            divisorLine.Draw(spriteBatch);

            stageInfo.Draw(spriteBatch, vsAiIcon, vsPlayerIcon);

            //help button
            helpButton.Draw(spriteBatch, bebasSmall, 1f);
        }
Exemple #3
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 #4
0
        private void Draw_UI(SpriteBatch spriteBatch)
        {
            helpButton.Draw(spriteBatch, bebasSmall, 1f);

            //draw the players character and money if vs an AI.
            if (useAiOpponent)
            {
                moneyUiBox.Draw(spriteBatch);
                string  moneyText = $"{playerToCheckWinCondition.Money}";
                Vector2 textSize  = bebasSmall.MeasureString(moneyText);
                Vector2 basePos   = moneyUiBox.GetPos() + new Vector2(moneyBoxDimensions.X / 2f, moneyBoxDimensions.Y / 2);
                spriteBatch.DrawString(bebasSmall, moneyText, basePos - new Vector2(0, textSize.Y / 2), Color.White);
                spriteBatch.Draw(moneyIcon,
                                 position: basePos + new Vector2(textSize.X + moneyBoxDimensions.X / 35, 0) - uiScale / 2 * new Vector2(0, moneyIcon.Height),
                                 scale: uiScaleVector
                                 );

                //Draw the player's character.
                spriteBatch.Draw(texture: characterBoundary, position: characterPos[0] - new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: playerToCheckWinCondition.Colour);
                spriteBatch.Draw(texture: playerToCheckWinCondition.CharacterSprite, position: characterPos[0], scale: uiScaleVector);
            }
            //otherwise, draw each players character and their win progress.
            else
            {
                //Draw each players win % bars.
                Vector2 barPos = characterPos[0] + new Vector2(uiScale * otherPlayer.CharacterSprite.Width / 2, 0f);
                PercentageBar.Draw(spriteBatch, emptyRect, barPos, winBarDimensions, otherPlayer.Colour, Color.Gray, otherPlayer.WinThreshold, otherPlayer.WinProgress);
                string text = $"{otherPlayer.WinProgress}/{otherPlayer.WinThreshold} Wins";
                spriteBatch.DrawString(bebasSmall, text, barPos + (winBarDimensions - 0.6f * bebasSmall.MeasureString(text)) / 2, Color.White, 0f, Vector2.Zero, 0.6f, SpriteEffects.None, 0f);

                Vector2 lowerBarPos = characterPos[1] + new Vector2(uiScale * playerToCheckWinCondition.CharacterSprite.Width / 2, -winBarDimensions.Y);
                PercentageBar.Draw(spriteBatch, emptyRect, lowerBarPos, winBarDimensions, playerToCheckWinCondition.Colour, Color.Gray, playerToCheckWinCondition.WinThreshold, playerToCheckWinCondition.WinProgress);
                text = $"{playerToCheckWinCondition.WinProgress}/{playerToCheckWinCondition.WinThreshold} Wins";
                spriteBatch.DrawString(bebasSmall, text, lowerBarPos + (winBarDimensions - 0.6f * bebasSmall.MeasureString(text)) / 2, Color.White, 0f, Vector2.Zero, 0.6f, SpriteEffects.None, 0f);

                //Draw each players character with their boundary (their respective colour)
                spriteBatch.Draw(texture: characterBoundary, position: characterPos[0] - new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: otherPlayer.Colour);
                spriteBatch.Draw(texture: otherPlayer.CharacterSprite, position: characterPos[0], scale: uiScaleVector);

                Vector2 lowerDrawPos = characterPos[1] - new Vector2(0, playerToCheckWinCondition.CharacterSprite.Height * uiScale);
                spriteBatch.Draw(texture: characterBoundary, position: lowerDrawPos - new Vector2(3 * uiScale, 0), scale: uiScaleVector, color: playerToCheckWinCondition.Colour);
                spriteBatch.Draw(texture: playerToCheckWinCondition.CharacterSprite, position: lowerDrawPos, scale: uiScaleVector);
            }

            logDisplay.Draw(spriteBatch, actionLog.GetActionsInOrder(), players, actionLogTextures);
        }
Exemple #5
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);
        }