summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-10-03 12:33:55 +0200
committerGitHub <noreply@github.com>2019-10-03 12:33:55 +0200
commit6fe3d38ce2cfe9c4f5b485f683689212cf227a15 (patch)
tree8746448ed97ad2db90dd2d3e6c3ae983d0f49a96
parentMerge pull request #218 from erorcun/erorcun (diff)
parentNo dw (diff)
downloadre3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar.gz
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar.bz2
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar.lz
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar.xz
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.tar.zst
re3-6fe3d38ce2cfe9c4f5b485f683689212cf227a15.zip
Diffstat (limited to '')
-rw-r--r--src/core/config.h1
-rw-r--r--src/render/MoneyMessages.cpp86
-rw-r--r--src/render/MoneyMessages.h24
3 files changed, 111 insertions, 0 deletions
diff --git a/src/core/config.h b/src/core/config.h
index f82967d5..4a9fa792 100644
--- a/src/core/config.h
+++ b/src/core/config.h
@@ -67,6 +67,7 @@ enum Config {
NUMANTENNAS = 8,
NUMCORONAS = 56,
NUMPOINTLIGHTS = 32,
+ NUMMONEYMESSAGES = 16,
NUMONSCREENTIMERENTRIES = 1,
NUMRADARBLIPS = 32,
diff --git a/src/render/MoneyMessages.cpp b/src/render/MoneyMessages.cpp
new file mode 100644
index 00000000..d80be276
--- /dev/null
+++ b/src/render/MoneyMessages.cpp
@@ -0,0 +1,86 @@
+#include "common.h"
+#include "patcher.h"
+#include "MoneyMessages.h"
+#include "Timer.h"
+#include "Sprite.h"
+#include "Font.h"
+#include "Text.h"
+
+#define MONEY_MESSAGE_LIFETIME_MS 2000
+
+CMoneyMessage CMoneyMessages::aMoneyMessages[NUMMONEYMESSAGES];
+
+void
+CMoneyMessage::Render()
+{
+ const float MAX_SCALE = 4.0f;
+ uint32 nLifeTime = CTimer::GetTimeInMilliseconds() - m_nTimeRegistered;
+ if (nLifeTime >= MONEY_MESSAGE_LIFETIME_MS) m_nTimeRegistered = 0;
+ else {
+ float fLifeTime = (float)nLifeTime / MONEY_MESSAGE_LIFETIME_MS;
+ RwV3d vecOut;
+ float fDistX, fDistY;
+ if (CSprite::CalcScreenCoors(m_vecPosition + CVector(0.0f, 0.0f, fLifeTime), &vecOut, &fDistX, &fDistY, true)) {
+ fDistX *= (0.7 * fLifeTime + 2.0) * m_fSize;
+ fDistY *= (0.7 * fLifeTime + 2.0) * m_fSize;
+ CFont::SetPropOn();
+ CFont::SetBackgroundOff();
+
+ float fScaleY = fDistY / 100.0f;
+ if (fScaleY > MAX_SCALE) fScaleY = MAX_SCALE;
+
+ float fScaleX = fDistX / 100.0f;
+ if (fScaleX > MAX_SCALE) fScaleX = MAX_SCALE;
+
+ CFont::SetScale(fScaleX, fScaleY); // maybe use SCREEN_SCALE_X and SCREEN_SCALE_Y here?
+ CFont::SetCentreOn();
+ CFont::SetCentreSize(SCREEN_WIDTH);
+ CFont::SetJustifyOff();
+ CFont::SetColor(CRGBA(m_Colour.r, m_Colour.g, m_Colour.b, (255.0f - 255.0f * fLifeTime) * m_fOpacity));
+ CFont::SetBackGroundOnlyTextOff();
+ CFont::SetFontStyle(FONT_BANK);
+ CFont::PrintString(vecOut.x, vecOut.y, m_aText);
+ }
+ }
+}
+
+void
+CMoneyMessages::Init()
+{
+ for (int32 i = 0; i < NUMMONEYMESSAGES; i++)
+ aMoneyMessages[i].m_nTimeRegistered = 0;
+}
+
+void
+CMoneyMessages::Render()
+{
+ for (int32 i = 0; i < NUMMONEYMESSAGES; i++) {
+ if (aMoneyMessages[i].m_nTimeRegistered)
+ aMoneyMessages[i].Render();
+ }
+}
+
+void
+CMoneyMessages::RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity)
+{
+ uint32 nIndex = 0;
+ while (aMoneyMessages[nIndex].m_nTimeRegistered != 0) {
+ if (++nIndex >= NUMMONEYMESSAGES) return;
+ }
+
+ // Add data of this money message to the array
+ AsciiToUnicode(pText, aMoneyMessages[nIndex].m_aText);
+
+ aMoneyMessages[nIndex].m_nTimeRegistered = CTimer::GetTimeInMilliseconds();
+ aMoneyMessages[nIndex].m_vecPosition = vecPos;
+ aMoneyMessages[nIndex].m_Colour.red = bRed;
+ aMoneyMessages[nIndex].m_Colour.green = bGreen;
+ aMoneyMessages[nIndex].m_Colour.blue = bBlue;
+ aMoneyMessages[nIndex].m_fSize = fSize;
+ aMoneyMessages[nIndex].m_fOpacity = fOpacity;
+}
+
+STARTPATCHES
+ InjectHook(0x51AF70, CMoneyMessages::Init, PATCH_JUMP);
+ InjectHook(0x51B030, CMoneyMessages::Render, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/render/MoneyMessages.h b/src/render/MoneyMessages.h
new file mode 100644
index 00000000..f0a48a84
--- /dev/null
+++ b/src/render/MoneyMessages.h
@@ -0,0 +1,24 @@
+#pragma once
+
+class CMoneyMessage
+{
+ friend class CMoneyMessages;
+
+ uint32 m_nTimeRegistered;
+ CVector m_vecPosition;
+ wchar m_aText[16];
+ CRGBA m_Colour;
+ float m_fSize;
+ float m_fOpacity;
+public:
+ void Render();
+};
+
+class CMoneyMessages
+{
+ static CMoneyMessage aMoneyMessages[NUMMONEYMESSAGES];
+public:
+ static void Init();
+ static void Render();
+ static void RegisterOne(CVector vecPos, const char *pText, uint8 bRed, uint8 bGreen, uint8 bBlue, float fSize, float fOpacity);
+}; \ No newline at end of file