summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2MoverModuleTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/T2MoverModuleTable.cpp')
-rw-r--r--src/T2DLL/T2MoverModuleTable.cpp358
1 files changed, 358 insertions, 0 deletions
diff --git a/src/T2DLL/T2MoverModuleTable.cpp b/src/T2DLL/T2MoverModuleTable.cpp
new file mode 100644
index 0000000..f025e6e
--- /dev/null
+++ b/src/T2DLL/T2MoverModuleTable.cpp
@@ -0,0 +1,358 @@
+#include "CT2App.h"
+#include "GlobalFunc.h"
+#include "T2BitImage.h"
+#include "T2DlgItemVScr.h"
+#include "T2ElevatorModule.h"
+#include "T2FloorNumberTable.h"
+#include "T2Mover.h"
+#include "T2MoverModuleList.h"
+#include "T2MoverModuleTable.h"
+
+/*virtual*/ BOOL T2MoverModuleTable::Create(const char* inWindowName, DWORD inStyle, const RECT& inRect, CWnd* inParentWnd, UINT inID) {
+ return T2DlgItem::Create(inWindowName, inStyle, inRect, inParentWnd, inID);
+}
+
+T2MoverModuleTable::T2MoverModuleTable(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette)
+ : T2DlgItemImageTable(inDoc, inImageObj, inPalette)
+ , mMover(NULL)
+ , mMoverModuleList(NULL)
+{
+ mImage = NULL;
+ SetRect(&mRect, 0, 0, 0, 0);
+ ((CT2App *) AfxGetApp())->app_vfA4(true);
+}
+
+/*virtual*/ T2MoverModuleTable::~T2MoverModuleTable() {
+ LArrayIterator iterator(*mMoverModuleList);
+ T2MoverModule *theModule;
+
+ while (iterator.Next(&theModule))
+ theModule->RemoveListener(this);
+
+ if (mImage)
+ delete mImage;
+}
+
+/*virtual*/ BOOL T2MoverModuleTable::OnT2DlgItemCreate(CREATESTRUCT* inCreateStruct) {
+ T2DlgItem::OnT2DlgItemCreate(inCreateStruct);
+
+ GetClientRect(&mRect);
+
+ RECT rect;
+ rect.left = mRect.right - 16;
+ rect.top = mRect.top;
+ rect.right = mRect.right;
+ rect.bottom = mRect.bottom;
+
+ T2DlgItemVScr *theScr = new T2DlgItemVScr(mTowerDoc, mImageObj, mPalette);
+ theScr->Create("", WS_VISIBLE | WS_CHILD, rect, this, 100);
+
+ rect.left = mRect.left;
+ rect.top = mRect.top;
+ rect.right = mRect.left + 24;
+ rect.bottom = mRect.bottom;
+
+ T2FloorNumberTable *theTable = new T2FloorNumberTable(mTowerDoc, mImageObj, mPalette);
+ theTable->Create("", WS_VISIBLE | WS_CHILD, rect, this, 101);
+
+ mImage = new T2BitImage(mRect);
+ mImage->Clear(0);
+ return false;
+}
+
+/*virtual*/ void T2MoverModuleTable::SpendTime() {
+}
+
+void T2MoverModuleTable::SetMover(T2Mover* inMover) {
+ mMover = inMover;
+ if (!mMover)
+ return;
+
+ mMoverModuleList = mMover->GetModuleList();
+ if (mMoverModuleList) {
+ LArrayIterator iterator(*mMoverModuleList);
+ T2MoverModule *theModule;
+
+ while (iterator.Next(&theModule))
+ theModule->AddListener(this);
+
+ InsertCols(mMoverModuleList->GetItemCount(), 0, NULL);
+ InsertRows(mMover->GetLength(), 0, NULL);
+ }
+}
+
+T2ElevatorModule* T2MoverModuleTable::GetModule(int inIndex) {
+ T2ElevatorModule *theModule = NULL;
+ LArrayIterator iterator(*mMoverModuleList);
+ int index = 0;
+
+ while (iterator.Next(&theModule)) {
+ if (theModule->IsUsed()) {
+ index++;
+ if (index >= inIndex)
+ return theModule;
+ }
+ }
+
+ return NULL;
+}
+
+int T2MoverModuleTable::GetCellContent(const TableCellT& inCell) {
+ int result = 0;
+
+ if (mMoverModuleList) {
+ T2ElevatorModule *theModule = GetModule(inCell.col);
+ if (theModule) {
+ int floor = mRows - inCell.row;
+
+ if (result == 0 && theModule->GetPosition() == floor)
+ result = 3010 + theModule->GetPatIndex();
+
+ if (result == 0) {
+ if (theModule->GetDirection() == kElevatorDirection1) {
+ if (theModule->GetTopTurn() == floor)
+ result = 3007;
+ } else if (theModule->GetDirection() == kElevatorDirection2) {
+ if (theModule->GetBottomTurn() == floor)
+ result = 3006;
+ }
+ }
+
+ if (result == 0) {
+ if (theModule->GetDirection() == kElevatorDirection1) {
+ if (theModule->IsOnStopPos(floor, ERequestUpDown_0))
+ result = 3004;
+ else if (theModule->IsOnStopPos(floor, ERequestUpDown_1))
+ result = 3005;
+ } else if (theModule->GetDirection() == kElevatorDirection2) {
+ if (theModule->IsOnStopPos(floor, ERequestUpDown_1))
+ result = 3005;
+ else if (theModule->IsOnStopPos(floor, ERequestUpDown_0))
+ result = 3004;
+ }
+ }
+
+ if (result == 0) {
+ if (theModule->GetDirection() == kElevatorDirection1) {
+ if (theModule->IsOffStopPos(floor, ERequestUpDown_0))
+ result = 3002;
+ else if (theModule->IsOffStopPos(floor, ERequestUpDown_1))
+ result = 3003;
+ } else if (theModule->GetDirection() == kElevatorDirection2) {
+ if (theModule->IsOffStopPos(floor, ERequestUpDown_1))
+ result = 3003;
+ else if (theModule->IsOffStopPos(floor, ERequestUpDown_0))
+ result = 3002;
+ }
+ }
+
+ if (result == 0) {
+ if (theModule->GetHomePosition() == floor)
+ result = 3001;
+ }
+
+ if (result == 0)
+ result = 3000;
+ }
+ }
+
+ return result;
+}
+
+int T2MoverModuleTable::GetVScrValue() {
+ T2DlgItemVScr *theScr = (T2DlgItemVScr *) GetDlgItem(100);
+ return theScr->GetValue();
+}
+
+/*virtual*/ void T2MoverModuleTable::DrawCellSelf(CDC* pDC, const TableCellT& inCell, BOOL inSelected) {
+ RECT cellRect;
+ if (FetchLocalCellFrame(inCell, cellRect)) {
+ int content = GetCellContent(inCell);
+ if (content != 0) {
+ int y = GetVScrValue() * mRowHeight;
+ OffsetRect(&cellRect, 24, -y);
+ BOOL doesIntersect = IntersectRect(&cellRect, &cellRect, &mRect);
+
+ T2BitImage *theImage = new T2BitImage(AfxGetResourceHandle(), content, true);
+ RECT theSrcRect;
+ theSrcRect.left = 0;
+ theSrcRect.top = 0;
+ theSrcRect.right = theImage->mBitmap.header.biWidth;
+ theSrcRect.bottom = theImage->mBitmap.header.biHeight;
+
+ if (doesIntersect) {
+ theImage->CopyImage(*mImage, theSrcRect, cellRect, SRCCOPY);
+ if (inSelected)
+ InvalidateRect(NULL);
+ }
+
+ // memory leak???
+ }
+ }
+}
+
+/*virtual*/ void T2MoverModuleTable::ListenToMessage(UINT inMessage, void *ioData) {
+ switch (inMessage) {
+ case 1000:
+ case 1001:
+ HomeNotification *info = (HomeNotification *) ioData;
+ T2MoverModule *module = NULL;
+ int i = 0;
+ LArrayIterator theIter(*mMoverModuleList);
+
+ while (theIter.Next(&module)) {
+ if (module->IsUsed()) {
+ i++;
+ if (module == info->theModule) {
+ int position = -1;
+ switch (inMessage) {
+ case 1000:
+ break;
+ case 1001:
+ position = module->GetPosition();
+ break;
+ }
+
+ RefreshMoverCell(position, i);
+ break;
+ }
+ }
+ }
+ break;
+ }
+}
+
+void T2MoverModuleTable::RefreshMoverCell(int inFloor, unsigned int inIndex) {
+ if (mMover) {
+ if (inFloor < 0) {
+ TableCellT topCell, bottomCell;
+ RECT topFrame, bottomFrame;
+ topCell.row = 1;
+ topCell.col = inIndex;
+ bottomCell.row = mRows;
+ bottomCell.col = inIndex;
+ if (FetchLocalCellFrame(topCell, topFrame) && FetchLocalCellFrame(bottomCell, bottomFrame)) {
+ RECT rect;
+ SetRect(&rect, topFrame.left, topFrame.top, bottomFrame.right, bottomFrame.bottom);
+
+ BOOL isVisible = IntersectRect(&rect, &rect, &mRect);
+ if (isVisible)
+ InvalidateRect(&rect);
+ }
+ } else {
+ TableCellT theCell;
+ RECT frame;
+ theCell.row = mRows - inFloor;
+ theCell.col = inIndex;
+ if (FetchLocalCellFrame(theCell, frame)) {
+ BOOL isVisible = IntersectRect(&frame, &frame, &mRect);
+ if (isVisible)
+ InvalidateRect(&frame);
+ }
+ }
+ }
+}
+
+void T2MoverModuleTable::DrawMoverCellByIndex(unsigned int inIndex) {
+ TableCellT cell;
+ cell.col = inIndex;
+
+ for (unsigned int i = 1; i <= mRows; i++) {
+ cell.row = i;
+ DrawCellSelf(NULL, cell, false);
+ }
+}
+
+/*virtual*/ void T2MoverModuleTable::ClickCell(const TableCellT& inCell, const POINT& inPt) {
+ T2TowerDoc *theDoc = GetCurrentT2TowerDoc();
+ if (mMoverModuleList && theDoc) {
+ int moverIndex = inCell.col;
+ T2ElevatorModule *theModule = GetModule(moverIndex);
+
+ if (theModule) {
+ HomeNotification info;
+ info.theModule = theModule;
+ info.whichMover = moverIndex;
+ info.whichFloor = mRows - inCell.row;
+ info.theTable = this;
+ BroadcastMessage('home', &info);
+ }
+ }
+}
+
+/*virtual*/ BOOL T2MoverModuleTable::OnCommand(WPARAM inWParam, LPARAM inLParam) {
+ BOOL result = false;
+
+ if (LOWORD(inWParam) == 100 || LOWORD(inWParam) == 101) {
+ InvalidateRect(NULL);
+ result = true;
+ }
+
+ return result;
+}
+
+/*virtual*/ BOOL T2MoverModuleTable::OnT2DlgItemEraseBkgnd(CDC* pDC) {
+ CRect theRect;
+ GetClientRect(theRect);
+ theRect.right -= 15;
+ theRect.left += 23;
+
+ int saved = pDC->SaveDC();
+ pDC->SelectPalette(mPalette, false);
+ pDC->RealizePalette();
+
+ CPen thePen;
+ CBrush theBrush, theNullBrush;
+
+ if (!mMoverModuleList) {
+ thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
+ theBrush.CreateSolidBrush(RGB(255, 255, 255));
+ pDC->SelectObject(theBrush);
+ pDC->SelectObject(thePen);
+ pDC->Rectangle(theRect);
+ } else {
+ thePen.CreatePen(PS_SOLID, 0, PALETTEINDEX(255));
+ theNullBrush.CreateStockObject(NULL_BRUSH);
+ pDC->SelectObject(theNullBrush);
+ pDC->SelectObject(thePen);
+ pDC->Rectangle(theRect);
+
+ theRect.top++;
+ theRect.left++;
+ theRect.right--;
+ theRect.bottom--;
+
+ unsigned int height, width;
+ GetTableSize(height, width);
+
+ for (unsigned int x = 1; x <= width; x++) {
+ for (unsigned int y = 1; y <= height; y++) {
+ TableCellT cell;
+ cell.row = y;
+ cell.col = x;
+ DrawCellSelf(pDC, cell, false);
+ }
+ }
+
+ pDC->IntersectClipRect(theRect);
+ StretchDIBits(pDC->m_hDC, theRect.left, theRect.bottom, theRect.right - theRect.left, theRect.bottom - theRect.top, 0, 0, mImage->mBitmap.header.biWidth, mImage->mBitmap.header.biHeight, mImage->mData, (BITMAPINFO *) &mImage->mBitmap, DIB_PAL_COLORS, SRCCOPY);
+
+ theRect.top--;
+ theRect.left--;
+ theRect.right++;
+ theRect.bottom++;
+ InvalidateRect(&theRect);
+ }
+
+ pDC->RestoreDC(saved);
+ return true;
+}
+
+/*virtual*/ void T2MoverModuleTable::OnT2DlgItemLButtonDown(UINT inFlags, CPoint inPt) {
+ POINT pt = inPt;
+ ClientToView(&pt, 1);
+
+ TableCellT cell;
+ FetchCellHitBy(pt, cell);
+ ClickCell(cell, inPt);
+}