Skip to content

Commit 059a8c0

Browse files
authored
feat: font families (AscensionGameDev#2620)
* replace font-per-size system with font families, and best-match font size this is in preparation for replacing the crappy SpriteFont system with a MTSDF text rendering system
1 parent afa19b6 commit 059a8c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1163
-436
lines changed

Intersect.Client.Core/Core/Graphics.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ namespace Intersect.Client.Core;
1919
public static partial class Graphics
2020
{
2121

22-
public static GameFont? ActionMsgFont;
22+
public static IFont? ActionMsgFont { get; set; }
23+
public static int ActionMsgFontSize { get; set; }
2324

2425
public static object AnimationLock = new();
2526

2627
//Darkness Stuff
27-
public static float BrightnessLevel;
28+
public static float BrightnessLevel { get; set; }
2829

29-
public static GameFont? ChatBubbleFont;
30+
public static IFont? ChatBubbleFont { get; set; }
31+
public static int ChatBubbleFontSize { get; set; }
3032

3133
private static FloatRect _currentView;
3234

@@ -51,10 +53,12 @@ public static FloatRect CurrentView
5153

5254
public static int EntitiesDrawn;
5355

54-
public static GameFont? EntityNameFont;
56+
public static IFont? EntityNameFont { get; set; }
57+
public static int EntityNameFontSize { get; set; }
5558

5659
//Screen Values
57-
public static GameFont? GameFont;
60+
public static IFont? GameFont { get; set; }
61+
public static int GameFontSize { get; set; }
5862

5963
public static object GfxLock = new();
6064

@@ -105,7 +109,8 @@ public static FloatRect CurrentView
105109

106110
private static float sPlayerLightSize;
107111

108-
public static GameFont? UIFont;
112+
public static IFont? UIFont { get; set; }
113+
public static int UIFontSize { get; set; }
109114

110115
public static float MinimumWorldScale => Options.Instance?.Map?.MinimumWorldScale ?? 1;
111116

@@ -117,27 +122,26 @@ public static void InitGraphics()
117122
Renderer?.Init();
118123
sContentManager = Globals.ContentManager;
119124
sContentManager.LoadAll();
120-
GameFont = FindFont(ClientConfiguration.Instance.GameFont);
121-
UIFont = FindFont(ClientConfiguration.Instance.UIFont);
122-
EntityNameFont = FindFont(ClientConfiguration.Instance.EntityNameFont);
123-
ChatBubbleFont = FindFont(ClientConfiguration.Instance.ChatBubbleFont);
124-
ActionMsgFont = FindFont(ClientConfiguration.Instance.ActionMsgFont);
125+
(GameFont, GameFontSize) = FindFont(ClientConfiguration.Instance.GameFont);
126+
(UIFont, UIFontSize) = FindFont(ClientConfiguration.Instance.UIFont);
127+
(EntityNameFont, EntityNameFontSize) = FindFont(ClientConfiguration.Instance.EntityNameFont);
128+
(ChatBubbleFont, ChatBubbleFontSize) = FindFont(ClientConfiguration.Instance.ChatBubbleFont);
129+
(ActionMsgFont, ActionMsgFontSize) = FindFont(ClientConfiguration.Instance.ActionMsgFont);
125130
}
126131

127-
public static GameFont FindFont(string font)
132+
private static (IFont?, int) FindFont(string font)
128133
{
129134
var size = 8;
130135

131-
if (font.IndexOf(',') < 0)
136+
// ReSharper disable once InvertIf
137+
if (font.IndexOf(',') > 0)
132138
{
133-
return sContentManager.GetFont(font, size);
139+
var parts = font.Split(',');
140+
font = parts[0];
141+
_ = int.TryParse(parts[1], out size);
134142
}
135143

136-
var parts = font.Split(',');
137-
font = parts[0];
138-
_ = int.TryParse(parts[1], out size);
139-
140-
return sContentManager.GetFont(font, size);
144+
return (sContentManager.GetFont(font), size);
141145
}
142146

143147
public static void InitInGame()

Intersect.Client.Core/Entities/ChatBubble.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public float Draw(float yoffset = 0f)
5858
mSourceText,
5959
200,
6060
Graphics.ChatBubbleFont,
61+
Graphics.ChatBubbleFontSize,
6162
Graphics.Renderer ?? throw new InvalidOperationException("No renderer")
6263
);
6364
}
@@ -68,26 +69,31 @@ public float Draw(float yoffset = 0f)
6869
}
6970

