#include "T2Archive.h" #include "T2ElvModuleList.h" #include "T2MoverDef.h" #include "T2MoverModule.h" #include "T2MoverModuleList.h" #include "T2StairModuleList.h" T2MoverModuleList::T2MoverModuleList() : LArray(sizeof(T2MoverModule *)) { mMaxModule = 0; mModuleCount = 0; SetRect(&mBaseRect, 0, 0, 0, 0); } /*virtual*/ T2MoverModuleList::~T2MoverModuleList() { LArrayIterator iterator(*this); T2MoverModule *theMoverModule = NULL; while (iterator.Next(&theMoverModule)) { if (theMoverModule) delete theMoverModule; } RemoveItemsAt(mItemCount, 1); } /*virtual*/ BOOL T2MoverModuleList::Init(T2MoverDef* moverDef, const RECT& baseRect) { mMaxModule = moverDef->GetMaxModule(); mModuleCount = 0; mBaseRect = baseRect; return true; } BOOL T2MoverModuleList::InsertModuleAt(int where, T2MoverModule* module) { InsertItemsAt(1, where, &module); return true; } void T2MoverModuleList::AllClear() { RemoveItemsAt(mItemCount, 1); } /*virtual*/ void T2MoverModuleList::Destruct(T2TowerDoc* towerDoc) { LArrayIterator iterator(*this); T2MoverModule *theMoverModule = NULL; while (iterator.Next(&theMoverModule)) { if (theMoverModule) RemoveModule(towerDoc, theMoverModule); } } /*virtual*/ void T2MoverModuleList::RemoveModule(T2TowerDoc* towerDoc, T2MoverModule* moverModule) { moverModule->RemoveContents(towerDoc); Remove(&moverModule); moverModule->SetUsed(false); delete moverModule; } /*virtual*/ void T2MoverModuleList::Read(T2Archive& archive, T2TowerDoc* towerDoc) { AllClear(); short v; archive >> v; mMaxModule = v; archive.ReadSRect(mBaseRect); } /*virtual*/ void T2MoverModuleList::Write(T2Archive& archive) { archive << (short) mMaxModule; archive.WriteSRect(mBaseRect); archive << mItemCount; LArrayIterator iterator(*this); T2MoverModule *theMoverModule = NULL; while (iterator.Next(&theMoverModule)) theMoverModule->Save(archive); } /*virtual*/ T2MoverModule* T2MoverModuleList::ConstructModule() { return new T2MoverModule; } /*virtual*/ void T2MoverModuleList::StopAdded(T2TowerDoc* towerDoc, T2Mover*, int) { } /*virtual*/ void T2MoverModuleList::StopRemoved(T2TowerDoc* towerDoc, T2Mover*, int) { } unsigned int T2MoverModuleList::GetItemCount() { return GetCount(); } /*static*/ T2MoverModuleList* T2MoverModuleList::ReadMMList(T2Archive& archive, T2TowerDoc* towerDoc) { T2MoverModuleList *theList = NULL; DWORD classID; archive >> classID; if (classID == '_MML') theList = new T2MoverModuleList; else if (classID == 'ElML') theList = new T2ElvModuleList; else if (classID == 'StML') theList = new T2StairModuleList; if (theList) theList->Read(archive, towerDoc); return theList; } /*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList* list, T2Archive& archive) { if (!list) { DWORD code = 'xMML'; archive << code; } else { archive << list->GetMMClassID(); list->Write(archive); } } inline /*virtual*/ int T2MoverModuleList::GetModuleCount() const { return mModuleCount; }