//-----------------------------------------------------------------------------
// TextureFontBigNumbers.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
using RacingGame.Helpers;
using RacingGame.GameLogic;
using Microsoft.Xna.Framework.Input;
namespace RacingGame.Graphics
{
///
/// TextureFontBigNumbers
///
public static class TextureFontBigNumbers
{
///
/// Big numbers in the Ingame.png graphic
///
private static readonly Rectangle[] BigNumberRects =
{
// 0
new Rectangle(2, 342, 80, 133),
// 1
new Rectangle(84, 342, 80, 133),
// 2
new Rectangle(167, 342, 80, 133),
// 3
new Rectangle(247, 342, 78, 133),
// 4
new Rectangle(330, 342, 80, 133),
// 5
new Rectangle(411, 342, 80, 133),
// 6
new Rectangle(495, 342, 80, 133),
// 7
new Rectangle(578, 342, 80, 133),
// 8
new Rectangle(659, 342, 80, 133),
// 9
new Rectangle(749, 342, 80, 133),
};
///
/// Write digit
///
/// X
/// Y
/// Digit
/// Int
private static int WriteDigit(int x, int y, int digit)
{
if (digit < 0)
return 0;
float resScalingX = (float)BaseGame.Width / 1600.0f;
float resScalingY = (float)BaseGame.Height / 1200.0f;
Rectangle rect = BigNumberRects[digit % BigNumberRects.Length];
BaseGame.UI.Ingame.RenderOnScreen(new Rectangle(x, y,
(int)Math.Round(rect.Width * resScalingX),
(int)Math.Round(rect.Height * resScalingY)), rect);
return (int)Math.Round(rect.Width * resScalingX);
}
///
/// Write digit
///
/// X
/// Y
/// Height
/// Digit
/// Int
private static int WriteDigit(int x, int y, int height, int digit)
{
if (digit < 0)
return 0;
float resScalingX = (float)BaseGame.Width / 1600.0f;
float resScalingY = (float)BaseGame.Height / 1200.0f;
float scaleFactor = height / (float)BigNumberRects[0].Height;
Rectangle rect = BigNumberRects[digit % BigNumberRects.Length];
BaseGame.UI.Ingame.RenderOnScreen(new Rectangle(x, y,
(int)Math.Round(rect.Width * resScalingX * scaleFactor),
(int)Math.Round(rect.Height * resScalingY * scaleFactor)), rect);
return (int)Math.Round(rect.Width * resScalingX * scaleFactor);
}
///
/// Write digit
///
/// X
/// Y
/// Digit
/// Alpha
/// Int
private static int WriteDigit(int x, int y, int digit, float alpha)
{
float resScalingX = (float)BaseGame.Width / 1600.0f;
float resScalingY = (float)BaseGame.Height / 1200.0f;
Rectangle rect = BigNumberRects[digit % BigNumberRects.Length];
BaseGame.UI.Ingame.RenderOnScreen(new Rectangle(x, y,
(int)Math.Round(rect.Width * resScalingX),
(int)Math.Round(rect.Height * resScalingY)), rect,
ColorHelper.ApplyAlphaToColor(Color.White, alpha));
return (int)Math.Round(rect.Width * resScalingX);
}
///
/// Write number
///
/// X
/// Y
/// Number
/// Int
public static int WriteNumber(int x, int y, int number)
{
// Convert to string
string numberText = number.ToString();
int width = 0;
// And now process every letter
//foreach (char numberChar in numberText.ToCharArray())
char[] chars = numberText.ToCharArray();
for (int num = 0; num < chars.Length; num++)
{
width += WriteDigit(x + width, y, (int)chars[num] - (int)'0');
}
return width;
}
///
/// Write number
///
/// X
/// Y
/// Number
/// Alpha
/// Int
public static int WriteNumber(int x, int y, int number, float alpha)
{
// Convert to string
string numberText = number.ToString();
int width = 0;
// And now process every letter
//foreach (char numberChar in numberText.ToCharArray())
char[] chars = numberText.ToCharArray();
for (int num = 0; num < chars.Length; num++)
{
width += WriteDigit(
x + width, y, (int)chars[num] - (int)'0', alpha);
}
return width;
}
///
/// Write number
///
/// X
/// Y
/// Height
/// Number
/// Int
public static int WriteNumber(int x, int y, int height, int number)
{
// Convert to string
string numberText = number.ToString();
int width = 0;
// And now process every letter
//foreach (char numberChar in numberText.ToCharArray())
char[] chars = numberText.ToCharArray();
for (int num = 0; num < chars.Length; num++)
{
width += WriteDigit(
x + width, y, height, (int)chars[num] - (int)'0');
}
return width;
}
///
/// Write number centered
///
/// X
/// Y
/// Number
public static void WriteNumberCentered(int x, int y, int number)
{
WriteNumber(
(int)(x - (number.ToString().Length * BigNumberRects[0].Width / 2) *
((float)BaseGame.Width / 1600.0f)),
y, number);
}
///
/// Write number centered
///
/// X
/// Y
/// Number
/// Alpha
public static void WriteNumberCentered(int x, int y, int number, float alpha)
{
WriteNumber(
(int)(x - (number.ToString().Length * BigNumberRects[0].Width / 2) *
((float)BaseGame.Width / 1600.0f)),
y, number, alpha);
}
}
}