Exemplo n.º 1
0
        public static bool PreDraw(SpriteBatch spriteBatch, BigProgressBarInfo info, ref BossBarDrawParams drawParams)
        {
            int index = info.npcIndexToAimAt;

            if (index < 0 || index > Main.maxNPCs)
            {
                return(false);                //Invalid data, abort
            }
            NPC npc = Main.npc[index];

            bool isModded = NpcToBossBar(npc, out ModBossBar bossBar);

            if (isModded)
            {
                drawParams.barTexture = GetTexture(bossBar).Value;
            }

            bool modify = true;

            foreach (GlobalBossBar globalBossBar in globalBossBars)
            {
                modify &= globalBossBar.PreDraw(spriteBatch, npc, ref drawParams);
            }

            if (modify && isModded)
            {
                modify = bossBar.PreDraw(spriteBatch, npc, ref drawParams);
            }

            return(modify);
        }
Exemplo n.º 2
0
        public override bool PreDraw(SpriteBatch spriteBatch, NPC npc, ref BossBarDrawParams drawParams)
        {
            if (npc.type == NPCID.EyeofCthulhu)
            {
                drawParams.iconColor = Main.DiscoColor;
            }

            return(true);
        }
Exemplo n.º 3
0
 public override void PostDraw(SpriteBatch spriteBatch, NPC npc, BossBarDrawParams drawParams)
 {
     if (npc.type == NPCID.EyeofCthulhu)
     {
         string  text = "GlobalBossBar Showcase";
         var     font = FontAssets.MouseText.Value;
         Vector2 size = font.MeasureString(text);
         spriteBatch.DrawString(font, text, drawParams.barCenter - size / 2, Color.White);
     }
 }
