diff options
Diffstat (limited to 'src/T2DLL/T2SantaClaus.cpp')
-rw-r--r-- | src/T2DLL/T2SantaClaus.cpp | 213 |
1 files changed, 208 insertions, 5 deletions
diff --git a/src/T2DLL/T2SantaClaus.cpp b/src/T2DLL/T2SantaClaus.cpp index df86e35..4aaa59d 100644 --- a/src/T2DLL/T2SantaClaus.cpp +++ b/src/T2DLL/T2SantaClaus.cpp @@ -1,25 +1,228 @@ +#include "CResFile.h" +#include "GlobalFunc.h" +#include "T2BitImage.h" +#include "T2DateTime.h" +#include "T2ImageObj.h" +#include "T2MainWindow.h" #include "T2SantaClaus.h" +#include "T2Sprite.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerEvent.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "UT2Coordinate.h" -T2SantaClaus::T2SantaClaus(T2TowerEvent*, CResFile*, int) { +T2SantaClaus::T2SantaClaus(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) + : T2EventItem(inTowerEvent, inResFile, inSubID) +{ + *inResFile >> m30; + if (m30 == 0) + m30 = 32; + + mWidth = GetWorldDef()->GetWidth(); + + mPosition.x = mWidth; + mPosition.y = GetWorldDef()->mTopFloorLine; + + m48 = 0; + mCounter = 0; + + mSpriteID = 0; + mSprite = NULL; + mImage = NULL; + mImageObj = NULL; + + mSpriteWidth = 0; + mSpriteHeight = 0; + + mAttach = NULL; + mMainView = NULL; + + m6C = false; + mVisible = false; + + mBeginTime = 1440 - (mWidth / 2); } /*virtual*/ T2SantaClaus::~T2SantaClaus() { + StopEvent(mTowerEvent->mDocument); + + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; } -/*virtual*/ int T2SantaClaus::Start(T2TowerDoc*) { +/*virtual*/ BOOL T2SantaClaus::Start(T2TowerDoc* inDoc) { + T2DateTime *theNow = inDoc->towerDoc_vf120(); + m48 = theNow ? (theNow->GetRawMinutes() - mBeginTime) : 0; + m4C = -6; + + mSprite = &inDoc->mSprite; + + mCounter = 0; + + if (!mImageObj) { + try { + mImage = new T2BitImage(inDoc->mWorldDef->mModuleHandle, 5003, true); + } catch (int err) { + return false; + } + mImageObj = new T2ImageObj; + mImageObj->AddObject(inDoc->mWorldDef->mModuleHandle, 5003, mImage); + } + + SIZE theSize; + mImageObj->GetObjectSize(0, &theSize); + mSpriteWidth = theSize.cx; + mSpriteHeight = theSize.cy; + mSpriteID = mSprite->NewSprite(*mImageObj, "SANTA", T2Sprite::ELayer_3); + + CPoint position = mPosition; + position.x -= m48; + UT2Coordinate::UnitToQD(position, 0); + + int yOffset = (m48 * 4) / m30; + position.y += yOffset; + + mSprite->MoveSprite(mSpriteID, position); + mSprite->ShowSprite(mSpriteID, true); + mVisible = true; + + mMainView = inDoc->GetTowerMainView(); + if (mMainView) { + mAttach = new T2SantaClausAttach(this, 0, true); + mMainView->AddAttachment(mAttach, NULL, true); + return true; + } else { + return false; + } } -/*virtual*/ int T2SantaClaus::IsBeginTime(unsigned int) { +/*virtual*/ BOOL T2SantaClaus::IsBeginTime(unsigned int inTime) { + m48 = inTime - mBeginTime; + return (m48 >= 0); } -/*virtual*/ int T2SantaClaus::Exec(T2TowerDoc*) { +/*virtual*/ int T2SantaClaus::Exec(T2TowerDoc* inDoc) { + if (!mMainView) + mMainView = inDoc->GetTowerMainView(); + + if (!mMainView) + return 0; + + if ((mCounter % 4) == 0) { + m48++; + + CPoint position = mPosition; + position.x -= m48; + UT2Coordinate::UnitToQD(position, 0); + + int vOffset = mCounter / m30; + position.y += vOffset; + position.y -= mSpriteWidth; + + CRect viewArea; + CRect spriteArea; + CRect intersect; + + mMainView->GetClientRect(viewArea); + viewArea.OffsetRect(mMainView->m64); + + spriteArea.SetRect(position.x, position.y, position.x + mSpriteHeight, position.y + mSpriteWidth); + + if (intersect.IntersectRect(viewArea, spriteArea)) { + Show(); + mSprite->MoveSprite(mSpriteID, position); + if (m6C) { + m4C = m48; + m6C = false; + } + + int pattern = (m48 & 1) + (((m48 - m4C) < 6) ? 2 : 0); + mSprite->ChangePattern(mSpriteID, pattern); + } else { + Hide(); + if (m48 > mWidth) + StopEvent(inDoc); + } + } + + mCounter++; + return mSprite ? 0 : 3; } -/*virtual*/ void T2SantaClaus::StopEvent(T2TowerDoc*) { +/*virtual*/ void T2SantaClaus::StopEvent(T2TowerDoc* inDoc) { + if (mSprite) { + mSprite->DeleteSprite(mSpriteID); + + delete mImageObj; + mImageObj = NULL; + delete mImage; + mImage = NULL; + + mSprite = NULL; + } + + if (mAttach) { + mMainView->RemoveAttachment(mAttach); + delete mAttach; + mAttach = NULL; + } } void T2SantaClaus::Show() { + if (!mVisible) { + mSprite->ShowSprite(mSpriteID, true); + mVisible = true; + } } void T2SantaClaus::Hide() { + if (mVisible) { + CPoint pt = mPosition; + UT2Coordinate::UnitToQD(pt, 0); + mSprite->MoveSprite(mSpriteID, pt); + + mSprite->ShowSprite(mSpriteID, false); + mVisible = false; + } +} + + + +T2SantaClausAttach::T2SantaClausAttach(T2SantaClaus* inOwner, unsigned int inMessage, BOOL inExecuteHost) + : LAttachment(inMessage, inExecuteHost) +{ + mOwner = inOwner; +} + +/*virtual*/ T2SantaClausAttach::~T2SantaClausAttach() { +} + +/*virtual*/ void T2SantaClausAttach::ExecuteSelf(unsigned int inMessage, void* ioData) { + if (inMessage == WM_LBUTTONDOWN) { + MSG *messagePtr = (MSG *) ioData; + + int id = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetSel(); + CString *theIconName = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconName(id); + T2TemplatePlugin *theTemplatePlugin = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconPlugin(id); + CProgramPlugin *theIconProgramPlugin = theTemplatePlugin->GetPlugin(); + unsigned int theIconValiation = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconValiation(id); + DWORD theIconOption = ((T2MainWindow *) AfxGetMainWnd())->mToolWindow->GetIconOption(id); + + if (theIconOption == 0 && *theIconName == "ToolInfo") { + CPoint pt(LOWORD(messagePtr->lParam), HIWORD(messagePtr->lParam)); + pt.Offset(GetCurrentT2TowerDoc()->GetTowerMainView()->m64); + + if (mOwner) { + CRect rect; + mOwner->mSprite->GetSpriteRect(mOwner->mSpriteID, rect); + mOwner->m6C = rect.PtInRect(pt); + } + } + } + + SetExecuteHost(true); } |