mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 13:01:47 +00:00
- streamlined font handling for scripts a bit.
- moved the two 'you raised the alarm' messages for Strife to the string table
This commit is contained in:
parent
5cfac78116
commit
b570d0819b
14 changed files with 144 additions and 35 deletions
|
@ -1752,11 +1752,10 @@ void C_MidPrintBold (FFont *font, const char *msg)
|
|||
DEFINE_ACTION_FUNCTION(_Console, MidPrint)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(font);
|
||||
PARAM_POINTER_NOT_NULL(fnt, FFont);
|
||||
PARAM_STRING(text);
|
||||
PARAM_BOOL_DEF(bold);
|
||||
|
||||
FFont *fnt = FFont::FindFont(font);
|
||||
const char *txt = text[0] == '$'? GStrings(&text[1]) : text.GetChars();
|
||||
if (!bold) C_MidPrint(fnt, txt);
|
||||
else C_MidPrintBold(fnt, txt);
|
||||
|
|
|
@ -2467,6 +2467,9 @@ void D_DoomMain (void)
|
|||
TexMan.Init();
|
||||
C_InitConback();
|
||||
|
||||
StartScreen->Progress();
|
||||
V_InitFonts();
|
||||
|
||||
// [CW] Parse any TEAMINFO lumps.
|
||||
if (!batchrun) Printf ("ParseTeamInfo: Load team definitions.\n");
|
||||
TeamLibrary.ParseTeamInfo ();
|
||||
|
|
|
@ -88,6 +88,7 @@ PColor *TypeColor;
|
|||
PTextureID *TypeTextureID;
|
||||
PSpriteID *TypeSpriteID;
|
||||
PStatePointer *TypeState;
|
||||
PPointer *TypeFont;
|
||||
PStateLabel *TypeStateLabel;
|
||||
PStruct *TypeVector2;
|
||||
PStruct *TypeVector3;
|
||||
|
@ -437,6 +438,7 @@ void PType::StaticInit()
|
|||
TypeVoidPtr = NewPointer(TypeVoid, false);
|
||||
TypeColorStruct = NewStruct("@ColorStruct", nullptr); //This name is intentionally obfuscated so that it cannot be used explicitly. The point of this type is to gain access to the single channels of a color value.
|
||||
TypeStringStruct = NewNativeStruct("Stringstruct", nullptr);
|
||||
TypeFont = NewPointer(NewNativeStruct("Font", nullptr));
|
||||
#ifdef __BIG_ENDIAN__
|
||||
TypeColorStruct->AddField(NAME_a, TypeUInt8);
|
||||
TypeColorStruct->AddField(NAME_r, TypeUInt8);
|
||||
|
|
|
@ -940,6 +940,7 @@ extern PStruct *TypeVector3;
|
|||
extern PStruct *TypeColorStruct;
|
||||
extern PStruct *TypeStringStruct;
|
||||
extern PStatePointer *TypeState;
|
||||
extern PPointer *TypeFont;
|
||||
extern PStateLabel *TypeStateLabel;
|
||||
extern PPointer *TypeNullPtr;
|
||||
extern PPointer *TypeVoidPtr;
|
||||
|
|
|
@ -337,8 +337,6 @@ void R_Init ()
|
|||
{
|
||||
atterm (R_Shutdown);
|
||||
|
||||
StartScreen->Progress();
|
||||
V_InitFonts();
|
||||
StartScreen->Progress();
|
||||
// Colormap init moved back to InitPalette()
|
||||
//R_InitColormaps ();
|
||||
|
|
|
@ -1420,6 +1420,76 @@ ExpEmit FxSoundCast::Emit(VMFunctionBuilder *build)
|
|||
return to;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxFontCast::FxFontCast(FxExpression *x)
|
||||
: FxExpression(EFX_FontCast, x->ScriptPosition)
|
||||
{
|
||||
basex = x;
|
||||
ValueType = TypeSound;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxFontCast::~FxFontCast()
|
||||
{
|
||||
SAFE_DELETE(basex);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FxExpression *FxFontCast::Resolve(FCompileContext &ctx)
|
||||
{
|
||||
CHECKRESOLVED();
|
||||
SAFE_RESOLVE(basex, ctx);
|
||||
|
||||
if (basex->ValueType == TypeFont)
|
||||
{
|
||||
FxExpression *x = basex;
|
||||
basex = nullptr;
|
||||
delete this;
|
||||
return x;
|
||||
}
|
||||
// This intentionally does not convert non-constants.
|
||||
// The sole reason for this cast is to allow passing both font pointers and string constants to printing functions and have the font names checked at compile time.
|
||||
else if ((basex->ValueType == TypeString || basex->ValueType == TypeName) && basex->isConstant())
|
||||
{
|
||||
ExpVal constval = static_cast<FxConstant *>(basex)->GetValue();
|
||||
FFont *font = V_GetFont(constval.GetString());
|
||||
// Font must exist. Most internal functions working with fonts do not like null pointers.
|
||||
// If checking is needed scripts will have to call Font.GetFont themselves.
|
||||
if (font == nullptr)
|
||||
{
|
||||
ScriptPosition.Message(MSG_ERROR, "Unknown font '%s'", constval.GetString().GetChars());
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FxExpression *x = new FxConstant(font, ScriptPosition);
|
||||
delete this;
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScriptPosition.Message(MSG_ERROR, "Cannot convert to font");
|
||||
delete this;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// generic type cast operator
|
||||
|
@ -1649,6 +1719,14 @@ FxExpression *FxTypeCast::Resolve(FCompileContext &ctx)
|
|||
{
|
||||
goto basereturn;
|
||||
}
|
||||
else if (ValueType == TypeFont)
|
||||
{
|
||||
FxExpression *x = new FxFontCast(basex);
|
||||
x = x->Resolve(ctx);
|
||||
basex = nullptr;
|
||||
delete this;
|
||||
return x;
|
||||
}
|
||||
// todo: pointers to class objects.
|
||||
// All other types are only compatible to themselves and have already been handled above by the equality check.
|
||||
// Anything that falls through here is not compatible and must print an error.
|
||||
|
|
|
@ -294,6 +294,7 @@ enum EFxType
|
|||
EFX_StrLen,
|
||||
EFX_ColorLiteral,
|
||||
EFX_GetDefaultByType,
|
||||
EFX_FontCast,
|
||||
EFX_COUNT
|
||||
};
|
||||
|
||||
|
@ -488,6 +489,13 @@ public:
|
|||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(FFont *state, const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
|
||||
{
|
||||
value.pointer = state;
|
||||
ValueType = value.Type = TypeFont;
|
||||
isresolved = true;
|
||||
}
|
||||
|
||||
FxConstant(const FScriptPosition &pos) : FxExpression(EFX_Constant, pos)
|
||||
{
|
||||
value.pointer = nullptr;
|
||||
|
@ -664,6 +672,18 @@ public:
|
|||
ExpEmit Emit(VMFunctionBuilder *build);
|
||||
};
|
||||
|
||||
class FxFontCast : public FxExpression
|
||||
{
|
||||
FxExpression *basex;
|
||||
|
||||
public:
|
||||
|
||||
FxFontCast(FxExpression *x);
|
||||
~FxFontCast();
|
||||
FxExpression *Resolve(FCompileContext&);
|
||||
};
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FxTypeCast
|
||||
|
|
|
@ -2187,13 +2187,13 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&fon
|
|||
{
|
||||
if (arc.isWriting())
|
||||
{
|
||||
const char *n = font->GetName();
|
||||
return arc.StringPtr(key, n);
|
||||
FName n = font->GetName();
|
||||
return arc(key, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *n;
|
||||
arc.StringPtr(key, n);
|
||||
FName n;
|
||||
arc(key, n);
|
||||
font = V_GetFont(n);
|
||||
if (font == nullptr)
|
||||
{
|
||||
|
|
|
@ -340,6 +340,14 @@ FFont *V_GetFont(const char *name)
|
|||
return font;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, GetFont)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_NAME(name);
|
||||
ACTION_RETURN_POINTER(V_GetFont(name.GetChars()));
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FFont :: FFont
|
||||
|
@ -366,7 +374,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
|
|||
LastChar = first + count - 1;
|
||||
FontHeight = 0;
|
||||
GlobalKerning = false;
|
||||
Name = copystring (name);
|
||||
FontName = name;
|
||||
Next = FirstFont;
|
||||
FirstFont = this;
|
||||
Cursor = '_';
|
||||
|
@ -478,11 +486,6 @@ FFont::~FFont ()
|
|||
delete[] PatchRemap;
|
||||
PatchRemap = NULL;
|
||||
}
|
||||
if (Name)
|
||||
{
|
||||
delete[] Name;
|
||||
Name = NULL;
|
||||
}
|
||||
|
||||
FFont **prev = &FirstFont;
|
||||
FFont *font = *prev;
|
||||
|
@ -508,27 +511,26 @@ FFont::~FFont ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
FFont *FFont::FindFont (const char *name)
|
||||
FFont *FFont::FindFont (FName name)
|
||||
{
|
||||
if (name == NULL)
|
||||
if (name == NAME_None)
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
FFont *font = FirstFont;
|
||||
|
||||
while (font != NULL)
|
||||
while (font != nullptr)
|
||||
{
|
||||
if (stricmp (font->Name, name) == 0)
|
||||
break;
|
||||
if (font->FontName == name) return font;
|
||||
font = font->Next;
|
||||
}
|
||||
return font;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION(FFont, FindFont)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
PARAM_STRING(name);
|
||||
PARAM_NAME(name);
|
||||
ACTION_RETURN_POINTER(FFont::FindFont(name));
|
||||
}
|
||||
|
||||
|
@ -935,7 +937,7 @@ FFont::FFont (int lump)
|
|||
Lump = lump;
|
||||
Chars = NULL;
|
||||
PatchRemap = NULL;
|
||||
Name = NULL;
|
||||
FontName = NAME_None;
|
||||
Cursor = '_';
|
||||
}
|
||||
|
||||
|
@ -951,7 +953,7 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump)
|
|||
{
|
||||
assert(lump >= 0);
|
||||
|
||||
Name = copystring (name);
|
||||
FontName = name;
|
||||
|
||||
FMemLump data1 = Wads.ReadLump (lump);
|
||||
const BYTE *data = (const BYTE *)data1.GetMem();
|
||||
|
@ -1189,7 +1191,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data)
|
|||
if (destSize < 0)
|
||||
{
|
||||
i += FirstChar;
|
||||
I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, Name);
|
||||
I_FatalError ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1491,7 +1493,7 @@ FSinglePicFont::FSinglePicFont(const char *picname) :
|
|||
|
||||
FTexture *pic = TexMan[picnum];
|
||||
|
||||
Name = copystring(picname);
|
||||
FontName = picname;
|
||||
FontHeight = pic->GetScaledHeight();
|
||||
SpaceWidth = pic->GetScaledWidth();
|
||||
GlobalKerning = 0;
|
||||
|
@ -1903,7 +1905,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
|
|||
|
||||
memcpy(this->notranslate, notranslate, 256*sizeof(bool));
|
||||
|
||||
Name = copystring(name);
|
||||
FontName = name;
|
||||
Chars = new CharData[count];
|
||||
charlumps = new FTexture*[count];
|
||||
PatchRemap = new BYTE[256];
|
||||
|
|
|
@ -88,9 +88,9 @@ public:
|
|||
int GetDefaultKerning () const { return GlobalKerning; }
|
||||
virtual void LoadTranslations();
|
||||
void Preload() const;
|
||||
const char *GetName() const { return Name; }
|
||||
FName GetName() const { return FontName; }
|
||||
|
||||
static FFont *FindFont (const char *fontname);
|
||||
static FFont *FindFont(FName fontname);
|
||||
static void StaticPreloadFonts();
|
||||
|
||||
// Return width of string in pixels (unscaled)
|
||||
|
@ -127,7 +127,7 @@ protected:
|
|||
BYTE *PatchRemap;
|
||||
|
||||
int Lump;
|
||||
char *Name;
|
||||
FName FontName;
|
||||
FFont *Next;
|
||||
|
||||
static FFont *FirstFont;
|
||||
|
|
|
@ -1417,6 +1417,9 @@ TXT_KILLED_ORACLE = "You've Killed The Oracle!";
|
|||
TXT_KILLED_MACIL = "You Killed Macil!";
|
||||
TXT_KILLED_LOREMASTER = "You've Killed the Loremaster!";
|
||||
|
||||
TXT_YOUFOOL = "You Fool! You've set off the alarm.";
|
||||
TXT_YOUREDEAD = "You're dead! You set off the alarm.";
|
||||
|
||||
// Strife pickup messages
|
||||
|
||||
TXT_METALARMOR = "You picked up the Metal Armor.";
|
||||
|
|
|
@ -70,13 +70,14 @@ struct Screen native
|
|||
|
||||
struct Font native
|
||||
{
|
||||
native static Font FindFont(String name);
|
||||
native static Font FindFont(Name fontname);
|
||||
native static Font GetFont(Name fontname);
|
||||
}
|
||||
|
||||
struct Console native
|
||||
{
|
||||
native static void HideConsole();
|
||||
native static void MidPrint(string fontname, string textlabel, bool bold = false); // always uses the stringtable.
|
||||
native static void MidPrint(Font fontname, string textlabel, bool bold = false);
|
||||
}
|
||||
|
||||
struct DamageTypeDefinition native
|
||||
|
|
|
@ -9,7 +9,9 @@ extend class Object
|
|||
|
||||
deprecated static void C_MidPrint(string fontname, string textlabel, bool bold = false) // deprecated for 2.4.x
|
||||
{
|
||||
return Console.MidPrint(fontname, textlabel, bold);
|
||||
let f = Font.GetFont(fontname);
|
||||
if (f == null) return;
|
||||
return Console.MidPrint(f, textlabel, bold);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -632,7 +632,7 @@ class RaiseAlarm : DummyStrifeItem
|
|||
dropper.target.SoundAlert(dropper.target);
|
||||
if (dropper.target.CheckLocalView(consoleplayer))
|
||||
{
|
||||
A_Log("You Fool! You've set off the alarm.");
|
||||
Console.MidPrint(SmallFont, "$TXT_YOUFOOL");
|
||||
}
|
||||
}
|
||||
Destroy ();
|
||||
|
@ -672,7 +672,7 @@ class CloseDoor222 : DummyStrifeItem
|
|||
{
|
||||
if (dropper.target.CheckLocalView(consoleplayer))
|
||||
{
|
||||
A_Log("You're dead! You set off the alarm.");
|
||||
Console.MidPrint(SmallFont, "$TXT_YOUREDEAD");
|
||||
}
|
||||
dropper.target.SoundAlert(dropper.target);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue