#include "StdAfx.h" #include "CResFile.h" #include "T2Archive.h" #include "T2DlgItemAnimation.h" #include "T2EventDialog.h" #include "T2EventItem.h" #include "T2SoundPlayer.h" #include "../T2TowerDoc.h" #include "T2TowerEvent.h" #include "../T2TowerMainView.h" #include "T2WorldDef.h" T2EventItem::T2EventItem(T2TowerEvent* inTowerEvent, CResFile* inResFile, int inSubID) { mSubID = inSubID; mTowerEvent = inTowerEvent; mStatus = 0; *inResFile >> mLevelBit; int v; *inResFile >> v; mExclusive = (v != 0); *inResFile >> v; mCycleDay = max(1, v); *inResFile >> mBeginTime; *inResFile >> mEndTime; mOriginalDef = this; mForceStart = false; } T2EventItem::T2EventItem(T2TowerEvent* inTowerEvent, int inSubID, int inLevelBit, BOOL inExclusive, int inCycleDay, int inBeginTime, int inEndTime) { mSubID = inSubID; mTowerEvent = inTowerEvent; mLevelBit = inLevelBit; mExclusive = inExclusive; mCycleDay = inCycleDay; mBeginTime = inBeginTime; mEndTime = inEndTime; mStatus = 0; mOriginalDef = NULL; mForceStart = false; } T2EventItem::T2EventItem(T2EventItem* inItem, int inSubID) { mSubID = inSubID; mTowerEvent = inItem->mTowerEvent; mLevelBit = inItem->mLevelBit; mExclusive = inItem->mExclusive; mCycleDay = inItem->mCycleDay; mBeginTime = inItem->mBeginTime; mEndTime = inItem->mEndTime; mStatus = 0; mOriginalDef = inItem; mForceStart = false; } /*virtual*/ T2EventItem::~T2EventItem() { } /*virtual*/ void T2EventItem::Init(T2TowerDoc* inDoc) { } /*virtual*/ BOOL T2EventItem::Start(T2TowerDoc* inDoc) { return true; } /*virtual*/ int T2EventItem::ReStart(T2TowerDoc* inDoc) { return 1; } /*virtual*/ void T2EventItem::StopEvent(T2TowerDoc* inDoc) { } T2WorldDef* T2EventItem::GetWorldDef() { return mTowerEvent->mWorldDef; } T2TowerDoc* T2EventItem::GetTowerDoc() const { return mTowerEvent->mDocument; } T2TowerEvent* T2EventItem::GetTowerEvent() { return mTowerEvent; } int T2EventItem::GetLevelBit() { return mLevelBit; } BOOL T2EventItem::IsExclusive() { return mExclusive; } int T2EventItem::GetCycleDay() { return mCycleDay; } int T2EventItem::GetBeginTime() { return mBeginTime; } void T2EventItem::SetBeginTime(int inTime) { mBeginTime = inTime; } int T2EventItem::GetEndTime() { return mEndTime; } /*virtual*/ BOOL T2EventItem::IsBeginTime(unsigned int inTime) { return (mBeginTime == inTime); } /*virtual*/ BOOL T2EventItem::IsBeginDay(int inDay) { return (inDay % mCycleDay) == 0; } int T2EventItem::GetStatus() { return mStatus; } void T2EventItem::SetStatus(int inStatus) { mStatus = inStatus; } T2EventItem* T2EventItem::GetOriginalDef() { return mOriginalDef; } /*virtual*/ unsigned int T2EventItem::DoDialog(T2TowerDoc* inDoc, int inDlgResID, int inAnimResID, int inAnimUnk, const char* inText) { T2WorldDef *theWorldDef = GetWorldDef(); inDoc->GetMainView()->HideToolSprite(); inDoc->towerDoc_vf290(true); unsigned int result = 0; while (result == 0) { T2EventDialog *theDialog = T2EventDialog::Show(this, inDoc, theWorldDef->mModuleHandle, inDlgResID); mEventDialog = theDialog; SetupDialog(theDialog); CWnd *theLabel = theDialog->GetDlgItem(100); if (theLabel) { CString str = inText; str = "l" + str; theLabel->SetWindowText(str); } T2DlgItemAnimation *animation = (T2DlgItemAnimation *) theDialog->GetDlgItem(101); if (animation) animation->SetAnimation(theWorldDef->mModuleHandle, inAnimResID, inAnimUnk); result = theDialog->DoModal(); result = DialogHook(theDialog, result, inDoc); } inDoc->towerDoc_vf290(false); inDoc->GetMainView()->UnhideToolSprite(); return result; } /*virtual*/ void T2EventItem::DoAlert(T2TowerDoc* inDoc, CString& inText, int inSoundID) { T2WorldDef *theWorldDef = GetWorldDef(); inDoc->GetMainView()->HideToolSprite(); inDoc->towerDoc_vf290(true); T2EventDialog *theDialog = T2EventDialog::Show(this, inDoc, theWorldDef->mModuleHandle, 8000); CWnd *theLabel = theDialog->GetDlgItem(100); if (theLabel) { theLabel->SetWindowText("l" + inText); } T2DlgItemAnimation *animation = (T2DlgItemAnimation *) theDialog->GetDlgItem(101); if (animation) animation->SetAnimation(theWorldDef->mModuleHandle, 9000, 0); if (inSoundID) { inDoc->mSoundPlayer->FadeOut(); inDoc->mSoundPlayer->AddSound("EVENT:Voice", SoundPriority_1, inSoundID, theWorldDef->mModuleHandle); inDoc->mSoundPlayer->Play("EVENT:Voice", SoundMask_10, SoundFlags_10 | SoundFlags_10000, NULL, PlayMode_0, 100); } theDialog->DoModal(); if (inSoundID) { inDoc->mSoundPlayer->Stop("EVENT:Voice"); inDoc->mSoundPlayer->DeleteSound("EVENT:Voice"); inDoc->mSoundPlayer->FadeIn(); } inDoc->towerDoc_vf294(); inDoc->GetMainView()->UnhideToolSprite(); } /*virtual*/ void T2EventItem::Write(T2Archive& inArchive) { unsigned int len = 0; inArchive << len; } /*virtual*/ void T2EventItem::Read(T2Archive& inArchive) { unsigned char tmp; unsigned int len; inArchive >> len; for (unsigned int i = 0; i < len; i++) inArchive >> tmp; }