diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 5af877849d..3c21c7fe1c 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -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> 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); } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 86161ea377..24c930c4c1 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -297,6 +297,7 @@ namespace OpenRA Sound.Initialize(); modData = new ModData( mm ); + Renderer.InitializeFonts(modData.Manifest); modData.LoadInitialAssets(); diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index 8b51267a60..cc1259f6eb 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -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> tempBuffersV = new Queue>(); - public enum FontType { Regular, Bold, Title, Tiny, TinyBold, BigBold } - public Dictionary Fonts; + public SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont, BigBoldFont; + public Dictionary Fonts; + public Renderer() { @@ -56,28 +57,24 @@ namespace OpenRA.Graphics RgbaSpriteRenderer = new SpriteRenderer( this, RgbaSpriteShader ); 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.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) diff --git a/OpenRA.Game/Widgets/LabelWidget.cs b/OpenRA.Game/Widgets/LabelWidget.cs index 86d7b80d6c..169f9f28d9 100644 --- a/OpenRA.Game/Widgets/LabelWidget.cs +++ b/OpenRA.Game/Widgets/LabelWidget.cs @@ -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(); diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 95d9bde4d3..618586b155 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -34,7 +34,6 @@ namespace OpenRA.Mods.Cnc float2 LogoPos; Renderer r; - SpriteFont Font; public void Init(Dictionary 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() ); } diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index d9cad49448..daaa52bbcd 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Widgets { public Func 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 IsDisabled = () => false; - public Renderer.FontType Font = Renderer.FontType.Bold; + public string Font = "Bold"; public CncDropDownButtonWidget() : base() { } protected CncDropDownButtonWidget(CncDropDownButtonWidget other) : base(other) diff --git a/OpenRA.Mods.RA/RALoadScreen.cs b/OpenRA.Mods.RA/RALoadScreen.cs index dc23a32351..768b2ef077 100644 --- a/OpenRA.Mods.RA/RALoadScreen.cs +++ b/OpenRA.Mods.RA/RALoadScreen.cs @@ -31,14 +31,12 @@ namespace OpenRA.Mods.RA float2 LogoPos; Renderer r; - SpriteFont Font; public void Init(Dictionary 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() ); } diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index e995302c5a..b29243ab73 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -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 diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index a5989a417b..b1ca17d99d 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -88,4 +88,24 @@ ServerTraits: MasterServerPinger ChromeMetrics: - mods/ra/metrics.yaml \ No newline at end of file + 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