2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 22:27:43 +00:00

Fix CGuiTextSupport crash

This commit is contained in:
2017-07-07 05:23:20 -07:00
parent bfb16a3a0d
commit b22c0bc75f
14 changed files with 126 additions and 21 deletions

View File

@@ -1,12 +1,17 @@
#include "CScriptCounter.hpp"
#include "CStateManager.hpp"
#include "TCastTo.hpp"
namespace urde
{
CScriptCounter::CScriptCounter(TUniqueId uid, const std::string& name, const CEntityInfo& info,
u32, u32, bool, bool active)
s32 initial, s32 max, bool autoReset, bool active)
: CEntity(uid, info, active, name)
, x34_initial(initial)
, x38_current(initial)
, x3c_max(max)
, x40_autoReset(autoReset)
{
}
@@ -15,4 +20,61 @@ void CScriptCounter::Accept(IVisitor& visitor)
visitor.Visit(this);
}
void CScriptCounter::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
{
switch(msg)
{
case EScriptObjectMessage::SetToZero:
if (GetActive())
{
x38_current = 0;
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
if (x40_autoReset)
x38_current = x34_initial;
}
break;
case EScriptObjectMessage::SetToMax:
if (GetActive())
{
x38_current = x3c_max;
SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None);
if (x40_autoReset)
x38_current = x34_initial;
}
break;
case EScriptObjectMessage::Decrement:
if (GetActive() && x38_current > 0)
{
--x38_current;
if (x38_current == 0)
{
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
if (x40_autoReset)
x38_current = x34_initial;
}
}
break;
case EScriptObjectMessage::Increment:
if (GetActive() && x38_current < x3c_max)
{
++x38_current;
if (x38_current >= x3c_max)
{
SendScriptMsgs(EScriptObjectState::Zero, stateMgr, EScriptObjectMessage::None);
if (x40_autoReset)
x38_current = x34_initial;
}
}
break;
case EScriptObjectMessage::Reset:
if (GetActive())
x38_current = x34_initial;
break;
}
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
}
}