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.

This commit is contained in:
JoshuaNavarro 2019-07-21 16:58:57 -07:00
parent fac35e0f9d
commit b11a37df31
27 changed files with 433 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 357 B

View File

@ -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)
{
}
}
}

View File

@ -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<char, TexturedCharacter>();
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];
}
}
}

View File

@ -464,7 +464,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCMenus
/// </summary> /// </summary>
private void setUpForGameplay() private void setUpForGameplay()
{ {
foreach(SSCPlayer p in SeasideScramble.self.players.Values)
{
p.HUD.displayHUD();
}
} }
/// <summary> /// <summary>

View File

@ -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;
}
}
/// <summary>
/// Draw the HUD to the screen.
/// </summary>
/// <param name="b"></param>
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);
}
/// <summary>
/// Display the HUD.
/// </summary>
public void displayHUD()
{
this.showHUD = true;
}
/// <summary>
/// Hide the HUD.
/// </summary>
public void hideHUD()
{
this.showHUD = false;
}
}
}

View File

@ -38,6 +38,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public Rectangle hitBox; public Rectangle hitBox;
public SSCMenus.HUD.CharacterHUD HUD;
public SSCPlayer(SSCEnums.PlayerID PlayerID) public SSCPlayer(SSCEnums.PlayerID PlayerID)
{ {
this.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.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.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);
} }
/// <summary> /// <summary>
@ -173,6 +176,10 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
{ {
this.mouseCursor.draw(b, 4f, 0f); this.mouseCursor.draw(b, 4f, 0f);
} }
public void drawHUD(SpriteBatch b)
{
this.HUD.draw(b);
}
#region #region
/// <summary> /// <summary>
@ -237,6 +244,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
} }
this.gun.update(Time); this.gun.update(Time);
this.HUD.update(Time);
} }
/// <summary> /// <summary>

View File

@ -156,7 +156,7 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame.SSCProjectiles
{ {
if (this.owner == other) if (this.owner == other)
{ {
ModCore.log("Can't get hit by own projectile."); //ModCore.log("Can't get hit by own projectile.");
return; return;
} }
} }

View File

@ -51,6 +51,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
public SSCProjectiles.SSCProjectileManager projectiles; public SSCProjectiles.SSCProjectileManager projectiles;
public SSCFonts.SSCFont gameFont;
public SeasideScramble() public SeasideScramble()
{ {
self = this; self = this;
@ -75,6 +77,8 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.menuManager.addNewMenu(new SSCMenus.TitleScreen(this.camera.viewport)); this.menuManager.addNewMenu(new SSCMenus.TitleScreen(this.camera.viewport));
this.oldMousePosition = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y); this.oldMousePosition = new Vector2(Game1.getMousePosition().X, Game1.getMousePosition().Y);
this.gameFont = new SSCFonts.SSCFont(new SSCFonts.SSCFontCharacterSheet());
} }
public SSCPlayer getPlayer(SSCEnums.PlayerID id) public SSCPlayer getPlayer(SSCEnums.PlayerID id)
@ -175,6 +179,11 @@ namespace Revitalize.Framework.Minigame.SeasideScrambleMinigame
this.projectiles.draw(b); this.projectiles.draw(b);
foreach (SSCPlayer p in this.players.Values)
{
p.drawHUD(b);
}
b.End(); b.End();
} }

View File

@ -69,8 +69,11 @@
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScrambleMap.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SeasideScrambleMap.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCCamera.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCCamera.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCEnums.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCEnums.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCFonts\SSCFontCharacterSheet.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCFonts\SSCFont.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCGuns\SSCGun.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCGuns\SSCGun.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\CharacterSelectScreen.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\CharacterSelectScreen.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\HUD\CharacterHUD.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\SSCMenuManager.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\SSCMenuManager.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\TitleScreen.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCMenus\TitleScreen.cs" />
<Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" /> <Compile Include="Framework\Minigame\SeasideScrambleMinigame\SSCPlayer.cs" />
@ -143,15 +146,51 @@
<Content Include="Content\Minigames\SeasideScramble\Graphics\Projectiles\Basic.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\Projectiles\Basic.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\0.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\1.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\2.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\3.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\4.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\5.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\6.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\7.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\8.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\9.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\AButton.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\UI\AButton.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\BlankTexture.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\UI\BlankTexture.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\Clock.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\Cursors.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\UI\Cursors.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\DialogBox.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Minigames\SeasideScramble\Graphics\UI\lastPageButton.png"> <Content Include="Content\Minigames\SeasideScramble\Graphics\UI\lastPageButton.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