7071
var x = (int)Math.Ceiling(mOwner.Origin.X);
71-
var y = (int) Math.Ceiling(mOwner.GetLabelLocation(LabelType.ChatBubble));
72+
var y = (int)Math.Ceiling(mOwner.GetLabelLocation(LabelType.ChatBubble));
7273

7374
if (mTextureBounds.Width == 0)
7475
{
7576
//Gotta Calculate Bounds
7677
for (var i = (mText?.Length ?? 0) - 1; i > -1; i--)
7778
{
78-
var textSize = Graphics.Renderer.MeasureText(mText![i], Graphics.ChatBubbleFont, 1);
79+
var textSize = Graphics.Renderer.MeasureText(
80+
mText![i],
81+
Graphics.ChatBubbleFont,
82+
Graphics.ChatBubbleFontSize,
83+
1
84+
);
7985
if (textSize.X > mTextureBounds.Width)
8086
{
81-
mTextureBounds.Width = (int) textSize.X + 16;
87+
mTextureBounds.Width = (int)textSize.X + 16;
8288
}
8389

84-
mTextureBounds.Height += (int) textSize.Y + 2;
90+
mTextureBounds.Height += (int)textSize.Y + 2;
8591
if (textSize.X > mTextBounds.Width)
8692
{
87-
mTextBounds.Width = (int) textSize.X;
93+
mTextBounds.Width = (int)textSize.X;
8894
}
8995

90-
mTextBounds.Height += (int) textSize.Y + 2;
96+
mTextBounds.Height += (int)textSize.Y + 2;
9197
}
9298

9399
mTextureBounds.Height += 16;
@@ -101,8 +107,8 @@ public float Draw(float yoffset = 0f)
101107
mTextureBounds.Height = 32;
102108
}
103109

104-
mTextureBounds.Width = (int) (Math.Round(mTextureBounds.Width / 8.0) * 8.0);
105-
mTextureBounds.Height = (int) (Math.Round(mTextureBounds.Height / 8.0) * 8.0);
110+
mTextureBounds.Width = (int)(Math.Round(mTextureBounds.Width / 8.0) * 8.0);
111+
mTextureBounds.Height = (int)(Math.Round(mTextureBounds.Height / 8.0) * 8.0);
106112
if (mTextureBounds.Width / 8 % 2 != 0)
107113
{
108114
mTextureBounds.Width += 8;
@@ -175,21 +181,38 @@ public float Draw(float yoffset = 0f)
175181
for (var y1 = 0; y1 < mTextureBounds.Height / 8; y1++)
176182
{
177183
Graphics.Renderer.DrawTexture(
178-
mBubbleTex, mTexSections[x1, y1].X * 8, mTexSections[x1, y1].Y * 8, 8, 8,
179-
x - mTextureBounds.Width / 2 + x1 * 8, y - mTextureBounds.Height - yoffset + y1 * 8, 8, 8,
184+
mBubbleTex,
185+
mTexSections[x1, y1].X * 8,
186+
mTexSections[x1, y1].Y * 8,
187+
8,
188+
8,
189+
x - mTextureBounds.Width / 2 + x1 * 8,
190+
y - mTextureBounds.Height - yoffset + y1 * 8,
191+
8,
192+
8,
180193
Color.White
181194
);
182195
}
183196
}
184197

185198
for (var i = mText.Length - 1; i > -1; i--)
186199
{
187-
var textSize = Graphics.Renderer.MeasureText(mText[i], Graphics.ChatBubbleFont, 1);
200+
var textSize = Graphics.Renderer.MeasureText(
201+
mText[i],
202+
Graphics.ChatBubbleFont,
203+
Graphics.ChatBubbleFontSize,
204+
1
205+
);
188206
Graphics.Renderer.DrawString(
189-
mText[i], Graphics.ChatBubbleFont,
190-
(int) (x - mTextureBounds.Width / 2 + (mTextureBounds.Width - textSize.X) / 2f),
191-
(int) (y - mTextureBounds.Height - yoffset + 8 + i * 16), 1,
192-
Color.FromArgb(CustomColors.Chat.ChatBubbleText.ToArgb()), true, null,
207+
mText[i],
208+
Graphics.ChatBubbleFont,
209+
Graphics.ChatBubbleFontSize,
210+
(int)(x - mTextureBounds.Width / 2 + (mTextureBounds.Width - textSize.X) / 2f),
211+
(int)(y - mTextureBounds.Height - yoffset + 8 + i * 16),
212+
1,
213+
Color.FromArgb(CustomColors.Chat.ChatBubbleText.ToArgb()),
214+
true,
215+
null,
193216
Color.FromArgb(CustomColors.Chat.ChatBubbleTextOutline.ToArgb())
194217
);
195218
}

