Use the font dictionary everywhere

This commit is contained in:
Paul Chote
2011-05-16 17:59:30 +12:00
parent e1c8658fdc
commit d7f009b218
17 changed files with 45 additions and 55 deletions

View File

@@ -42,10 +42,8 @@ namespace OpenRA.Graphics
Queue<IVertexBuffer<Vertex>> tempBuffersV = new Queue<IVertexBuffer<Vertex>>();
public SpriteFont RegularFont, BoldFont, TitleFont, TinyFont, TinyBoldFont, BigBoldFont;
public Dictionary<string, SpriteFont> Fonts;
public Renderer()
{
SpriteShader = device.CreateShader("world-shp");
@@ -65,14 +63,6 @@ namespace OpenRA.Graphics
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; } }

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Widgets
public override void DrawInner()
{
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
WidgetUtils.DrawPanel(Depressed ? "dialog3" : "dialog2", RenderBounds);

View File

@@ -52,13 +52,13 @@ namespace OpenRA.Widgets
if (!string.IsNullOrEmpty(line.Owner))
{
var owner = line.Owner + ":";
inset = Game.Renderer.RegularFont.Measure(owner).X + 10;
inset = Game.Renderer.Fonts["Regular"].Measure(owner).X + 10;
Game.Renderer.RegularFont.DrawTextWithContrast(owner, chatpos,
Game.Renderer.Fonts["Regular"].DrawTextWithContrast(owner, chatpos,
line.Color, Color.Black, UseContrast ? 1 : 0);
}
Game.Renderer.RegularFont.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Game.Renderer.Fonts["Regular"].DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Color.White, Color.Black, UseContrast ? 1 : 0);
}

View File

@@ -39,10 +39,10 @@ namespace OpenRA.Widgets
if (composing)
{
var text = teamChat ? "Chat (Team): " : "Chat (All): ";
var w = Game.Renderer.BoldFont.Measure(text).X;
var w = Game.Renderer.Fonts["Bold"].Measure(text).X;
Game.Renderer.BoldFont.DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
Game.Renderer.RegularFont.DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
Game.Renderer.Fonts["Bold"].DrawTextWithContrast(text, RenderOrigin + new float2(3, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
Game.Renderer.Fonts["Regular"].DrawTextWithContrast(content, RenderOrigin + new float2(3 + w, 7), Color.White, Color.Black, UseContrast ? 1 : 0);
}
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Widgets
public override void DrawInner()
{
var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = Bold ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var pos = RenderOrigin;
var rect = RenderBounds;
var check = new Rectangle(rect.Location,

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Widgets
u + new float2(12, 10 * k + 4),
item.c, item.c);
Game.Renderer.TinyFont.DrawText(item.Name, new float2(rect.Left, rect.Top) + new float2(18, 10 * k - 3), Color.White);
Game.Renderer.Fonts["Tiny"].DrawText(item.Name, new float2(rect.Left, rect.Top) + new float2(18, 10 * k - 3), Color.White);
Game.Renderer.Flush();
++k;
}

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Widgets
if (bg != null)
WidgetUtils.DrawPanel(bg, RenderBounds);
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var text = GetText();
if (text == null)
return;

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Widgets
if (Text == null)
return 0;
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var textSize = font.Measure(Text);
var start = RenderOrigin.X + LeftMargin;
@@ -187,7 +187,7 @@ namespace OpenRA.Widgets
{
if (text == null) text = "";
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var pos = RenderOrigin;
if (CursorPosition > text.Length)

View File

@@ -26,10 +26,10 @@ namespace OpenRA.Widgets
public override void DrawInner()
{
var s = WidgetUtils.FormatTime(Game.LocalTick);
var size = Game.Renderer.TitleFont.Measure(s);
var size = Game.Renderer.Fonts["Title"].Measure(s);
var pos = new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20);
Game.Renderer.TitleFont.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
Game.Renderer.Fonts["Title"].DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
}
}
}

View File

@@ -266,7 +266,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public void AddChatLine(Color c, string from, string text)
{
var name = from+":";
var font = Game.Renderer.RegularFont;
var font = Game.Renderer.Fonts["Regular"];
var nameSize = font.Measure(from);
var template = chatTemplate.Clone() as ContainerWidget;

View File

@@ -190,7 +190,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{
if (text == null) text = "";
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"];
var pos = RenderOrigin;
if (CursorPosition > text.Length)

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects
this.color = color;
this.velocity = velocity;
s = "{0}${1}".F(value < 0 ? "-" : "+", value);
this.pos = pos - 0.5f*Game.Renderer.TinyBoldFont.Measure(s).ToFloat2();
this.pos = pos - 0.5f*Game.Renderer.Fonts["TinyBold"].Measure(s).ToFloat2();
remaining = lifetime;
}
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render()
{
Game.Renderer.TinyBoldFont.DrawTextWithContrast(s, pos - Game.viewport.Location, color, Color.Black,1);
Game.Renderer.Fonts["TinyBold"].DrawTextWithContrast(s, pos - Game.viewport.Location, color, Color.Black,1);
yield break;
}
}

