#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 *moverModule = NULL; while (iterator.Next(&moverModule)) { if (moverModule) delete moverModule; } 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 *moverModule = NULL; while (iterator.Next(&moverModule)) { if (moverModule) RemoveModule(towerDoc, moverModule); } } /*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 *moverModule = NULL; while (iterator.Next(&moverModule)) moverModule->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 *list = NULL; DWORD code; archive >> code; if (code == '_MML') list = new T2MoverModuleList; else if (code == 'ElML') list = new T2ElvModuleList; else if (code == 'StML') list = new T2StairModuleList; if (list) list->Read(archive, towerDoc); return list; } /*static*/ void T2MoverModuleList::WriteMMList(T2MoverModuleList* list, T2Archive& archive) { if (!list) { DWORD code = 'xMML'; archive << code; } else { archive << list->GetMMClassID(); list->Write(archive); } } /*virtual*/ int T2MoverModuleList::GetModuleCount() const { return mModuleCount; }