Skip to content

Commit

Permalink
Add Safety Check to getting font for HUD Elements
Browse files Browse the repository at this point in the history
If the font doesn't exist, just fallback to NewSmallFont, as that's HDest's default font anyways.
  • Loading branch information
UndeadZeratul committed Jan 19, 2024
1 parent c00bb9b commit 4ee5eb4
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/base/BaseCounter.zs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class BaseCounterHUDElement : HUDElement abstract {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZAmmoCounters.zs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class UZAmmoCounters : HUDAmmoCounters {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZArmour.zs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class UZArmour : HUDElement {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZCompass.zs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class UZCompass : HUDCompass {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZEKG.zs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class UZEKG : HUDEKG {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZEncumbrance.zs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class UZEncumbrance : HUDEncumbrance {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZInventory.zs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class UZInventory : HUDInventory {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZObjectDescription.zs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class UZObjectDescription : HUDElement {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZPosition.zs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class UZPosition : HUDPosition {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZSquadStatus.zs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class UZSquadStatus : HUDElement {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZWeaponHelp.zs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class UZWeaponHelp : HUDElement {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZWeaponStash.zs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class UZWeaponStash : HUDWeaponStash {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}
}
Expand Down
3 changes: 2 additions & 1 deletion zscript/undeadzeratul/elements/UZWoundCounter.zs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class UZWoundCounter : HUDElement {

string newFont = _font.GetString();
if (_prevFont != newFont) {
_hudFont = HUDFont.create(Font.FindFont(newFont));
let font = Font.FindFont(newFont);
_hudFont = HUDFont.create(font ? font : Font.FindFont('NewSmallFont'));
_prevFont = newFont;
}

Expand Down

0 comments on commit 4ee5eb4

Please sign in to comment.