From f0f786ab92e06f6d4e7c19d79513eea16fa4bc38 Mon Sep 17 00:00:00 2001 From: IbanPlay <56191483+IbanPlay@users.noreply.github.com> Date: Wed, 16 Feb 2022 00:09:17 +0100 Subject: [PATCH] Possibility to use a sprite for the bar cooldown --- CalPlayer/CalamityPlayerMiscEffects.cs | 1 - Effects/CalamityShaders.cs | 3 ++ Effects/CircularBarSpriteShader.fx | 50 ++++++++++++++++++ Effects/CircularBarSpriteShader.xnb | Bin 0 -> 2276 bytes UI/CooldownIndicators/BarBase.png | Bin 145 -> 100 bytes UI/CooldownIndicators/CooldownIndicator.cs | 36 ++++++++++--- UI/CooldownIndicators/CooldownRackUI.cs | 2 +- UI/CooldownIndicators/SirenIceShield.png | Bin 0 -> 328 bytes .../SirenIceShieldOutline.png | Bin 0 -> 196 bytes .../SirenIceShieldOverlay.png | Bin 0 -> 152 bytes 10 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 Effects/CircularBarSpriteShader.fx create mode 100644 Effects/CircularBarSpriteShader.xnb create mode 100644 UI/CooldownIndicators/SirenIceShield.png create mode 100644 UI/CooldownIndicators/SirenIceShieldOutline.png create mode 100644 UI/CooldownIndicators/SirenIceShieldOverlay.png diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 8e357b5623..184ff8d0b4 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -948,7 +948,6 @@ namespace CalamityMod.CalPlayer // Cooldowns and timers - foreach (CooldownIndicator cd in Cooldowns) { if (cd.CanTickDown(player)) diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 6968b556c7..e39af2af3f 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -26,6 +26,7 @@ namespace CalamityMod.Effects public static Effect RancorMagicCircleShader; public static Effect BasicTintShader; public static Effect CircularBarShader; + public static Effect CircularBarSpriteShader; public static Effect DoGDisintegrationShader; public static Effect ArtAttackTrailShader; public static Effect CircularAoETelegraph; @@ -58,6 +59,7 @@ namespace CalamityMod.Effects RancorMagicCircleShader = CalamityMod.Instance.GetEffect("Effects/RancorMagicCircle"); BasicTintShader = CalamityMod.Instance.GetEffect("Effects/BasicTint"); CircularBarShader = CalamityMod.Instance.GetEffect("Effects/CircularBarShader"); + CircularBarSpriteShader = CalamityMod.Instance.GetEffect("Effects/CircularBarSpriteShader"); DoGDisintegrationShader = CalamityMod.Instance.GetEffect("Effects/DoGDisintegration"); ArtAttackTrailShader = CalamityMod.Instance.GetEffect("Effects/ArtAttackTrail"); CircularAoETelegraph = CalamityMod.Instance.GetEffect("Effects/CircularAoETelegraph"); @@ -88,6 +90,7 @@ namespace CalamityMod.Effects GameShaders.Misc["CalamityMod:RancorMagicCircle"] = new MiscShaderData(new Ref(RancorMagicCircleShader), "ShieldPass"); GameShaders.Misc["CalamityMod:BasicTint"] = new MiscShaderData(new Ref(BasicTintShader), "TintPass"); GameShaders.Misc["CalamityMod:CircularBarShader"] = new MiscShaderData(new Ref(CircularBarShader), "Pass0"); + GameShaders.Misc["CalamityMod:CircularBarSpriteShader"] = new MiscShaderData(new Ref(CircularBarSpriteShader), "Pass0"); GameShaders.Misc["CalamityMod:DoGDisintegration"] = new MiscShaderData(new Ref(DoGDisintegrationShader), "DisintegrationPass"); GameShaders.Misc["CalamityMod:ArtAttack"] = new MiscShaderData(new Ref(ArtAttackTrailShader), "TrailPass"); GameShaders.Misc["CalamityMod:CircularAoETelegraph"] = new MiscShaderData(new Ref(CircularAoETelegraph), "TelegraphPass"); diff --git a/Effects/CircularBarSpriteShader.fx b/Effects/CircularBarSpriteShader.fx new file mode 100644 index 0000000000..38e979b9d6 --- /dev/null +++ b/Effects/CircularBarSpriteShader.fx @@ -0,0 +1,50 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; //Saturation is being used as completion here +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; + +float4 MainPS(float2 coords : TEXCOORD0) : COLOR +{ + //this is the center of the sprite, coords work from 0 - 1 + float2 center = float2(0.5, 0.5); + //get the vector between them + float2 between = coords - center; + //get the length + float newLength = length(between); + + + float angle = atan2(between.x, between.y) + 3.1415926; + //get the progress of the angle + float anglePercent = angle / 6.28318531; + + //if we are below the progress point, return the pixel at the coords specified + if (anglePercent < uSaturation) + { + float4 barColor = tex2D(uImage0, coords); + float opacity = uOpacity * barColor.a; + return float4(barColor.rbg, opacity); + } + + float4 subBarColor = tex2D(uImage1, coords); + float subOpacity = uOpacity * subBarColor.a; + return float4(subBarColor.rbg, subOpacity); +} + + +technique Technique1 +{ + pass Pass0 + { + PixelShader = compile ps_2_0 MainPS(); + } +} \ No newline at end of file diff --git a/Effects/CircularBarSpriteShader.xnb b/Effects/CircularBarSpriteShader.xnb new file mode 100644 index 0000000000000000000000000000000000000000..6862892bf67b3d6f931d636caf78c7f9e7be9bf8 GIT binary patch literal 2276 zcma)6O>7%Q6n?w5QcjMdDB#smg%^hXOfpfD;@zM1)i2V-GzbwOqPg z+B#1Ca$s-wJZCsNU&TlQ7A zMoM!jpOxT9Q>Ox41}xMx%BQ*L1W45K`+h)q%uP-3Uol*J)Nvhuuwe%~GMIHd{*-^> z$?LQ6I0=j1*tQ)n++nWtlS%-euAgLm$3}DP}i<(~5&9Q1c4iL4ytG%!ziX`e8O80>l`)G|~U*djsy!Ua(RLtK0 zj;V{Xr?cuP7f8N)s>+}ZRJCR!_dIFsH%rU$a|DT4baTZ`s5&XAdJ&nh} zUuyg|@PWqf0+&@&fv13*8gB#lH2xm&7aIQ-_&1H;1uknnnF4NVd<{6%_zmEj8Xsqv zQyyse^Q`8d;M>>ynVV7!g&*+Ym}&YjU8L6P3ky@Ahdc=%_m4S-^*bJYm^@1}{}y~A zd>g zJ@xl}d$`_MuTlP8w$83RXT8$yw5?8$KiO8x-`e*20OzZXbJg>+jcTJgGed6@l}xH6 z$ok{@tC(r4KXXCqiJq2iim{iy41Y@HN}{j6nt_O^mE=<-b*OdE| zwaXq9MGYxx$@j-Kz?iGvjIv&FZc)3|AFi3QeyIA=gnJ^_VP6+EN?0fBQF&7Il566% zqz^qyaDQ=LW?ahaSNd*@xv#jd_)6e>Q<&5fO#q)k3>6H_8QL7)L+~@AM#4SeIt&^^ PKjwVcrnoyXe*yjh&b3K3 literal 0 HcmV?d00001 diff --git a/UI/CooldownIndicators/BarBase.png b/UI/CooldownIndicators/BarBase.png index 931e6e6ecca998e770fadc15abddcae39c33941f..f6dc997ee736028ef868e4513c3b7d40804d846c 100644 GIT binary patch delta 57 zcmbQpm@>i8SkBYMF(jh(?Lk9E1_p*h3%>g2vehpDGC|;hv0M%V public virtual void CustomDrawCompact(SpriteBatch spriteBatch, Vector2 position, float opacity, float scale) { } + /// + /// The texture of the charge bar. If set to a different texture path than the bar base, and if UseCustomDraw is set to false , it will be used as the ring around the cooldown icon + /// Please keep this sprite 44x44 (In 2x2) + /// + public virtual string ChargeBarTexture => "CalamityMod/UI/CooldownIndicators/BarBase"; + + /// + /// The texture under the charge bar. Will be used if ChargeBarTexture is set to an actual texture. Leave this as is to have nothing below the charge bar texture + /// Please keep this sprite 44x44 (In 2x2) + /// + public virtual string ChargeBarBackTexture => "CalamityMod/UI/CooldownIndicators/BarBase"; + /// /// Method used to determine the color of the outline around the icon, and the overlay that goes above the icon in compact mode /// public virtual Color OutlineColor => Color.White; /// - /// The color of the bar as it starts going around the icon + /// The color of the bar as it starts going around the icon. Only used if no charge bar texture is provided /// public virtual Color CooldownColorStart => Color.Gray; /// - /// The color of the bar as it finishes going around the icon + /// The color of the bar as it finishes going around the icon. Only used if no charge bar texture is provided /// public virtual Color CooldownColorEnd => Color.White; @@ -115,12 +127,22 @@ namespace CalamityMod.UI.CooldownIndicators /// public virtual void ApplyBarShaders(float opacity) { - GameShaders.Misc["CalamityMod:CircularBarShader"].UseOpacity(opacity); - GameShaders.Misc["CalamityMod:CircularBarShader"].UseSaturation(1 - Completion); - GameShaders.Misc["CalamityMod:CircularBarShader"].UseColor(CooldownColorStart); - GameShaders.Misc["CalamityMod:CircularBarShader"].UseSecondaryColor(CooldownColorEnd); - GameShaders.Misc["CalamityMod:CircularBarShader"].Apply(); + if (ChargeBarTexture == "CalamityMod/UI/CooldownIndicators/BarBase") + { + GameShaders.Misc["CalamityMod:CircularBarShader"].UseOpacity(opacity); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSaturation(1 - Completion); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseColor(CooldownColorStart); + GameShaders.Misc["CalamityMod:CircularBarShader"].UseSecondaryColor(CooldownColorEnd); + GameShaders.Misc["CalamityMod:CircularBarShader"].Apply(); + } + else + { + GameShaders.Misc["CalamityMod:CircularBarSpriteShader"].SetShaderTexture(ModContent.GetTexture(ChargeBarBackTexture)); + GameShaders.Misc["CalamityMod:CircularBarSpriteShader"].UseOpacity(opacity); + GameShaders.Misc["CalamityMod:CircularBarSpriteShader"].UseSaturation(1 - Completion); + GameShaders.Misc["CalamityMod:CircularBarSpriteShader"].Apply(); + } } /// diff --git a/UI/CooldownIndicators/CooldownRackUI.cs b/UI/CooldownIndicators/CooldownRackUI.cs index d6f1122574..0a7c65fbc5 100644 --- a/UI/CooldownIndicators/CooldownRackUI.cs +++ b/UI/CooldownIndicators/CooldownRackUI.cs @@ -87,7 +87,7 @@ namespace CalamityMod.UI.CooldownIndicators { Texture2D sprite = ModContent.GetTexture(cooldown.Texture); Texture2D outline = ModContent.GetTexture(cooldown.TextureOutline); - Texture2D barBase = ModContent.GetTexture("CalamityMod/UI/CooldownIndicators/BarBase"); + Texture2D barBase = ModContent.GetTexture(cooldown.ChargeBarTexture); //Draw the ring if (!CompactIcons) diff --git a/UI/CooldownIndicators/SirenIceShield.png b/UI/CooldownIndicators/SirenIceShield.png new file mode 100644 index 0000000000000000000000000000000000000000..28afc678662553bc19e8365c43ed17decb93edca GIT binary patch literal 328 zcmV-O0k{5%P)Px$0!c(cR5*>j)IV#&Kpe*L?}=-Q4i3#^DK4FYT0#06#P?82v$DGB3(?#p|os&EAn~rQ^$GV0Qvjr@ws-41KA)7yf7p4*2mm^| zg*USy07g710G8913sAN#WkdI+q{xiLTzP+Wp$HaF#a95#tS9@KeJeM)nYD!912F0| a^$HJ7@kCdS5q}r}0000O5T>Lp(a) zPIcruV8Fq0{nG#Xn{ip4YiBiN=--^ovZ!wp=R+}Ld&MFp1_dRC0~3ABu38?sWT{%b z%4RK#m(k%+Uh5Do^&6~Zjj;*^n=Fc-Wt=~_D2ypHbZ?tn=f#~rrT%Yfo^T}KNB|D$J|-0YG|f7VJgri44$rjF6*2UngF;2Nn8K` literal 0 HcmV?d00001 diff --git a/UI/CooldownIndicators/SirenIceShieldOverlay.png b/UI/CooldownIndicators/SirenIceShieldOverlay.png new file mode 100644 index 0000000000000000000000000000000000000000..63a806f6332661f4072731e96a44aceb7d04544f GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VV{wqX6T`Z5GB1IgAWs*^5R2aA zl!m7NK#;zG!N3Rz41gdoiNnkw>%oe~#cX{1%#jmr^aRYh64Wj@(>Yjt(QS_tOM7mx ttbFIh6TLy?&I=}uss*g3G68p68EzMG=_X4)@&uaB;OXk;vd$@?2>@>BFhl?V literal 0 HcmV?d00001