diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.cs new file mode 100644 index 0000000000..4ab1f0cd24 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearl : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 0; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.png new file mode 100644 index 0000000000..ff5ff49441 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearl.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.cs new file mode 100644 index 0000000000..a8d8bb6e08 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlBlack : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 9; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.png new file mode 100644 index 0000000000..a43d3168e5 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlBlack.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.cs new file mode 100644 index 0000000000..d4b7fba3c3 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlDarkBlue : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 6; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.png new file mode 100644 index 0000000000..91069572d9 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkBlue.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.cs new file mode 100644 index 0000000000..dcc21e9d11 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlDarkGreen : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 8; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.png new file mode 100644 index 0000000000..b2db9441cc Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlDarkGreen.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.cs new file mode 100644 index 0000000000..c8b2afa3c9 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlLightBlue : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 5; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.png new file mode 100644 index 0000000000..3adeb8f808 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightBlue.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.cs new file mode 100644 index 0000000000..e171db4133 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlLightGreen : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 4; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.png new file mode 100644 index 0000000000..9a81959456 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlLightGreen.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.cs new file mode 100644 index 0000000000..9aaf7d9de3 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlOrange : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 2; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.png new file mode 100644 index 0000000000..6f95f02fb3 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlOrange.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.cs new file mode 100644 index 0000000000..327b8eb2c2 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlPurple : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 7; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.png new file mode 100644 index 0000000000..7b6a250a74 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlPurple.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.cs new file mode 100644 index 0000000000..3a5d3f958a --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlRed : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 1; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.png new file mode 100644 index 0000000000..59db227945 Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlRed.png differ diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.cs b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.cs new file mode 100644 index 0000000000..20f06dcc55 --- /dev/null +++ b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.cs @@ -0,0 +1,17 @@ +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls +{ + public class WhisperingPearlYellow : ModItem, ILocalizedModType + { + public new string LocalizationCategory => "Items.Placeables"; + + public override void SetDefaults() + { + Item.DefaultToPlaceableTile(ModContent.TileType()); + Item.rare = ItemRarityID.Blue; + Item.placeStyle = 3; + } + } +} diff --git a/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.png b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.png new file mode 100644 index 0000000000..35a652f78c Binary files /dev/null and b/Items/Placeables/SunkenSea/WhisperingPearls/WhisperingPearlYellow.png differ diff --git a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson index afef9d3c6a..05dc28d410 100644 --- a/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson +++ b/Localization/en-US/Mods.CalamityMod.Items.Placeables.hjson @@ -3207,6 +3207,56 @@ VoidWorkBench: { Tooltip: "" } +WhisperingPearl: { + DisplayName: Whispering Pearl + Tooltip: Contains knowledge +} + +WhisperingPearlBlack: { + DisplayName: Black Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlDarkBlue: { + DisplayName: Dark Blue Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlDarkGreen: { + DisplayName: Dark Green Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlLightBlue: { + DisplayName: Light Blue Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlLightGreen: { + DisplayName: Light Green Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlOrange: { + DisplayName: Orange Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlPurple: { + DisplayName: Purple Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlRed: { + DisplayName: Red Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + +WhisperingPearlYellow: { + DisplayName: Yellow Whispering Pearl + Tooltip: "{$Items.Placeables.WhisperingPearl.Tooltip}" +} + WulfrumBathtub: { DisplayName: Wulfrum Bathtub Tooltip: "" diff --git a/Localization/en-US/Mods.CalamityMod.Tiles.hjson b/Localization/en-US/Mods.CalamityMod.Tiles.hjson index 32316202fc..958be955cd 100644 --- a/Localization/en-US/Mods.CalamityMod.Tiles.hjson +++ b/Localization/en-US/Mods.CalamityMod.Tiles.hjson @@ -32,6 +32,8 @@ SpineTree.MapEntry: Giant Spine InactivePowerCellFactory.MapEntry: Inactive Power Cell Factory OnyxExcavatorTile.MapEntry: Onyx Excavator CodebreakerTile.MapEntry: The Codebreaker +// Sunken Sea +WhisperingPearl: "{$Items.Placeables.SunkenSea.WhisperingPearl.DisplayName}" // Ores AerialiteOre.MapEntry: Aerialite AerialiteOreDisenchanted.MapEntry: Disenchanted Aerialite diff --git a/Localization/en-US/Mods.CalamityMod.UI.hjson b/Localization/en-US/Mods.CalamityMod.UI.hjson index 0691f76312..32e48661fe 100644 --- a/Localization/en-US/Mods.CalamityMod.UI.hjson +++ b/Localization/en-US/Mods.CalamityMod.UI.hjson @@ -588,6 +588,127 @@ Lecherous: { Description: Spawns a resilient brimstone monster that stays between you and your mouse that interferes with your homing weapons. It releases a bunch of hearts on death. } +// Moving text to a new line inserts a paragraph break. Two blank newlines separate pages. +WhisperingPearl: { + Basic: + ''' + Something about clams + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + Red: + ''' + Something about red clams + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + Orange: + ''' + Something about orange clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + Yellow: + ''' + Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams + Like yknow those shellfish? Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams Something about yellow clams + + + By the way I ate curry today + + + MMM.... + ''' + LightGreen: + ''' + Something about light green clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + LightBlue: + ''' + Something about light blue clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + DarkBlue: + ''' + Something about dark blue clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + Purple: + ''' + Something about purple clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + DarkGreen: + ''' + Something about dark green clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' + Black: + ''' + Something about black clams + + Like yknow those shellfish? + + + By the way I ate curry today + + + MMM.... + ''' +} + Disenchant: Disenchant // Worldgen Tasks BetterUnderworld: Creating a smoother Underworld diff --git a/Systems/UIManagementSystem.cs b/Systems/UIManagementSystem.cs index fa9408ef58..b1267fe728 100644 --- a/Systems/UIManagementSystem.cs +++ b/Systems/UIManagementSystem.cs @@ -34,6 +34,12 @@ namespace CalamityMod.Systems int mouseIndex = layers.FindIndex(layer => layer.Name == "Vanilla: Mouse Text"); if (mouseIndex != -1) { + layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Whispering Pearl", () => + { + WhisperingPearlUI.Draw(Main.spriteBatch); + return true; + }, InterfaceScaleType.Game)); + layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Draedon Hologram", () => { LabHologramProjectorUI.Draw(Main.spriteBatch); diff --git a/Tiles/SunkenSea/WhisperingPearl.cs b/Tiles/SunkenSea/WhisperingPearl.cs new file mode 100644 index 0000000000..e1478d1175 --- /dev/null +++ b/Tiles/SunkenSea/WhisperingPearl.cs @@ -0,0 +1,99 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Items.Placeables.SunkenSea.WhisperingPearls; +using CalamityMod.TileEntities; +using CalamityMod.UI; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using Terraria; +using Terraria.Audio; +using Terraria.Enums; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; +using Terraria.ObjectData; + +namespace CalamityMod.Tiles.SunkenSea +{ + public class WhisperingPearl : ModTile + { + public override void SetStaticDefaults() + { + Main.tileFrameImportant[Type] = true; + Main.tileLighted[Type] = true; + Main.tileNoFail[Type] = true; + Main.tileWaterDeath[Type] = false; + + TileID.Sets.HasOutlines[Type] = true; + TileID.Sets.DisableSmartCursor[Type] = true; + + TileObjectData.newTile.CopyFrom(TileObjectData.Style1x1); + TileObjectData.newTile.StyleHorizontal = true; + TileObjectData.newTile.WaterDeath = false; + TileObjectData.newTile.WaterPlacement = LiquidPlacement.Allowed; + TileObjectData.newTile.LavaDeath = false; + TileObjectData.newTile.LavaPlacement = LiquidPlacement.NotAllowed; + TileObjectData.addTile(Type); + + AddMapEntry(Color.LightCyan, CalamityUtils.GetText("Tiles.WhisperingPearl")); + + DustType = DustID.BlueCrystalShard; + HitSound = SoundID.Item27; + } + + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + r = 0f; + g = 0.3f; + b = 0.3f; + } + + public override bool RightClick(int i, int j) + { + int frameNum = Main.tile[i, j].TileFrameX / 18; + string key = frameNum switch + { + 1 => "Red", + 2 => "Orange", + 3 => "Yellow", + 4 => "LightGreen", + 5 => "LightBlue", + 6 => "DarkBlue", + 7 => "Purple", + 8 => "DarkGreen", + 9 => "Black", + _ => "Basic" + }; + if (!WhisperingPearlUI.IsActive) + { + WhisperingPearlUI.StartDialogue(new Vector2(i, j) * 16, key); + } + else + { + WhisperingPearlUI.ProgressDialogue(new Vector2(i, j) * 16, key); + } + return true; + } + public override bool HasSmartInteract(int i, int j, Terraria.GameContent.ObjectInteractions.SmartInteractScanSettings settings) => true; + + public override void MouseOver(int i, int j) + { + int frameNum = Main.tile[i, j].TileFrameX / 18; + int pearl = frameNum switch + { + 1 => ModContent.ItemType(), + 2 => ModContent.ItemType(), + 3 => ModContent.ItemType(), + 4 => ModContent.ItemType(), + 5 => ModContent.ItemType(), + 6 => ModContent.ItemType(), + 7 => ModContent.ItemType(), + 8 => ModContent.ItemType(), + 9 => ModContent.ItemType(), + _ => ModContent.ItemType(), + }; + Main.LocalPlayer.cursorItemIconID = pearl; + Main.LocalPlayer.noThrow = 2; + Main.LocalPlayer.cursorItemIconEnabled = true; + } + } +} diff --git a/Tiles/SunkenSea/WhisperingPearl.png b/Tiles/SunkenSea/WhisperingPearl.png new file mode 100644 index 0000000000..db431067e2 Binary files /dev/null and b/Tiles/SunkenSea/WhisperingPearl.png differ diff --git a/Tiles/SunkenSea/WhisperingPearl_Highlight.png b/Tiles/SunkenSea/WhisperingPearl_Highlight.png new file mode 100644 index 0000000000..d725bbf09d Binary files /dev/null and b/Tiles/SunkenSea/WhisperingPearl_Highlight.png differ diff --git a/UI/WhisperingPearlUI.cs b/UI/WhisperingPearlUI.cs new file mode 100644 index 0000000000..3b9a0cbf33 --- /dev/null +++ b/UI/WhisperingPearlUI.cs @@ -0,0 +1,189 @@ +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; +using CalamityMod.CalPlayer; +using CalamityMod.Items.Weapons.Typeless; +using CalamityMod.TileEntities; +using CalamityMod.Tiles.SunkenSea; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.Localization; +using Terraria.ModLoader; + +namespace CalamityMod.UI +{ + public class WhisperingPearlUI + { + /// + /// Controls how many characters can currently be displayed + /// + public static float textTimer = -1; + /// + /// The maximum amount of characters to display for this page + /// + public static int maxTextTime = -1; + /// + /// Which page are we reading? + /// + public static int currentPage = -1; + /// + /// The localization key for the dialogue + /// + public static string key = ""; + /// + /// The bottom position of the text + /// + public static Vector2 position = Vector2.Zero; + /// + /// How many page there are + /// + public static int pageCount = 0; + + public static void Draw(SpriteBatch sb) + { + if (IsActive) + { + bool noPearl = false; + Point pearlTilePos = new Point((int)position.X / 16, (int)position.Y / 16); + Tile target = CalamityUtils.ParanoidTileRetrieval(pearlTilePos.X, pearlTilePos.Y); + // If there is no pearl, stop the dialogue + if (!target.HasTile || target.TileType != ModContent.TileType()) + { + noPearl = true; + } + // If the player is too far from the pearl, cancel the dialogue + else if (!Main.LocalPlayer.IsInTileInteractionRange(pearlTilePos.X, pearlTilePos.Y, TileReachCheckSettings.Simple)) + { + noPearl = true; + } + + if (noPearl) + { + FinishDialogue(); + return; + } + + string text = CalamityUtils.GetTextValue("UI.WhisperingPearl." + key); + + // Separate the text into pages + string[] separated = text.Split("\n\n"); + pageCount = separated.Length; + // If the current page is more than the total amount of pages, stop the dialogue + if (currentPage > separated.Length - 1) + { + FinishDialogue(); + return; + } + + // Cut the page even further down into individual lines + string[] wrapped = Utils.WordwrapString(separated[currentPage], FontAssets.MouseText.Value, 600, 100000, out int lineAmt); + string combined = ""; + + // Combine them back together with newlines separating them + for (int i = 0; i < wrapped.Length; i++) + { + if (wrapped[i] != null) + { + combined += '\n' + wrapped[i]; + } + } + + // Remove the newlines from every line except the last which doesn't have one + maxTextTime = combined.Length; + Vector2 size = FontAssets.MouseText.Value.MeasureString(combined); + // Shave off text based on the timer + combined = combined.Remove((int)textTimer, (combined.Length - (int)textTimer)); + + // How much further the BOTTOM of the text should be drawn above the pearl + float yOffset = 40; + + Utils.DrawBorderString(sb, combined, position - Main.screenPosition - Vector2.UnitY * (size.Y + yOffset), Color.White, anchorx: 0.5f, anchory: 0, maxCharactersDisplayed: 100000); + + // Increment the text timer + // 0.33 means that it takes 3ish frames for 1 letter to appear + if (textTimer < maxTextTime) + { + textTimer += 0.33f; + } + } + // If dialogue can't be active, finish it + else + { + FinishDialogue(); + } + } + + /// + /// Checks if the dialogue is active + /// + public static bool IsActive => textTimer >= 0 && currentPage >= 0 && key != "" && position != Vector2.Zero; + + /// + /// Manually progresses dialogue + /// + public static void ProgressDialogue(Vector2 drawPos, string pearlKey) + { + bool samePearl = pearlKey == key && drawPos == position; + if (IsActive && samePearl) + { + // If the timer hasn't finished, set it to max + if (textTimer < maxTextTime) + { + textTimer = maxTextTime; + } + // If the tmier has finished, progress to the next page or finish if we're out of pages + else + { + if (currentPage + 1 > pageCount) + { + FinishDialogue(); + } + else + { + currentPage++; + } + textTimer = 0; + } + } + else if (!samePearl) + { + StartDialogue(drawPos, pearlKey); + } + else + { + FinishDialogue(); + } + } + + /// + /// Starts up pearl dialogue + /// + /// The position of the bottom of the text + /// The name of the pearl's localization key + public static void StartDialogue(Vector2 drawPos, string pearlkey) + { + position = drawPos; + currentPage = 0; + textTimer = 0; + key = pearlkey; + pageCount = 0; + } + + /// + /// Resets all of the dialogue's variables + /// + public static void FinishDialogue() + { + position = Vector2.Zero; + currentPage = -1; + textTimer = -1; + key = ""; + pageCount = 0; + } + } +}