Skip to content

Commit

Permalink
Add Echoes differences to CHUDMemoParms
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquegemignani committed May 30, 2021
1 parent 1d7dd9a commit a194b03
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
15 changes: 15 additions & 0 deletions Runtime/CStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2879,4 +2879,19 @@ const CGameArea* CStateManager::GetCurrentArea() const {
}
return x850_world->GetAreaAlways(x850_world->GetCurrentAreaId());
};

#ifdef PRIME2

int CStateManager::MaskUIdNumPlayers(TUniqueId uid) const {
// Give a TUniqueId of a CPlayer object, returns the player index
u16 uVar1 = uid.Value();
if (uVar1 < numPlayers) {
return uVar1;
} else {
return 0;
}
}

#endif

} // namespace metaforce
7 changes: 6 additions & 1 deletion Runtime/CStateManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,14 @@ class CStateManager {
bool FUN_801eaf90(CPlayer* player, CStateManager& mgr) { /* NYI */ return false; }
};

// x294c
int MaskUIdNumPlayers(TUniqueId uid) const;

// Echoes: x294c
bool echoesFlags_31_inDarkWorld;

// Echoes: x14f8
int numPlayers;

astruct_6* field_0x1638;
#endif
};
Expand Down
15 changes: 15 additions & 0 deletions Runtime/World/CHUDMemoParms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ class CHUDMemoParms {
bool x4_clearMemoWindow = false;
bool x5_fadeOutOnly = false;
bool x6_hintMemo = false;
#ifdef PRIME2
// Echoes: x7
bool fadeInText = false;
// Echoes: x8
int playerMask = 0;
#endif

public:
CHUDMemoParms() = default;
CHUDMemoParms(float dispTime, bool clearMemoWindow, bool fadeOutOnly, bool hintMemo)
: x0_dispTime(dispTime), x4_clearMemoWindow(clearMemoWindow), x5_fadeOutOnly(fadeOutOnly), x6_hintMemo(hintMemo) {}
#ifdef PRIME2
CHUDMemoParms(float dispTime, bool clearMemoWindow, bool fadeOutOnly, bool hintMemo, int playerMask, bool fadeInText)
: x0_dispTime(dispTime), x4_clearMemoWindow(clearMemoWindow), x5_fadeOutOnly(fadeOutOnly), x6_hintMemo(hintMemo), fadeInText(fadeInText), playerMask(playerMask) {}
#endif

explicit CHUDMemoParms(CInputStream& in) {
x0_dispTime = in.readFloatBig();
x4_clearMemoWindow = in.readBool();
Expand All @@ -23,6 +34,10 @@ class CHUDMemoParms {
bool IsClearMemoWindow() const { return x4_clearMemoWindow; }
bool IsFadeOutOnly() const { return x5_fadeOutOnly; }
bool IsHintMemo() const { return x6_hintMemo; }
#ifdef PRIME2
bool IsFadeInOnly() const { return fadeInText; }
int GetPlayerMask() const { return playerMask; }
#endif
};

} // namespace metaforce
25 changes: 21 additions & 4 deletions Runtime/World/CScriptHUDMemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ namespace metaforce {

CScriptHUDMemo::CScriptHUDMemo(TUniqueId uid, std::string_view name, const CEntityInfo& info,
const CHUDMemoParms& parms, EDisplayType disp, CAssetId msg, bool active)
: CEntity(uid, info, active, name), x34_parms(parms), x3c_dispType(disp), x40_stringTableId(msg) {
: CEntity(uid, info, active, name)
, x34_parms(parms)
#ifdef PRIME2
, useOriginator(false)
#endif
, x3c_dispType(disp)
, x40_stringTableId(msg) {
if (msg.IsValid()) {
x44_stringTable.emplace(g_SimplePool->GetObj({FOURCC('STRG'), msg}));
}
Expand All @@ -20,15 +26,26 @@ CScriptHUDMemo::CScriptHUDMemo(TUniqueId uid, std::string_view name, const CEnti
void CScriptHUDMemo::Accept(IVisitor& visitor) { visitor.Visit(this); }

void CScriptHUDMemo::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CHUDMemoParms parms = x34_parms;
#ifdef PRIME2
if (useOriginator) {
auto originator = ScriptObjectMessage_GetOriginator(msg);
if (TCastToPtr<CPlayer> player = mgr.ObjectById(originator)) {
parms = CHUDMemoParms(x34_parms.GetDisplayTime(), x34_parms.IsClearMemoWindow(), x34_parms.IsFadeOutOnly(),
x34_parms.IsHintMemo(), 1 << mgr.MaskUIdNumPlayers(originator), x34_parms.IsFadeInOnly());
}
}
#endif

if (msg == EScriptObjectMessage::SetToZero) {
if (GetActive()) {
if (x3c_dispType == EDisplayType::MessageBox) {
mgr.ShowPausedHUDMemo(x40_stringTableId, x34_parms.GetDisplayTime());
mgr.ShowPausedHUDMemo(x40_stringTableId, parms.GetDisplayTime());
} else if (x3c_dispType == EDisplayType::StatusMessage) {
if (x44_stringTable) {
MP1::CSamusHud::DisplayHudMemo((*x44_stringTable)->GetString(0), x34_parms);
MP1::CSamusHud::DisplayHudMemo((*x44_stringTable)->GetString(0), parms);
} else {
MP1::CSamusHud::DisplayHudMemo(u"", x34_parms);
MP1::CSamusHud::DisplayHudMemo(u"", parms);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Runtime/World/CScriptHUDMemo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ class CScriptHUDMemo : public CEntity {
StatusMessage,
MessageBox,
};
// Prime: x34; Echoes: x24
CHUDMemoParms x34_parms;
#ifdef PRIME2
// Echoes: x30
bool useOriginator;
#endif
// Prime: x3c; Echoes: x34
EDisplayType x3c_dispType;
// Prime: x40; Echoes: x38
CAssetId x40_stringTableId;
// Prime: x44; Echoes: x3c
std::optional<TLockedToken<CStringTable>> x44_stringTable;

private:
Expand Down
4 changes: 4 additions & 0 deletions Runtime/World/ScriptObjectSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,9 @@ enum class EScriptObjectMessage {
std::string_view ScriptObjectTypeToStr(EScriptObjectType type);
std::string_view ScriptObjectStateToStr(EScriptObjectState state);
std::string_view ScriptObjectMessageToStr(EScriptObjectMessage message);
#if PRIME2
// TODO: Kludge for not having Prime2's AcceptScriptMsg API
TUniqueId ScriptObjectMessage_GetOriginator(EScriptObjectMessage message) { return kInvalidUniqueId; }
#endif

} // namespace metaforce

0 comments on commit a194b03

Please sign in to comment.