Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text card updates #775

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content/Bosses/GlassMiniboss/NPCs.Glassweaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public override void AI()
case (int)Phases.ReturnToForeground:

if (AttackTimer == 1 && Main.netMode != NetmodeID.Server) // Only display in singelplayer or multiplayer client
UILoader.GetUIState<TextCard>().Display("Glassweaver", "Worker of the Anvil", null, 240, 1.2f, false);
TextCard.Display("Glassweaver", "Worker of the Anvil", 240, 1.2f);

JumpBackAnimation();

Expand Down
2 changes: 1 addition & 1 deletion Content/Bosses/SquidBoss/NPCs.SquidBoss.Cutscenes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void SpawnAnimation()
if (GlobalTimer == 100 && !Main.dedServ)
{
string title = Main.rand.NextBool(10000) ? "Jammed Mod" : "The Venerated";
UILoader.GetUIState<TextCard>().Display("Auroracle", title, null, 440);
TextCard.Display("Auroracle", title, 440);
CameraSystem.DoPanAnimation(440, NPC.Center + new Vector2(0, -600));
}

Expand Down
2 changes: 1 addition & 1 deletion Content/Bosses/VitricBoss/NPCs.VitricBoss.Cutscenes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void SpawnAnimation() //The animation which plays when the boss is spawn
if (checkSpecificTime(454))
{
if (Main.netMode != NetmodeID.Server)
UILoader.GetUIState<TextCard>().Display(NPC.FullName, Main.rand.NextBool(10000) ? "Glass tax returns" : "Shattered Sentinel", null, 310, 1.25f); //intro text
TextCard.Display(NPC.FullName, Main.rand.NextBool(10000) ? "Glass tax returns" : "Shattered Sentinel", 310, 1.25f); //intro text

if (IsInsideArena())
{
Expand Down
55 changes: 28 additions & 27 deletions Content/GUI/TextCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
using System;
using System.Collections.Generic;
using Terraria.UI;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
using static Terraria.ModLoader.ModContent;

namespace StarlightRiver.Content.GUI
{
public class TextCard : SmartUIState
{
private Ability abilityToAnnounce;
private bool usedAnnouncedAbility = false;

private string title;
private string message;
private string subMessage;

private float textScale = 1;
private string texturePath = "StarlightRiver/Assets/GUI/DefaultCard";
Expand All @@ -25,6 +22,11 @@ public class TextCard : SmartUIState
private int tempTime = 0;
private int tempTimeMax = 0;

private Func<bool> endCondition;
private bool ended;

private bool UsesEndCondition => tempTimeMax == 0 && endCondition != null;

private Texture2D Texture => Request<Texture2D>(texturePath).Value;

public override int InsertionIndex(List<GameInterfaceLayer> layers)
Expand All @@ -37,19 +39,27 @@ public void SetTexture(string path)
texturePath = path;
}

public void Display(string title, string message, Ability ability = null, int time = 0, float scale = 1, bool titleFirst = false, string subMessage = "")
public static void Display(string title, string message, int time, float scale = 1, bool reversed = false)
{
UILoader.GetUIState<TextCard>().DisplayInner(title, message, time, scale, reversed);
}

public static void Display(string title, string message, Func<bool> endCondition, float scale = 1, bool reversed = false)
{
UILoader.GetUIState<TextCard>().DisplayInner(title, message, 0, scale, reversed);
UILoader.GetUIState<TextCard>().endCondition = endCondition;
}

private void DisplayInner(string title, string message, int time = 0, float scale = 1, bool reversed = false)
{
abilityToAnnounce = ability;
this.title = title;
this.message = message;
Visible = true;
usedAnnouncedAbility = false;
tempTimeMax = time;
tempTime = 0;
timer = 1;
textScale = scale;
reverse = titleFirst;
this.subMessage = subMessage;
reverse = reversed;
}

public override void Draw(SpriteBatch spriteBatch)
Expand All @@ -67,9 +77,10 @@ public override void Draw(SpriteBatch spriteBatch)
Color barColor = Color.White * Math.Clamp(timer / 45f, 0f, 1f);

spriteBatch.End();
spriteBatch.Begin(default, BlendState.AlphaBlend, SamplerState.PointClamp, default, default, default, Main.UIScaleMatrix);
spriteBatch.Begin(default, BlendState.AlphaBlend, SamplerState.LinearWrap, default, default, default, Main.UIScaleMatrix);

spriteBatch.Draw(Assets.Keys.Glow.Value, new Rectangle(startX - (int)(Longest * 2 * slide2), startY - (int)(25 * textScale), (int)(Longest * 4 * slide2), (int)(150 * textScale)), Color.Black * 0.6f * Math.Clamp(timer / 60f, 0f, 1f));
var glowTex = Assets.Keys.Glow.Value;
spriteBatch.Draw(glowTex, new Rectangle(startX - (int)(Longest * 2 * slide2), startY - (int)(15 * textScale), (int)(Longest * 4 * slide2), (int)(120 * textScale)), new Rectangle(5, 5, glowTex.Width - 10, glowTex.Height - 10), Color.Black * 0.6f * Math.Clamp(timer / 60f, 0f, 1f));

spriteBatch.End();
spriteBatch.Begin(default, default, SamplerState.PointClamp, default, default, default, Main.UIScaleMatrix);
Expand All @@ -90,23 +101,12 @@ public override void Draw(SpriteBatch spriteBatch)
spriteBatch.Draw(Texture, new Vector2(startX - (int)(Longest * 1.2f * slide) - 46, startY + (int)(75 * textScale) - 34), new Rectangle(0, 0, 46, 46), barColor);
spriteBatch.Draw(Texture, new Rectangle(startX + (int)(Longest * 1.2f * slide), startY + (int)(75 * textScale) - 34, 46, 46), new Rectangle(46, 0, 46, 46), barColor);

if (subMessage != "")
{
string[] lines = subMessage.Split('\n');
for (int k = 0; k < lines.Length; k++)
{
string message = lines[k];
Utils.DrawBorderStringBig(spriteBatch, message, new Vector2(startX, startY + (int)(95 * textScale + k * 20 * textScale)), textColor, textScale * 0.4f, 0.5f, 0);
}
//spriteBatch.DrawString(Terraria.GameContent.FontAssets.DeathText.Value, SubMessage, , textColor, 0f, new Vector2(0.5f, 0), 0.4f * textScale, 0, 0);
}

if (abilityToAnnounce != null)
if (UsesEndCondition)
{
if (abilityToAnnounce.Active)
usedAnnouncedAbility = true;
if (endCondition())
ended = true;

if (usedAnnouncedAbility)
if (ended)
timer--;
else if (timer < 120)
timer++;
Expand All @@ -133,7 +133,8 @@ private void Reset()
{
Visible = false;
textScale = 1;
abilityToAnnounce = null;
endCondition = null;
ended = false;
SetTexture("StarlightRiver/Assets/GUI/DefaultCard");
}
}
Expand Down
3 changes: 2 additions & 1 deletion Content/Items/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public override void UpdateAccessory(Player player, bool hideVisual)
public override bool? UseItem(Player player)
{
//StarlightEventSequenceSystem.sequence = 0;
player.GetHandler().unlockedAbilities.Add(typeof(Dash), new Dash());
TextCard.Display("Blorgus", "schmungus!", () => Main.LocalPlayer.velocity.Y < 0);
player.GetHandler().unlockedAbilities.Clear();
player.GetHandler().InfusionLimit = 1;

//Main.time = 53999;
Expand Down
3 changes: 1 addition & 2 deletions Content/NPCs/Starlight/Crow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ public void StarsightTutorial()
$"Aim your cursor and press {StarlightRiver.Instance.AbilityKeys.Get<HintAbility>().GetAssignedKeys()[0]} to inspect the world." :
"Aim your cursor and press [Please bind a key] to inspect the world.";

Main.LocalPlayer.GetHandler().GetAbility(out HintAbility hint);
UILoader.GetUIState<TextCard>().Display("Starsight", message, hint);
TextCard.Display("Starsight", message, () => Main.LocalPlayer.GetModPlayer<AbilityHandler>().ActiveAbility is HintAbility);
}

private void SetFrame(int x, int y)
Expand Down
3 changes: 1 addition & 2 deletions Content/Pickups/ForbiddenWindsPickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public override void PickupVisuals(int timer)
"Press W/A/S/D + " + StarlightRiver.Instance.AbilityKeys.Get<Dash>().GetAssignedKeys()[0] + " to dash." :
"Press W/A/S/D + [Please Bind a Key] to dash.";

Main.LocalPlayer.GetHandler().GetAbility<Dash>(out Dash dash);
UILoader.GetUIState<TextCard>().Display("Forbidden Winds", message, dash);
TextCard.Display("Forbidden Winds", message, () => Main.LocalPlayer.GetModPlayer<AbilityHandler>().ActiveAbility is Dash);

Filters.Scene.Activate("Shockwave", Player.Center).GetShader().UseProgress(0f).UseIntensity(0);
Filters.Scene.Deactivate("Shockwave");
Expand Down
4 changes: 2 additions & 2 deletions Content/Pickups/StaminaShard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public override void PickupEffects(Player Player)
ah.Shards.Add(Parent.TileFrameX);

if (ah.ShardCount % 3 == 0)
UILoader.GetUIState<TextCard>().Display("Starlight Vessel", "Your maximum starlight has increased by 1", null, 240, 1f);
TextCard.Display("Starlight Vessel", "Your maximum starlight has increased by 1", 240, 1f);
else
UILoader.GetUIState<TextCard>().Display("Starlight Vessel Shard", "Collect " + (3 - ah.ShardCount % 3) + " more to increase your maximum starlight", null, 240, 1f);
TextCard.Display("Starlight Vessel Shard", "Collect " + (3 - ah.ShardCount % 3) + " more to increase your maximum starlight", 240, 1f);

Player.GetModPlayer<StarlightPlayer>().maxPickupTimer = 1;
}
Expand Down
Loading