diff --git a/Tiles/BaseTiles/BaseBossRelic.cs b/Tiles/BaseTiles/BaseBossRelic.cs index 4805328ac3..3e2575ff6e 100644 --- a/Tiles/BaseTiles/BaseBossRelic.cs +++ b/Tiles/BaseTiles/BaseBossRelic.cs @@ -95,25 +95,21 @@ namespace CalamityMod.Tiles.BaseTiles public override void SpecialDraw(int i, int j, SpriteBatch spriteBatch) { - // This is lighting-mode specific, always include this if you draw tiles manually + // This is lighting-mode specific, always include this if you draw tiles manually. Vector2 offScreen = new Vector2(Main.offScreenRange); if (Main.drawToScreen) - { offScreen = Vector2.Zero; - } - // Take the tile, check if it actually exists + // Take the tile, check if it actually exists. Point p = new Point(i, j); Tile tile = Main.tile[p.X, p.Y]; if (tile == null || !tile.HasTile) - { return; - } - // Get the initial draw parameters + // Get the initial draw parameters. Texture2D texture = RelicTexture.Value; - int frameY = tile.TileFrameX / FrameWidth; // Picks the frame on the sheet based on the placeStyle of the item + int frameY = tile.TileFrameX / FrameWidth; // Picks the frame on the sheet based on the placeStyle of the item. Rectangle frame = texture.Frame(HorizontalFrames, VerticalFrames, 0, frameY); Vector2 origin = frame.Size() / 2f; @@ -121,26 +117,26 @@ namespace CalamityMod.Tiles.BaseTiles Color color = Lighting.GetColor(p.X, p.Y); - bool direction = tile.TileFrameY / FrameHeight != 0; // This is related to the alternate tile data we registered before + bool direction = tile.TileFrameY / FrameHeight != 0; // This is related to the alternate tile data we registered before. SpriteEffects effects = direction ? SpriteEffects.FlipHorizontally : SpriteEffects.None; - // Some math magic to make it smoothly move up and down over time + // Some math magic to make it smoothly move up and down over time. const float TwoPi = (float)Math.PI * 2f; float offset = (float)Math.Sin(Main.GlobalTimeWrappedHourly * TwoPi / 5f); Vector2 drawPos = worldPos + offScreen - Main.screenPosition + new Vector2(0f, -40f) + new Vector2(0f, offset * 4f); - // Draw the main texture + // Draw the main texture. spriteBatch.Draw(texture, drawPos, frame, color, 0f, origin, 1f, effects, 0f); - // Draw the periodic glow effect + // Draw the periodic glow effect. float scale = (float)Math.Sin(Main.GlobalTimeWrappedHourly * TwoPi / 2f) * 0.3f + 0.7f; Color effectColor = color; effectColor.A = 0; effectColor = effectColor * 0.1f * scale; - for (float num5 = 0f; num5 < 1f; num5 += 1f / 6f) - { - spriteBatch.Draw(texture, drawPos + (TwoPi * num5).ToRotationVector2() * (6f + offset * 2f), frame, effectColor, 0f, origin, 1f, effects, 0f); - } + float offset2 = 6f + offset * 2f; + float oneSixth = 1f / 6f; + for (float k = 0f; k < 1f; k += oneSixth) + spriteBatch.Draw(texture, drawPos + (TwoPi * k).ToRotationVector2() * offset2, frame, effectColor, 0f, origin, 1f, effects, 0f); } } } diff --git a/Tiles/BaseTiles/BasePylonTile.cs b/Tiles/BaseTiles/BasePylonTile.cs index 78555f954a..c5f751bdc4 100644 --- a/Tiles/BaseTiles/BasePylonTile.cs +++ b/Tiles/BaseTiles/BasePylonTile.cs @@ -102,18 +102,18 @@ namespace CalamityMod.Tiles.BaseTiles Rectangle frame = crystalTexture.Frame(CrystalHorizontalFrameCount, CrystalVerticalFrameCount, 0, frameY); Vector2 origin = frame.Size() / 2f; - //Used to make the crystal bob, and the 6-way glow pulse a bit + // Used to make the crystal bob, and the 6-way glow pulse a bit. float sineOffset = (float)Math.Sin(Main.GlobalTimeWrappedHourly * MathHelper.TwoPi / 5f); Vector2 tilePosition = p.ToWorldCoordinates(24f, 64f); Vector2 drawCenter = tilePosition + offScreen + Vector2.UnitY * (-40f + sineOffset * 4f); - drawCenter -= Vector2.One; //This isn't vanilla, but since our sheets lack the extra side 2 pixels, it makes our pylons offset by one pixel in each direction (imperceptible). This makes our pylons 100% aligned with vanilla + drawCenter -= Vector2.One; // This isn't vanilla, but since our sheets lack the extra side 2 pixels, it makes our pylons offset by one pixel in each direction (imperceptible). This makes our pylons 100% aligned with vanilla. - //Vanilla just has a nextbool(4) but thats because vanilla doesnt care about the update rate. We do this because in the updateEveryFrame lightning mode, the game runs the draw calls 4x as often + // Vanilla just has a nextbool(4) but thats because vanilla doesnt care about the update rate. We do this because in the updateEveryFrame lightning mode, the game runs the draw calls 4x as often. bool frameToSpawnDust = !Lighting.UpdateEveryFrame || Main.rand.NextBool(4); if (!Main.gamePaused && Main.instance.IsActive && frameToSpawnDust && Main.rand.NextBool(10)) { - //Important to remember to remove the offscreen vector. Vanilla drawing doesn't have this vector, but we do. If we don't remove it, the dust just gets spawned offscreen + //Important to remember to remove the offscreen vector. Vanilla drawing doesn't have this vector, but we do. If we don't remove it, the dust just gets spawned offscreen. Rectangle dustBox = Utils.CenteredRectangle(drawCenter - offScreen, frame.Size()); int dust = Dust.NewDust(dustBox.TopLeft(), dustBox.Width, dustBox.Height, DustID, 0f, 0f, 254, DustColor, 0.5f); @@ -121,35 +121,33 @@ namespace CalamityMod.Tiles.BaseTiles Main.dust[dust].velocity.Y -= 0.2f; } - //Crystal is 80% fullbright + // Crystal is 80% fullbright. Color crystalColor = Color.Lerp(Lighting.GetColor(p.X, p.Y), Color.White, 0.8f); spriteBatch.Draw(crystalTex, drawCenter - Main.screenPosition, frame, crystalColor * 0.7f, 0f, origin, 1f, 0f, 0f); - //Draw a 6-way glowing effect + // Draw a 6-way glowing effect. float glowOpacity = (float)Math.Sin((double)Main.GlobalTimeWrappedHourly * MathHelper.TwoPi) * 0.2f + 0.8f; Color glowColor = new Color(255, 255, 255, 0) * 0.1f * glowOpacity; - for (float k = 0f; k < 1f; k += 1 / 6f) - { - spriteBatch.Draw(crystalTex, drawCenter - Main.screenPosition + (MathHelper.TwoPi * k).ToRotationVector2() * (6f + sineOffset * 2f), frame, glowColor, 0f, origin, 1f, 0f, 0f); - } + float oneSixth = 1f / 6f; + float offset = 6f + sineOffset * 2f; + for (float k = 0f; k < 1f; k += oneSixth) + spriteBatch.Draw(crystalTex, drawCenter - Main.screenPosition + (MathHelper.TwoPi * k).ToRotationVector2() * offset, frame, glowColor, 0f, origin, 1f, 0f, 0f); int tileSelectionTier = 0; if (Main.InSmartCursorHighlightArea(p.X, p.Y, out var actuallySelected)) { tileSelectionTier = 1; if (actuallySelected) - { tileSelectionTier = 2; - } } - //Draw the selection glow + // Draw the selection glow. if (tileSelectionTier != 0) { int averageBrightness = (crystalColor.R + crystalColor.G + crystalColor.B) / 3; if (averageBrightness > 10) { - //Use the vanilla crystal sheet to get the autoselect outline + // Use the vanilla crystal sheet to get the autoselect outline. Texture2D vanillaCrystalSheet = TextureAssets.Extra[181].Value; Rectangle smartCursorGlowFrame = vanillaCrystalSheet.Frame(12, 8, 2, frameY); diff --git a/UI/AstralArcanumUI.cs b/UI/AstralArcanumUI.cs index cabd3d2c78..ef5cc8cbfb 100644 --- a/UI/AstralArcanumUI.cs +++ b/UI/AstralArcanumUI.cs @@ -55,40 +55,43 @@ namespace CalamityMod.UI } else { - //Closed, do stuff in here if need be + // Closed, do stuff in here if need be. } } public static void UpdateAndDraw(SpriteBatch sb) { - //Don't do anything if not open + // Don't do anything if not open. if (!Open) return; - //Draw center circle + // Draw center circle DrawCircle(sb, CenterPoint, 0, CircleStyle.Normal); Vector2 centerToMouse = Main.MouseScreen - CenterPoint; float rotation = centerToMouse.ToRotation(); - //Draw the arrow that points towards the mouse + // Draw the arrow that points towards the mouse. sb.Draw(CircleTextures, CenterPoint, new Rectangle(0, CircleTextureSize, 24, 10), Color.White, rotation, new Vector2(12, 5f), 1f, SpriteEffects.None, 0f); int current = 0; int selectedCircle = -1; + int offset = CircleOffset * 2; + int radius = CircleTextureSize / 2; + for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { Vector2 center = new Vector2( - CenterPoint.X - CircleOffset + x * CircleOffset * 2, - CenterPoint.Y - CircleOffset + y * CircleOffset * 2); + CenterPoint.X - CircleOffset + x * offset, + CenterPoint.Y - CircleOffset + y * offset); - Circle c = new Circle(center, CircleTextureSize / 2); + Circle c = new Circle(center, radius); CircleStyle style = CircleStyle.Normal; - //If the mouse is in the circle + // If the mouse is in the circle. if (c.Contains(Main.MouseScreen)) { style = CircleStyle.Selected; @@ -97,7 +100,7 @@ namespace CalamityMod.UI selectedCircle = current; - //If left clicked + // If left clicked. if ((Main.mouseLeft && Main.mouseLeftRelease)) { Main.mouseLeftRelease = false; @@ -113,7 +116,7 @@ namespace CalamityMod.UI } } - //Literally so the sound plays + // Literally so the sound plays. if (LastHovered != selectedCircle) { LastHovered = selectedCircle; diff --git a/UI/BossHealthBarManager.cs b/UI/BossHealthBarManager.cs index 94f6ae7b6a..82f4d3e09b 100644 --- a/UI/BossHealthBarManager.cs +++ b/UI/BossHealthBarManager.cs @@ -695,10 +695,12 @@ namespace CalamityMod.UI { float pulse = (float)Math.Sin(Main.GlobalTimeWrappedHourly * 4.5f) * 0.5f + 0.5f; float outwardness = EnrageTimer / (float)EnrageAnimationTime * 1.5f + pulse * 2f; + Color color1 = Color.Red * 0.6f; + Color color2 = Color.Black * 0.2f; for (int i = 0; i < 4; i++) { Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * outwardness; - CalamityUtils.DrawBorderStringEightWay(sb, FontAssets.MouseText.Value, name, new Vector2(x + BarMaxWidth - nameSize.X, y + 23 - nameSize.Y) + drawOffset, Color.Red * 0.6f, Color.Black * 0.2f); + CalamityUtils.DrawBorderStringEightWay(sb, FontAssets.MouseText.Value, name, new Vector2(x + BarMaxWidth - nameSize.X, y + 23 - nameSize.Y) + drawOffset, color1, color2); } } } @@ -708,10 +710,12 @@ namespace CalamityMod.UI { float pulse = (float)Math.Sin(Main.GlobalTimeWrappedHourly * 4.5f) * 0.5f + 0.5f; float outwardness = IncreasingDefenseOrDRTimer / (float)IncreasedDefenseOrDRAnimationTime * 1.5f + pulse * 2f; + Color color1 = Color.LightGray * 0.6f; + Color color2 = Color.Black * 0.2f; for (int i = 0; i < 4; i++) { Vector2 drawOffset = (MathHelper.TwoPi * i / 4f).ToRotationVector2() * outwardness; - CalamityUtils.DrawBorderStringEightWay(sb, FontAssets.MouseText.Value, name, new Vector2(x + BarMaxWidth - nameSize.X, y + 23 - nameSize.Y) + drawOffset, Color.LightGray * 0.6f, Color.Black * 0.2f); + CalamityUtils.DrawBorderStringEightWay(sb, FontAssets.MouseText.Value, name, new Vector2(x + BarMaxWidth - nameSize.X, y + 23 - nameSize.Y) + drawOffset, color1, color2); } } } diff --git a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs index e3a00ad00d..9eaeb4654f 100644 --- a/UI/CalamitasEnchantments/CalamitasEnchantUI.cs +++ b/UI/CalamitasEnchantments/CalamitasEnchantUI.cs @@ -188,9 +188,10 @@ namespace CalamityMod.UI.CalamitasEnchants costDrawPositionTopLeft.X += (int)((FontAssets.MouseText.Value.MeasureString(costText).X * 0.5f + 12f) * Main.UIScale); int[] coinsArray = Utils.CoinsSplit(cost); + float y = costDrawPositionTopLeft.Y + 54f * Main.UIScale; for (int i = 0; i < 4; i++) { - Vector2 drawPosition = new Vector2(costDrawPositionTopLeft.X + (ChatManager.GetStringSize(FontAssets.MouseText.Value, costText, Vector2.One, -1f).X + ((24 * i) - 24f)) * Main.UIScale, costDrawPositionTopLeft.Y + 54f * Main.UIScale); + Vector2 drawPosition = new Vector2(costDrawPositionTopLeft.X + (ChatManager.GetStringSize(FontAssets.MouseText.Value, costText, Vector2.One, -1f).X + ((24 * i) - 24f)) * Main.UIScale, y); spriteBatch.Draw(TextureAssets.Item[ItemID.PlatinumCoin - i].Value, drawPosition, null, Color.White, 0f, TextureAssets.Item[ItemID.PlatinumCoin - i].Size() * 0.5f, Main.UIScale, SpriteEffects.None, 0f); Utils.DrawBorderStringFourWay(spriteBatch, FontAssets.ItemStack.Value, coinsArray[3 - i].ToString(), drawPosition.X - 11f, drawPosition.Y, Color.White, Color.Black, new Vector2(0.3f), 0.75f * Main.UIScale); } diff --git a/UI/DraedonLogs/DraedonsLogGUI.cs b/UI/DraedonLogs/DraedonsLogGUI.cs index 89bfd6a208..e14730ab4f 100644 --- a/UI/DraedonLogs/DraedonsLogGUI.cs +++ b/UI/DraedonLogs/DraedonsLogGUI.cs @@ -61,23 +61,15 @@ namespace CalamityMod.UI.DraedonLogs float yPageTop = MathHelper.Lerp(Main.screenHeight * 2, Main.screenHeight * 0.25f, FadeTime / (float)FadeTimeMax); Rectangle mouseRectangle = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 2, 2); + float drawPositionX = Main.screenWidth * 0.5f; + Vector2 drawPosition = new Vector2(drawPositionX, yPageTop); + Rectangle pageRectangle = new Rectangle((int)drawPosition.X - (int)(pageTexture.Width * scale.X), (int)yPageTop, (int)(pageTexture.Width * scale.X) * 2, (int)(pageTexture.Height * scale.Y)); for (int i = 0; i < 2; i++) { - Vector2 drawPosition = new Vector2(Main.screenWidth * 0.5f, yPageTop); - spriteBatch.Draw(pageTexture, - drawPosition, - null, - Color.White, - 0f, - new Vector2(i == 0f ? pageTexture.Width : 0f, 0f), - scale, - i == 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, - 0f); + spriteBatch.Draw(pageTexture, drawPosition, null, Color.White, 0f, new Vector2(i == 0f ? pageTexture.Width : 0f, 0f), scale, i == 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f); + if (!HoveringOverBook) - { - Rectangle pageRectangle = new Rectangle((int)drawPosition.X - (int)(pageTexture.Width * scale.X), (int)yPageTop, (int)(pageTexture.Width * scale.X) * 2, (int)(pageTexture.Height * scale.Y)); HoveringOverBook = mouseRectangle.Intersects(pageRectangle); - } } // Create text and arrows. @@ -100,24 +92,19 @@ namespace CalamityMod.UI.DraedonLogs Page = TotalPages; DrawArrows(spriteBatch, xResolutionScale, yResolutionScale, yPageTop + 506f * yResolutionScale, mouseRectangle); + + int textDrawPositionX = (int)(pageTexture.Width * xResolutionScale + 350 * xResolutionScale); + int yScale = (int)(42 * yResolutionScale); + int yScale2 = (int)(yOffsetPerLine * yResolutionScale); for (int i = 0; i < dialogLines.Count; i++) { if (dialogLines[i] != null) { - int textDrawPositionX = (int)(pageTexture.Width * xResolutionScale + 350 * xResolutionScale); - int textDrawPositionY = (int)(42 * yResolutionScale) + i * (int)(yOffsetPerLine * yResolutionScale) + (int)yPageTop; - - Utils.DrawBorderStringFourWay(spriteBatch, - FontAssets.MouseText.Value, - dialogLines[i], - textDrawPositionX, - textDrawPositionY, - Color.DarkCyan, - Color.Black, - Vector2.Zero, - xResolutionScale); + int textDrawPositionY = yScale + i * yScale2 + (int)yPageTop; + Utils.DrawBorderStringFourWay(spriteBatch, FontAssets.MouseText.Value, dialogLines[i], textDrawPositionX, textDrawPositionY, Color.DarkCyan, Color.Black, Vector2.Zero, xResolutionScale); } } + DrawSpecialImage(spriteBatch, xResolutionScale, yResolutionScale, yPageTop - 70f * yResolutionScale); } } diff --git a/UI/DraedonsArsenal/LabHologramProjectorUI.cs b/UI/DraedonsArsenal/LabHologramProjectorUI.cs index 967fcd109c..a1e3263a62 100644 --- a/UI/DraedonsArsenal/LabHologramProjectorUI.cs +++ b/UI/DraedonsArsenal/LabHologramProjectorUI.cs @@ -83,14 +83,14 @@ namespace CalamityMod.UI.DraedonsArsenal Vector2.Zero, 1f, SpriteEffects.None, 0f); // Draw the dialogue itself. + float x = (int)TextPadding + (int)(Main.screenWidth - TextAreaWidth) / 2; for (int i = 0; i < lineCount + 1; i++) { string text = dialogLines[i]; if (text is null) continue; - Utils.DrawBorderStringFourWay(spriteBatch, FontAssets.MouseText.Value, dialogLines[i], - (int)TextPadding + (int)(Main.screenWidth - TextAreaWidth) / 2, 120 + i * YOffsetPerLine, Color.Cyan, Color.Black, - Vector2.Zero); + + Utils.DrawBorderStringFourWay(spriteBatch, FontAssets.MouseText.Value, dialogLines[i], x, 120 + i * YOffsetPerLine, Color.Cyan, Color.Black, Vector2.Zero); } } } diff --git a/UI/ModeIndicator/ModeIndicatorUI.cs b/UI/ModeIndicator/ModeIndicatorUI.cs index 7bb61f7a36..90c6b4b05d 100644 --- a/UI/ModeIndicator/ModeIndicatorUI.cs +++ b/UI/ModeIndicator/ModeIndicatorUI.cs @@ -18,6 +18,7 @@ using Terraria.GameInput; using Terraria.UI.Chat; using System.Text.RegularExpressions; using static Terraria.GameContent.FontAssets; +using System.Runtime.InteropServices; namespace CalamityMod.UI.ModeIndicator { @@ -310,35 +311,39 @@ namespace CalamityMod.UI.ModeIndicator text = string.Empty; bool modeHovered = false; + Vector2 positionOffset = (barLength / (float)(tiers + 1f)) * Vector2.UnitY; + float progressMult = 0.8f * progress; + Color progressColor = Color.White * progress; for (int i = 0; i < tiers; i++) { int modesAtTier = DifficultyTiers[i].Length; + float width = WidthForTier(modesAtTier) * 0.5f; for (int j = 0; j < modesAtTier; j++) { DifficultyMode mode = DifficultyTiers[i][j]; Texture2D hexIcon = mode.Texture.Value; + Vector2 hexIconSize = hexIcon.Size(); - //Get position - Vector2 iconPosition = basePosition + (barLength / (float)(tiers + 1f)) * Vector2.UnitY * i; + // Get position. + Vector2 iconPosition = basePosition + positionOffset * i; if (modesAtTier > 1) - iconPosition += Vector2.UnitX * MathHelper.Lerp(WidthForTier(modesAtTier) * -0.5f, WidthForTier(modesAtTier) * 0.5f, j / (float)(modesAtTier - 1)) * BarWidthExpansionProgress; + iconPosition += Vector2.UnitX * MathHelper.Lerp(width * -1f, width, j / (float)(modesAtTier - 1)) * BarWidthExpansionProgress; - bool hovered = MouseScreenArea.Intersects(Utils.CenteredRectangle(iconPosition, hexIcon.Size())); + bool hovered = MouseScreenArea.Intersects(Utils.CenteredRectangle(iconPosition, hexIconSize)); float usedOpacity = mode.Enabled ? 0.85f : 0.55f; - if (hovered) usedOpacity = MathHelper.Lerp(usedOpacity, 1f, 0.7f); - //outline the currently selected difficulty. + // Outline the currently selected difficulty. if (mode == GetCurrentDifficulty) { usedOpacity = 1f; - spriteBatch.Draw(outlineTexture, iconPosition, null, mode.ChatTextColor * 0.8f * progress, 0f, outlineTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + spriteBatch.Draw(outlineTexture, iconPosition, null, mode.ChatTextColor * progressMult, 0f, outlineTexture.Size() * 0.5f, 1f, SpriteEffects.None, 0f); } - spriteBatch.Draw(hexIcon, iconPosition, null, Color.White * usedOpacity * progress, 0f, hexIcon.Size() * 0.5f, 1f, SpriteEffects.None, 0f); + spriteBatch.Draw(hexIcon, iconPosition, null, progressColor * usedOpacity, 0f, hexIconSize * 0.5f, 1f, SpriteEffects.None, 0f); if (menuOpenTransitionTime == 0 && hovered) { @@ -376,10 +381,10 @@ namespace CalamityMod.UI.ModeIndicator string text = "\n" + mode.ShortDescription.ToString(); - //Not scuffed anymore + // Not scuffed anymore. if (mode.ExpandedDescription != LocalizedText.Empty) { - //Show the description either if the player is holding shift. + // Show the description either if the player is holding shift. if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift)) text += "\n" + mode.ExpandedDescription.ToString(); @@ -393,47 +398,45 @@ namespace CalamityMod.UI.ModeIndicator public static void SwitchToDifficulty(DifficultyMode mode) { //No swap on server (although this doesn't matter anymore since it's not an item but dnc. - //No swap if the requested difficulty is the same as the current one + //No swap if the requested difficulty is the same as the current one. if (mode == GetCurrentDifficulty) return; - //Todo, maybe in the future having a way to have multiple difficulty options on the same tier that can coexist, and it works in branching pathes? Not very necessary for cal & addons - //But would be super useful so other mods can let their own difficulties go there. + // Todo, maybe in the future having a way to have multiple difficulty options on the same tier that can coexist, and it works in branching pathes? Not very necessary for cal & addons. + // But would be super useful so other mods can let their own difficulties go there. - //Disable difficulties + // Disable difficulties. for (int i = 0; i < Difficulties.Length; i++) { - //Disable all difficulties at the same tier / at a tier above itself + // Disable all difficulties at the same tier / at a tier above itself. if (Difficulties[i]._difficultyTier >= mode._difficultyTier && Difficulties[i] != mode) { if (Difficulties[i].Enabled) { if (Difficulties[i].DeactivationTextKey != string.Empty) DisplayLocalizedText(Difficulties[i].DeactivationTextKey, Difficulties[i].ChatTextColor); + Difficulties[i].Enabled = false; } } } - //Look at all the lower tiers. + // Look at all the lower tiers. for (int i = 0; i < mode._difficultyTier; i++) { - //If there are no alternate difficulties at that tier, no need to ask, just choose that one. + // If there are no alternate difficulties at that tier, no need to ask, just choose that one. if (DifficultyTiers[i].Length == 1) { DifficultyTiers[i][0].Enabled = true; - } - - //if there are alternate difficulties, we ask nicely to know which one is the preffered one. + } + // If there are alternate difficulties, we ask nicely to know which one is the preffered one. else { - //First off, disable them all to avoid conflicts if one was already selected before. + // First off, disable them all to avoid conflicts if one was already selected before. for (int j = 0; j < DifficultyTiers[i].Length; j++) - { DifficultyTiers[i][j].Enabled = false; - } - //Enable the one favored by the mode. + // Enable the one favored by the mode. DifficultyTiers[i][mode.FavoredDifficultyAtTier(i)].Enabled = true; } } diff --git a/Utilities/CollisionUtils.cs b/Utilities/CollisionUtils.cs index f8b02121b2..bdfb95b8ea 100644 --- a/Utilities/CollisionUtils.cs +++ b/Utilities/CollisionUtils.cs @@ -75,6 +75,7 @@ namespace CalamityMod if (WorldGen.SolidTile(tile) || (checkDirection.Y >= 0f && tile.HasTile && Main.tileSolidTop[tile.TileType])) return i; } + return null; } } diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 690ebe06ac..8e7d8da452 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -73,6 +73,7 @@ namespace CalamityMod if (CalamityConfig.Instance.Afterimages) { Vector2 centerOffset = drawCentered ? proj.Size / 2f : Vector2.Zero; + Color alphaColor = proj.GetAlpha(lightColor); switch (mode) { // Standard afterimages. No customizable features other than total afterimage count. @@ -82,7 +83,7 @@ namespace CalamityMod { Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Color color = alphaColor * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, rotation, origin, scale, spriteEffects, 0f); } break; @@ -92,7 +93,7 @@ namespace CalamityMod case 1: // Safety check: the loop must increment int increment = Math.Max(1, typeOneIncrement); - Color drawColor = proj.GetAlpha(lightColor); + Color drawColor = alphaColor; int afterimageCount = ProjectileID.Sets.TrailCacheLength[proj.type]; float afterimageColorCount = (float)afterimageCount * 1.5f; int k = 0; @@ -120,7 +121,7 @@ namespace CalamityMod Vector2 drawPos = proj.oldPos[i] + centerOffset - Main.screenPosition + new Vector2(0f, proj.gfxOffY); // DO NOT REMOVE THESE "UNNECESSARY" FLOAT CASTS. THIS WILL BREAK THE AFTERIMAGES. - Color color = proj.GetAlpha(lightColor) * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); + Color color = alphaColor * ((float)(proj.oldPos.Length - i) / (float)proj.oldPos.Length); Main.spriteBatch.Draw(texture, drawPos, new Rectangle?(rectangle), color, afterimageRot, origin, scale, sfxForThisAfterimage, 0f); } break; diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs index 5197f0a9b8..452c1edf1d 100644 --- a/Utilities/PlayerUtils.cs +++ b/Utilities/PlayerUtils.cs @@ -226,10 +226,9 @@ namespace CalamityMod { if (player.inventory[item].pick <= 0) continue; + if (player.inventory[item].pick > highestPickPower) - { highestPickPower = player.inventory[item].pick; - } } return highestPickPower; @@ -256,23 +255,25 @@ namespace CalamityMod /// How many tiles above every checked tile are checked for non-solid ground public static bool CheckSolidGround(this Player player, int solidGroundAhead = 0, int airExposureNeeded = 0) { - if (player.velocity.Y != 0) //Player gotta be standing still in any case + if (player.velocity.Y != 0) // Player gotta be standing still in any case. return false; Tile checkedTile; bool ConditionMet = true; - for (int i = 0; i <= solidGroundAhead; i++) //Check i tiles in front of the player + int playerCenterX = (int)player.Center.X / 16; + int playerCenterY = (int)(player.position.Y + (float)player.height - 1f) / 16 + 1; + for (int i = 0; i <= solidGroundAhead; i++) // Check i tiles in front of the player. { - ConditionMet = Main.tile[(int)player.Center.X / 16 + player.direction * i, (int)(player.position.Y + (float)player.height - 1f) / 16 + 1].IsTileSolidGround(); + ConditionMet = Main.tile[playerCenterX + player.direction * i, playerCenterY].IsTileSolidGround(); if (!ConditionMet) return ConditionMet; - for (int j = 1; j <= airExposureNeeded; j++) //Check j tiles ontop of each checked tiles for non-solid ground + for (int j = 1; j <= airExposureNeeded; j++) // Check j tiles ontop of each checked tiles for non-solid ground. { - checkedTile = Main.tile[(int)player.Center.X / 16 + player.direction * i, (int)(player.position.Y + (float)player.height - 1f) / 16 + 1 - j]; + checkedTile = Main.tile[playerCenterX + player.direction * i, playerCenterY - j]; - ConditionMet = !(checkedTile != null && checkedTile.HasUnactuatedTile && Main.tileSolid[checkedTile.TileType]); //IsTileSolidGround minus the ground part, to avoid platforms and other half solid tiles messing it up + ConditionMet = !(checkedTile != null && checkedTile.HasUnactuatedTile && Main.tileSolid[checkedTile.TileType]); // IsTileSolidGround minus the ground part, to avoid platforms and other half solid tiles messing it up. if (!ConditionMet) return ConditionMet; } @@ -283,6 +284,7 @@ namespace CalamityMod #region Location and Biomes public static bool IsUnderwater(this Player player) => Collision.DrownCollision(player.position, player.width, player.height, player.gravDir); + public static bool InSpace(this Player player) { float x = Main.maxTilesX / 4200f; @@ -290,10 +292,15 @@ namespace CalamityMod float spaceGravityMult = (float)((player.position.Y / 16f - (60f + 10f * x)) / (Main.worldSurface / 6.0)); return spaceGravityMult < 1f; } + public static bool PillarZone(this Player player) => player.ZoneTowerStardust || player.ZoneTowerSolar || player.ZoneTowerVortex || player.ZoneTowerNebula; + public static bool InCalamity(this Player player) => player.Calamity().ZoneCalamity; + public static bool InSunkenSea(this Player player) => player.Calamity().ZoneSunkenSea; + public static bool InSulphur(this Player player) => player.Calamity().ZoneSulphur; + public static bool InAstral(this Player player, int biome = 0) //1 is above ground, 2 is underground, 3 is desert { switch (biome) @@ -311,6 +318,7 @@ namespace CalamityMod return player.Calamity().ZoneAstral; } } + public static bool InAbyss(this Player player, int layer = 0) { switch (layer) @@ -390,6 +398,7 @@ namespace CalamityMod for (int i = 0; i < player.hurtCooldowns.Length; ++i) if (player.hurtCooldowns[i] < frames) player.hurtCooldowns[i] = frames; + return true; }