Intersect.Client.Core/Entities/Entity.cs

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,22 +1537,32 @@ public void DrawLabels(
15371537
textColor = labelColor;
15381538
}
15391539

1540-
var textSize = Graphics.Renderer.MeasureText(label, Graphics.EntityNameFont, 1);
1540+
var textSize = Graphics.Renderer.MeasureText(label, Graphics.EntityNameFont, Graphics.EntityNameFontSize, 1);
15411541

15421542
var x = (int)Math.Ceiling(Origin.X);
15431543
var y = position == 0 ? GetLabelLocation(LabelType.Header) : GetLabelLocation(LabelType.Footer);
15441544

15451545
if (backgroundColor != Color.Transparent)
15461546
{
15471547
Graphics.DrawGameTexture(
1548-
Graphics.Renderer.WhitePixel, new FloatRect(0, 0, 1, 1),
1549-
new FloatRect(x - textSize.X / 2f - 4, y, textSize.X + 8, textSize.Y), backgroundColor
1548+
Graphics.Renderer.WhitePixel,
1549+
new FloatRect(0, 0, 1, 1),
1550+
new FloatRect(x - textSize.X / 2f - 4, y, textSize.X + 8, textSize.Y),
1551+
backgroundColor
15501552
);
15511553
}
15521554

15531555
Graphics.Renderer.DrawString(
1554-
label, Graphics.EntityNameFont, x - (int)Math.Ceiling(textSize.X / 2f), (int)y, 1,
1555-
Color.FromArgb(textColor.ToArgb()), true, null, Color.FromArgb(borderColor.ToArgb())
1556+
label,
1557+
Graphics.EntityNameFont,
1558+
Graphics.EntityNameFontSize,
1559+
x - (int)Math.Ceiling(textSize.X / 2f),
1560+
(int)y,
1561+
1,
1562+
Color.FromArgb(textColor.ToArgb()),
1563+
true,
1564+
null,
1565+
Color.FromArgb(borderColor.ToArgb())
15561566
);
15571567
}
15581568

@@ -1595,27 +1605,38 @@ public virtual void DrawName(Color? textColor, Color? borderColor = null, Color?
15951605
}
15961606

15971607
var name = Name;
1598-
if ((this is Player && Options.Instance.Player.ShowLevelByName) || (Type == EntityType.GlobalEntity && Options.Instance.Npc.ShowLevelByName))
1608+
if ((this is Player && Options.Instance.Player.ShowLevelByName) ||
1609+
(Type == EntityType.GlobalEntity && Options.Instance.Npc.ShowLevelByName))
15991610
{
16001611
name = Strings.GameWindow.EntityNameAndLevel.ToString(Name, Level);
16011612
}
16021613

1603-
var textSize = Graphics.Renderer.MeasureText(name, Graphics.EntityNameFont, 1);
1614+
var textSize = Graphics.Renderer.MeasureText(name, Graphics.EntityNameFont, Graphics.EntityNameFontSize, 1);
16041615

16051616
var x = (int)Math.Ceiling(Origin.X);
16061617
var y = GetLabelLocation(LabelType.Name);
16071618

16081619
if (backgroundColor != Color.Transparent)
16091620
{
16101621
Graphics.DrawGameTexture(
1611-
Graphics.Renderer.WhitePixel, new FloatRect(0, 0, 1, 1),
1612-
new FloatRect(x - textSize.X / 2f - 4, y, textSize.X + 8, textSize.Y), backgroundColor
1622+
Graphics.Renderer.WhitePixel,
1623+
new FloatRect(0, 0, 1, 1),
1624+
new FloatRect(x - textSize.X / 2f - 4, y, textSize.X + 8, textSize.Y),
1625+
backgroundColor
16131626
);
16141627
}
16151628

