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