From b11a37df31d5994c816bbe5a9ec88e72c152eed3 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Sun, 21 Jul 2019 16:58:57 -0700 Subject: [PATCH] Upgraded Stardust Core Textured Strings to allow for scaling and made custom sprite fonts easier to use. Also implemented super simple HUD into Seaside Scramble. --- .../SeasideScramble/Graphics/UI/0.png | Bin 0 -> 223 bytes .../SeasideScramble/Graphics/UI/1.png | Bin 0 -> 193 bytes .../SeasideScramble/Graphics/UI/2.png | Bin 0 -> 222 bytes .../SeasideScramble/Graphics/UI/3.png | Bin 0 -> 203 bytes .../SeasideScramble/Graphics/UI/4.png | Bin 0 -> 173 bytes .../SeasideScramble/Graphics/UI/5.png | Bin 0 -> 186 bytes .../SeasideScramble/Graphics/UI/6.png | Bin 0 -> 185 bytes .../SeasideScramble/Graphics/UI/7.png | Bin 0 -> 178 bytes .../SeasideScramble/Graphics/UI/8.png | Bin 0 -> 212 bytes .../SeasideScramble/Graphics/UI/9.png | Bin 0 -> 163 bytes .../Graphics/UI/Clock.aseprite | Bin 0 -> 664 bytes .../SeasideScramble/Graphics/UI/Clock.png | Bin 0 -> 248 bytes .../SeasideScramble/Graphics/UI/DialogBox.png | Bin 0 -> 357 bytes .../SSCFonts/SSCFont.cs | 24 +++++ .../SSCFonts/SSCFontCharacterSheet.cs | 35 ++++++++ .../SSCMenus/CharacterSelectScreen.cs | 5 +- .../SSCMenus/HUD/CharacterHUD.cs | 77 ++++++++++++++++ .../SeasideScrambleMinigame/SSCPlayer.cs | 8 ++ .../SSCProjectiles/SSCProjectile.cs | 2 +- .../SeasideScramble.cs | 9 ++ GeneralMods/Revitalize/Revitalize.csproj | 39 ++++++++ .../StardustCore/Animations/AnimatedSprite.cs | 19 ++++ .../Animations/AnimationManager.cs | 51 +++++++++++ .../CharacterSheets/GenericCharacterSheets.cs | 16 ++++ .../Fonts/Components/TexturedCharacter.cs | 27 ++++++ .../Fonts/Components/TexturedString.cs | 44 +++++++++- .../SpriteFonts/Fonts/GenericFont.cs | 83 ++++++++++++++++++ 27 files changed, 433 insertions(+), 6 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/0.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/1.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/2.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/3.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/4.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/5.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/6.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/7.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/8.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/9.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Clock.aseprite create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/Clock.png create mode 100644 GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/DialogBox.png create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFont.cs create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs create mode 100644 GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/0.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/0.png new file mode 100644 index 0000000000000000000000000000000000000000..efeca4c71799a6321999eb2382de364e889c0687 GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`%RF5iLo9liPQJ){*nq>Oe^qvc z-1$kJHr(Aem<>4oa*CBL$ejAS>)}0C)foj-*-Z7l_}Pq&y)?a@T>`St?%>om&Q?nc z``pSXSLVhl&>G`rY1z>6ZQne$`|1o8u8ZFkWb2yNa_?w;&!ko(;f^UA_Th z!2SQJO#I8en9VHio>O&jVPM!>u6?#X&-C+*X|@cHOuy;hxc>8FY=_;2`0XDz+ATAw Vf2CLM=nZr+gQu&X%Q~loCIFAWP}~3j literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/1.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/1.png new file mode 100644 index 0000000000000000000000000000000000000000..d4a49d417674a118e3f1e3329dfa68a915688c78 GIT binary patch literal 193 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`9iA?ZAr`$yCmrNDxTkzKj(^h2eIU2JrZw}s&j_IdL0+qwqN s2_aLb1X*mn=5_Ap(Y-#8n3z5=$lugf*Km`#Aa6&71{W3YbF*_O#yS3eyWR_0VKIU%znbwa2T>8ie() WS!C7KdY=S3n8DN4&t;ucLK6VUcv%7f literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/3.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/3.png new file mode 100644 index 0000000000000000000000000000000000000000..e808ecc23bf4bdf706dbf186876abb586a8aaf02 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`lRRAf%~XP1Vy|*mhoN>JUiIiM!UnQIPwmkYdZjdDjkoFxRR5Z|HZ?>5ZXr1;g>3 WGUnGz^c;ZpGkCiCxvXoSw7aLJfc=nz_a~3y3sK## z`eZ9k8%*b5IN$dU{m5^|E2Rf(~4Jf#06iaH^{A1)OoGBS(4Xnvx$H( z>ytU0{q;>Z8>S{5zRS6@zDX|0tMif*$Ml|?3uf)sSy9fm>D`VlGmWKN+*OU`85j)R jmfz9*thN73{dGqD!}6=$4=q~-bPI#0tDnm{r-UW|?axF= literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/7.png b/GeneralMods/Revitalize/Content/Minigames/SeasideScramble/Graphics/UI/7.png new file mode 100644 index 0000000000000000000000000000000000000000..58cba7ad59ecad81a6b45ad2cf43ad5d90f0518b GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`m7Xq+Ar`$?C++4vpupoIFL-$a z$7Tb;%^NsWd7CX#86MWK_})>xzxlj+!p1WnrmbI-n>ew2kKy%uj}N=ub$jh3{A>33KE}6pc;hz6j`x6VM6y4r`+99cjp+z9%?YH%J dEGrh(}b!3_8InUg{8MnVq_GW8OMp6r}0_%e>Od=1sd=9b2>@Mp~ zxxV0bPgD83JDkbFPno{FIQmkwi+N%O^Sisd-KE7RFmbrOJix$U+a#AB@MrZQpsfs^ Lu6{1-oD!MY=>D*B>&Yiq1t6T z2z%2&J$TcLmsp^J;wcL{G!YLPOz@CG9!g62^}HGt-u=P*!24dF=kva=c}8S&$|mRK zoM>Vbkq)kZr$}tp!&5t#@c;Z~|7-n<>9SVz$LBifRU$5}4Boj~1p^gs8244ejfcf> zZ6W}7mqy{Qy>j?^>pl$4m%{5KVOSfy2J36DKu=W#tgh~crTP$T34ejcn1XE|GVuNS z0aP53v6;7U_{j?x4258`uO9Z?j=^b<2d*_5aJBy(j3;Ygtjn?|lS!CLrC>UpRuR_O zt#@wCWfq$l#2TisgAptspLW8jCYfGhDJ7Fe0`H97hZ6kq1}IK?TC-xzu{n$x_awoRKey1($$qwD5Pb71h^ zp=$imI<)L9dwHQDdvW}`{n@g&$(OkJ(edhe#@nuyujJ()^YnvA iBAB>ww;&VFo%7Lz%TRcx&{zLS#j>*~L=1xG(5OcZ_c$NuOy{^o6Zhc2w1 vE-6vOx7om^?*CjtS3@7>stJcgCh;(A*q$}Nu~qc~&?^j{u6{1-oD!M(8_&hm5Z;;Ig$k-w56;e}Wv=?VK18RvO4vJ#% z;y3!w_kQ2!bfSt$OMMw#u!K`7Xe%# zLKD3SUE-Xhs;b52Qp(9XL4ermtxXGHj7bX+QU=HX86X2>fPVv^l%@rkod=XsD9bX6 z`Ba@C0HqX4sVL@Cb-YaYdcOmC-np@Ho!fSnaVXfnHH{b1y-c|88oZcC06*XCVY8V9 zFs4f?nvCV^!-*WX+A+o!8xEzl2JrbosR!%He@0m!j6rSTLgg8E00000NkvXXu0mjf Da-5hT literal 0 HcmV?d00001 diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFont.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFont.cs new file mode 100644 index 00000000..307d0042 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFont.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using StardustCore.UIUtilities.SpriteFonts.CharacterSheets; +using StardustCore.UIUtilities.SpriteFonts.Fonts; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCFonts +{ + public class SSCFont:GenericFont + { + public SSCFont() + { + + } + + public SSCFont(GenericCharacterSheets sheet):base(sheet) + { + + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs new file mode 100644 index 00000000..66b9cde7 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCFonts/SSCFontCharacterSheet.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using StardustCore.UIUtilities.SpriteFonts.Components; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCFonts +{ + public class SSCFontCharacterSheet:StardustCore.UIUtilities.SpriteFonts.CharacterSheets.GenericCharacterSheets + { + + public SSCFontCharacterSheet() + { + this.CharacterAtlus = new Dictionary(); + this.CharacterAtlus.Add('0', new TexturedCharacter('0', SeasideScramble.self.textureUtils.getTexture("SSCUI", "0"), Color.White)); + this.CharacterAtlus.Add('1', new TexturedCharacter('1', SeasideScramble.self.textureUtils.getTexture("SSCUI", "1"), Color.White)); + this.CharacterAtlus.Add('2', new TexturedCharacter('2', SeasideScramble.self.textureUtils.getTexture("SSCUI", "2"), Color.White)); + this.CharacterAtlus.Add('3', new TexturedCharacter('3', SeasideScramble.self.textureUtils.getTexture("SSCUI", "3"), Color.White)); + this.CharacterAtlus.Add('4', new TexturedCharacter('4', SeasideScramble.self.textureUtils.getTexture("SSCUI", "4"), Color.White)); + this.CharacterAtlus.Add('5', new TexturedCharacter('5', SeasideScramble.self.textureUtils.getTexture("SSCUI", "5"), Color.White)); + this.CharacterAtlus.Add('6', new TexturedCharacter('6', SeasideScramble.self.textureUtils.getTexture("SSCUI", "6"), Color.White)); + this.CharacterAtlus.Add('7', new TexturedCharacter('7', SeasideScramble.self.textureUtils.getTexture("SSCUI", "7"), Color.White)); + this.CharacterAtlus.Add('8', new TexturedCharacter('8', SeasideScramble.self.textureUtils.getTexture("SSCUI", "8"), Color.White)); + this.CharacterAtlus.Add('9', new TexturedCharacter('9', SeasideScramble.self.textureUtils.getTexture("SSCUI", "9"), Color.White)); + } + + public override TexturedCharacter getTexturedCharacter(char c) + { + return this.CharacterAtlus[c]; + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs index fe290989..da73ac1c 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/CharacterSelectScreen.cs @@ -464,7 +464,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus /// private void setUpForGameplay() { - + foreach(SSCPlayer p in SeasideScramble.self.players.Values) + { + p.HUD.displayHUD(); + } } /// diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs new file mode 100644 index 00000000..e699368b --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCMenus/HUD/CharacterHUD.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using StardustCore.Animations; +using StardustCore.UIUtilities; +using StardustCore.UIUtilities.SpriteFonts.Components; + +namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus.HUD +{ + public class CharacterHUD: IClickableMenuExtended + { + public AnimatedSprite background; + public SSCEnums.PlayerID playerID; + public bool showHUD; + + public TexturedString str; + + public CharacterHUD() + { + + } + + public CharacterHUD(int x, int y, int width, int height,SSCEnums.PlayerID Player) : base(x, y, width, height, false) + { + this.background = new AnimatedSprite("Background",new Vector2(x,y),new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("SSCUI", "DialogBox"),new Animation(0,0,32,32)),Color.White); + + this.playerID = Player; + this.showHUD = false; + this.str = SeasideScramble.self.gameFont.ParseString("012",new Vector2(100,100),Color.White,true,2f); + this.str.setPosition(new Vector2(this.xPositionOnScreen+100, this.yPositionOnScreen+50)); + + } + + public override void update(GameTime time) + { + if (this.showHUD == false) return; + if (SeasideScramble.self.getPlayer(this.playerID) != null) + { + this.background.color = SeasideScramble.self.getPlayer(this.playerID).playerColor; + } + } + + /// + /// Draw the HUD to the screen. + /// + /// + public override void draw(SpriteBatch b) + { + if (this.showHUD == false) return; + //Draw the HUD background. + //b.Draw(this.background.texture, new Vector2(100, 100), SeasideScramble.self.camera.getXNARect(), SeasideScramble.self.players[this.playerID].playerColor, 0f, Vector2.Zero, new Vector2(4f, 2f), SpriteEffects.None, 0f); + this.background.draw(b,this.background.position,new Vector2(8f,4f),0f); + this.str.draw(b,new Rectangle(0,0,16,16),0f); + } + + /// + /// Display the HUD. + /// + public void displayHUD() + { + this.showHUD = true; + } + + /// + /// Hide the HUD. + /// + public void hideHUD() + { + this.showHUD = false; + } + + } +} diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs index 6057aa23..8c620269 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCPlayer.cs @@ -38,6 +38,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame public Rectangle hitBox; + public SSCMenus.HUD.CharacterHUD HUD; + public SSCPlayer(SSCEnums.PlayerID PlayerID) { this.playerID = PlayerID; @@ -129,6 +131,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.gun=new SSCGuns.SSCGun(new StardustCore.Animations.AnimatedSprite("MyFirstGun",this.position,new AnimationManager(SeasideScramble.self.textureUtils.getExtendedTexture("Guns","BasicGun"),new Animation(0,0,16,16)),Color.White), SeasideScramble.self.projectiles.getDefaultProjectile(this, this.position, Vector2.Zero, 1f, new Rectangle(0, 0, 16, 16), Color.White, 4f, 300),10,1000,3000); this.hitBox = new Rectangle((int)this.position.X, (int)this.position.Y, 64, 64); + this.HUD = new SSCMenus.HUD.CharacterHUD(100, 100, 200, 200, this.playerID); } /// @@ -173,6 +176,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame { this.mouseCursor.draw(b, 4f, 0f); } + public void drawHUD(SpriteBatch b) + { + this.HUD.draw(b); + } #region /// @@ -237,6 +244,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame } this.gun.update(Time); + this.HUD.update(Time); } /// diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs index d07d8dcd..512daf2f 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SSCProjectiles/SSCProjectile.cs @@ -156,7 +156,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles { if (this.owner == other) { - ModCore.log("Can't get hit by own projectile."); + //ModCore.log("Can't get hit by own projectile."); return; } } diff --git a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs index fb7343ca..1a27825d 100644 --- a/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs +++ b/GeneralMods/Revitalize/Framework/Minigame/SeasideScrambleMinigame/SeasideScramble.cs @@ -51,6 +51,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame public SSCProjectiles.SSCProjectileManager projectiles; + public SSCFonts.SSCFont gameFont; + public SeasideScramble() { self = this; @@ -75,6 +77,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.menuManager.addNewMenu(new SSCMenus.TitleScreen(this.camera.viewport)); this.oldMousePosition = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y); + + this.gameFont = new SSCFonts.SSCFont(new SSCFonts.SSCFontCharacterSheet()); } public SSCPlayer getPlayer(SSCEnums.PlayerID id) @@ -175,6 +179,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame this.projectiles.draw(b); + foreach (SSCPlayer p in this.players.Values) + { + p.drawHUD(b); + } + b.End(); } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index 7ca71b3e..f4dca3ce 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -69,8 +69,11 @@ + + + @@ -143,15 +146,51 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + Always Always + + Always + Always + + Always + Always diff --git a/GeneralMods/StardustCore/Animations/AnimatedSprite.cs b/GeneralMods/StardustCore/Animations/AnimatedSprite.cs index 1a1ff6f5..0c57ea44 100644 --- a/GeneralMods/StardustCore/Animations/AnimatedSprite.cs +++ b/GeneralMods/StardustCore/Animations/AnimatedSprite.cs @@ -83,11 +83,30 @@ namespace StardustCore.Animations this.animation.draw(b, this.position, this.color, scale, SpriteEffects.None, depth); } + /// + /// Draws the sprite to the screen. + /// + /// + /// + /// + /// public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth) { this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth); } + /// + /// Draws the sprite to the screen. + /// + /// + /// + /// + /// + public virtual void draw(SpriteBatch b, Vector2 position, Vector2 scale, float depth) + { + this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth); + } + } } diff --git a/GeneralMods/StardustCore/Animations/AnimationManager.cs b/GeneralMods/StardustCore/Animations/AnimationManager.cs index a8c76f3e..7f19e4c6 100644 --- a/GeneralMods/StardustCore/Animations/AnimationManager.cs +++ b/GeneralMods/StardustCore/Animations/AnimationManager.cs @@ -257,6 +257,34 @@ namespace StardustCore.Animations } } + /// + /// Draws the texture to the screen. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public void draw(SpriteBatch spriteBatch, Texture2D texture, Vector2 Position, Rectangle? sourceRectangle, Color drawColor, float rotation, Vector2 origin, Vector2 scale, SpriteEffects spriteEffects, float LayerDepth) + { + //Log.AsyncC("Animation Manager is working!"); + spriteBatch.Draw(texture, Position, sourceRectangle, drawColor, rotation, origin, scale, spriteEffects, LayerDepth); + try + { + this.tickAnimation(); + // Log.AsyncC("Tick animation"); + } + catch (Exception err) + { + ModCore.ModMonitor.Log(err.ToString()); + } + } + /// /// Used to draw the current animation to the screen. /// @@ -280,6 +308,29 @@ namespace StardustCore.Animations } } + /// + /// Draws the animated texture to the screen. + /// + /// The Sprite Batch used to draw. + /// The position to draw the sprite to. + /// The color to draw the sprite to. + /// The scale for the sprite as a Vector2. (Width,Height) + /// If the sprite is flipped. + /// The depth of the sprite. + public void draw(SpriteBatch b, Vector2 Position, Color drawColor, Vector2 scale, SpriteEffects flipped, float depth) + { + b.Draw(this.objectTexture.texture, Position, this.currentAnimation.sourceRectangle, drawColor, 0f, Vector2.Zero, scale, flipped, depth); + try + { + this.tickAnimation(); + // Log.AsyncC("Tick animation"); + } + catch (Exception err) + { + ModCore.ModMonitor.Log(err.ToString()); + } + } + public Texture2DExtended getExtendedTexture() { return this.objectTexture; diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs index 173efae1..ca844abf 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/CharacterSheets/GenericCharacterSheets.cs @@ -7,9 +7,25 @@ namespace StardustCore.UIUtilities.SpriteFonts.CharacterSheets { public Dictionary CharacterAtlus; + + public GenericCharacterSheets() + { + + } + + public GenericCharacterSheets(string Path) + { + + } + public virtual TexturedCharacter getTexturedCharacter(char c) { return new TexturedCharacter(); } + + public virtual GenericCharacterSheets create(string Path) + { + return new GenericCharacterSheets(Path); + } } } diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedCharacter.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedCharacter.cs index 82278088..6c2622cc 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedCharacter.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedCharacter.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using StardewValley; namespace StardustCore.UIUtilities.SpriteFonts.Components { @@ -24,6 +25,15 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components this.position = new Vector2(); } + public TexturedCharacter(char Character, Texture2D Texture, Color color) + { + this.character = Character; + this.texture = Texture; + this.spacing = new CharacterSpacing(); + this.drawColor = color; + this.position = new Vector2(); + } + public TexturedCharacter(char Character, string PathToTexture, Color color, int left, int right, int top, int bottom) { this.character = Character; @@ -37,6 +47,18 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components public static TexturedCharacter Copy(TexturedCharacter original) { + if (string.IsNullOrEmpty(original.pathToTexture)) + { + Texture2D text = new Texture2D(Game1.graphics.GraphicsDevice, original.texture.Width, original.texture.Height); + Color[] colors = new Color[text.Width * text.Height]; + original.texture.GetData(colors); + text.SetData(colors); + return new TexturedCharacter(original.character, text, original.drawColor) + { + spacing = new CharacterSpacing(original.spacing.LeftPadding, original.spacing.RightPadding, original.spacing.TopPadding, original.spacing.BottomPadding) + }; + } + return new TexturedCharacter(original.character, original.pathToTexture, original.drawColor) { spacing = new CharacterSpacing(original.spacing.LeftPadding, original.spacing.RightPadding, original.spacing.TopPadding, original.spacing.BottomPadding) @@ -48,5 +70,10 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components { b.Draw(this.texture, this.position, this.drawColor); } + + public void draw(SpriteBatch b,Rectangle sourceRectangle,float Scale, float Depth) + { + b.Draw(this.texture, this.position, sourceRectangle, this.drawColor, 0f, Vector2.Zero, Scale, SpriteEffects.None, Depth); + } } } diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs index c8dc8afe..8eebc878 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/Components/TexturedString.cs @@ -9,12 +9,14 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components public List characters; public Vector2 position; public string label; + public float scale; - public TexturedString(string Label, Vector2 Position, List Characters, bool useRightPadding = true) + public TexturedString(string Label, Vector2 Position, List Characters, bool useRightPadding = true,float Scale=1f) { this.label = Label; this.characters = Characters; this.position = Position; + this.scale = Scale; this.setCharacterPositions(useRightPadding); } @@ -26,11 +28,11 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components foreach (var c in this.characters) { if (index == 0) - c.position = new Vector2(this.position.X + c.spacing.LeftPadding, this.position.Y); + c.position = new Vector2(this.position.X + (c.spacing.LeftPadding*this.scale), this.position.Y); else if (useRightPadding) - c.position = new Vector2(this.position.X + c.spacing.LeftPadding + lastSeenChar.spacing.RightPadding + lastSeenChar.texture.Width * index, this.position.Y); + c.position = new Vector2(this.position.X + (c.spacing.LeftPadding*this.scale) + (lastSeenChar.spacing.RightPadding*this.scale) + (lastSeenChar.texture.Width*this.scale * index), this.position.Y); else - c.position = new Vector2(this.position.X + c.spacing.LeftPadding + lastSeenChar.texture.Width * index, this.position.Y); + c.position = new Vector2(this.position.X + (c.spacing.LeftPadding*this.scale) + (lastSeenChar.texture.Width*this.scale * index), this.position.Y); //StardustCore.ModCore.ModMonitor.Log(c.character.ToString()); //StardustCore.ModCore.ModMonitor.Log(c.position.ToString()); lastSeenChar = c; @@ -38,6 +40,16 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components } } + /// + /// Sets the position of the textured string and all characters accordingly. + /// + /// + public void setPosition(Vector2 pos) + { + this.position = pos; + this.setCharacterPositions(); + } + /// Adds a textured character to a textured string. public void addCharacterToEnd(TexturedCharacter ch, bool useRightPadding = true) { @@ -87,6 +99,30 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components v.draw(b); } + /// + /// Draw the textured string. + /// + /// + /// + /// + /// + public void draw(SpriteBatch b, Rectangle sourceRectangle, float Scale, float Depth) + { + foreach (var v in this.characters) + v.draw(b,sourceRectangle,Scale,Depth); + } + /// + /// Draw the textured string. + /// + /// + /// + /// + public void draw(SpriteBatch b, Rectangle sourceRectangle, float Depth) + { + foreach (var v in this.characters) + v.draw(b, sourceRectangle, this.scale, Depth); + } + /// Returns a copy of this object. public TexturedString copy() { diff --git a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/GenericFont.cs b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/GenericFont.cs index 78dc769e..eb11a870 100644 --- a/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/GenericFont.cs +++ b/GeneralMods/StardustCore/UIUtilities/SpriteFonts/Fonts/GenericFont.cs @@ -1,8 +1,91 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.Xna.Framework; +using StardustCore.UIUtilities.SpriteFonts.CharacterSheets; +using StardustCore.UIUtilities.SpriteFonts.Components; + namespace StardustCore.UIUtilities.SpriteFonts.Fonts { public class GenericFont { public CharacterSheets.GenericCharacterSheets characterSheet; public string path; + + public GenericFont() + { + + } + + public GenericFont(GenericCharacterSheets CharacterSheet) + { + this.characterSheet = CharacterSheet; + } + + /// Takes a string and returns a textured string in it's place. + public virtual TexturedString ParseString(string str) + { + List characters = new List(); + foreach (char chr in str) + characters.Add(this.characterSheet.getTexturedCharacter(chr)); + return new TexturedString(str, Vector2.Zero, characters); + } + + /// Takes a string and returns a textured string in it's place. Also sets the new position. + public virtual TexturedString ParseString(string str, Vector2 position) + { + List characters = new List(); + foreach (char chr in str) + characters.Add(this.characterSheet.getTexturedCharacter(chr)); + return new TexturedString(str, position, characters); + } + + /// Takes a string and returns a textured string in it's place. Also sets the new position and string color. + public virtual TexturedString ParseString(string str, Vector2 position, Color stringColor, bool useRightPadding = true,float Scale=1f) + { + List characters = new List(); + foreach (char chr in str) + { + var c = this.characterSheet.getTexturedCharacter(chr); + c.drawColor = stringColor; + characters.Add(c); + } + return new TexturedString(str, position, characters, useRightPadding,Scale); + } + + /// Takes a string and returns a textured string in it's place. Also sets the new position, label and string color. + /// The label for the string. + /// The string that wil be parsed into textured characters. + /// The position to draw the textured string. + /// The color of the textured string. + public virtual TexturedString ParseString(string label, string str, Vector2 position, Color stringColor, bool useRightPadding = true) + { + List characters = new List(); + foreach (char chr in str) + { + var c = this.characterSheet.getTexturedCharacter(chr); + c.drawColor = stringColor; + characters.Add(c); + } + return new TexturedString(label, position, characters, false); + } + + /// Takes a string and returns a textured string in it's place. Also sets the new position and string color. + /// The string that wil be parsed into textured characters. + /// The position to draw the textured string. + /// The color for the individual characters. + public virtual TexturedString ParseString(string str, Vector2 position, List stringColor) + { + List characters = new List(); + int index = 0; + foreach (char chr in str) + { + var c = this.characterSheet.getTexturedCharacter(chr); + c.drawColor = stringColor.ElementAt(index); + characters.Add(c); + index++; + } + return new TexturedString(str, position, characters); + } } }