#include "StdAfx.h" #include "GlobalFunc.h" #include "LArray.h" #include "T2Balloon.h" #include "T2DLL.h" #include "T2Equip.h" #include "T2EquipDef.h" #include "T2Message.h" #include "T2People.h" #include "T2SoundPlayer.h" #include "T2StewardDialog.h" #include "../T2TowerDoc.h" #include "../T2TowerMainView.h" #include "T2TowerMessage.h" #include "UT2Coordinate.h" T2TowerMessage::T2TowerMessage(HINSTANCE inModuleHandle, T2TowerDoc* inDoc) { mDocument = inDoc; _14 = 0; mModuleHandle = inModuleHandle; mInfoBarMsgItems = new LArray; mEquipBalloonMessages = new LArray; mObjectBalloonMessages = new LArray; mHasCapture = false; inDoc->GetMainView()->AddAttachment(this); } /*virtual*/ T2TowerMessage::~T2TowerMessage() { T2Balloon *theT2Balloon; LArrayIterator iterator1(*mEquipBalloonMessages); while (iterator1.Next(&theT2Balloon)) { mEquipBalloonMessages->Remove(&theT2Balloon); iterator1.Reset(); } LArrayIterator iterator2(*mObjectBalloonMessages); while (iterator2.Next(&theT2Balloon)) { mObjectBalloonMessages->Remove(&theT2Balloon); iterator2.Reset(); } if (mInfoBarMsgItems) { InfoBarMsgItem *theItem; while (mInfoBarMsgItems->FetchItemAt(1, &theItem)) { mInfoBarMsgItems->RemoveItemsAt(1, 1); delete theItem; } delete mInfoBarMsgItems; } delete mEquipBalloonMessages; delete mObjectBalloonMessages; } void T2TowerMessage::InfoBarMessage(const CString& inText, int inDelay, const char* inSoundID) { if (mInfoBarMsgItems && mInfoBarMsgItems->GetCount() < 20) { InfoBarMsgItem *theMsgItem = new InfoBarMsgItem(inText, (inDelay * 1000) / 60, inSoundID); int index = mInfoBarMsgItems->GetCount() + 1; mInfoBarMsgItems->InsertItemsAt(1, index, &theMsgItem); } } void T2TowerMessage::SetInfoBarMsg(InfoBarMsgItem* inItem) { CString empty; CString *theString = inItem ? &inItem->mText : ∅ mDocument->SetInfoBarText(*theString); if (inItem && inItem->mSoundID != "") Sounds->Play(inItem->mSoundID, SoundMask_10, SoundFlags_10, NULL, PlayMode_0, 100); if (inItem && inItem->mDelay != -1) inItem->mEndTicks = GetTickCount() + inItem->mDelay; } void T2TowerMessage::EquipBalloonMessage(const CString& inText, T2Equip* inEquip) { if (inEquip) { RECT equipArea; inEquip->GetEquipArea(equipArea); CPoint pt; pt.y = equipArea.top + (equipArea.bottom - equipArea.top) / 2; pt.x = equipArea.left + (equipArea.right - equipArea.left) / 2; UT2Coordinate::UnitToQD(pt); EquipBalloonMessage(inText, pt); } } void T2TowerMessage::PeopleBalloonMessage(const CString& inText, T2People* inPeople) { if (inPeople) { CRect silhouetteArea; inPeople->CalcWalkingSilhouetteArea(silhouetteArea); CPoint pt = silhouetteArea.CenterPoint(); UT2Coordinate::UnitToQD(pt); EquipBalloonMessage(inText, pt); } } void T2TowerMessage::EquipBalloonMessage(const CString& inText, POINT inPt) { T2Balloon *theBalloon = new T2Balloon; theBalloon->Show(inPt.x, inPt.y, inText, false); mEquipBalloonMessages->Add(&theBalloon); } void T2TowerMessage::BuildErr(const CString& inText) { POINT otherPt = mDocument->GetMainView()->m7C; (new T2Message)->ShowMessage(inText); } void T2TowerMessage::BuildErr(unsigned int inID, T2EquipDef* inDef) { CString errString; if (GetBuildErrString(inID, errString)) { if (inDef) { CString nameString; inDef->GetToolName(nameString, 0); errString = nameString + errString; } BuildErr(errString); } } BOOL T2TowerMessage::GetBuildErrString(unsigned int inID, CString& outStr) { BOOL ok = (inID > 0 && inID < 76); if (ok) outStr = LoadStringTable(INSTANCE_ANY, 9999, inID); return ok; } void T2TowerMessage::ObjectBalloonMessage(const CString& inText, const RECT& inRect) { T2TowerMainView *theView = mDocument->GetMainView(); CRect rect = inRect; UT2Coordinate::UnitToQD(rect, 0, true); CPoint pt = rect.CenterPoint(); T2Balloon *balloon = new T2Balloon; balloon->Show(pt.x, pt.y, inText, false); SetCaptureRect(rect); mObjectBalloonMessages->Add(&balloon); } void T2TowerMessage::InfoDialogMessage(const CString& inText, int inID, int inDelay) { CWnd *search = CWnd::GetForegroundWindow(); while (search) { if (search->ContinueModal()) break; search = search->GetNextWindow(); } if (search) { CWnd *window = search->GetDescendantWindow(inID); if (window) { CString previousText; if (inDelay != -1) window->GetWindowText(previousText); window->SetWindowText(inText); window->RedrawWindow(); if (inDelay != -1) { DWORD time = GetTickCount() + inDelay; while (time > GetTickCount()) {} window->SetWindowText(previousText); window->RedrawWindow(); } } } } void T2TowerMessage::AleatMessage(const CString& inText, int inAlertType) { switch (inAlertType) { case kAlertType0: T2StewardDialog::MessageBox(inText, "Stop"); break; case kAlertType1: T2StewardDialog::MessageBox(inText, "Note"); break; case kAlertType2: T2StewardDialog::MessageBox(inText, "Caution"); break; default: T2StewardDialog::MessageBox(inText, "Question"); break; } } void T2TowerMessage::SpendTime() { if (mInfoBarMsgItems) { BOOL done = false; InfoBarMsgItem *theMsgItem; while (mInfoBarMsgItems->GetCount() > 0) { done = false; if (mInfoBarMsgItems->FetchItemAt(1, &theMsgItem)) { if (!theMsgItem->mEndTicks) SetInfoBarMsg(theMsgItem); if (theMsgItem->mDelay == -1 || theMsgItem->mEndTicks < GetTickCount()) { mInfoBarMsgItems->RemoveItemsAt(1, 1); done = (theMsgItem->mDelay != -1); delete theMsgItem; } else { break; } } } if (done) SetInfoBarMsg(NULL); } } void T2TowerMessage::SpendTime2() { T2Balloon *balloon; DWORD time = GetTickCount(); // these arbitrary letter suffixes are just there // so that the compiler puts the vars in the right order LArrayIterator balloonIteratorM(*mEquipBalloonMessages); while (balloonIteratorM.Next(&balloon)) { if (balloon->mEndTime < time) { mEquipBalloonMessages->Remove(&balloon); delete balloon; balloonIteratorM.ResetTo(1); } } LArrayIterator balloonIteratorP(*mObjectBalloonMessages); while (balloonIteratorP.Next(&balloon)) { if (balloon->mEndTime < time) { mObjectBalloonMessages->Remove(&balloon); delete balloon; balloonIteratorP.ResetTo(1); mHasCapture = false; } } } /*virtual*/ void T2TowerMessage::ExecuteSelf(unsigned int inMessage, void* ioData) { BOOL newExecuteHost = true; switch (inMessage) { case WM_MOUSEMOVE: if (mHasCapture) { MSG *pMsg = (MSG *) ioData; CPoint pt; pt.x = LOWORD(pMsg->lParam); pt.y = HIWORD(pMsg->lParam); pt += GetCurrentT2TowerDoc()->GetMainView()->mScrollOffset; if (PtInRect(&mCaptureRect, pt)) { newExecuteHost = false; break; } mHasCapture = false; } case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: if (mObjectBalloonMessages->GetCount() > 0) { T2Balloon *balloon; LArrayIterator balloonIterator(*mObjectBalloonMessages); while (balloonIterator.Next(&balloon)) { mObjectBalloonMessages->Remove(&balloon); delete balloon; balloonIterator.ResetTo(1); mHasCapture = false; } } break; } SetExecuteHost(newExecuteHost); } CWnd* T2TowerMessage::FindFloatingWindow(int inID) { CWnd *window = CWnd::GetForegroundWindow(); while (window) { if (window->IsWindowVisible() && window->GetDlgCtrlID() == inID) break; window = window->GetNextWindow(); } return window; } void T2TowerMessage::CancelInfoBarMessage(const CString& inText) { if (mInfoBarMsgItems) { InfoBarMsgItem *theMsgItem = NULL; LArrayIterator iterator(*mInfoBarMsgItems); while (iterator.Next(&theMsgItem)) { if (iterator.GetCurrentIndex() > 1 && !inText.Compare(theMsgItem->mText)) { mInfoBarMsgItems->RemoveItemsAt(1, iterator.GetCurrentIndex()); iterator.Reset(); delete theMsgItem; } } } } void T2TowerMessage::PassiveInfoBarMessage(const char* inText, int inDelay, const char* inSoundID) { BOOL done = false; if (mInfoBarMsgItems) { InfoBarMsgItem *theMsgItem = NULL; LArrayIterator iterator(*mInfoBarMsgItems); while (!done && iterator.Next(&theMsgItem)) done = !strcmp(inText, theMsgItem->mText); if (!done) InfoBarMessage(inText, inDelay, inSoundID); } } void T2TowerMessage::SetCaptureRect(RECT inRect) { mCaptureRect = inRect; mHasCapture = true; } InfoBarMsgItem::InfoBarMsgItem(const CString &inText, int inDelay, const char *inSoundID) { mSoundID = ""; mText = inText; mDelay = inDelay; if (inSoundID) mSoundID = inSoundID; mEndTicks = 0; } InfoBarMsgItem::~InfoBarMsgItem() { }