Exemplo n.º 4
0
        public override bool PreDraw(SpriteBatch spriteBatch, NPC npc, ref BossBarDrawParams drawParams)
        {
            //Make the bar shake the less health the NPC has
            float shakeIntensity = Utils.Clamp(1f - drawParams.lifePercentToShow - 0.2f, 0f, 1f);

            drawParams.barCenter.Y -= 20f;
            drawParams.barCenter   += new Vector2(Main.rand.NextFloat(-1f, 1f), Main.rand.NextFloat(-1f, 1f)) * shakeIntensity * 15f;

            drawParams.iconColor = Main.DiscoColor;

            return(true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws a healthbar with fixed barTexture dimensions (516x348) where the effective bar top left starts at 32x24, and is 456x22 big
        /// <para>The icon top left starts at 4x20, and is 26x28 big</para>
        /// <para>Frame 0 contains the frame (outline)</para>
        /// <para>Frame 1 contains the 2 pixel wide strip for the tip of the bar itself</para>
        /// <para>Frame 2 contains the 2 pixel wide strip for the bar itself, stretches out</para>
        /// <para>Frame 3 contains the background</para>
        /// <para>Frame 4 contains the 2 pixel wide strip for the tip of the bar itself (optional shield)</para>
        /// <para>Frame 5 contains the 2 pixel wide strip for the bar itself, stretches out (optional shield)</para>
        /// <para>Supply your own textures if you need a different shape/color, otherwise you can make your own method to draw it</para>
        /// </summary>
        /// <param name="spriteBatch">The spriteBatch that is drawn on</param>
        /// <param name="drawParams">The draw parameters for the boss bar</param>
        public static void DrawFancyBar_TML(SpriteBatch spriteBatch, BossBarDrawParams drawParams)
        {
            //DrawFancyBar without shieldPercent gets redirected to DrawFancyBar with shieldPercent as 0f
            //DrawFancyBar with shieldPercent gets redirected to this

            (Texture2D barTexture, Vector2 barCenter, Texture2D iconTexture, Rectangle iconFrame, Color iconColor, float lifePercentToShow, float shieldPercentToShow, float iconScale) = drawParams;

            Point barSize       = new Point(456, 22);       //Size of the bar
            Point topLeftOffset = new Point(32, 24);        //Where the top left of the bar starts
            int   frameCount    = 6;

            Rectangle bgFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 3);
            Color     bgColor = Color.White * 0.2f;

            int scale = (int)(barSize.X * lifePercentToShow);

            scale -= scale % 2;
            Rectangle barFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 2);

            barFrame.X     += topLeftOffset.X;
            barFrame.Y     += topLeftOffset.Y;
            barFrame.Width  = 2;
            barFrame.Height = barSize.Y;

            Rectangle tipFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 1);

            tipFrame.X     += topLeftOffset.X;
            tipFrame.Y     += topLeftOffset.Y;
            tipFrame.Width  = 2;
            tipFrame.Height = barSize.Y;

            int shieldScale = (int)(barSize.X * shieldPercentToShow);

            shieldScale -= shieldScale % 2;

            Rectangle barShieldFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 5);

            barShieldFrame.X     += topLeftOffset.X;
            barShieldFrame.Y     += topLeftOffset.Y;
            barShieldFrame.Width  = 2;
            barShieldFrame.Height = barSize.Y;

            Rectangle tipShieldFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 4);

            tipShieldFrame.X     += topLeftOffset.X;
            tipShieldFrame.Y     += topLeftOffset.Y;
            tipShieldFrame.Width  = 2;
            tipShieldFrame.Height = barSize.Y;

            Rectangle barPosition = Utils.CenteredRectangle(barCenter, barSize.ToVector2());
            Vector2   barTopLeft  = barPosition.TopLeft();
            Vector2   topLeft     = barTopLeft - topLeftOffset.ToVector2();

            //Background
            spriteBatch.Draw(barTexture, topLeft, bgFrame, bgColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            //Bar itself
            Vector2 stretchScale = new Vector2(scale / barFrame.Width, 1f);
            Color   barColor     = Color.White;

            spriteBatch.Draw(barTexture, barTopLeft, barFrame, barColor, 0f, Vector2.Zero, stretchScale, SpriteEffects.None, 0f);

            //Tip
            spriteBatch.Draw(barTexture, barTopLeft + new Vector2(scale - 2, 0f), tipFrame, barColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            //Bar itself (shield)
            if (shieldPercentToShow != 0f)
            {
                stretchScale = new Vector2(shieldScale / barFrame.Width, 1f);
                spriteBatch.Draw(barTexture, barTopLeft, barShieldFrame, barColor, 0f, Vector2.Zero, stretchScale, SpriteEffects.None, 0f);

                //Tip
                spriteBatch.Draw(barTexture, barTopLeft + new Vector2(shieldScale - 2, 0f), tipShieldFrame, barColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }

            //Frame
            Rectangle frameFrame = barTexture.Frame(verticalFrames: frameCount, frameY: 0);

            spriteBatch.Draw(barTexture, topLeft, frameFrame, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            //Icon
            Vector2 iconOffset = new Vector2(4f, 20f);
            Vector2 iconSize   = new Vector2(26f, 28f);
            //The vanilla method with the shieldPercent parameter, which is used only by the lunar pillars, uses iconSize = iconFrame.Size() instead, which have a size of 26x30,
            //causing a slight vertical offset that is barely noticeable. Concidering that the non-shieldPercent method is the more general one, let's keep it like this
            //(changing that using the lunar pillar code will cause many other icons to be offset instead) --direwolf420
            Vector2 iconPos = iconOffset + iconSize / 2f;

            //iconFrame Centered around iconPos
            spriteBatch.Draw(iconTexture, topLeft + iconPos, iconFrame, iconColor, 0f, iconFrame.Size() / 2f, iconScale, SpriteEffects.None, 0f);
        }
Exemplo n.º 6
0
        public static void PostDraw(SpriteBatch spriteBatch, BigProgressBarInfo info, BossBarDrawParams drawParams)
        {
            int index = info.npcIndexToAimAt;

            if (index < 0 || index > Main.maxNPCs)
            {
                return;                 //Invalid data, abort
            }
            NPC npc = Main.npc[index];

            if (NpcToBossBar(npc, out ModBossBar bossBar))
            {
                bossBar.PostDraw(spriteBatch, npc, drawParams);
            }

            foreach (GlobalBossBar globalBossBar in globalBossBars)
            {
                globalBossBar.PostDraw(spriteBatch, npc, drawParams);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Allows you to draw things after the bar has been drawn. skipped is true if you or another mod has skipped drawing the bar in PreDraw (possibly hiding it or in favor of new visuals).
 /// </summary>
 /// <param name="spriteBatch">The spriteBatch that is drawn on</param>
 /// <param name="npc">The NPC this ModBossBar is focused on</param>
 /// <param name="drawParams">The draw parameters for the boss bar</param>
 public virtual void PostDraw(SpriteBatch spriteBatch, NPC npc, BossBarDrawParams drawParams)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Allows you to draw things before the default draw code is ran. Return false to prevent drawing the ModBossBar. Returns true by default.
 /// </summary>
 /// <param name="spriteBatch">The spriteBatch that is drawn on</param>
 /// <param name="npc">The NPC this ModBossBar is focused on</param>
 /// <param name="drawParams">The draw parameters for the boss bar</param>
 /// <returns><see langword="true"/> for allowing drawing, <see langword="false"/> for preventing drawing</returns>
 public virtual bool PreDraw(SpriteBatch spriteBatch, NPC npc, ref BossBarDrawParams drawParams) => true;