Fonts are now defined in mod.yaml
This commit is contained in:
@@ -22,6 +22,7 @@ namespace OpenRA.FileFormats
|
|||||||
Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
|
Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
|
||||||
Weapons, Voices, Music, Movies, TileSets, ChromeMetrics;
|
Weapons, Voices, Music, Movies, TileSets, ChromeMetrics;
|
||||||
public readonly MiniYaml LoadScreen;
|
public readonly MiniYaml LoadScreen;
|
||||||
|
public readonly Dictionary<string, Pair<string,int>> Fonts;
|
||||||
public readonly int TileSize = 24;
|
public readonly int TileSize = 24;
|
||||||
|
|
||||||
public Manifest(string[] mods)
|
public Manifest(string[] mods)
|
||||||
@@ -48,7 +49,9 @@ namespace OpenRA.FileFormats
|
|||||||
TileSets = YamlList(yaml, "TileSets");
|
TileSets = YamlList(yaml, "TileSets");
|
||||||
ChromeMetrics = YamlList(yaml, "ChromeMetrics");
|
ChromeMetrics = YamlList(yaml, "ChromeMetrics");
|
||||||
LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value;
|
LoadScreen = yaml.First( x => x.Key == "LoadScreen" ).Value;
|
||||||
|
Fonts = yaml.First( x => x.Key == "Fonts" ).Value
|
||||||
|
.NodesDict.ToDictionary(x => x.Key, x => Pair.New(x.Value.NodesDict["Font"].Value,
|
||||||
|
int.Parse(x.Value.NodesDict["Size"].Value)));
|
||||||
if (yaml.FirstOrDefault( x => x.Key == "TileSize" ) != null)
|
if (yaml.FirstOrDefault( x => x.Key == "TileSize" ) != null)
|
||||||
TileSize = int.Parse(yaml.First( x => x.Key == "TileSize" ).Value.Value);
|
TileSize = int.Parse(yaml.First( x => x.Key == "TileSize" ).Value.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ namespace OpenRA
|
|||||||
Sound.Initialize();
|
Sound.Initialize();
|
||||||
|
|
||||||
modData = new ModData( mm );
|
modData = new ModData( mm );
|
||||||
|
Renderer.InitializeFonts(modData.Manifest);
|
||||||
modData.LoadInitialAssets();
|
modData.LoadInitialAssets();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ using System.Drawing;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.FileFormats.Graphics;
|
using OpenRA.FileFormats.Graphics;
|
||||||
using OpenRA.Support;
|
using OpenRA.Support;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
@@ -35,15 +37,14 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public ITexture PaletteTexture;
|
public ITexture PaletteTexture;
|
||||||
|
|
||||||
public readonly SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont, BigBoldFont;
|
|
||||||
|
|
||||||
internal const int TempBufferSize = 8192;
|
internal const int TempBufferSize = 8192;
|
||||||
const int TempBufferCount = 8;
|
const int TempBufferCount = 8;
|
||||||
|
|
||||||
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
|
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
|
||||||
|
|
||||||
public enum FontType { Regular, Bold, Title, Tiny, TinyBold, BigBold }
|
public SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont, BigBoldFont;
|
||||||
public Dictionary<FontType, SpriteFont> Fonts;
|
public Dictionary<string, SpriteFont> Fonts;
|
||||||
|
|
||||||
|
|
||||||
public Renderer()
|
public Renderer()
|
||||||
{
|
{
|
||||||
@@ -56,28 +57,24 @@ namespace OpenRA.Graphics
|
|||||||
RgbaSpriteRenderer = new SpriteRenderer( this, RgbaSpriteShader );
|
RgbaSpriteRenderer = new SpriteRenderer( this, RgbaSpriteShader );
|
||||||
WorldSpriteRenderer = new SpriteRenderer( this, WorldSpriteShader );
|
WorldSpriteRenderer = new SpriteRenderer( this, WorldSpriteShader );
|
||||||
LineRenderer = new LineRenderer(this);
|
LineRenderer = new LineRenderer(this);
|
||||||
|
|
||||||
RegularFont = new SpriteFont("FreeSans.ttf", 14);
|
|
||||||
BoldFont = new SpriteFont("FreeSansBold.ttf", 14);
|
|
||||||
TitleFont = new SpriteFont("titles.ttf", 48);
|
|
||||||
BigBoldFont = new SpriteFont("FreeSansBold.ttf", 24);
|
|
||||||
TinyFont = new SpriteFont("FreeSans.ttf", 10);
|
|
||||||
TinyBoldFont = new SpriteFont("FreeSansBold.ttf", 10);
|
|
||||||
|
|
||||||
Fonts = new Dictionary<FontType, SpriteFont>()
|
|
||||||
{
|
|
||||||
{FontType.Regular, RegularFont},
|
|
||||||
{FontType.Bold, BoldFont},
|
|
||||||
{FontType.Title, TitleFont},
|
|
||||||
{FontType.Tiny, TinyFont},
|
|
||||||
{FontType.TinyBold, TinyBoldFont},
|
|
||||||
{FontType.BigBold, BigBoldFont}
|
|
||||||
};
|
|
||||||
|
|
||||||
for( int i = 0 ; i < TempBufferCount ; i++ )
|
for( int i = 0 ; i < TempBufferCount ; i++ )
|
||||||
tempBuffersV.Enqueue( device.CreateVertexBuffer( TempBufferSize ) );
|
tempBuffersV.Enqueue( device.CreateVertexBuffer( TempBufferSize ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InitializeFonts(Manifest m)
|
||||||
|
{
|
||||||
|
Fonts = m.Fonts.ToDictionary(x => x.Key, x => new SpriteFont(x.Value.First, x.Value.Second));
|
||||||
|
|
||||||
|
// TODO: Remove these
|
||||||
|
RegularFont = Fonts["Regular"];
|
||||||
|
BoldFont = Fonts["Bold"];
|
||||||
|
TitleFont = Fonts["Title"];
|
||||||
|
BigBoldFont = Fonts["BigBold"];
|
||||||
|
TinyFont = Fonts["Tiny"];
|
||||||
|
TinyBoldFont = Fonts["TinyBold"];
|
||||||
|
}
|
||||||
|
|
||||||
internal IGraphicsDevice Device { get { return device; } }
|
internal IGraphicsDevice Device { get { return device; } }
|
||||||
|
|
||||||
public void BeginFrame(float2 scroll)
|
public void BeginFrame(float2 scroll)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace OpenRA.Widgets
|
|||||||
[Obsolete] public string Background = null;
|
[Obsolete] public string Background = null;
|
||||||
public TextAlign Align = TextAlign.Left;
|
public TextAlign Align = TextAlign.Left;
|
||||||
public TextVAlign VAlign = TextVAlign.Middle;
|
public TextVAlign VAlign = TextVAlign.Middle;
|
||||||
public Renderer.FontType Font = Renderer.FontType.Regular;
|
public string Font = "Regular";
|
||||||
public Color Color = Color.White;
|
public Color Color = Color.White;
|
||||||
public bool Bold = false; // Legacy flag. TODO: Remove
|
public bool Bold = false; // Legacy flag. TODO: Remove
|
||||||
public bool Contrast = false;
|
public bool Contrast = false;
|
||||||
@@ -61,8 +61,8 @@ namespace OpenRA.Widgets
|
|||||||
if (bg != null)
|
if (bg != null)
|
||||||
WidgetUtils.DrawPanel(bg, RenderBounds );
|
WidgetUtils.DrawPanel(bg, RenderBounds );
|
||||||
|
|
||||||
if (Font == Renderer.FontType.Regular && Bold)
|
if (Font == "Regular" && Bold)
|
||||||
Font = Renderer.FontType.Bold;
|
Font = "Bold";
|
||||||
|
|
||||||
SpriteFont font = Game.Renderer.Fonts[Font];
|
SpriteFont font = Game.Renderer.Fonts[Font];
|
||||||
var text = GetText();
|
var text = GetText();
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ namespace OpenRA.Mods.Cnc
|
|||||||
float2 LogoPos;
|
float2 LogoPos;
|
||||||
|
|
||||||
Renderer r;
|
Renderer r;
|
||||||
SpriteFont Font;
|
|
||||||
public void Init(Dictionary<string, string> info)
|
public void Init(Dictionary<string, string> info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
@@ -42,7 +41,6 @@ namespace OpenRA.Mods.Cnc
|
|||||||
// can display loadscreen as early as possible
|
// can display loadscreen as early as possible
|
||||||
r = Game.Renderer;
|
r = Game.Renderer;
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
Font = r.BoldFont;
|
|
||||||
|
|
||||||
var s = new Sheet("mods/cnc/uibits/loadscreen.png");
|
var s = new Sheet("mods/cnc/uibits/loadscreen.png");
|
||||||
Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha);
|
Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha);
|
||||||
@@ -65,13 +63,13 @@ namespace OpenRA.Mods.Cnc
|
|||||||
|
|
||||||
lastLoadScreen.Reset();
|
lastLoadScreen.Reset();
|
||||||
var text = Comments.Random(Game.CosmeticRandom);
|
var text = Comments.Random(Game.CosmeticRandom);
|
||||||
var textSize = Font.Measure(text);
|
var textSize = r.Fonts["Bold"].Measure(text);
|
||||||
|
|
||||||
r.BeginFrame(float2.Zero);
|
r.BeginFrame(float2.Zero);
|
||||||
WidgetUtils.FillRectWithSprite(BgRect, Bg);
|
WidgetUtils.FillRectWithSprite(BgRect, Bg);
|
||||||
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
||||||
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
||||||
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.Black);
|
r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.Black);
|
||||||
r.EndFrame( new NullInputHandler() );
|
r.EndFrame( new NullInputHandler() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
{
|
{
|
||||||
public Func<bool> IsDisabled = () => false;
|
public Func<bool> IsDisabled = () => false;
|
||||||
public Action OnClick = () => {};
|
public Action OnClick = () => {};
|
||||||
public Renderer.FontType Font = Renderer.FontType.Bold;
|
public string Font = "Bold";
|
||||||
|
|
||||||
public CncMenuButtonWidget()
|
public CncMenuButtonWidget()
|
||||||
: base()
|
: base()
|
||||||
@@ -276,7 +276,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
public class CncDropDownButtonWidget : DropDownButtonWidget
|
public class CncDropDownButtonWidget : DropDownButtonWidget
|
||||||
{
|
{
|
||||||
public Func<bool> IsDisabled = () => false;
|
public Func<bool> IsDisabled = () => false;
|
||||||
public Renderer.FontType Font = Renderer.FontType.Bold;
|
public string Font = "Bold";
|
||||||
|
|
||||||
public CncDropDownButtonWidget() : base() { }
|
public CncDropDownButtonWidget() : base() { }
|
||||||
protected CncDropDownButtonWidget(CncDropDownButtonWidget other) : base(other)
|
protected CncDropDownButtonWidget(CncDropDownButtonWidget other) : base(other)
|
||||||
|
|||||||
@@ -31,14 +31,12 @@ namespace OpenRA.Mods.RA
|
|||||||
float2 LogoPos;
|
float2 LogoPos;
|
||||||
|
|
||||||
Renderer r;
|
Renderer r;
|
||||||
SpriteFont Font;
|
|
||||||
public void Init(Dictionary<string, string> info)
|
public void Init(Dictionary<string, string> info)
|
||||||
{
|
{
|
||||||
// Avoid standard loading mechanisms so we
|
// Avoid standard loading mechanisms so we
|
||||||
// can display loadscreen as early as possible
|
// can display loadscreen as early as possible
|
||||||
r = Game.Renderer;
|
r = Game.Renderer;
|
||||||
if (r == null) return;
|
if (r == null) return;
|
||||||
Font = r.BoldFont;
|
|
||||||
|
|
||||||
var s = new Sheet("mods/ra/uibits/loadscreen.png");
|
var s = new Sheet("mods/ra/uibits/loadscreen.png");
|
||||||
Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha);
|
Logo = new Sprite(s, new Rectangle(0,0,256,256), TextureChannel.Alpha);
|
||||||
@@ -58,12 +56,12 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
lastLoadScreen.Reset();
|
lastLoadScreen.Reset();
|
||||||
var text = Comments.Random(Game.CosmeticRandom);
|
var text = Comments.Random(Game.CosmeticRandom);
|
||||||
var textSize = Font.Measure(text);
|
var textSize = r.Fonts["Bold"].Measure(text);
|
||||||
|
|
||||||
r.BeginFrame(float2.Zero);
|
r.BeginFrame(float2.Zero);
|
||||||
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
WidgetUtils.FillRectWithSprite(StripeRect, Stripe);
|
||||||
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
r.RgbaSpriteRenderer.DrawSprite(Logo, LogoPos);
|
||||||
Font.DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
|
r.Fonts["Bold"].DrawText(text, new float2(Renderer.Resolution.Width - textSize.X - 20, Renderer.Resolution.Height - textSize.Y - 20), Color.White);
|
||||||
r.EndFrame( new NullInputHandler() );
|
r.EndFrame( new NullInputHandler() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,3 +109,23 @@ ServerTraits:
|
|||||||
|
|
||||||
ChromeMetrics:
|
ChromeMetrics:
|
||||||
mods/cnc/metrics.yaml
|
mods/cnc/metrics.yaml
|
||||||
|
|
||||||
|
Fonts:
|
||||||
|
Regular:
|
||||||
|
Font:FreeSans.ttf
|
||||||
|
Size:14
|
||||||
|
Bold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:14
|
||||||
|
Title:
|
||||||
|
Font:titles.ttf
|
||||||
|
Size:48
|
||||||
|
BigBold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:24
|
||||||
|
Tiny:
|
||||||
|
Font:FreeSans.ttf
|
||||||
|
Size:10
|
||||||
|
TinyBold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:10
|
||||||
|
|||||||
@@ -88,4 +88,24 @@ ServerTraits:
|
|||||||
MasterServerPinger
|
MasterServerPinger
|
||||||
|
|
||||||
ChromeMetrics:
|
ChromeMetrics:
|
||||||
mods/ra/metrics.yaml
|
mods/ra/metrics.yaml
|
||||||
|
|
||||||
|
Fonts:
|
||||||
|
Regular:
|
||||||
|
Font:FreeSans.ttf
|
||||||
|
Size:14
|
||||||
|
Bold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:14
|
||||||
|
Title:
|
||||||
|
Font:titles.ttf
|
||||||
|
Size:48
|
||||||
|
BigBold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:24
|
||||||
|
Tiny:
|
||||||
|
Font:FreeSans.ttf
|
||||||
|
Size:10
|
||||||
|
TinyBold:
|
||||||
|
Font:FreeSansBold.ttf
|
||||||
|
Size:10
|
||||||
|
|||||||
Reference in New Issue
Block a user