HUDs and Actors and Fonts and Such
Posted: Sun Jan 30, 2022 10:59 pm
Yo,
I'm currently messing around with a HUD that can be customized using actor properties in the player class, to avoid turning the HUD into a bloated mess of switch cases or if/else statements for per-class HUD customization. Currently it works fairly well for stuff in the Draw/DrawMainBar function like changing the STBAR graphic or the Y height of the numbers, but it's fallen apart when it comes to fonts.
One of the properties in the PlayerClass is a string called SBarFont. The draw method grabs the player's SBarFont string, tries to find a font based on it, and creates it if it exists. At least, in theory.Problem is, for some reason it returns null unless the font has previously been loaded in the Init() function. Moving this code to Init() as it stands results in a "VM execution aborted: tried to read from address zero" fatal error, which I'm assuming (without knowing exactly how the engine does it) is done because Init() runs before actors etc. like the player are loaded into the map.
So! Here lies the question. How would I grab the player's playerclass's properties in the Init() function?
Alternatively, if that's not possible: Currently I'm using the workaround of loading all the custom fonts manually in the Init() function so that they exist for the Draw() function...
...but naturally, this'll fall apart as more player classes are added, especially if they're added by people who aren't me. Would there be a way within the confines of the Init() function to iterate through all the classes in the playerclasses array, grab their SBarFont property string and load their font as a sort of precaching state/workaround? I've tried to do this myself, but haven't figured out a way that works.
I'm currently messing around with a HUD that can be customized using actor properties in the player class, to avoid turning the HUD into a bloated mess of switch cases or if/else statements for per-class HUD customization. Currently it works fairly well for stuff in the Draw/DrawMainBar function like changing the STBAR graphic or the Y height of the numbers, but it's fallen apart when it comes to fonts.
One of the properties in the PlayerClass is a string called SBarFont. The draw method grabs the player's SBarFont string, tries to find a font based on it, and creates it if it exists. At least, in theory.
Code: Select all
protected void DrawMainBar (double TicFrac)
{
let plr = Mix_PlayerPawn(CPlayer.mo);
Font plrfnt = Font.FindFont(plr.SBarFont);
if (!plrfnt)
{
Console.Printf(String.Format("\cdMix_Error: Font ''%s'' not found! Resorting to BigFont...", plr.SBarFont));
playerfont = HUDFont.Create("BIGFONT");
} else {
playerfont = HUDFont.Create(plrfnt);
}
So! Here lies the question. How would I grab the player's playerclass's properties in the Init() function?
Alternatively, if that's not possible: Currently I'm using the workaround of loading all the custom fonts manually in the Init() function so that they exist for the Draw() function...
Code: Select all
override void Init()
{
Super.Init();
SetSize(32, 320, 200);
// Create the font used for the fullscreen HUD
Font fnt = "HUDFONT_DOOM";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft, 1, 1);
fnt = "INDEXFONT_DOOM";
mIndexFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), Mono_CellLeft);
mAmountFont = HUDFont.Create("INDEXFONT");
diparms = InventoryBarState.Create();
// i need to define the fonts in init for them to load for reasons.
// i can't access the player class in init because nothing's spawned yet.
// i'm hoping to work around this in the future, but for now consider
// this bullshit precaching or summat
font fart;
fart = "bigfont_consoledoom";
fart = "hudnums_wolf";
}