- changed the return value of PickupMessage to an FString so that it can interface with scripts.

- use standard convention of prefacing localizable strings with "$" for C_MidPrint.
This commit is contained in:
Christoph Oelckers 2016-11-28 16:19:01 +01:00
parent 53318f4bde
commit d2ce78fae7
11 changed files with 44 additions and 19 deletions

View file

@ -1738,7 +1738,7 @@ DEFINE_ACTION_FUNCTION(DObject, C_MidPrint)
PARAM_BOOL_DEF(bold);
FFont *fnt = FFont::FindFont(font);
const char *txt = GStrings(text);
const char *txt = text[0] == '$'? GStrings(&text[1]) : text.GetChars();
if (!bold) C_MidPrint(fnt, txt);
else C_MidPrintBold(fnt, txt);
return 0;

View file

@ -3144,7 +3144,7 @@ bool ADehackedPickup::TryPickup (AActor *&toucher)
return false;
}
const char *ADehackedPickup::PickupMessage ()
FString ADehackedPickup::PickupMessage ()
{
if (RealPickup != nullptr)
return RealPickup->PickupMessage ();

View file

@ -42,7 +42,7 @@ class ADehackedPickup : public AInventory
HAS_OBJECT_POINTERS
public:
void Destroy() override;
const char *PickupMessage ();
FString PickupMessage ();
bool ShouldRespawn ();
bool ShouldStay ();
bool TryPickup (AActor *&toucher);

View file

@ -475,7 +475,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_RestoreSpecialPosition)
}
int AInventory::StaticLastMessageTic;
const char *AInventory::StaticLastMessage;
FString AInventory::StaticLastMessage;
IMPLEMENT_CLASS(AInventory, false, true)
@ -1205,10 +1205,10 @@ void AInventory::Touch (AActor *toucher)
if (!(ItemFlags & IF_QUIET))
{
const char * message = PickupMessage ();
FString message = GetPickupMessage ();
if (message != NULL && *message != 0 && localview
&& (StaticLastMessageTic != gametic || StaticLastMessage != message))
if (message.IsNotEmpty() && localview
&& (StaticLastMessageTic != gametic || StaticLastMessage.Compare(message)))
{
StaticLastMessageTic = gametic;
StaticLastMessage = message;
@ -1283,11 +1283,32 @@ void AInventory::DoPickupSpecial (AActor *toucher)
//
//===========================================================================
const char *AInventory::PickupMessage ()
FString AInventory::PickupMessage ()
{
return GetClass()->PickupMessage;
}
DEFINE_ACTION_FUNCTION(AInventory, PickupMessage)
{
PARAM_SELF_PROLOGUE(AInventory);
ACTION_RETURN_STRING(self->PickupMessage());
}
FString AInventory::GetPickupMessage()
{
IFVIRTUAL(AInventory, PickupMessage)
{
VMValue params[1] = { (DObject*)this };
VMReturn ret;
VMFrameStack stack;
FString retval;
ret.StringAt(&retval);
stack.Call(func, params, 1, &ret, 1, nullptr);
return retval;
}
else return PickupMessage();
}
//===========================================================================
//
// AInventory :: PlayPickupSound
@ -1884,7 +1905,7 @@ DEFINE_FIELD(AHealth, PrevHealth)
// AHealth :: PickupMessage
//
//===========================================================================
const char *AHealth::PickupMessage ()
FString AHealth::PickupMessage ()
{
int threshold = GetClass()->LowHealth;

View file

@ -173,7 +173,8 @@ public:
virtual void DoEffect ();
virtual bool Grind(bool items);
virtual const char *PickupMessage ();
virtual FString PickupMessage ();
FString GetPickupMessage();
virtual void PlayPickupSound (AActor *toucher);
bool DoRespawn ();
@ -228,7 +229,7 @@ protected:
private:
static int StaticLastMessageTic;
static const char *StaticLastMessage;
static FString StaticLastMessage;
};
class AStateProvider : public AInventory
@ -438,7 +439,7 @@ class AHealth : public AInventory
public:
int PrevHealth;
virtual bool TryPickup (AActor *&other);
virtual const char *PickupMessage ();
virtual FString PickupMessage ();
};
// HealthPickup is some item that gives the player health when used.

View file

@ -177,7 +177,7 @@ bool AWeaponPiece::PrivateShouldStay ()
//
//===========================================================================
const char *AWeaponPiece::PickupMessage ()
FString AWeaponPiece::PickupMessage ()
{
if (FullWeapon)
{

View file

@ -22,7 +22,7 @@ public:
bool TryPickup (AActor *&toucher);
bool TryPickupRestricted (AActor *&toucher);
bool ShouldStay ();
virtual const char *PickupMessage ();
virtual FString PickupMessage ();
virtual void PlayPickupSound (AActor *toucher);
int PieceValue;

View file

@ -8,6 +8,7 @@
IMPLEMENT_CLASS(ACoin, false, false)
/*
const char *ACoin::PickupMessage ()
{
if (Amount == 1)
@ -22,6 +23,7 @@ const char *ACoin::PickupMessage ()
return msg;
}
}
*/
bool ACoin::HandlePickup (AInventory *item)
{

View file

@ -17,7 +17,7 @@ class ACoin : public AInventory
{
DECLARE_CLASS (ACoin, AInventory)
public:
const char *PickupMessage ();
//const char *PickupMessage ();
bool HandlePickup (AInventory *item);
AInventory *CreateTossable ();
AInventory *CreateCopy (AActor *other);

View file

@ -30,6 +30,7 @@ class Inventory : Actor native
virtual native bool HandlePickup(Inventory item);
virtual native Inventory CreateCopy(Actor other);
virtual native bool SpecialDropAction (Actor dropper);
virtual native String PickupMessage();
native void GoAwayAndDie();

View file

@ -108,13 +108,13 @@ class AlienSpectre1 : SpectralMonster
}
else if (cls == "AlienSpectre2")
{
C_MidPrint("SmallFont", "TXT_KILLED_BISHOP");
C_MidPrint("SmallFont", "$TXT_KILLED_BISHOP");
log = 74;
player.GiveInventoryType ("QuestItem21");
}
else if (cls == "AlienSpectre3")
{
C_MidPrint("SmallFont", "TXT_KILLED_ORACLE");
C_MidPrint("SmallFont", "$TXT_KILLED_ORACLE");
// If there are any Oracles still alive, kill them.
ThinkerIterator it = ThinkerIterator.Create("Oracle");
Actor oracle;
@ -144,7 +144,7 @@ class AlienSpectre1 : SpectralMonster
}
else if (cls == "AlienSpectre4")
{
C_MidPrint("SmallFont", "TXT_KILLED_MACIL");
C_MidPrint("SmallFont", "$TXT_KILLED_MACIL");
player.GiveInventoryType ("QuestItem24");
if (player.FindInventory ("QuestItem25") == null)
{ // Richter has taken over. Macil is a snake.
@ -157,7 +157,7 @@ class AlienSpectre1 : SpectralMonster
}
else if (cls == "AlienSpectre5")
{
C_MidPrint("SmallFont", "TXT_KILLED_LOREMASTER");
C_MidPrint("SmallFont", "$TXT_KILLED_LOREMASTER");
player.GiveInventoryType ("QuestItem26");
if (!multiplayer)