View File

@@ -422,12 +422,12 @@ namespace OpenRA.Mods.RA.Widgets
if (rect.Contains(Viewport.LastMousePos))
{
var text = queue.Info.Type;
var sz = Game.Renderer.BoldFont.Measure(text);
var sz = Game.Renderer.Fonts["Bold"].Measure(text);
WidgetUtils.DrawPanelPartial("dialog4",
Rectangle.FromLTRB((int)rect.Left - sz.X - 30, (int)rect.Top, (int)rect.Left - 5, (int)rect.Bottom),
PanelSides.All);
Game.Renderer.BoldFont.DrawText(text,
Game.Renderer.Fonts["Bold"].DrawText(text,
new float2(rect.Left - sz.X - 20, rect.Top + 12), Color.White);
}
@@ -437,8 +437,8 @@ namespace OpenRA.Mods.RA.Widgets
void DrawRightAligned(string text, int2 pos, Color c)
{
Game.Renderer.BoldFont.DrawText(text,
pos - new int2(Game.Renderer.BoldFont.Measure(text).X, 0), c);
Game.Renderer.Fonts["Bold"].DrawText(text,
pos - new int2(Game.Renderer.Fonts["Bold"].Measure(text).X, 0), c);
}
void DrawProductionTooltip(World world, string unit, int2 pos)
@@ -454,12 +454,12 @@ namespace OpenRA.Mods.RA.Widgets
var cost = info.Traits.Get<ValuedInfo>().Cost;
var canBuildThis = CurrentQueue.CanBuild(info);
var longDescSize = Game.Renderer.RegularFont.Measure(tooltip.Description.Replace("\\n", "\n")).Y;
var longDescSize = Game.Renderer.Fonts["Regular"].Measure(tooltip.Description.Replace("\\n", "\n")).Y;
if (!canBuildThis) longDescSize += 8;
WidgetUtils.DrawPanel("dialog4", new Rectangle(Game.viewport.Width - 300, pos.Y, 300, longDescSize + 65));
Game.Renderer.BoldFont.DrawText(
Game.Renderer.Fonts["Bold"].DrawText(
tooltip.Name + ((buildable.Hotkey != null)? " ({0})".F(buildable.Hotkey.ToUpper()) : ""),
p.ToInt2() + new int2(5, 5), Color.White);
@@ -484,7 +484,7 @@ namespace OpenRA.Mods.RA.Widgets
{
var prereqs = buildable.Prerequisites
.Select( a => Description( a ) );
Game.Renderer.RegularFont.DrawText(
Game.Renderer.Fonts["Regular"].DrawText(
"Requires {0}".F(string.Join(", ", prereqs.ToArray())),
p.ToInt2(),
Color.White);
@@ -493,7 +493,7 @@ namespace OpenRA.Mods.RA.Widgets
}
p += new int2(0, 15);
Game.Renderer.RegularFont.DrawText(tooltip.Description.Replace("\\n", "\n"),
Game.Renderer.Fonts["Regular"].DrawText(tooltip.Description.Replace("\\n", "\n"),
p.ToInt2(), Color.White);
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Widgets
var m = pos + new int2(rect.Width, rect.Height);
var br = pos + new int2(rect.Width, rect.Height + 20);
var u = Game.Renderer.RegularFont.Measure(GetLongDesc().Replace("\\n", "\n"));
var u = Game.Renderer.Fonts["Regular"].Measure(GetLongDesc().Replace("\\n", "\n"));
br.X -= u.X;
br.Y += u.Y;
@@ -65,10 +65,10 @@ namespace OpenRA.Mods.RA.Widgets
pos.X = br.X + 8;
pos.Y = m.Y + 8;
Game.Renderer.BoldFont.DrawText(GetDescription(), pos, Color.White);
Game.Renderer.Fonts["Bold"].DrawText(GetDescription(), pos, Color.White);
pos += new int2(0, 20);
Game.Renderer.RegularFont.DrawText(GetLongDesc().Replace("\\n", "\n"), pos, Color.White);
Game.Renderer.Fonts["Regular"].DrawText(GetLongDesc().Replace("\\n", "\n"), pos, Color.White);
}
Game.Renderer.RgbaSpriteRenderer.DrawSprite(image, new int2(RenderBounds.X, RenderBounds.Y));

View File

@@ -111,7 +111,7 @@ namespace OpenRA.Mods.RA.Widgets
br += new int2(0,20);
if (sp.Info.LongDesc != null)
br += Game.Renderer.RegularFont.Measure(sp.Info.LongDesc.Replace("\\n", "\n"));
br += Game.Renderer.Fonts["Regular"].Measure(sp.Info.LongDesc.Replace("\\n", "\n"));
else
br += new int2(300,0);
@@ -125,19 +125,19 @@ namespace OpenRA.Mods.RA.Widgets
PanelSides.Left | PanelSides.Right | PanelSides.Bottom);
pos += new int2(77, 5);
Game.Renderer.BoldFont.DrawText(sp.Info.Description, pos, Color.White);
Game.Renderer.Fonts["Bold"].DrawText(sp.Info.Description, pos, Color.White);
if (sp.TotalTime > 0)
{
pos += new int2(0,20);
Game.Renderer.BoldFont.DrawText(WidgetUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White);
Game.Renderer.BoldFont.DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White);
Game.Renderer.Fonts["Bold"].DrawText(WidgetUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White);
Game.Renderer.Fonts["Bold"].DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45,0), Color.White);
}
if (sp.Info.LongDesc != null)
{
pos += new int2(0, 20);
Game.Renderer.RegularFont.DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
Game.Renderer.Fonts["Regular"].DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
}
}

