From 5e61c1280c15ab9969b94cd360cafd4a11b2dd30 Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 5 Jul 2023 19:04:06 +0100 Subject: matched T2.exe --- src/T2TowerMainView.cpp | 1738 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1738 insertions(+) create mode 100644 src/T2TowerMainView.cpp (limited to 'src/T2TowerMainView.cpp') diff --git a/src/T2TowerMainView.cpp b/src/T2TowerMainView.cpp new file mode 100644 index 0000000..87508af --- /dev/null +++ b/src/T2TowerMainView.cpp @@ -0,0 +1,1738 @@ +#include "DbgEquipInfo.h" +#include "GlobalFunc.h" +#include "T2.h" +#include "T2BitImage.h" +#include "T2CrossEquipArray.h" +#include "T2DLL.h" +#include "T2FInfoAreaIterator.h" +#include "T2FloorInfo.h" +#include "T2MainWindow.h" +#include "T2Mover.h" +#include "T2MoverArray.h" +#include "T2MoverArrayList.h" +#include "T2Request.h" +#include "T2Tenant.h" +#include "T2TenantArray.h" +#include "T2TenantArrayList.h" +#include "T2ToolDef.h" +#include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2TowerMainView.h" +#include "T2WorldDef.h" +#include "URect.h" +#include "UT2BkgndInfo.h" +#include "UT2Coordinate.h" +#include "UT2Utils.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#line 24 +IMPLEMENT_DYNCREATE(T2TowerMainView, CView) + +BEGIN_MESSAGE_MAP(T2TowerMainView, CView) + ON_WM_CREATE() + ON_WM_SIZE() + ON_COMMAND(0x8006, OnDebugNormalDisplay) + ON_UPDATE_COMMAND_UI(0x8006, OnUpdateDebugNormalDisplay) + ON_COMMAND(0x8008, OnDebugBkgndInfo) + ON_UPDATE_COMMAND_UI(0x8008, OnUpdateDebugBkgndInfo) + ON_COMMAND(0x8007, OnDebugFloorInfoTenant) + ON_UPDATE_COMMAND_UI(0x8007, OnUpdateDebugFloorInfoTenant) + ON_WM_LBUTTONDOWN() + ON_WM_MOUSEMOVE() + ON_WM_LBUTTONUP() + ON_UPDATE_COMMAND_UI(0x800B, OnUpdateDebugGrid) + ON_COMMAND(0x800B, OnDebugGrid) + ON_UPDATE_COMMAND_UI(0x800C, OnUpdateDebugFloorInfoMover) + ON_COMMAND(0x800C, OnDebugFloorInfoMover) + ON_WM_RBUTTONDOWN() + ON_COMMAND(0x800E, OnDebugFloorInfoRequest) + ON_UPDATE_COMMAND_UI(0x800E, OnUpdateDebugFloorInfoRequest) + ON_UPDATE_COMMAND_UI(0x800F, OnUpdateDebugDisplaySpeedMeasuring) + ON_COMMAND(0x800F, OnDebugDisplaySpeedMeasuring) + ON_UPDATE_COMMAND_UI(0x8017, OnUpdateDebugOffscreenSpeedMeasuring) + ON_COMMAND(0x8017, OnDebugOffscreenSpeedMeasuring) + ON_WM_RBUTTONUP() + ON_WM_TIMER() + ON_WM_DESTROY() + ON_COMMAND_RANGE(10000, 10010, OnCommand10000to10010) +END_MESSAGE_MAP() + +T2TowerMainView::T2TowerMainView() { + mImage = NULL; + SetRectEmpty(&mWorldBounds); + SetRectEmpty(&mVisibleArea); + ClearUpdateRect(); + mScrollOffset.x = 0; + mScrollOffset.y = 0; + mActiveTool = kTool0_Null; + mDebugMode = 0; + mDbgEquipID = 0; + mSkipOffscreenDraw = false; + mIsDebugGrid = false; + mActiveToolDef = NULL; + _108.x = -1; + _108.y = -1; + mImageOrigin.x = 0; + mImageOrigin.y = 0; + mPressedButtons = 0; + mHideToolSpriteCount = 0; + mDC = false; + mAnotherToolVar = kAnotherToolVar0; + SetRectEmpty(&m6C); + _EC = 0; + mToolSpriteIndex = -1; +} + +/*virtual*/ T2TowerMainView::~T2TowerMainView() { + if (mImage) + delete mImage; +} + +/*virtual*/ void T2TowerMainView::tmv_vf110() { + SetRectEmpty(&mWorldBounds); + SetRectEmpty(&mVisibleArea); + ClearUpdateRect(); + mScrollOffset.x = 0; + mScrollOffset.y = 0; + mActiveTool = kTool0_Null; + mDebugMode = 0; + mDbgEquipID = 0; + mSkipOffscreenDraw = false; + mIsDebugGrid = false; + mActiveToolDef = NULL; + _108.x = -1; + _108.y = -1; + mImageOrigin.x = 0; + mImageOrigin.y = 0; + mPressedButtons = 0; + mHideToolSpriteCount = 0; + mDC = false; + mAnotherToolVar = kAnotherToolVar0; + SetRectEmpty(&m6C); + _EC = 0; + mToolSpriteIndex = -1; +} + +/*virtual*/ BOOL T2TowerMainView::PreCreateWindow(CREATESTRUCT &cs) { + cs.dwExStyle |= WS_EX_CLIENTEDGE; + cs.style &= ~WS_VISIBLE; + return CView::PreCreateWindow(cs); +} + +/*virtual*/ void T2TowerMainView::OnDraw(CDC *pDC) { +#pragma var_order(brush, save, h, v, theDoc, interiorRect, clientRect, bgRect, mysteryRect) + T2TowerDoc *theDoc = GetTowerDoc(); +#line 142 + ASSERT_VALID(theDoc); + + CBrush brush; + brush.CreateStockObject(GRAY_BRUSH); + + CRect clientRect; + GetClientRect(clientRect); + + CRect bgRect; + if (!theDoc->mIsStuffLoadedFlag || !theDoc->Get22C()) { + pDC->FillRect(clientRect, &brush); + return; + } + + int h = mDocument->mWorldDef->GetWidth() - 1; + int v = mDocument->mWorldDef->GetHeight() - 1; + UT2Coordinate::UnitToQD(v, h, mDocument->mZoomLevel); + + if (mImageOrigin.x != 0) { + bgRect = clientRect; + bgRect.right = mImageOrigin.x; + pDC->FillRect(bgRect, &brush); + + bgRect = clientRect; + bgRect.left = mImageOrigin.x + h; + pDC->FillRect(bgRect, &brush); + } + + if (mImageOrigin.y != 0) { + bgRect = clientRect; + bgRect.bottom = mImageOrigin.y; + pDC->FillRect(bgRect, &brush); + + bgRect = clientRect; + bgRect.top = mImageOrigin.y + v; + pDC->FillRect(bgRect, &brush); + } + + if (!theDoc->mWorldDef) + return; + + int save = pDC->SaveDC(); + + RECT mysteryRect; + mysteryRect.left = 0; + mysteryRect.top = 0; + mysteryRect.right = mysteryRect.left + mImage->mBitmap.header.biWidth; + mysteryRect.bottom = mysteryRect.top + mImage->mBitmap.header.biHeight; + + RECT interiorRect; + GetClientRect(&interiorRect); + + x42B484(pDC, interiorRect); + pDC->RestoreDC(save); +} + +/*virtual*/ void T2TowerMainView::AssertValid() const { + CView::AssertValid(); +} + +/*virtual*/ void T2TowerMainView::Dump(CDumpContext &dc) const { + CView::Dump(dc); +} + +/*virtual*/ T2TowerDoc *T2TowerMainView::GetTowerDoc() { +#line 223 + ASSERT_KINDOF(T2TowerDoc, m_pDocument); + return (T2TowerDoc *) m_pDocument; +} + +int T2TowerMainView::OnCreate(LPCREATESTRUCT lpcs) { + if (CView::OnCreate(lpcs) == -1) + return -1; + + mDocument = GetTowerDoc(); + mDocument->mTowerMainView = this; + SetRect(&mWorldBounds, 0, 0, 100, 100); + AdjustWorldBounds(); + + ShowWindow(SW_HIDE); + SetTimer(12345, 100, NULL); + SetClassLong(m_hWnd, GCL_HBRBACKGROUND, 0); + + return 0; +} + +void T2TowerMainView::OnDestroy() { + mDocument->mTowerMainView = NULL; + CView::OnDestroy(); + KillTimer(12345); +} + +void T2TowerMainView::AdjustWorldBounds() { + if (!mDocument->mWorldDef) + return; + + if (mImage) + delete mImage; + + RECT rect; + GetClientRect(&rect); + + CRect worldRect; + worldRect.SetRect(0, 0, mDocument->mWorldDef->GetWidth() - 1, mDocument->mWorldDef->GetHeight() - 1); + UT2Coordinate::UnitToQD(worldRect, mDocument->mZoomLevel, true); + + if (rect.right > worldRect.right) + rect.right = worldRect.right; + if (rect.bottom > worldRect.bottom) + rect.bottom = worldRect.bottom; + +#line 282 + mImage = new T2BitImage(rect); + + mUpdateRect1 = mVisibleArea; + mUpdateRect2 = mVisibleArea; +} + +void T2TowerMainView::ClearUpdateRect() { + SetRectEmpty(&mUpdateRect1); + SetRectEmpty(&mUpdateRect2); +} + +void T2TowerMainView::x42AC1B() { + if (!mDocument->mWorldDef) + return; + + GetClientRect(&mVisibleArea); + OffsetRect(&mVisibleArea, mScrollOffset.x, mScrollOffset.y); + UT2Coordinate::QDToUnit(mVisibleArea, mDocument->GetZoomLevel()); + IntersectRect(&mVisibleArea, &mWorldBounds, &mVisibleArea); +} + +void T2TowerMainView::OnSize(UINT nType, int cx, int cy) { + CWnd::OnSize(nType, cx, cy); + AdjustWorldBounds(); +} + +/*virtual*/ void T2TowerMainView::tmv_vf120() { + if (!mDocument->mWorldDef || !mDocument->Get22C()) + return; + + mDocument->mSprite.GetUpdateRect(&mSpriteUpdateRect, mDocument->mZoomLevel); + UT2Coordinate::QDToUnit(mSpriteUpdateRect, mDocument->mZoomLevel); + UT2Coordinate::UnitToQD(mSpriteUpdateRect, mDocument->mZoomLevel, true); + + RECT rect1, rect2; + rect1 = mSpriteUpdateRect; + + UT2Coordinate::UnitToQD(mUpdateRect1, rect2, mDocument->mZoomLevel, true); + UnionRect(&rect1, &rect1, &rect2); + + UT2Coordinate::UnitToQD(mUpdateRect2, rect2, mDocument->mZoomLevel, true); + UnionRect(&rect1, &rect1, &rect2); + + UT2Coordinate::QDToUnit(rect1, mDocument->mZoomLevel); + + UT2Coordinate::QDToUnit(mSpriteUpdateRect, rect2, mDocument->mZoomLevel); + UnionRect(&mUpdateRect1, &mUpdateRect1, &rect2); + UnionRect(&mUpdateRect2, &mUpdateRect2, &rect2); + UnionRect(&mUpdateRect2, &mUpdateRect2, &mUpdateRect1); + + if (!IsRectEmpty(&rect1)) { + tmv_vf11C(); + if (mIsDebugGrid) + DrawDebugGrid(); + if (!mSkipOffscreenDraw) { + CopySimulationImage(rect1); + mDocument->mPaletteUpdated = false; + } + } + + if (mDocument->mPaletteUpdated) { + GetClientRect(&rect1); + CopySimulationImage(rect1); + mDocument->mPaletteUpdated = false; + } +} + +/*virtual*/ void T2TowerMainView::tmv_vf11C() { +#pragma var_order(rect5, rect1, rect4, rect3, rect2) + RECT rect1, rect2, rect3, rect4, rect5; + + mImage->SetOrigin(mScrollOffset.x, mScrollOffset.y); + + UT2Coordinate::QDToUnit(m6C, rect1, mDocument->mZoomLevel); + UT2Coordinate::UnitToQD(rect1, mDocument->mZoomLevel, true); + if (!IsRectEmpty(&rect1) && mToolSpriteName != "") + UnionRect(&mSpriteUpdateRect, &mSpriteUpdateRect, &rect1); + + mImage->SetClipRect(&mSpriteUpdateRect); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_0, mDocument->mZoomLevel); + + UT2Coordinate::UnitToQD(mUpdateRect1, rect2, mDocument->mZoomLevel, true); + mImage->SetClipRect(&rect2); + UnionRect(&rect3, &mSpriteUpdateRect, &rect2); + + UT2Coordinate::UnitToBkgnd(mUpdateRect1, rect4); + mDocument->DrawBkgnd(rect4); + + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_1, mDocument->mZoomLevel); + + UT2Coordinate::UnitToQD(mUpdateRect2, rect2, mDocument->mZoomLevel, true); + UT2Coordinate::UnitToQD(mUpdateRect1, rect5, mDocument->mZoomLevel, true); + UnionRect(&rect2, &rect2, &rect5); + UnionRect(&rect3, &rect3, &rect2); + mImage->SetClipRect(&rect2); + mDocument->towerDoc_vfF0(mUpdateRect2, mUpdateRect1); + + if (mDocument->GetViewMode() != kOutView) { + mImage->SetClipRect(&rect3); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_2, mDocument->mZoomLevel); + } + + mDocument->DrawBuilding(mUpdateRect2, mUpdateRect1); + + if (mDocument->GetViewMode() != kOutView) { + mImage->SetClipRect(&rect3); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_3, mDocument->mZoomLevel); + } + + UT2Coordinate::UnitToQD(mUpdateRect1, rect2, mDocument->mZoomLevel, true); + mImage->SetClipRect(&rect2); + mDocument->towerDoc_vf100(mVisibleArea); + + mImage->SetClipRect(&rect3); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_4, mDocument->mZoomLevel); + + mImage->SetClipRect(&mSpriteUpdateRect); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_5, mDocument->mZoomLevel); + + if (!IsRectEmpty(&rect1) && !mHideToolSpriteCount && mToolSpriteName != "") + mImage->DrawFocusRect(rect1); + + mImage->SetClipRect(&rect3); + mDocument->mSprite.DrawLayer(mImage, T2Sprite::ELayer_6, mDocument->mZoomLevel); + + mImage->SetClipRect(NULL); + DispatchOptionEvent(kTowerDrawFinishedOptionEvent, NULL); + + mImage->SetOrigin(0, 0); + ClearUpdateRect(); +} + +void func42B3A2(RECT &outRect, const RECT &inRect) { + outRect = inRect; + if (!IsRectEmpty(&outRect)) { + outRect.left -= 7; + outRect.right += 7; + outRect.bottom += 2; + outRect.top -= 2; + } +} + +/*virtual*/ void T2TowerMainView::CopySimulationImage(const RECT &inRect) { + RECT rect; + UT2Coordinate::UnitToQD(inRect, rect, mDocument->GetZoomLevel(), true); + OffsetRect(&rect, -mScrollOffset.x, -mScrollOffset.y); + + CDC *pDC = GetDC(); + x42B484(pDC, rect); + ReleaseDC(pDC); +} + +void T2TowerMainView::x42B484(CDC *pDC, const RECT &inRect) { + if (!DispatchOptionEvent(kTowerPreDrawOptionEvent, pDC)) + return; + + T2TowerDoc *theDoc = GetTowerDoc(); + if (!theDoc || !theDoc->mWorldDef) + return; + + RECT theDstRect = inRect; + RECT theRect = theDstRect; + + int saved = pDC->SaveDC(); + pDC->SelectPalette(theDoc->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + + theDstRect.left += mImageOrigin.x; + theDstRect.right += mImageOrigin.x; + theDstRect.top += mImageOrigin.y; + theDstRect.bottom += mImageOrigin.y; + mImage->CopyImage(pDC, theRect, theDstRect); + + if (mDebugMode == 1) + DrawDebugBkgndInfo(pDC); + else if (mDebugMode == 2) + DrawDebugFloorInfoTenant(pDC, mVisibleArea); + else if (mDebugMode == 3) + DrawDebugFloorInfoMover(pDC, mVisibleArea); + else if (mDebugMode == 4) + DrawDebugFloorInfoRequest(pDC, mVisibleArea); + + if (mDbgEquipID) + DrawDebugEquip(pDC, mVisibleArea); + + int theZoom = mDocument->GetZoomLevel(); + pDC->SetViewportOrg( + -mScrollOffset.x + UT2Coordinate::UnitHSize(theZoom) / 2, + -mScrollOffset.y + UT2Coordinate::UnitVSize(theZoom) / 2 + ); + + CPen pen; + pen.CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); + pDC->SelectObject(pen); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + pDC->SelectObject(nullBrush); + + CFont font; + font.CreateFont(-14, 0, 0, 0, FW_BOLD, false, false, false, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DRAFT_QUALITY, DEFAULT_PITCH, "Arial"); + pDC->SelectObject(font); + + pDC->SetBkMode(TRANSPARENT); + pDC->SetTextColor(RGB(255, 0, 0)); + + pDC->RestoreDC(saved); +} + +/*virtual*/ void T2TowerMainView::DrawDebugGrid() { + int stride = ((mImage->mBitmap.header.biWidth + 3) / 4) * 4; + + for (int x1 = 8 - (mScrollOffset.x % 8); x1 < mImage->mBitmap.header.biWidth; x1 += (8 >> mDocument->mZoomLevel)) { + for (int y1 = 4 - (mScrollOffset.y % 4); y1 < mImage->mBitmap.header.biHeight; y1 += (4 >> mDocument->mZoomLevel)) { + mImage->mData[stride * y1 + x1] = 0; + } + } + + for (int y2 = 36 - (mScrollOffset.y % 36); y2 < mImage->mBitmap.header.biHeight; y2 += (36 >> mDocument->mZoomLevel)) { + for (int x2 = 4 - (mScrollOffset.x % 4); x2 < mImage->mBitmap.header.biWidth; x2 += (4 >> mDocument->mZoomLevel)) { + mImage->mData[stride * y2 + x2] = 0; + } + } +} + +/*virtual*/ void T2TowerMainView::Invalidate(BOOL inFlag) { + InvalUnitRect(mVisibleArea, inFlag); +} + +/*virtual*/ void T2TowerMainView::InvalUnitRect(const RECT &inRect, BOOL inFlag) { +#pragma var_order(rect2, rect3, rect5, rect4, rect1) + CRect rect1; + CRect rect2 = inRect; + CRect rect3 = mVisibleArea; + CRect rect4 = mUpdateRect1; + CRect rect5 = mUpdateRect2; + + rect1.IntersectRect(&rect2, &rect3); + if (!rect1.IsRectEmpty()) { + if (inFlag) + rect4.UnionRect(&rect4, &rect1); + rect5.UnionRect(&rect5, &rect1); + } + + mUpdateRect1.top = rect4.top; + mUpdateRect1.bottom = rect4.bottom; + mUpdateRect1.left = rect4.left; + mUpdateRect1.right = rect4.right; + mUpdateRect2.top = rect5.top; + mUpdateRect2.bottom = rect5.bottom; + mUpdateRect2.left = rect5.left; + mUpdateRect2.right = rect5.right; +} + +void T2TowerMainView::OnDebugNormalDisplay() { + mDebugMode = 0; + InvalidateRect(NULL); +} + +void T2TowerMainView::OnUpdateDebugNormalDisplay(CCmdUI *pCmdUI) { + if (mDebugMode == 0) + pCmdUI->SetCheck(true); + else + pCmdUI->SetCheck(false); +} + +void T2TowerMainView::OnDebugBkgndInfo() { + mDebugMode = 1; + InvalidateRect(NULL); +} + +void T2TowerMainView::OnUpdateDebugBkgndInfo(CCmdUI *pCmdUI) { + if (mDebugMode == 1) + pCmdUI->SetCheck(true); + else + pCmdUI->SetCheck(false); +} + +void T2TowerMainView::OnDebugFloorInfoTenant() { + mDebugMode = 2; + InvalidateRect(NULL); +} + +void T2TowerMainView::OnUpdateDebugFloorInfoTenant(CCmdUI *pCmdUI) { + if (mDebugMode == 2) + pCmdUI->SetCheck(true); + else + pCmdUI->SetCheck(false); +} + +void T2TowerMainView::OnDebugFloorInfoMover() { + mDebugMode = 3; + InvalidateRect(NULL); +} + +void T2TowerMainView::OnUpdateDebugFloorInfoMover(CCmdUI *pCmdUI) { + if (mDebugMode == 3) + pCmdUI->SetCheck(true); + else + pCmdUI->SetCheck(false); +} + +void T2TowerMainView::OnDebugFloorInfoRequest() { + mDebugMode = 4; + InvalidateRect(NULL); +} + +void T2TowerMainView::OnUpdateDebugFloorInfoRequest(CCmdUI *pCmdUI) { + if (mDebugMode == 4) + pCmdUI->SetCheck(true); + else + pCmdUI->SetCheck(false); +} + +void T2TowerMainView::DrawDebugBkgndInfo(CDC *pDC) { + CFont dbgFont; + dbgFont.CreateFont(-15, 10, 900, 900, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS | CLIP_LH_ANGLES, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + + CPen pen(PS_DOT, 1, RGB(0, 0, 0)); + + int saved = pDC->SaveDC(); + pDC->SelectObject(dbgFont); + pDC->SelectObject(nullBrush); + pDC->SelectObject(pen); + pDC->SetBkMode(OPAQUE); + pDC->SetViewportOrg(-mScrollOffset.x, -mScrollOffset.y); + + T2TowerDoc *theDoc = GetTowerDoc(); + char tmpStr[12]; + + RECT rect; + UT2Coordinate::UnitToBkgnd(mWorldBounds, rect); + + for (int v = rect.top; v < rect.bottom; v++) { + for (int h = rect.left; h < rect.right; h++) { + unsigned int bkgndInfo = UT2BkgndInfo::GetBkgndInfo(theDoc->mBkgndInfo, v, h); + + RECT bkgndInfoRect; + SetRect(&bkgndInfoRect, h, v, h + 1, v + 1); + UT2Coordinate::BkgndToQD(bkgndInfoRect, theDoc->mZoomLevel); + + wsprintf(tmpStr, "%04d", bkgndInfo); + pDC->TextOut(bkgndInfoRect.left, bkgndInfoRect.top + 42, tmpStr); + + pDC->Rectangle(&bkgndInfoRect); + } + } + + pDC->RestoreDC(saved); + + dbgFont.DeleteObject(); + nullBrush.DeleteObject(); + pen.DeleteObject(); +} + +void T2TowerMainView::DrawDebugFloorInfoTenant(CDC *pDC, const RECT &inRect) { + CFont dbgFont; + dbgFont.CreateFont(-9, 5, 900, 900, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS | CLIP_LH_ANGLES, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + + CPen pen(PS_DOT, 1, RGB(0, 0, 0)); + + int saved = pDC->SaveDC(); + pDC->SelectObject(dbgFont); + pDC->SelectObject(nullBrush); + pDC->SelectObject(pen); + pDC->SetBkMode(OPAQUE); + pDC->SetViewportOrg(-mScrollOffset.x, -mScrollOffset.y); + + T2TowerDoc *theDoc = GetTowerDoc(); + char tmpStr[12]; + + T2FInfoAreaIterator areaIterator(*theDoc->mFloorInfo, inRect); + T2Tenant *theTenant; + + while (areaIterator.NextTenant(theTenant)) { + if (theTenant) { + RECT tenantRect; + theTenant->GetEquipArea(tenantRect); + areaIterator.GetTenantRect(tenantRect); + UT2Coordinate::UnitToQD(tenantRect, theDoc->mZoomLevel, true); + + wsprintf(tmpStr, "%04d", theTenant->mEquipID); + pDC->TextOut(tenantRect.left, tenantRect.top + 22, tmpStr); + + wsprintf(tmpStr, "%02d", theTenant->GetStatus()); + pDC->TextOut(tenantRect.left, tenantRect.bottom - 2, tmpStr); + + pDC->Rectangle(&tenantRect); + } + } + + pDC->RestoreDC(saved); + + dbgFont.DeleteObject(); + nullBrush.DeleteObject(); + pen.DeleteObject(); +} + +void T2TowerMainView::DrawDebugFloorInfoMover(CDC *pDC, const RECT &inRect) { + CFont dbgFont; + dbgFont.CreateFont(-9, 5, 900, 900, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS | CLIP_LH_ANGLES, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + + CPen pen(PS_DOT, 1, RGB(0, 0, 0)); + + int saved = pDC->SaveDC(); + pDC->SelectObject(dbgFont); + pDC->SelectObject(nullBrush); + pDC->SelectObject(pen); + pDC->SetBkMode(OPAQUE); + pDC->SetViewportOrg(-mScrollOffset.x, -mScrollOffset.y); + + T2TowerDoc *theDoc = GetTowerDoc(); + T2MoverArrayList *theMoverList = theDoc->mFloorInfo->GetMoverArrayList(); + LArrayIterator iterator(*theMoverList); + T2MoverArray *theMoverArray; + + char tmpStr[12]; + + while (iterator.Next(&theMoverArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + if (theMoverArray->mMover[i].IsUsed()) { + T2Mover *theMover = &theMoverArray->mMover[i]; + + RECT moverRect; + theMover->GetEquipArea(moverRect); + UT2Coordinate::UnitToQD(moverRect, theDoc->mZoomLevel, true); + + wsprintf(tmpStr, "%04d", theMover->mEquipID); + pDC->TextOut(moverRect.left, moverRect.top + 22, tmpStr); + pDC->Rectangle(&moverRect); + } + } + } + + pDC->RestoreDC(saved); + + dbgFont.DeleteObject(); + nullBrush.DeleteObject(); + pen.DeleteObject(); +} + +void T2TowerMainView::DrawDebugFloorInfoRequest(CDC *pDC, const RECT &inRect) { + CFont dbgFont; + dbgFont.CreateFont(-9, 5, 900, 900, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS | CLIP_LH_ANGLES, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + + CPen pen(PS_DOT, 1, RGB(0, 0, 0)); + + int saved = pDC->SaveDC(); + pDC->SelectObject(dbgFont); + pDC->SelectObject(nullBrush); + pDC->SelectObject(pen); + pDC->SetBkMode(OPAQUE); + pDC->SetViewportOrg(-mScrollOffset.x, -mScrollOffset.y); + + T2TowerDoc *theDoc = GetTowerDoc(); + char tmpStr[12]; + + T2FInfoAreaIterator areaIterator(*theDoc->mFloorInfo, inRect); + T2Request *theReq; + + while (areaIterator.NextRequest(theReq)) { + if (!theReq->IsUsed()) + continue; + + RECT requestRect; + theReq->CalcArea(requestRect); + UT2Coordinate::UnitToQD(requestRect, theDoc->mZoomLevel); + + wsprintf(tmpStr, "%04d", theReq->mRequestID); + + if (theReq->mIsGoDown) + pDC->SetBkColor(PALETTERGB(0, 255, 255)); + else + pDC->SetBkColor(PALETTERGB(255, 0, 255)); + + pDC->TextOut(requestRect.left, requestRect.top + 22, tmpStr); + pDC->Rectangle(&requestRect); + } + + pDC->RestoreDC(saved); + + dbgFont.DeleteObject(); + nullBrush.DeleteObject(); + pen.DeleteObject(); +} + +void T2TowerMainView::DrawDebugEquip(CDC *pDC, const RECT &inRect) { + CFont dbgFont; + dbgFont.CreateFont(-9, 5, 900, 900, FW_DONTCARE, false, false, false, SHIFTJIS_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS | CLIP_LH_ANGLES, DRAFT_QUALITY, FIXED_PITCH, "\x82\x6C\x82\x72 \x83\x53\x83\x56\x83\x62\x83\x4E"); + + CBrush nullBrush; + nullBrush.CreateStockObject(NULL_BRUSH); + + CPen pen(PS_DOT, 1, RGB(0, 0, 0)); + + int saved = pDC->SaveDC(); + pDC->SelectObject(dbgFont); + pDC->SelectObject(nullBrush); + pDC->SelectObject(pen); + pDC->SetBkMode(OPAQUE); + pDC->SetViewportOrg(-mScrollOffset.x, -mScrollOffset.y); + + T2TowerDoc *theDoc = GetTowerDoc(); + T2Equip *theSelEquip = NULL; + char tmpStr[12]; + + T2TenantArrayList *theTenantArrayList = theDoc->mFloorInfo->GetTenantArrayList(); + LArrayIterator arrayIterator(*theTenantArrayList); + T2TenantArray *thisArray; + + while (arrayIterator.Next(&thisArray) && !theSelEquip) { + for (int i = 0; i < T2TenantArray::kGroupSize; i++) { + if ( + thisArray->mTenants[i].IsUsed() && + thisArray->mTenants[i].mEquipID == mDbgEquipID + ) + { + theSelEquip = &thisArray->mTenants[i]; + break; + } + } + } + + T2FInfoAreaIterator areaIterator(*theDoc->mFloorInfo, inRect); + T2Tenant *theTenant = NULL; + + while (areaIterator.NextTenant(theTenant)) { + if (theTenant && theTenant->mEquipID == mDbgEquipID) { + theSelEquip = theTenant; + break; + } + } + + if (!theSelEquip) { + T2MoverArrayList *theList = theDoc->mFloorInfo->GetMoverArrayList(); + LArrayIterator iterator(*theList); + T2MoverArray *theMoverArray; + + while (iterator.Next(&theMoverArray)) { + for (int i = 0; i < T2MoverArray::kGroupSize; i++) { + if (theMoverArray->mMover[i].IsUsed()) { + T2Mover *theMover = &theMoverArray->mMover[i]; + if (theMover->mEquipID == mDbgEquipID) { + theSelEquip = theMover; + break; + } + } + } + } + } + + if (theSelEquip) { + RECT equipArea; + theSelEquip->GetEquipArea(equipArea); + UT2Coordinate::UnitToQD(equipArea, theDoc->mZoomLevel, true); + + wsprintf(tmpStr, "%04d", theSelEquip->mEquipID); + pDC->TextOut(equipArea.left, equipArea.top + 22, tmpStr); + pDC->Rectangle(&equipArea); + } + + pDC->RestoreDC(saved); + + dbgFont.DeleteObject(); + nullBrush.DeleteObject(); + pen.DeleteObject(); +} + +void T2TowerMainView::x42CA08(const POINT &inPt) { + if (mDbgEquipID) { + mDbgEquipID = 0; + InvalidateRect(NULL); + return; + } + + POINT pt = inPt; + UT2Coordinate::QDToUnit(pt, mDocument->mZoomLevel); + + T2Equip *theEquip = NULL; + theEquip = mDocument->mFloorInfo->GetMover(pt.y, pt.x); + if (!theEquip) + theEquip = mDocument->mFloorInfo->GetTenant(pt.y, pt.x); + if (!theEquip) + theEquip = mDocument->mFloorInfo->GetFloor(pt.y, pt.x); + + if (theEquip) { + mDbgEquip = theEquip; + + DbgEquipInfo dlg(NULL); + dlg.SetEquip(theEquip); + dlg.SetDocument(mDocument); + dlg.SetTowerMainView(this); + dlg.DoModal(); + + mDbgEquipID = 0; + InvalidateRect(NULL); + tmv_vf120(); + } +} + +void T2TowerMainView::OnCommand10000to10010(UINT nCmd) { + mDbgEquip->mCEArray->FetchItemAt(nCmd - 9999, &mDbgEquipID); + InvalidateRect(NULL); +} + +/*virtual*/ void T2TowerMainView::SetScrollV(int inV) { + RECT oldRect, diff; + + oldRect = mVisibleArea; + mScrollOffset.y = inV; + x42AC1B(); + + SubtractRect(&diff, &mVisibleArea, &oldRect); + diff = mVisibleArea; + InvalUnitRect(diff, true); + tmv_vf120(); +} + +/*virtual*/ void T2TowerMainView::SetScrollH(int inH) { + RECT oldRect, diff; + + oldRect = mVisibleArea; + mScrollOffset.x = inH; + x42AC1B(); + + SubtractRect(&diff, &mVisibleArea, &oldRect); + diff = mVisibleArea; + InvalUnitRect(diff, true); + tmv_vf120(); +} + +/*virtual*/ BOOL T2TowerMainView::tmv_vf160(POINT &outPt) { + BOOL result = false; + + GetCursorPos(&outPt); + ScreenToClient(&outPt); + + CRect rect; + GetClientRect(rect); + + if (rect.PtInRect(outPt)) { + outPt.x -= mImageOrigin.x; + outPt.y -= mImageOrigin.y; + outPt.x += mScrollOffset.x; + outPt.y += mScrollOffset.y; + + mImage->SetOrigin(mScrollOffset.x, mScrollOffset.y); + if (mImage->GetPixel(outPt) != -1) + result = true; + mImage->SetOrigin(0, 0); + } + + return result; +} + +void T2TowerMainView::OnLButtonDown(UINT nFlags, CPoint point) { + SetCapture(); + + if (!mDocument || !mDocument->mIsStuffLoadedFlag) + return; + + HandleLButtonDown(point); +} + +void T2TowerMainView::HandleLButtonDown(CPoint inPt) { + mPressedButtons |= MK_LBUTTON; + mDocument->SetCursorType(kCursorNoChange, true); + + if (!mDocument || !mDocument->mIsStuffLoadedFlag) + return; + if (mDocument->towerDoc_vf1A4()) + return; + + mInitialClickPos = inPt; + + inPt.x -= mImageOrigin.x; + inPt.y -= mImageOrigin.y; + + CRect clientArea; + GetClientRect(&clientArea); + if (!clientArea.PtInRect(inPt)) + return; + + inPt.Offset(mScrollOffset); + if (!PtInRect(&mWorldBounds, m7C)) + return; + + if (!DispatchOptionEvent(kLButtonDownOptionEvent, &inPt)) + return; + + int theTool = T2_MAIN_WINDOW->mToolWindow->GetSel(); + CString *theToolName = T2_MAIN_WINDOW->mToolWindow->GetIconName(theTool); + T2ToolDef *theToolDef = (T2ToolDef *) T2_MAIN_WINDOW->mToolWindow->GetIconPlugin(theTool); + unsigned int theIconValiation = T2_MAIN_WINDOW->mToolWindow->GetIconValiation(theTool); + DWORD option = T2_MAIN_WINDOW->mToolWindow->GetIconOption(theTool); + +#line 1081 + _ASSERT(theToolName != NULL); + + RECT unitRect; + UT2Coordinate::QDToUnit(m6C, unitRect, mDocument->mZoomLevel); + + if (mAnotherToolVar == kAnotherToolVar1) { + if (mDocument->DoClickByFingerTool(inPt)) + mActiveTool = kTool4_Finger; + else + mAnotherToolVar = kAnotherToolVar0; + } else if (*theToolName == "ToolDestruct") { + mDocument->DoDestruct(inPt); + } else if (*theToolName == "ToolFinger") { + if (mDocument->DoClickByFingerTool(inPt)) + mActiveTool = kTool4_Finger; + } else if (*theToolName == "ToolInfo" && GetAsyncKeyState(VK_CONTROL) < 0) { + CPoint pt = inPt; + UT2Coordinate::QDToUnit(pt, mDocument->mZoomLevel); + + T2Tenant *theTenant = mDocument->mFloorInfo->GetTenant(pt.y, pt.x); + if (theTenant && !theTenant->IsFloor()) + theTenant->CollectCustomer(mDocument, (T2Tenant *) NULL); + } else if (*theToolName == "ToolInfo") { + mDocument->DoGetInfo(inPt); + } else if (*theToolName == "ToolZoom") { + mDocument->CallbackZoomIn(inPt); + } else if (*theToolName == "ToolHand") { + HandToolClick(mInitialClickPos); + mActiveTool = kTool5_Hand; + } else if (*theToolName == "ToolMic") { + // nothing + } else if (*theToolName == "ToolRoot") { + mDocument->DoSearchRangeTool(inPt); + } else if (option == kToolOption1) { + mActiveTool = kTool1_Tenant; + mDocument->DoClickByTenantTool(unitRect, (T2TenantDef *) theToolDef, theIconValiation); + _108.x = -1; + _108.y = inPt.y; + } else if (option == kToolOption2) { + mActiveTool = kTool2_Mover; + mDocument->DoClickByMoverTool(unitRect, (T2MoverDef *) theToolDef, theIconValiation, false); + } else if (option == kToolOption3) { + mActiveTool = kTool3_OutObj; + mDocument->DoClickByOutObjTool(unitRect, (T2OuterObjDef *) theToolDef, theIconValiation); + } + + if (mActiveTool != kTool0_Null) + mDocument->towerDoc_vf290(true); +} + +void T2TowerMainView::OnMouseMove(UINT nFlags, CPoint point) { + if (!mDocument || !mDocument->mIsStuffLoadedFlag) + return; + + if (mDocument->towerDoc_vf1A4()) { + ReleaseCapture(); + return; + } + + if (nFlags & MK_LBUTTON) { + if (!(mPressedButtons & MK_LBUTTON)) + mDocument->SetCursorType(kCursorNoChange, true); + } else { + if (mPressedButtons & MK_LBUTTON) + mDocument->SetCursorType(kCursorNoChange, false); + } + + CPoint thePoint = point; + CURSORTYPE theNextCursor = CursorType_0; + + int theTool = T2_MAIN_WINDOW->mToolWindow->GetSel(); + CString *theToolName = T2_MAIN_WINDOW->mToolWindow->GetIconName(theTool); + T2ToolDef *theToolDef = (T2ToolDef *) T2_MAIN_WINDOW->mToolWindow->GetIconPlugin(theTool); + unsigned int theIconValiation = T2_MAIN_WINDOW->mToolWindow->GetIconValiation(theTool); + DWORD option = T2_MAIN_WINDOW->mToolWindow->GetIconOption(theTool); + + _E0 = point; + _E0.x += mScrollOffset.x; + _E0.y += mScrollOffset.y; + _E0.x -= mImageOrigin.x; + _E0.y -= mImageOrigin.y; + + if (!DispatchOptionEvent(kMouseMoveOptionEvent, &_E0)) + return; + + if (_108.x != -1) + _E0.x = _108.x; + if (_108.y != -1) + _E0.y = _108.y; + + if (mActiveTool == kTool0_Null) { + if (mAnotherToolVar != kAnotherToolVar1) { + if (mToolSpriteName != "" && mToolSpriteName != "Focus") + DeleteToolSprite(); + + mActiveToolDef = NULL; + + if (option == kToolOption1) { + mActiveToolDef = theToolDef; + if (mActiveToolDef) { + mToolSpriteName = ""; + theNextCursor = mActiveToolDef->QueryCursor(mDocument, _E0, mToolSpriteName, m6C, m7C, mDocument->mZoomLevel, theIconValiation, 0); + if (mToolSpriteName != "") { + CreateToolSprite(); + mDocument->SetCursorType(kCursorDefault, false); + } else { + mDocument->SetCursorType(kCursorNo, false); + } + } + } else if (option == kToolOption2) { + mActiveToolDef = theToolDef; + if (mActiveToolDef) { + mToolSpriteName = ""; + theNextCursor = mActiveToolDef->QueryCursor(mDocument, _E0, mToolSpriteName, m6C, m7C, mDocument->mZoomLevel, theIconValiation, 0); + CreateToolSprite(); + } + } else if (option == kToolOption3) { + mActiveToolDef = theToolDef; + if (mActiveToolDef) { + mToolSpriteName = ""; + theNextCursor = mActiveToolDef->QueryCursor(mDocument, _E0, mToolSpriteName, m6C, m7C, mDocument->mZoomLevel, theIconValiation, 0); + CreateToolSprite(); + } + } + } + + BOOL var34 = false; + int var38 = kAnotherToolVar0; + + if (option == kToolOption2) { + RECT rect48; + UT2Coordinate::QDToUnit(m6C, rect48, mDocument->mZoomLevel); + + if (!mDocument->DoClickByMoverTool(rect48, (T2MoverDef *) theToolDef, theIconValiation, true)) + var38 = kAnotherToolVar2; + + CPoint pt50 = point; + pt50.x -= mImageOrigin.x; + pt50.y -= mImageOrigin.y; + pt50.Offset(mScrollOffset); + if (mDocument->towerDoc_vf23C(pt50)) + var38 = kAnotherToolVar1; + + var34 = true; + } + + if (var34) { + mAnotherToolVar = var38; + + int var54; + switch (mAnotherToolVar) { + case kAnotherToolVar0: + var54 = kCursorDefault; + break; + case kAnotherToolVar1: + var54 = kCursorFinger; + mAnotherToolVar = kAnotherToolVar3; + break; + case kAnotherToolVar2: + var54 = kCursorNo; + break; + default: + var54 = kCursorDefault; + } + + mDocument->SetCursorType(var54, false); + } + } + + if (mActiveToolDef) { + if (mAnotherToolVar != kAnotherToolVar1) { + CString theOldSprite = mToolSpriteName; + theNextCursor = mActiveToolDef->QueryCursor(mDocument, _E0, mToolSpriteName, m6C, m7C, mDocument->mZoomLevel, theIconValiation, mActiveTool != kTool0_Null); + if (theOldSprite != mToolSpriteName) { + if (theOldSprite != "") + DeleteToolSprite(); + CreateToolSprite(true); + } + + POINT spritePt; + spritePt.x = m6C.left; + spritePt.y = m6C.top; + spritePt.x <<= mDocument->mZoomLevel; + spritePt.y <<= mDocument->mZoomLevel; + + if (mToolSpriteIndex != -1 && !mHideToolSpriteCount) { + mDocument->mSprite.MoveSprite(mToolSpriteIndex, spritePt); + if (theOldSprite != mToolSpriteName) + mDocument->mSprite.ShowSprite(mToolSpriteIndex, true); + } + } + } else { + m7C = _E0; + UT2Coordinate::QDToUnit(m7C, mDocument->mZoomLevel); + } + + if (mActiveTool == kTool0_Null) { + if (mAnotherToolVar != kAnotherToolVar1 && *theToolName == "ToolMic") + mDocument->DoInterview(_E0); + } else { + point.Offset(mScrollOffset); + + CPoint unitPoint = point; + UT2Coordinate::QDToUnit(unitPoint, mDocument->mZoomLevel); + RECT unitRect; + UT2Coordinate::QDToUnit(m6C, unitRect, mDocument->mZoomLevel); + + if (thePoint != mInitialClickPos) + mDocument->_B0 = false; + + BOOL var64 = true; + if ((unitRect.right - unitRect.left) <= 0 || (unitRect.bottom - unitRect.top) <= 0) + var64 = false; + + switch (mActiveTool) { + case kTool1_Tenant: + if (var64) + mDocument->DoDragByTenantTool(unitRect); + break; + case kTool2_Mover: + if (var64) + mDocument->DoDragByMoverTool(unitRect); + break; + case kTool3_OutObj: + if (var64) + mDocument->DoDragByOutObjTool(unitRect); + break; + case kTool4_Finger: + mDocument->DoDragByFingerTool(point); + break; + case kTool5_Hand: + HandToolDrag(thePoint); + break; + } + + mDocument->_B0 = true; + } + + if (mAnotherToolVar == kAnotherToolVar3) + mAnotherToolVar = kAnotherToolVar1; +} + +void T2TowerMainView::OnLButtonUp(UINT nFlags, CPoint point) { + HandleLButtonUp(point); + ReleaseCapture(); +} + +void T2TowerMainView::HandleLButtonUp(CPoint inPt) { + mPressedButtons &= MK_RBUTTON; + mDocument->SetCursorType(kCursorNoChange, false); + + if (!mDocument) + return; + if (mDocument->towerDoc_vf1A4()) + return; + if (!mDocument->mWorldDef) + return; + + if (mActiveTool == kTool0_Null) + return; + + inPt.x -= mImageOrigin.x; + inPt.y -= mImageOrigin.y; + inPt.Offset(mScrollOffset); + + if (!DispatchOptionEvent(kLButtonUpOptionEvent, &inPt)) + return; + + if (_108.x != -1) + inPt.x = _108.x; + if (_108.y != -1) + inPt.y = _108.y; + + RECT unitRect; + CPoint unitPt = inPt; + UT2Coordinate::QDToUnit(unitPt, mDocument->mZoomLevel); + UT2Coordinate::QDToUnit(m6C, unitRect, mDocument->mZoomLevel); + + if (mActiveTool == kTool1_Tenant) + mDocument->DoReleaseByTenantTool(unitRect); + else if (mActiveTool == kTool2_Mover) + mDocument->DoReleaseByMoverTool(unitRect); + else if (mActiveTool == kTool3_OutObj) + mDocument->DoReleaseByOutObjTool(unitRect); + else if (mActiveTool == kTool4_Finger) + mDocument->DoReleaseByFingerTool(inPt); + else if (mActiveTool == kTool5_Hand) + HandToolRelease(inPt); + + _108.x = -1; + _108.y = -1; + + if (mActiveTool != kTool0_Null) + mDocument->towerDoc_vf294(); + mActiveTool = kTool0_Null; +} + +void T2TowerMainView::OnUpdateDebugGrid(CCmdUI *pCmdUI) { + pCmdUI->SetCheck(mIsDebugGrid != FALSE); +} + +void T2TowerMainView::OnDebugGrid() { + mIsDebugGrid = !mIsDebugGrid; + AdjustWorldBounds(); + tmv_vf120(); +} + +void T2TowerMainView::x42E366(int inType) { + HCURSOR cursor; + + if (inType == 0) + cursor = LoadCursor(NULL, IDC_ARROW); + else if (inType == 1) + cursor = LoadCursor(NULL, IDC_SIZENS); + else if (inType == 2) + cursor = LoadCursor(NULL, IDC_SIZEWE); + else if (inType == 3) + cursor = LoadCursor(NULL, IDC_NO); + + SetCursor(cursor); +} + +void T2TowerMainView::OnRButtonDown(UINT nFlags, CPoint point) { + if (!mDocument || !mDocument->mIsStuffLoadedFlag) + return; + + HandleRButtonDown(point); +} + +void T2TowerMainView::HandleRButtonDown(CPoint inPt) { + mPressedButtons |= MK_RBUTTON; + + if (!mDocument->mWorldDef) + return; + T2TowerDoc *theTowerDoc = GetTowerDoc(); + if (theTowerDoc->towerDoc_vf1A4()) + return; + + inPt.x -= mImageOrigin.x; + inPt.y -= mImageOrigin.y; + + CRect mainViewRect; + GetClientRect(&mainViewRect); + if (!mainViewRect.PtInRect(inPt)) + return; + + inPt.Offset(mScrollOffset); + if (!PtInRect(&mWorldBounds, m7C)) + return; + + if (!DispatchOptionEvent(kRButtonDownOptionEvent, &inPt)) + return; + + int theTool = T2_MAIN_WINDOW->mToolWindow->GetSel(); + CString *theToolName = T2_MAIN_WINDOW->mToolWindow->GetIconName(theTool); +#line 1637 + _ASSERT(theToolName != NULL); + + RECT unitRect; + UT2Coordinate::QDToUnit(m6C, unitRect, mDocument->mZoomLevel); + + if (*theToolName == "ToolZoom") + mDocument->CallbackZoomOut(); +} + +void T2TowerMainView::OnRButtonUp(UINT nFlags, CPoint point) { + if (!mDocument || !mDocument->mIsStuffLoadedFlag) + return; + + HandleRButtonUp(point); +} + +void T2TowerMainView::HandleRButtonUp(CPoint inPt) { + mPressedButtons &= MK_LBUTTON; + + T2TowerDoc *theTowerDoc = GetTowerDoc(); + if (theTowerDoc->towerDoc_vf1A4()) + return; + if (!mDocument->mWorldDef) + return; + + inPt.x -= mImageOrigin.x; + inPt.y -= mImageOrigin.y; + + CRect mainViewRect; + GetClientRect(&mainViewRect); + if (!mainViewRect.PtInRect(inPt)) + return; + + inPt.Offset(mScrollOffset); + if (!PtInRect(&mWorldBounds, m7C)) + return; + + DispatchOptionEvent(kRButtonUpOptionEvent, &inPt); +} + + +/*virtual*/ void T2TowerMainView::tmv_vf13C(int inX, int inY, unsigned int inCode) { + POINT pt; + pt.x = inX; + pt.y = inY; + tmv_vf138(pt, inCode); +} + +/*virtual*/ void T2TowerMainView::tmv_vf138(const POINT &inPt, unsigned int inCode) { +#pragma var_order(worldRect, code3, viewRect, pt, code2, code1) + int code1 = inCode & kScrollOpt2Mask; + int code2 = inCode & kScrollOptionMask; + int code3 = inCode & kScrollOpt3Mask; + + POINT pt = inPt; + if (code2 == kScroll2) + pt.y += 2; + if (code2 != kScroll3) + UT2Coordinate::UnitToQD(pt, mDocument->mZoomLevel); + + CRect viewRect, worldRect; + GetClientRect(&viewRect); + + worldRect.SetRect(0, 0, mDocument->mWorldDef->GetWidth(), mDocument->mWorldDef->GetHeight()); + UT2Coordinate::UnitToQD(worldRect, mDocument->mZoomLevel, true); + + mImageOrigin.x = viewRect.Width() - worldRect.Width(); + mImageOrigin.y = viewRect.Height() - worldRect.Height(); + + if (mImageOrigin.x < 0) + mImageOrigin.x = 0; + else + mImageOrigin.x /= 2; + + if (mImageOrigin.y < 0) + mImageOrigin.y = 0; + else + mImageOrigin.y /= 2; + + if (code2 == kScroll1) { + mNextScrollOffset.x = pt.x - viewRect.Width() / 2; + mNextScrollOffset.y = pt.y - viewRect.Height() / 2; + } else if (code2 == kScroll2) { + mNextScrollOffset.x = pt.x - viewRect.Width() / 2; + mNextScrollOffset.y = pt.y - (viewRect.Height() * 4) / 5; + } else if (code2 == kScroll3) { + mNextScrollOffset.x = pt.x; + mNextScrollOffset.y = pt.y; + } + + if (mNextScrollOffset.x < 0) { + mNextScrollOffset.x = 0; + } else if ((mNextScrollOffset.x + viewRect.Width()) > worldRect.Width()) { + mNextScrollOffset.x = worldRect.Width() - viewRect.Width(); + if (mNextScrollOffset.x < 0) + mNextScrollOffset.x = 0; + } + + if (mNextScrollOffset.y < 0) { + mNextScrollOffset.y = 0; + } else if ((mNextScrollOffset.y + viewRect.Height()) > worldRect.Height()) { + mNextScrollOffset.y = worldRect.Height() - viewRect.Height(); + if (mNextScrollOffset.y < 0) + mNextScrollOffset.y = 0; + } + + if (code1 == kScrollOpt2) { + AfxGetMainWnd()->SetScrollPos(SB_HORZ, mNextScrollOffset.x); + AfxGetMainWnd()->SetScrollPos(SB_VERT, mNextScrollOffset.y); + + mScrollOffset = mNextScrollOffset; + + x42AC1B(); + + CRect rect3(0, 0, mDocument->mWorldDef->GetWidth(), mDocument->mWorldDef->GetHeight()); + AfxGetMainWnd()->Invalidate(); + InvalUnitRect(rect3, true); + if (!code3) + tmv_vf120(); + } +} + +/*virtual*/ void T2TowerMainView::DoZoomIn(POINT inPt) { + if (mDocument->mZoomLevel <= 0) + return; + + UT2Coordinate::QDToUnit(inPt, mDocument->mZoomLevel); + mDocument->mZoomLevel--; + + InvalidateRect(NULL, false); + + T2_MAIN_WINDOW->x4144FA(); + AdjustWorldBounds(); + tmv_vf138(inPt, kScroll1 | kScrollOpt2); +} + +/*virtual*/ void T2TowerMainView::DoZoomOut() { + if (mDocument->mZoomLevel >= 2) + return; + + POINT pt; + pt.x = (mVisibleArea.right + mVisibleArea.left) / 2; + pt.y = (mVisibleArea.bottom + mVisibleArea.top) / 2; + + mDocument->mZoomLevel++; + + InvalidateRect(NULL, false); + + T2_MAIN_WINDOW->x4144FA(); + AdjustWorldBounds(); + tmv_vf138(pt, kScroll1 | kScrollOpt2); +} + +/*virtual*/ void T2TowerMainView::UnhideToolSprite() { + if (mHideToolSpriteCount == 0) + return; + + mHideToolSpriteCount--; + if (mHideToolSpriteCount != 0) + return; + + if (!mDC) + return; + + if (mToolSpriteIndex != -1) { + POINT pt; + pt.x = m6C.left; + pt.y = m6C.top; + pt.x <<= mDocument->mZoomLevel; + pt.y <<= mDocument->mZoomLevel; + + mDocument->mSprite.MoveSprite(mToolSpriteIndex, pt); + mDocument->mSprite.ShowSprite(mToolSpriteIndex, true); + Invalidate(true); + } +} + +/*virtual*/ void T2TowerMainView::HideToolSprite() { + if (mHideToolSpriteCount == 0 && mActiveToolDef && mToolSpriteIndex != -1) { + mDocument->mSprite.ShowSprite(mToolSpriteIndex, false); + Invalidate(true); + } + + mHideToolSpriteCount++; +} + +/*virtual*/ void T2TowerMainView::CenterOnRectAndZoom(const RECT &inRect) { + POINT pt = URect::Center(inRect); + mDocument->SetZoomLevel(0); + tmv_vf138(pt, kScroll1 | kScrollOpt2); +} + +/*virtual*/ void T2TowerMainView::CenterOnRect(const RECT *inRect) { + int x = inRect->left + ((inRect->right - inRect->left) + 1) / 2; + int y = inRect->top + ((inRect->bottom - inRect->top) + 1) / 2; + tmv_vf13C(x, y, kScroll1 | kScrollOpt2); +} + +/*virtual*/ void T2TowerMainView::OnUpdate(CView *pSender, LPARAM lHint, CObject *pHint) { + if (mDocument->mWorldDef) { + SetRect(&mWorldBounds, 0, 0, mDocument->mWorldDef->GetWidth(), mDocument->mWorldDef->GetHeight()); + } else { + SetRect(&mWorldBounds, 0, 0, 100, 100); + InvalidateRect(NULL); + } + + AdjustWorldBounds(); + + if (mDocument->Get22C()) { +#pragma var_order(numTileY, grayBrush, tileFlags, saved, timeBegin, index, numTiles, viewRect, numTileX, rect3, bufferRect, pDC) + T2_MAIN_WINDOW->x4144FA(); + tmv_vf138(mDocument->m188, kScroll3 | kScrollOpt2 | kScrollOpt3); + Invalidate(true); + tmv_vf11C(); + + CDC *pDC = T2_MAIN_WINDOW->GetDC(); + int saved = pDC->SaveDC(); + pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + pDC->RestoreDC(saved); + T2_MAIN_WINDOW->ReleaseDC(pDC); + + gT2App->app_vfB4(); + + pDC = GetDC(); + saved = pDC->SaveDC(); + pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + + CBrush grayBrush; + grayBrush.CreateStockObject(GRAY_BRUSH); + + CRect viewRect; + GetClientRect(viewRect); + pDC->FillRect(viewRect, &grayBrush); + + CRect bufferRect, rect3; + bufferRect.SetRect(0, 0, mImage->mBitmap.header.biWidth, mImage->mBitmap.header.biHeight); + rect3 = bufferRect; + rect3.OffsetRect(mImageOrigin); + + int numTileX = (bufferRect.Width() + 24) / 25; + int numTileY = (bufferRect.Height() + 24) / 25; + int numTiles = numTileX * numTileY; + + unsigned char *tileFlags = (unsigned char *) malloc(numTiles); + memset(tileFlags, 0, numTiles); + + DWORD timeBegin = timeGetTime(); + int index = 0; + + while (index < numTiles) { + DWORD elapsed = timeGetTime() - timeBegin; + int end = min(numTiles, (int) ((numTiles * elapsed) / 1000)); + for (; index < end; index++) { + int h, v; + do { + h = UT2Utils::Randomize(numTileX); + v = UT2Utils::Randomize(numTileY); + } while (tileFlags[h + v * numTileX]); + + tileFlags[h + v * numTileX] = true; + + CRect copyRectSrc, copyRectDest; + copyRectSrc.SetRect(h * 25, v * 25, h * 25 + 25, v * 25 + 25); + copyRectDest = copyRectSrc; + copyRectDest.OffsetRect(mImageOrigin); + mImage->CopyImage(pDC, copyRectSrc, copyRectDest); + } + } + + free(tileFlags); + + pDC->RestoreDC(saved); + ReleaseDC(pDC); + + InvalidateRect(NULL); + UpdateWindow(); + } +} + +void T2TowerMainView::OnUpdateDebugDisplaySpeedMeasuring(CCmdUI *pCmdUI) { + pCmdUI->Enable(); +} + +void T2TowerMainView::OnDebugDisplaySpeedMeasuring() { + time_t t = time(NULL); +retry: + if (time(NULL) == t) + goto retry; + + t = time(NULL); + int counter = 0; + + while ((time(NULL) - t) < 5) { + Invalidate(false); + tmv_vf120(); + counter++; + } + + CString str; + str.Format("%.2f Frames/sec.", counter / 5.0f); + MessageBox(str, "RESULT"); +} + +void T2TowerMainView::OnUpdateDebugOffscreenSpeedMeasuring(CCmdUI *pCmdUI) { + pCmdUI->Enable(); +} + +void T2TowerMainView::OnDebugOffscreenSpeedMeasuring() { + time_t t = time(NULL); + retry: + if (time(NULL) == t) + goto retry; + + t = time(NULL); + int counter = 0; + + mSkipOffscreenDraw = true; + while ((time(NULL) - t) < 5) { + Invalidate(false); + tmv_vf120(); + counter++; + } + mSkipOffscreenDraw = false; + + CString str; + str.Format("%.2f Frames/sec.", counter / 5.0f); + MessageBox(str, "RESULT"); +} + +/*virtual*/ BOOL T2TowerMainView::PreTranslateMessage(MSG *pMsg) { + return !ExecuteAttachments(pMsg->message, pMsg); +} + +void T2TowerMainView::OnTimer(UINT nIDEvent) { + if (nIDEvent == 12345) { + CPoint cursorPos; + GetCursorPos(&cursorPos); + if (WindowFromPoint(cursorPos)->m_hWnd == m_hWnd) { + if (!_EC) { + UnhideToolSprite(); + _EC = true; + } + } else { + if (_EC) { + HideToolSprite(); + _EC = false; + } + } + } else { + MSG msg; + msg.message = WM_TIMER; + msg.wParam = nIDEvent; + PreTranslateMessage(&msg); + } +} + +/*virtual*/ void T2TowerMainView::GetVisibleUnitRect(RECT &outRect) const { + CRect rect; + GetClientRect(rect); + rect.OffsetRect(mScrollOffset); + UT2Coordinate::QDToUnit(rect, outRect, mDocument->mZoomLevel); +} + +void T2TowerMainView::HandToolClick(CPoint inPt) { + mHandToolLastPos = inPt; +} + +void T2TowerMainView::HandToolDrag(CPoint inPt) { + POINT pt; + pt.x = mHandToolLastPos.x - inPt.x; + pt.y = mHandToolLastPos.y - inPt.y; + + pt.x += mScrollOffset.x; + if (pt.x < 0) + pt.x = 0; + + pt.y += mScrollOffset.y; + if (pt.y < 0) + pt.y = 0; + + mHandToolLastPos = inPt; + InvalidateRect(NULL, false); + T2_MAIN_WINDOW->x4144FA(); + tmv_vf138(pt, kScroll3 | kScrollOpt2); +} + +void T2TowerMainView::HandToolRelease(CPoint inPt) { +} + +/*virtual*/ void T2TowerMainView::tmv_vf144() { + if (!mDocument) + return; + if (!mDocument->mWorldDef) + return; + + tmv_vf138(mScrollOffset, kScroll3 | kScrollOpt2); +} + +/*virtual*/ void T2TowerMainView::OnActivateView(BOOL bActivate, CView *pActivateView, CView *pDeactiveView) { + CView::OnActivateView(bActivate, pActivateView, pDeactiveView); +} + +BOOL T2TowerMainView::CreateToolSprite(BOOL inSkipShowing) { + if (mToolSpriteName != "" && mToolSpriteIndex == -1) { + mToolSpriteIndex = mDocument->mSprite.NewSprite(*mActiveToolDef->mImageObj, mToolSpriteName, T2Sprite::ELayer_5); + if (!mHideToolSpriteCount) { + mDC = true; + if (!inSkipShowing) + mDocument->mSprite.ShowSprite(mToolSpriteIndex, true); + } + } + + return false; +} + +BOOL T2TowerMainView::DeleteToolSprite() { + if (mToolSpriteIndex != -1) { + if (!mHideToolSpriteCount) { + mDC = false; + mDocument->mSprite.ShowSprite(mToolSpriteIndex, false); + } + + mDocument->mSprite.DeleteSprite(mToolSpriteIndex); + mToolSpriteName = ""; + mToolSpriteIndex = -1; + } + + return true; +} -- cgit v1.2.3