Skip to content

Commit

Permalink
Converted nameplates to use TTF fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
bittiez committed Feb 7, 2024
1 parent 20e53b5 commit 5349bb6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 88 deletions.
1 change: 1 addition & 0 deletions src/ClassicUO.Client/Configuration/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ public class TazUO
public string TooltipFont { get; set; } = "Tooltip font";
public string OverheadFont { get; set; } = "Overhead font";
public string JournalFont { get; set; } = "Journal font";
public string NameplateFont { get; set; } = "Nameplate font";
#endregion

#region Controller
Expand Down
3 changes: 3 additions & 0 deletions src/ClassicUO.Client/Configuration/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ public int CoolDownConditionCount
public int OverheadChatFontSize { get; set; } = 20;
public int OverheadChatWidth { get; set; } = 200;

public string NamePlateFont { get; set; } = "avadonian";
public int NamePlateFontSize { get; set; } = 20;

public string DefaultTTFFont { get; set; } = "Roboto-Regular";
public int TextBorderSize { get; set; } = 1;

Expand Down
11 changes: 11 additions & 0 deletions src/ClassicUO.Client/Game/UI/Gumps/ModernOptionsGump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,17 @@ private void BuildTazUO()
}), true, page);
content.RemoveIndent();
content.BlankLine();
content.AddToRight(GenerateFontSelector(lang.GetTazUO.NameplateFont, ProfileManager.CurrentProfile.NamePlateFont, (i, s) =>
{
ProfileManager.CurrentProfile.NamePlateFont = s;
}), true, page);
content.Indent();
content.AddToRight(new SliderWithLabel(lang.GetTazUO.SharedSize, 0, Theme.SLIDER_WIDTH, 5, 40, profile.NamePlateFontSize, (i) =>
{
profile.NamePlateFontSize = i;
}), true, page);
content.RemoveIndent();
content.BlankLine();
#endregion

#region Controller settings
Expand Down
134 changes: 47 additions & 87 deletions src/ClassicUO.Client/Game/UI/Gumps/NameOverheadGump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ internal class NameOverheadGump : Gump
private Point _lockedPosition,
_lastLeftMousePositionDown;
private bool _positionLocked,
_leftMouseIsDown;
private readonly RenderedText _renderedText;
_leftMouseIsDown,
_isLastTarget,
_needsNameUpdate;
private TextBox _text;
private Texture2D _borderColor = SolidColorTextureCache.GetTexture(Color.Black);
private Vector2 _textDrawOffset = Vector2.Zero;

public NameOverheadGump(uint serial) : base(serial, 0)
{
Expand All @@ -70,21 +73,12 @@ public NameOverheadGump(uint serial) : base(serial, 0)
return;
}

_renderedText = RenderedText.Create(
string.Empty,
entity is Mobile m ? Notoriety.GetHue(m.NotorietyFlag) : (ushort)0x0481,
0xFF,
true,
FontStyle.BlackBorder,
TEXT_ALIGN_TYPE.TS_CENTER,
100,
30,
true
);
_text = new TextBox(string.Empty, ProfileManager.CurrentProfile.NamePlateFont, ProfileManager.CurrentProfile.NamePlateFontSize, 100, entity is Mobile m ? Notoriety.GetHue(m.NotorietyFlag) : (ushort)0x0481, FontStashSharp.RichText.TextHorizontalAlignment.Center);

SetTooltip(entity);

BuildGump();
SetName();
}

public bool SetName()
Expand All @@ -100,6 +94,7 @@ public bool SetName()
{
if (!World.OPL.TryGetNameAndData(item, out string t, out _))
{
_needsNameUpdate = true;
if (!item.IsCorpse && item.Amount > 1)
{
t = item.Amount.ToString() + ' ';
Expand All @@ -119,40 +114,22 @@ public bool SetName()
);
}
}

if (string.IsNullOrEmpty(t))
else
{
return false;
_needsNameUpdate = false;
}

FontsLoader.Instance.SetUseHTML(true);
FontsLoader.Instance.RecalculateWidthByInfo = true;

int width = FontsLoader.Instance.GetWidthUnicode(_renderedText.Font, t);

if (width > Constants.OBJECT_HANDLES_GUMP_WIDTH)
if (string.IsNullOrEmpty(t))
{
t = FontsLoader.Instance.GetTextByWidthUnicode(
_renderedText.Font,
t.AsSpan(),
Constants.OBJECT_HANDLES_GUMP_WIDTH,
true,
TEXT_ALIGN_TYPE.TS_CENTER,
(ushort)FontStyle.BlackBorder
);

width = Constants.OBJECT_HANDLES_GUMP_WIDTH;
return false;
}

_renderedText.MaxWidth = width;
_renderedText.Text = t;

FontsLoader.Instance.RecalculateWidthByInfo = false;
FontsLoader.Instance.SetUseHTML(false);

Width = _background.Width = Math.Max(60, _renderedText.Width) + 4;
Height = _background.Height = Constants.OBJECT_HANDLES_GUMP_HEIGHT + 4;
_text.UpdateText(t);