View File

@@ -82,10 +82,10 @@ namespace OpenRA.Mods.RA.Widgets
isVictory ? "victory" : "defeat",
WidgetUtils.FormatTime(Math.Max(winnerSvc.CriticalTicksLeft, winnerSvc.TicksLeft)));
var size = Game.Renderer.BoldFont.Measure(tc);
var size = Game.Renderer.Fonts["Bold"].Measure(tc);
Game.Renderer.BoldFont.DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2 + 1, RenderBounds.Top + 1), Color.Black);
Game.Renderer.BoldFont.DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top), Color.WhiteSmoke);
Game.Renderer.Fonts["Bold"].DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2 + 1, RenderBounds.Top + 1), Color.Black);
Game.Renderer.Fonts["Bold"].DrawText(tc, offset + new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top), Color.WhiteSmoke);
offset += new int2(0, size.Y + 1);
}

View File

@@ -38,13 +38,13 @@ namespace OpenRA.Mods.RA.Widgets
if (!world.LocalPlayer.Shroud.IsExplored(cell))
{
var utext = "Unexplored Terrain";
var usz = Game.Renderer.BoldFont.Measure(utext) + new int2(20, 24);
var usz = Game.Renderer.Fonts["Bold"].Measure(utext) + new int2(20, 24);
WidgetUtils.DrawPanel("dialog4", Rectangle.FromLTRB(
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
Viewport.LastMousePos.X + usz.X + 20, Viewport.LastMousePos.Y + usz.Y + 20));
Game.Renderer.BoldFont.DrawText(utext,
Game.Renderer.Fonts["Bold"].DrawText(utext,
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
return;
@@ -60,9 +60,9 @@ namespace OpenRA.Mods.RA.Widgets
var owner = (tooltip != null && !tooltip.Owner().NonCombatant) ? "{0}".F(tooltip.Owner().PlayerName) : "";
var stance = (tooltip != null && tooltip.Owner() != actor.World.LocalPlayer && !tooltip.Owner().NonCombatant) ? " ({0})".F(tooltip.Stance()) : "";
var nameSize = Game.Renderer.BoldFont.Measure(name);
var ownerSize = Game.Renderer.RegularFont.Measure(owner);
var stanceSize = Game.Renderer.RegularFont.Measure(stance);
var nameSize = Game.Renderer.Fonts["Bold"].Measure(name);
var ownerSize = Game.Renderer.Fonts["Regular"].Measure(owner);
var stanceSize = Game.Renderer.Fonts["Regular"].Measure(stance);
var panelSize = new int2(Math.Max(nameSize.X, ownerSize.X + stanceSize.X + 35) + 20, nameSize.Y + 24);
@@ -72,15 +72,15 @@ namespace OpenRA.Mods.RA.Widgets
Viewport.LastMousePos.X + 20, Viewport.LastMousePos.Y + 20,
Viewport.LastMousePos.X + panelSize.X + 20, Viewport.LastMousePos.Y + panelSize.Y + 20));
Game.Renderer.BoldFont.DrawText(name,
Game.Renderer.Fonts["Bold"].DrawText(name,
new float2(Viewport.LastMousePos.X + 30, Viewport.LastMousePos.Y + 30), Color.White);
if (owner != "")
{
Game.Renderer.RegularFont.DrawText(owner,
Game.Renderer.Fonts["Regular"].DrawText(owner,
new float2(Viewport.LastMousePos.X + 65, Viewport.LastMousePos.Y + 50), actor.Owner.ColorRamp.GetColor(0));
Game.Renderer.RegularFont.DrawText(stance,
Game.Renderer.Fonts["Regular"].DrawText(stance,
new float2(Viewport.LastMousePos.X + 65 + ownerSize.X, Viewport.LastMousePos.Y + 50), Color.White);
WidgetUtils.DrawRGBA(