From d2ce78fae7da67b8df0023cb66125fcc9bb0965e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 28 Nov 2016 16:19:01 +0100 Subject: [PATCH] - 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. --- src/c_console.cpp | 2 +- src/d_dehacked.cpp | 2 +- src/d_dehacked.h | 2 +- src/g_shared/a_pickups.cpp | 33 +++++++++++++++---- src/g_shared/a_pickups.h | 7 ++-- src/g_shared/a_weaponpiece.cpp | 2 +- src/g_shared/a_weaponpiece.h | 2 +- src/g_strife/a_coin.cpp | 2 ++ src/g_strife/a_strifeglobal.h | 2 +- wadsrc/static/zscript/shared/inventory.txt | 1 + .../static/zscript/strife/alienspectres.txt | 8 ++--- 11 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/c_console.cpp b/src/c_console.cpp index 1016be9fd..691c4a3ca 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -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; diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 624116e06..e9e5a58d0 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -3144,7 +3144,7 @@ bool ADehackedPickup::TryPickup (AActor *&toucher) return false; } -const char *ADehackedPickup::PickupMessage () +FString ADehackedPickup::PickupMessage () { if (RealPickup != nullptr) return RealPickup->PickupMessage (); diff --git a/src/d_dehacked.h b/src/d_dehacked.h index a622707a3..434853bf2 100644 --- a/src/d_dehacked.h +++ b/src/d_dehacked.h @@ -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); diff --git a/src/g_shared/a_pickups.cpp b/src/g_shared/a_pickups.cpp index cb5f4dd12..ad9fb70ce 100644 --- a/src/g_shared/a_pickups.cpp +++ b/src/g_shared/a_pickups.cpp @@ -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; diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index e15f0724c..76a326254 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -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. diff --git a/src/g_shared/a_weaponpiece.cpp b/src/g_shared/a_weaponpiece.cpp index 52c9a9e38..bb98415fc 100644 --- a/src/g_shared/a_weaponpiece.cpp +++ b/src/g_shared/a_weaponpiece.cpp @@ -177,7 +177,7 @@ bool AWeaponPiece::PrivateShouldStay () // //=========================================================================== -const char *AWeaponPiece::PickupMessage () +FString AWeaponPiece::PickupMessage () { if (FullWeapon) { diff --git a/src/g_shared/a_weaponpiece.h b/src/g_shared/a_weaponpiece.h index 3a6fbcbd7..e293637cf 100644 --- a/src/g_shared/a_weaponpiece.h +++ b/src/g_shared/a_weaponpiece.h @@ -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; diff --git a/src/g_strife/a_coin.cpp b/src/g_strife/a_coin.cpp index f74d92e55..a94b1375d 100644 --- a/src/g_strife/a_coin.cpp +++ b/src/g_strife/a_coin.cpp @@ -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) { diff --git a/src/g_strife/a_strifeglobal.h b/src/g_strife/a_strifeglobal.h index c07bce63c..2561d961e 100644 --- a/src/g_strife/a_strifeglobal.h +++ b/src/g_strife/a_strifeglobal.h @@ -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); diff --git a/wadsrc/static/zscript/shared/inventory.txt b/wadsrc/static/zscript/shared/inventory.txt index 1bc695339..d1164f2c4 100644 --- a/wadsrc/static/zscript/shared/inventory.txt +++ b/wadsrc/static/zscript/shared/inventory.txt @@ -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(); diff --git a/wadsrc/static/zscript/strife/alienspectres.txt b/wadsrc/static/zscript/strife/alienspectres.txt index 2beee63ea..39cbc8331 100644 --- a/wadsrc/static/zscript/strife/alienspectres.txt +++ b/wadsrc/static/zscript/strife/alienspectres.txt @@ -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)