Width = _background.Width = Math.Max(60, _text.Width) + 4;
Height = _background.Height = Math.Max(Constants.OBJECT_HANDLES_GUMP_HEIGHT, _text.Height) + 4;
_textDrawOffset.X = (Width - _text.Width - 4) >> 1;
_textDrawOffset.Y = (Height - _text.Height) >> 1;
WantUpdateSize = false;

return true;
Expand All @@ -162,29 +139,12 @@ public bool SetName()
{
string t = entity.Name;

int width = FontsLoader.Instance.GetWidthUnicode(_renderedText.Font, t);

if (width > Constants.OBJECT_HANDLES_GUMP_WIDTH)
{
t = FontsLoader.Instance.GetTextByWidthUnicode(
_renderedText.Font,
t.AsSpan(),
Constants.OBJECT_HANDLES_GUMP_WIDTH,
true,
TEXT_ALIGN_TYPE.TS_CENTER,
(ushort)FontStyle.BlackBorder
);

width = Constants.OBJECT_HANDLES_GUMP_WIDTH;
}

_renderedText.MaxWidth = width;

_renderedText.Text = t;

Width = _background.Width = Math.Max(60, _renderedText.Width) + 4;
Height = _background.Height = Constants.OBJECT_HANDLES_GUMP_HEIGHT + 4;
_text.UpdateText(t);

Width = _background.Width = Math.Max(60, _text.Width) + 4;
Height = _background.Height = Math.Max(Constants.OBJECT_HANDLES_GUMP_HEIGHT, _text.Height) + 4;
_textDrawOffset.X = (Width - _text.Width - 4) >> 1;
_textDrawOffset.Y = (Height - _text.Height) >> 1;
WantUpdateSize = false;

return true;
Expand Down Expand Up @@ -557,25 +517,37 @@ public override void Update()
{
if (entity == TargetManager.LastTargetInfo.Serial)
{
_borderColor = SolidColorTextureCache.GetTexture(Color.Red);
_background.Hue = _renderedText.Hue = entity is Mobile m
? Notoriety.GetHue(m.NotorietyFlag)
: (ushort)0x0481;
if (!_isLastTarget) //Only set this if it was not already last target
{
_borderColor = SolidColorTextureCache.GetTexture(Color.Red);
_background.Hue = (ushort)(_text.Hue = entity is Mobile m
? Notoriety.GetHue(m.NotorietyFlag)
: (ushort)0x0481);
_isLastTarget = true;
}
}
else
{
_borderColor = SolidColorTextureCache.GetTexture(Color.Black);
_background.Hue = _renderedText.Hue = entity is Mobile m
? Notoriety.GetHue(m.NotorietyFlag)
: (ushort)0x0481;
_background.Alpha = ProfileManager.CurrentProfile.NamePlateOpacity / 100f;
if (_isLastTarget)//If we make it here, it is no longer the last target so we update colors and set this to false.
{
_borderColor = SolidColorTextureCache.GetTexture(Color.Black);
_background.Hue = (ushort)(_text.Hue = entity is Mobile m
? Notoriety.GetHue(m.NotorietyFlag)
: (ushort)0x0481);
_isLastTarget = false;
}
}

if (_needsNameUpdate)
{
SetName();
}
}
}

public override bool Draw(UltimaBatcher2D batcher, int x, int y)
{
if (IsDisposed || !SetName())
if (IsDisposed)
{
return false;
}
Expand Down Expand Up @@ -720,7 +692,7 @@ out int height

Point p = Client.Game.Scene.Camera.WorldToScreen(new Point(x, y));
x = p.X - (Width >> 1);
y = p.Y - (Height >> 1);
y = p.Y - (Height);// >> 1);

var camera = Client.Game.Scene.Camera;
x += camera.Bounds.X;
Expand Down Expand Up @@ -764,24 +736,12 @@ out int height
);
}

int renderedTextOffset = Math.Max(0, Width - _renderedText.Width - 4) >> 1;

return _renderedText.Draw(
batcher,
Width,
Height,
x + 2 + renderedTextOffset,
y + 2,
Width,
Height,
0,
0
);
return _text.Draw(batcher, (int)(x + 2 + _textDrawOffset.X), (int)(y + 2 + _textDrawOffset.Y));
}

public override void Dispose()
{
_renderedText?.Destroy();
_text.Dispose();
base.Dispose();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ClassicUO.Client/Game/UI/Gumps/VersionHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ internal class VersionHistory : Gump
private static string[] updateTexts = {
"/c[white][3.21.0]/cd\n" +
"- A few bug fixes\n" +
"- A few fixes from CUO",
"- A few fixes from CUO\n" +
"- Converted nameplates to use TTF fonts",

"/c[white][3.20.0]/cd\n" +
"- Being frozen wont cancel auto follow\n" +
Expand Down

0 comments on commit 5349bb6

Please sign in to comment.