private void calculateTextOrigin(Renderer renderer)
 {
     if (center)
         textOrigin = renderer.Font.MeasureString(text, Font.DefaultSize * scale.X) / 2;
     else
         textOrigin = Vector2.Zero;
 }
 protected override void draw(Renderer renderer)
 {
     base.draw(renderer);
     renderer.Draw(whitePixelTextureData, Vector2.Zero, Color.Black, 0.0f, Game1.ScreenSize, false);
     Vector2 minScale = Game1.MinScreenScaleFactor;
     Vector2 fontScale = 4f * minScale;
     Vector2 textSize = renderer.Font.MeasureString(gameOverText, fontScale.Y * Font.DefaultSize);
     float alpha = gameOverAlphaTimer / gameOverAlphaTime;
     renderer.DrawText(gameOverText, Game1.ScreenSize / 2.0f, new Color(1.0f, 1.0f, 1.0f, alpha), 0.0f, textSize / 2.0f, fontScale);
 }
        protected override void draw(Renderer renderer)
        {
            sceneStack.Pop();
            Scene.DrawCurrent(renderer);
            sceneStack.Push(this);

            const float overlayAlpha = 0.7f;
            renderer.Draw(pixelTextureData, Vector2.Zero, Color.Black * overlayAlpha, 0.0f, Game1.ScreenSize);

            for (int i = 0; i < options.Count; ++i)
            {
                Color color = currentOptionIndex == i ? Color.Blue : Color.White;
                renderer.DrawText(options[i], new Vector2(200.0f, 200.0f + (i * 50.0f)), color, 0.0f, Vector2.Zero, Game1.ScreenScaleFactor);
            }
        }
        public Vector2 DrawButtonWithText(InputButton button, string text, Vector2 position, Color color, Renderer renderer, bool flip = false)
        {
            if (text != null && text.Length == 0)
                text = null;

            TextureData textureData = Input.GamePadUsedLast ? gamepadButtonTextureData[button] : keyboardButtonTextureData;
            Vector2 minScale = Game1.MinScreenScaleFactor;
            Vector2 textSize = renderer.Font.MeasureString(text ?? "I", Font.DefaultSize * minScale.Y);
            Vector2 buttonScale = new Vector2((textSize.Y * 1.1f) / textureData.Height);
            float halfButtonWidth = textureData.Width * 0.5f * buttonScale.X;
            Vector2 flipScale = flip ? new Vector2(-1.0f, 1.0f) : Vector2.One;

            if (text != null)
            {
                float buttonHeight = textureData.Height * buttonScale.Y;
                if (!Input.GamePadUsedLast)
                    buttonHeight -= buttonScale.Y;
                Vector2 backingSize = new Vector2((textSize.X * 1.1f) + (halfButtonWidth * 2.0f), buttonHeight);
                Vector2 backingPosition = position + new Vector2(halfButtonWidth, 0.0f);
                if (flip)
                    backingPosition.X -= backingSize.X;
                renderer.Draw(whitePixelTextureData, backingPosition, UiColor, 0.0f, backingSize * flipScale, false);
                const float borderScale = 0.2f;
                Vector2 borderScaleX = new Vector2(backingSize.X / BorderTextureData[N].Width, borderScale * minScale.Y);
                renderer.Draw(BorderTextureData[N], backingPosition, Color.White, 0.0f, borderScaleX * flipScale, false);
                renderer.Draw(BorderTextureData[S], backingPosition + new Vector2(0.0f, backingSize.Y - (BorderTextureData[S].Height * borderScaleX.Y)), Color.White, 0.0f, borderScaleX * flipScale, false);
                Vector2 cornerScale = borderScale * minScale;
                float cornerX = flip ? -BorderTextureData[NE].Width * cornerScale.X : backingSize.X;
                renderer.Draw(BorderTextureData[flip ? NW : NE], backingPosition + new Vector2(cornerX, 0.0f), Color.White, 0.0f, cornerScale, false);
                renderer.Draw(BorderTextureData[flip ? SW : SE], backingPosition + new Vector2(cornerX, backingSize.Y - (BorderTextureData[SE].Height * cornerScale.Y)), Color.White, 0.0f, cornerScale, false);
                Vector2 borderScaleY = new Vector2(borderScale * minScale.X, (backingSize.Y - (BorderTextureData[NE].Height * cornerScale.Y * 2.0f)) / BorderTextureData[E].Height);
                renderer.Draw(BorderTextureData[flip ? W : E], backingPosition + new Vector2(cornerX, BorderTextureData[NE].Height * cornerScale.Y), Color.White, 0.0f, borderScaleY, false);
                Vector2 textPosition = backingPosition + (flip ? Vector2.Zero : new Vector2(halfButtonWidth, 0.0f)) + ((backingSize - new Vector2(halfButtonWidth, 0.0f) - textSize) / 2.0f) + new Vector2(0.0f, minScale.Y);
                renderer.DrawText(text, textPosition, color, 0.0f, Vector2.Zero, minScale);
            }

            renderer.Draw(textureData, position, color, 0.0f, buttonScale, false);
            if (!Input.GamePadUsedLast)
            {
                text = Input.KeyboardMapping[button].ToString();
                textSize = renderer.Font.MeasureString(text, Font.DefaultSize);
                renderer.DrawText(text, new Vector2(position.X + (((halfButtonWidth * 2.0f) - textSize.X) / 2.0f), position.Y), Color.White, 0.0f, Vector2.Zero, minScale);
            }
            return textureData.Size * buttonScale;
        }
        protected override void draw(Renderer renderer)
        {
            Game1.BackgroundColor = Game1.GrassColor;
            renderer.Camera = Camera;
            renderer.Tint = Clock.GetCurrentColor();

            drawBackground(renderer);

            if (CurrentBattleState.BattleStateRenderer != null)
                CurrentBattleState.BattleStateRenderer.BeforeDraw(renderer);

            base.draw(renderer);

            renderer.ResetTint();

            drawPersistentGui(renderer);

            if (CurrentBattleState.BattleStateRenderer != null)
                CurrentBattleState.BattleStateRenderer.AfterDraw(renderer);

            renderer.Camera = null;
        }
        public virtual void DrawShadow(Renderer renderer)
        {
            if (!RenderShadow || !Visible)
                return;

            Vector2 shadowPosition = Position;
            Vector2 shadowScale = new Vector2(1.5f);
            if (Skeleton != null)
            {
                if (ShadowFollowBone != null)
                {
                    shadowPosition.X = ShadowFollowBone.WorldX;
                    shadowScale += new Vector2(ShadowFollowBone.WorldY - Skeleton.RootBone.WorldY) / 400.0f;
                }
            }
            else if (Sprite != null)
                shadowScale *= (Sprite.Data.Width * Sprite.TextureData.ScaleX) / (float)shadowTextureData.Width;

            renderer.SetShader(null);
            renderer.Draw(shadowTextureData, shadowPosition, Color.White * 0.5f, 0.0f, shadowScale * Scale);
        }
 public void DrawArrowOverPartyMember(PartyMember partyMember, Color color, Renderer renderer)
 {
     Rectangle boundingBox = partyMember.BattleEntity.GetBoundingBox();
     Vector2 position = new Vector2(boundingBox.X + (boundingBox.Width / 2) - (arrowTextureData.Width / 2), boundingBox.Y - arrowTextureData.Height);
     renderer.Draw(arrowTextureData, position, color);
 }
        private void drawPersistentGui(Renderer renderer)
        {
            Vector2 screenScaleFactor = new Vector2(MathHelper.Min(Game1.ScreenScaleFactor.X, Game1.ScreenScaleFactor.Y));
            Vector2 headPadding = new Vector2(30.0f) * screenScaleFactor;
            Vector2 barPadding = new Vector2(20.0f) * screenScaleFactor;
            Vector2 barSize = new Vector2(290, 30) * screenScaleFactor;

            Vector2 uiPosition = new Vector2(0.0f, Game1.ScreenSize.Y - (uiHeight * screenScaleFactor.Y));
            Vector2 uiSize = new Vector2(Game1.ScreenSize.X, uiHeight * screenScaleFactor.Y);
            renderer.Draw(whitePixelTextureData, uiPosition, UiColor, 0.0f, uiSize, false);
            drawGuiBorder(uiPosition, uiSize, renderer);

            Vector2 position = new Vector2(headPadding.X, uiPosition.Y + headPadding.Y);
            for (int i = 0; i < PlayerParty.Count; ++i)
            {
                drawPartyMemberUi(PlayerParty[i], position, headPadding, barPadding, barSize, renderer);
                position.X += (headPadding.X * 2) + barPadding.X + barSize.X + (CharacterClassHeadTextureData[PlayerParty[i].CharacterClass].Width * screenScaleFactor.X);
            }
        }
 public override void Draw(Renderer renderer)
 {
     foreach (Particle particle in particles)
     {
         if (particle.Alive)
             particle.Draw(tint, renderer, textureData);
     }
 }
 public static void DrawCurrent(Renderer renderer)
 {
     if (Current != null)
         Current.draw(renderer);
 }
 private void drawGuiBorder(Vector2 uiPosition, Vector2 uiSize, Renderer renderer)
 {
     Vector2 screenScaleFactor = Game1.ScreenScaleFactor;
     float borderWidth = uiSize.X - (BorderTextureData[E].Width * 2 * screenScaleFactor.X);
     Vector2 borderScaleX = new Vector2((1.0f / BorderTextureData[N].Width) * borderWidth, screenScaleFactor.Y);
     Vector2 borderScaleY = new Vector2(screenScaleFactor.X, (1.0f / BorderTextureData[W].Height) * uiSize.Y);
     Vector2 position = uiPosition - new Vector2(0.0f, BorderTextureData[N].Height * screenScaleFactor.Y);
     renderer.Draw(BorderTextureData[NW], position, Color.White, 0.0f, screenScaleFactor, false);
     renderer.Draw(BorderTextureData[W], uiPosition, Color.White, 0.0f, borderScaleY, false);
     position.X += BorderTextureData[NW].Width * screenScaleFactor.X;
     renderer.Draw(BorderTextureData[N], position, Color.White, 0.0f, borderScaleX, false);
     position.X += borderWidth;
     renderer.Draw(BorderTextureData[NE], position, Color.White, 0.0f, screenScaleFactor, false);
     position.Y = uiPosition.Y;
     renderer.Draw(BorderTextureData[E], position, Color.White, 0.0f, borderScaleY, false);
 }
        private void drawMap(Renderer renderer)
        {
            TileData testTile = Area.Data.OverworldTileTextureNamesToList()[0];
            TextureData testTextureData = ResourceManager.GetTextureData(testTile.TextureDataName);
            //TextureData pixelTexture = ResourceManager.GetTextureData("white_pixel");

            Rectangle cameraBoundingBox = camera.GetBoundingBox();
            int startX = Math.Max((cameraBoundingBox.Left / Map.TileSize) - 1, 0);
            int finishX = Math.Min(((cameraBoundingBox.Left + cameraBoundingBox.Width) / Map.TileSize) + 2, Map.TileWidth - 1);
            int startY = Math.Max((cameraBoundingBox.Top / Map.TileSize) - 1, 0);
            int finishY = Math.Min(((cameraBoundingBox.Top + cameraBoundingBox.Height) / Map.TileSize) + 2, Map.TileHeight - 1);

            /*for (int x = startX; x <= finishX; ++x)
            {
                for (int y = startY; y <= finishY; ++y)
                {
                    if (Map.CollisionMap[x, y])
                        renderer.Draw(pixelTexture, new Vector2(x, y) * Map.TileSize, Color.Black * 0.5f, 0.0f, new Vector2(Map.TileSize));
                }
            }*/

            for (int x = startX; x <= finishX; ++x)
            {
                for (int y = startY; y <= finishY; ++y)
                {
                    if (Map.CollisionMap[x, y])// && x % 2 == 0 && y % 2 == 0)
                    {
                        renderer.Draw(testTextureData, new Vector2(x, y) * Map.TileSize, Color.White);
                    }
                }
            }
        }
 protected virtual void draw(Renderer renderer)
 {
     Entities.Sort((a, b) => {
         if (a.ZIndex == b.ZIndex)
         {
             float aPos = a.DepthOverride > 0.0f ? a.DepthOverride : a.Position.Y;
             float bPos = b.DepthOverride > 0.0f ? b.DepthOverride : b.Position.Y;
             return aPos.CompareTo(bPos);
         }
         return b.ZIndex.CompareTo(a.ZIndex);
     });
     foreach (Entity entity in Entities)
         entity.DrawShadow(renderer);
     foreach (Entity entity in Entities)
         entity.Draw(renderer);
 }
        protected override void draw(Renderer renderer)
        {
            Game1.BackgroundColor = Game1.GrassColor;
            renderer.Camera = camera;
            renderer.Tint = Clock.GetCurrentColor();

            if (CurrentOverworldState.OverworldStateRenderer != null)
                CurrentOverworldState.OverworldStateRenderer.BeforeDraw(renderer);

            if (CurrentOverworldState.RenderWorld)
            {
                drawMap(renderer);
                base.draw(renderer);
            }

            renderer.ResetTint();

            if (CurrentOverworldState.OverworldStateRenderer != null)
                CurrentOverworldState.OverworldStateRenderer.AfterDraw(renderer);

            renderer.Camera = null;
        }
 protected override void LoadContent()
 {
     Input.Initialize(Content);
     ResourceManager.Initialize(Content, GraphicsDevice);
     renderer = new Renderer(GraphicsDevice, ResourceManager.GetShader("BasicTexture"));
     renderer.Font = ResourceManager.GetFont("verdana");
     restart();
 }
 public void Draw(Color tint, Renderer renderer, TextureData textureData)
 {
     float alpha = 1.0f - (time / lifeTime);
     renderer.Draw(textureData, position, new Color(tint.R, tint.G, tint.B, (byte)(255 * alpha)), rotation, new Vector2(scale));
 }
        private void drawBackground(Renderer renderer)
        {
            const float scale = 0.5f;
            Rectangle cameraBoundingBox = Camera.GetBoundingBox();

            float textureWidth = lowestBackgroundTextureWidth * scale * Camera.Scale.X;
            int drawCount = (int)Math.Ceiling(cameraBoundingBox.Right / textureWidth) + 1;
            int textureDataIndex = 0;
            for (int i = 0; i < drawCount; ++i)
            {
                TextureData textureData = backgroundTextureData[textureDataIndex];
                renderer.Draw(textureData, new Vector2(textureData.Width * scale * i, 0.0f), Color.White, 0.0f, new Vector2(scale));
                if (++textureDataIndex > backgroundTextureData.Count)
                    textureDataIndex = 0;
            }

            if (cameraBoundingBox.Left < 0)
            {
                drawCount = (int)Math.Ceiling(Math.Abs(cameraBoundingBox.Left) / textureWidth) + 1;
                textureDataIndex = backgroundTextureData.Count - 1;
                for (int i = -1; i >= -drawCount; --i)
                {
                    TextureData textureData = backgroundTextureData[textureDataIndex];
                    renderer.Draw(textureData, new Vector2(textureData.Width * scale * i, 0.0f), Color.White, 0.0f, new Vector2(scale));
                    if (--textureDataIndex < 0)
                        textureDataIndex = backgroundTextureData.Count - 1;
                }
            }
        }
 public abstract void AfterDraw(Renderer renderer);
 private void drawBar(Vector2 position, Vector2 size, float percentage, Color color, bool drawBacking, Renderer renderer)
 {
     if (drawBacking)
         renderer.Draw(whitePixelTextureData, position, Color.Black, 0.0f, size, false);
     renderer.Draw(whitePixelTextureData, position, color, 0.0f, new Vector2(size.X * percentage, size.Y), false);
 }
 public override void Draw(Renderer renderer)
 {
     if (textOrigin.X < 0.0f)
         calculateTextOrigin(renderer);
     renderer.DrawText(text, Position, new Color(Tint.R, Tint.G, Tint.B, (byte)(255 * (1.0f - (time / floatTimeInSeconds)))), 0.0f, textOrigin, scale, true);
 }
        private void drawPartyMemberUi(PartyMember partyMember, Vector2 position, Vector2 headPadding, Vector2 barPadding, Vector2 barSize, Renderer renderer)
        {
            Vector2 screenScaleFactor = Game1.ScreenScaleFactor;
            Vector2 minScale = new Vector2(MathHelper.Min(screenScaleFactor.X, screenScaleFactor.Y));
            Vector2 shadowOffset = new Vector2(-5.0f, 5.0f) * minScale;
            Color shadowColor = Color.Black * 0.4f;

            TextureData textureData = CharacterClassHeadTextureData[partyMember.CharacterClass];
            bool partyMemberThinking = partyMemberIsThinking(partyMember);

            if (partyMemberThinking)
            {
                renderer.Draw(textureData, position + (shadowOffset * 2.0f), shadowColor, 0.0f, minScale, false);
            }
            renderer.Draw(textureData, position, Color.White, 0.0f, minScale, false);

            if (partyMemberIsSelected(partyMember))
                renderer.Draw(arrowTextureData, position + new Vector2((textureData.Width / 2) - (arrowTextureData.Width / 2), -arrowTextureData.Height), Color.White, 0.0f, minScale, false);

            position.X += (textureData.Width * screenScaleFactor.X) + headPadding.X;

            Vector2 partyMemberNameSize = renderer.Font.MeasureString(partyMember.Name, Font.DefaultSize * minScale.Y);
            Vector2 partyMemberNamePosition = position + new Vector2(barSize.X / 2.0f, 20.0f * minScale.Y);
            if (partyMemberThinking)
                renderer.DrawText(partyMember.Name, partyMemberNamePosition + shadowOffset, shadowColor, 0.0f, partyMemberNameSize / 2.0f, minScale);
            renderer.DrawText(partyMember.Name, partyMemberNamePosition, Color.White, 0.0f, partyMemberNameSize / 2.0f, minScale);

            position.Y += partyMemberNameSize.Y + (20.0f * minScale.Y);
            float percentageHealth = partyMember.Health / (float)partyMember.MaxHealth;
            Color healthBarColor = percentageHealth > 0.5f ? Color.Lerp(Color.Yellow, Color.Green, (percentageHealth - 0.5f) / 0.5f) : Color.Lerp(Color.Red, Color.Yellow, percentageHealth / 0.5f);
            if (partyMemberThinking)
                drawBar(position + shadowOffset, barSize, 1.0f, shadowColor, false, renderer);
            drawBar(position, barSize, percentageHealth, healthBarColor, true, renderer);
            string barText = "HP: " + partyMember.Health.ToString() + "/" + partyMember.MaxHealth;
            Vector2 barTextSize = renderer.Font.MeasureString(barText, Font.DefaultSize * minScale.Y);
            renderer.DrawText(barText, position + (barSize / 2.0f), Color.White, 0.0f, barTextSize / 2.0f, minScale);

            position.Y += barSize.Y * 1.5f;
            partyMember.ForEachStatusEffect((statusEffect) => {
                float widthWithPadding = barSize.Y * 1.1f;
                Vector2 scale = new Vector2((1.0f / statusEffect.TextureData.Height) * barSize.Y);
                Vector2 nudge = new Vector2((widthWithPadding - (statusEffect.TextureData.Width * scale.X)) / 2.0f, 0.0f);
                renderer.Draw(statusEffect.TextureData, position + (statusEffect.TextureData.Origin * scale) + nudge, Color.White, 0.0f, scale, false);
                position.X += barSize.Y * 1.1f;
            });
        }
        public virtual void Draw(Renderer renderer)
        {
            if (!Visible)
                return;

            renderer.SetShader(Shader);

            if (Skeleton != null)
            {
                if (Altitude == 0.0f)
                    renderer.Draw(Skeleton, Tint);
                else
                {
                    Skeleton.RootBone.Y -= Altitude;
                    Skeleton.UpdateWorldTransform();
                    renderer.Draw(Skeleton, Tint);
                    Skeleton.RootBone.Y += Altitude;
                }
            }
            else if (Sprite != null)
                renderer.Draw(Sprite, Position - new Vector2(0.0f, Altitude), Tint, Rotation, Scale);
        }
 public abstract void BeforeDraw(Renderer renderer);
 public override void Draw(Renderer renderer)
 {
     renderer.Draw(textureData, Position, new Color(1.0f, 1.0f, 1.0f, alpha), 0.0f, Scale);
 }