16161629
Graphics.Renderer.DrawString(
1617-
name, Graphics.EntityNameFont, x - (int)Math.Ceiling(textSize.X / 2f), (int)y, 1,
1618-
textColor, true, null, Color.FromArgb(borderColor.ToArgb())
1630+
name,
1631+
Graphics.EntityNameFont,
1632+
Graphics.EntityNameFontSize,
1633+
x - (int)Math.Ceiling(textSize.X / 2f),
1634+
(int)y,
1635+
1,
1636+
textColor,
1637+
true,
1638+
null,
1639+
Color.FromArgb(borderColor.ToArgb())
16191640
);
16201641
}
16211642

@@ -1644,7 +1665,12 @@ public float GetLabelLocation(LabelType type)
16441665
break;
16451666
}
16461667

1647-
var headerSize = Graphics.Renderer.MeasureText(HeaderLabel.Text, Graphics.EntityNameFont, 1);
1668+
var headerSize = Graphics.Renderer.MeasureText(
1669+
HeaderLabel.Text,
1670+
Graphics.EntityNameFont,
1671+
Graphics.EntityNameFontSize,
1672+
1
1673+
);
16481674
y -= headerSize.Y + 2;
16491675
break;
16501676

@@ -1654,13 +1680,23 @@ public float GetLabelLocation(LabelType type)
16541680
break;
16551681
}
16561682

1657-
var footerSize = Graphics.Renderer.MeasureText(FooterLabel.Text, Graphics.EntityNameFont, 1);
1683+
var footerSize = Graphics.Renderer.MeasureText(
1684+
FooterLabel.Text,
1685+
Graphics.EntityNameFont,
1686+
Graphics.EntityNameFontSize,
1687+
1
1688+
);
16581689
y -= footerSize.Y - 6;
16591690
break;
16601691

16611692
case LabelType.Name:
16621693
y = GetLabelLocation(LabelType.Footer);
1663-
var nameSize = Graphics.Renderer.MeasureText(Name, Graphics.EntityNameFont, 1);
1694+
var nameSize = Graphics.Renderer.MeasureText(
1695+
Name,
1696+
Graphics.EntityNameFont,
1697+
Graphics.EntityNameFontSize,
1698+
1
1699+
);
16641700
y -= nameSize.Y + (string.IsNullOrEmpty(FooterLabel.Text) ? -6 : 2);
16651701
break;
16661702

@@ -1686,7 +1722,12 @@ public float GetLabelLocation(LabelType type)
16861722
break;
16871723
}
16881724

1689-
var guildSize = Graphics.Renderer.MeasureText(player.Guild, Graphics.EntityNameFont, 1);
1725+
var guildSize = Graphics.Renderer.MeasureText(
1726+
player.Guild,
1727+
Graphics.EntityNameFont,
1728+
Graphics.EntityNameFontSize,
1729+
1
1730+
);
16901731
y -= 2 + guildSize.Y;
16911732
}
16921733

Intersect.Client.Core/Entities/Player.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,9 @@ public virtual void DrawGuildName(Color textColor, Color? borderColor = default,
26852685
}
26862686

26872687
var guildLabel = Guild?.Trim();
2688-
if (!ShouldDrawName || string.IsNullOrWhiteSpace(guildLabel) || !Options.Instance.Guild.ShowGuildNameTagsOverMembers)
2688+
if (!ShouldDrawName ||
2689+
string.IsNullOrWhiteSpace(guildLabel) ||
2690+
!Options.Instance.Guild.ShowGuildNameTagsOverMembers)
26892691
{
26902692
return;
26912693
}
@@ -2701,7 +2703,12 @@ public virtual void DrawGuildName(Color textColor, Color? borderColor = default,
27012703
return;
27022704
}
27032705

2704-
var textSize = Graphics.Renderer.MeasureText(guildLabel, Graphics.EntityNameFont, 1);
2706+
var textSize = Graphics.Renderer.MeasureText(
2707+
guildLabel,
2708+
Graphics.EntityNameFont,
2709+
Graphics.EntityNameFontSize,
2710+
1
2711+
);
27052712

27062713
var x = (int)Math.Ceiling(Origin.X);
27072714
var y = GetLabelLocation(LabelType.Guild);
@@ -2721,6 +2728,7 @@ public virtual void DrawGuildName(Color textColor, Color? borderColor = default,
27212728
Graphics.Renderer.DrawString(
27222729
guildLabel,
27232730
Graphics.EntityNameFont,
2731+
Graphics.EntityNameFontSize,
27242732
x - (int)Math.Ceiling(textSize.X / 2f),
27252733
(int)y,
27262734
1,

0 commit comments

Comments
 (0)