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";
}