View File

@ -83,11 +83,30 @@ namespace StardustCore.Animations
this.animation.draw(b, this.position, this.color, scale, SpriteEffects.None, depth); this.animation.draw(b, this.position, this.color, scale, SpriteEffects.None, depth);
} }
/// <summary>
/// Draws the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="position"></param>
/// <param name="scale"></param>
/// <param name="depth"></param>
public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth) public virtual void draw(SpriteBatch b,Vector2 position ,float scale, float depth)
{ {
this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth); this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth);
} }
/// <summary>
/// Draws the sprite to the screen.
/// </summary>
/// <param name="b"></param>
/// <param name="position"></param>
/// <param name="scale"></param>
/// <param name="depth"></param>
public virtual void draw(SpriteBatch b, Vector2 position, Vector2 scale, float depth)
{
this.animation.draw(b, position, this.color, scale, SpriteEffects.None, depth);
}
} }
} }

View File

@ -257,6 +257,34 @@ namespace StardustCore.Animations
} }
} }
/// <summary>
/// Draws the texture to the screen.
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="texture"></param>
/// <param name="Position"></param>
/// <param name="sourceRectangle"></param>
/// <param name="drawColor"></param>
/// <param name="rotation"></param>
/// <param name="origin"></param>
/// <param name="scale"></param>
/// <param name="spriteEffects"></param>
/// <param name="LayerDepth"></param>
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());
}
}
/// <summary> /// <summary>
/// Used to draw the current animation to the screen. /// Used to draw the current animation to the screen.
/// </summary> /// </summary>
@ -280,6 +308,29 @@ namespace StardustCore.Animations
} }
} }
/// <summary>
/// Draws the animated texture to the screen.
/// </summary>
/// <param name="b">The Sprite Batch used to draw.</param>
/// <param name="Position">The position to draw the sprite to.</param>
/// <param name="drawColor">The color to draw the sprite to.</param>
/// <param name="scale">The scale for the sprite as a Vector2. (Width,Height)</param>
/// <param name="flipped">If the sprite is flipped.</param>
/// <param name="depth">The depth of the sprite.</param>
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() public Texture2DExtended getExtendedTexture()
{ {
return this.objectTexture; return this.objectTexture;

View File

@ -7,9 +7,25 @@ namespace StardustCore.UIUtilities.SpriteFonts.CharacterSheets
{ {
public Dictionary<char, TexturedCharacter> CharacterAtlus; public Dictionary<char, TexturedCharacter> CharacterAtlus;
public GenericCharacterSheets()
{
}
public GenericCharacterSheets(string Path)
{
}
public virtual TexturedCharacter getTexturedCharacter(char c) public virtual TexturedCharacter getTexturedCharacter(char c)
{ {
return new TexturedCharacter(); return new TexturedCharacter();
} }
public virtual GenericCharacterSheets create(string Path)
{
return new GenericCharacterSheets(Path);
}
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewValley;
namespace StardustCore.UIUtilities.SpriteFonts.Components namespace StardustCore.UIUtilities.SpriteFonts.Components
{ {
@ -24,6 +25,15 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
this.position = new Vector2(); 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) public TexturedCharacter(char Character, string PathToTexture, Color color, int left, int right, int top, int bottom)
{ {
this.character = Character; this.character = Character;
@ -37,6 +47,18 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
public static TexturedCharacter Copy(TexturedCharacter original) 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) return new TexturedCharacter(original.character, original.pathToTexture, original.drawColor)
{ {
spacing = new CharacterSpacing(original.spacing.LeftPadding, original.spacing.RightPadding, original.spacing.TopPadding, original.spacing.BottomPadding) 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); 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);
}
} }
} }

View File

@ -9,12 +9,14 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
public List<TexturedCharacter> characters; public List<TexturedCharacter> characters;
public Vector2 position; public Vector2 position;
public string label; public string label;
public float scale;
public TexturedString(string Label, Vector2 Position, List<TexturedCharacter> Characters, bool useRightPadding = true) public TexturedString(string Label, Vector2 Position, List<TexturedCharacter> Characters, bool useRightPadding = true,float Scale=1f)
{ {
this.label = Label; this.label = Label;
this.characters = Characters; this.characters = Characters;
this.position = Position; this.position = Position;
this.scale = Scale;
this.setCharacterPositions(useRightPadding); this.setCharacterPositions(useRightPadding);
} }
@ -26,11 +28,11 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
foreach (var c in this.characters) foreach (var c in this.characters)
{ {
if (index == 0) 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) 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 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.character.ToString());
//StardustCore.ModCore.ModMonitor.Log(c.position.ToString()); //StardustCore.ModCore.ModMonitor.Log(c.position.ToString());
lastSeenChar = c; lastSeenChar = c;
@ -38,6 +40,16 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
} }
} }
/// <summary>
/// Sets the position of the textured string and all characters accordingly.
/// </summary>
/// <param name="pos"></param>
public void setPosition(Vector2 pos)
{
this.position = pos;
this.setCharacterPositions();
}
/// <summary>Adds a textured character to a textured string.</summary> /// <summary>Adds a textured character to a textured string.</summary>
public void addCharacterToEnd(TexturedCharacter ch, bool useRightPadding = true) public void addCharacterToEnd(TexturedCharacter ch, bool useRightPadding = true)
{ {
@ -87,6 +99,30 @@ namespace StardustCore.UIUtilities.SpriteFonts.Components
v.draw(b); v.draw(b);
} }
/// <summary>
/// Draw the textured string.
/// </summary>
/// <param name="b"></param>
/// <param name="sourceRectangle"></param>
/// <param name="Scale"></param>
/// <param name="Depth"></param>
public void draw(SpriteBatch b, Rectangle sourceRectangle, float Scale, float Depth)
{
foreach (var v in this.characters)
v.draw(b,sourceRectangle,Scale,Depth);
}
/// <summary>
/// Draw the textured string.
/// </summary>
/// <param name="b"></param>
/// <param name="sourceRectangle"></param>
/// <param name="Depth"></param>
public void draw(SpriteBatch b, Rectangle sourceRectangle, float Depth)
{
foreach (var v in this.characters)
v.draw(b, sourceRectangle, this.scale, Depth);
}
/// <summary>Returns a copy of this object.</summary> /// <summary>Returns a copy of this object.</summary>
public TexturedString copy() public TexturedString copy()
{ {

View File

@ -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 namespace StardustCore.UIUtilities.SpriteFonts.Fonts
{ {
public class GenericFont public class GenericFont
{ {
public CharacterSheets.GenericCharacterSheets characterSheet; public CharacterSheets.GenericCharacterSheets characterSheet;
public string path; public string path;
public GenericFont()
{
}
public GenericFont(GenericCharacterSheets CharacterSheet)
{
this.characterSheet = CharacterSheet;
}
/// <summary> Takes a string and returns a textured string in it's place.</summary>
public virtual TexturedString ParseString(string str)
{
List<TexturedCharacter> characters = new List<TexturedCharacter>();
foreach (char chr in str)
characters.Add(this.characterSheet.getTexturedCharacter(chr));
return new TexturedString(str, Vector2.Zero, characters);
}
/// <summary>Takes a string and returns a textured string in it's place. Also sets the new position.</summary>
public virtual TexturedString ParseString(string str, Vector2 position)
{
List<TexturedCharacter> characters = new List<TexturedCharacter>();
foreach (char chr in str)
characters.Add(this.characterSheet.getTexturedCharacter(chr));
return new TexturedString(str, position, characters);
}
/// <summary>Takes a string and returns a textured string in it's place. Also sets the new position and string color.</summary>
public virtual TexturedString ParseString(string str, Vector2 position, Color stringColor, bool useRightPadding = true,float Scale=1f)
{
List<TexturedCharacter> characters = new List<TexturedCharacter>();
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);
}
/// <summary>Takes a string and returns a textured string in it's place. Also sets the new position, label and string color.</summary>
/// <param name="label">The label for the string.</param>
/// <param name="str">The string that wil be parsed into textured characters.</param>
/// <param name="position">The position to draw the textured string.</param>
/// <param name="stringColor">The color of the textured string.</param>
public virtual TexturedString ParseString(string label, string str, Vector2 position, Color stringColor, bool useRightPadding = true)
{
List<TexturedCharacter> characters = new List<TexturedCharacter>();
foreach (char chr in str)
{
var c = this.characterSheet.getTexturedCharacter(chr);
c.drawColor = stringColor;
characters.Add(c);
}
return new TexturedString(label, position, characters, false);
}
/// <summary>Takes a string and returns a textured string in it's place. Also sets the new position and string color.</summary>
/// <param name="str">The string that wil be parsed into textured characters.</param>
/// <param name="position">The position to draw the textured string.</param>
/// <param name="stringColor">The color for the individual characters.</param>
public virtual TexturedString ParseString(string str, Vector2 position, List<Color> stringColor)
{
List<TexturedCharacter> characters = new List<TexturedCharacter>();
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);
}
} }
} }