Modules made more useable by improving or fixing some of the drawing position logic. Variable names refactored as well.
This commit is contained in:
@@ -23,12 +23,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <summary>
|
||||
/// Scale of of the X axis.
|
||||
/// </summary>
|
||||
public float ScaleX { get { return (float)bounds.Width / texture.Width; } set { bounds.Width = (int)(texture.Width * value); } }
|
||||
public float ScaleX { get { return (float)situation.Width / texture.Width; } set { situation.Width = (int)(texture.Width * value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Scale of the Y axis.
|
||||
/// </summary>
|
||||
public float ScaleY { get { return (float)bounds.Height / texture.Height; } set { bounds.Height = (int)(texture.Height * value); } }
|
||||
public float ScaleY { get { return (float)situation.Height / texture.Height; } set { situation.Height = (int)(texture.Height * value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Sets scale of X and Y.
|
||||
@@ -42,7 +42,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
public Image(Texture2D texture)
|
||||
{
|
||||
this.texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
||||
bounds = texture.Bounds;
|
||||
situation = texture.Bounds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,7 +51,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="batch">The batch to use.</param>
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
batch.Draw(texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
batch.Draw(texture, situation, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
base.Draw(batch);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
this.color = color;
|
||||
this.rotation = rotation;
|
||||
this.origin = origin;
|
||||
bounds = destination;
|
||||
situation = destination;
|
||||
Draw(spriteBatch);
|
||||
}
|
||||
}
|
||||
|
@@ -69,12 +69,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
/// </summary>
|
||||
/// <param name="skin">The skin the definition is defined in.</param>
|
||||
/// <param name="skinDefinition">The definition itself.</param>
|
||||
public Button(ISkin skin, ButtonSkinDefinition skinDefinition) :
|
||||
this(skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
|
||||
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
|
||||
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
||||
public Button(ISkin skin, ButtonSkinDefinition skinDefinition) :
|
||||
this(skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
|
||||
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
|
||||
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
||||
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
||||
{}
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Draws the button.
|
||||
@@ -84,17 +84,21 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
{
|
||||
if (disabled)
|
||||
{
|
||||
disabledTexture?.Draw(batch, bounds, color);
|
||||
disabledTexture?.Draw(batch, Boundaries, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pressed)
|
||||
{
|
||||
downTexture.Draw(batch, bounds, color);
|
||||
downTexture.Draw(batch, Boundaries, color);
|
||||
}
|
||||
else if (Highlighted)
|
||||
{
|
||||
highlightedTexture?.Draw(batch, Boundaries, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
upTexture.Draw(batch, bounds, color);
|
||||
upTexture.Draw(batch, Boundaries, color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +112,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
/// <returns>Whether or not to continue calling the next mouse change listener.</returns>
|
||||
public sealed override bool MouseStateChanged(MouseState state)
|
||||
{
|
||||
if (InputUtilities.MouseWithinBoundries(bounds))
|
||||
if (InputUtilities.MouseWithinBoundries(Boundaries))
|
||||
{
|
||||
if (state.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
|
@@ -76,7 +76,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
/// <param name="gameTime">Snapshot of information about time for game.</param>
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
text.bounds = bounds;
|
||||
text.situation = Boundaries;
|
||||
text.Update(gameTime);
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
@@ -67,8 +67,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="gameTime">The game time.</param>
|
||||
public override void Update(GameTime gameTime)
|
||||
{
|
||||
position.X = bounds.X;
|
||||
position.Y = bounds.Y;
|
||||
position.X = situation.X;
|
||||
position.Y = situation.Y;
|
||||
|
||||
if (useEllipses) AttemptToApplyEllipsis();
|
||||
if (autoWrap) AttemptToWrapText();
|
||||
@@ -84,7 +84,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="batch">Batch to use.</param>
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
batch.DrawString(font, Content, position, color, 0f, origin, scale, SpriteEffects.None, 0f);
|
||||
batch.DrawString(font, Content, position, color, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
|
||||
base.Draw(batch);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// </summary>
|
||||
public void AttemptToApplyEllipsis()
|
||||
{
|
||||
if (modifiedTextSize.X * scale > bounds.Width && ModifiedText.Length > ellipsis.Length + 1)
|
||||
if (modifiedTextSize.X * scale > situation.Width && ModifiedText.Length > ellipsis.Length + 1)
|
||||
{
|
||||
RemoveLineBreaks();
|
||||
StringBuilder stringBuilder = new StringBuilder(ModifiedText);
|
||||
@@ -102,7 +102,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
stringBuilder.Remove(stringBuilder.Length, ellipsis.Length - 1);
|
||||
stringBuilder.Insert(stringBuilder.Length, ellipsis);
|
||||
}
|
||||
while (font.MeasureString(stringBuilder).X * scale > bounds.Width);
|
||||
while (font.MeasureString(stringBuilder).X * scale > situation.Width);
|
||||
|
||||
ModifiedText = stringBuilder.ToString();
|
||||
}
|
||||
@@ -114,18 +114,18 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
public void AttemptToScaleFont()
|
||||
{
|
||||
|
||||
if (bounds.Width < bounds.Height)
|
||||
if (situation.Width < situation.Height)
|
||||
{
|
||||
if (Math.Round(modifiedTextSize.X * scale ) != bounds.Width)
|
||||
if (Math.Round(modifiedTextSize.X * scale ) != situation.Width)
|
||||
{
|
||||
scale = bounds.Width / modifiedTextSize.X;
|
||||
scale = situation.Width / modifiedTextSize.X;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Math.Round(modifiedTextSize.Y * scale ) != bounds.Height)
|
||||
if (Math.Round(modifiedTextSize.Y * scale ) != situation.Height)
|
||||
{
|
||||
scale = bounds.Height / (modifiedTextSize.Y);
|
||||
scale = situation.Height / (modifiedTextSize.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
public void AttemptToWrapText(bool unwrap = false)
|
||||
{
|
||||
if (unwrap) RemoveLineBreaks();
|
||||
if (modifiedTextSize.X * scale > bounds.Width)
|
||||
if (modifiedTextSize.X * scale > situation.Width)
|
||||
{
|
||||
ModifiedText = ModifiedText.Replace("\n", " ");
|
||||
string[] words = ModifiedText.Split(' ');
|
||||
@@ -165,7 +165,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
string word = words[w];
|
||||
float scaledWidth = font.MeasureString(word).X * scale;
|
||||
|
||||
if (currentScaledLineWidth + scaledWidth <= bounds.Width)
|
||||
if (currentScaledLineWidth + scaledWidth <= situation.Width)
|
||||
{
|
||||
stringBuilder.Append(word);
|
||||
currentScaledLineWidth += scaledWidth;
|
||||
@@ -184,18 +184,18 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
Vector2 textSize = new Vector2(modifiedTextSize.X * scale, modifiedTextSize.Y * scale);
|
||||
|
||||
if (textSize.X <= bounds.Width)
|
||||
if (textSize.X <= situation.Width)
|
||||
{
|
||||
position.X = bounds.X + (bounds.Width - textSize.X) / 2f;
|
||||
position.X = situation.X + (situation.Width - textSize.X) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (textSize.Y <= bounds.Height)
|
||||
if (textSize.Y <= situation.Height)
|
||||
{
|
||||
position.Y = bounds.Y + (bounds.Height - textSize.Y) / 2f;
|
||||
position.Y = situation.Y + (situation.Height - textSize.Y) / 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user