summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2TowerMessage.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-28 22:22:32 +0100
commitc0c336500955a23e344651e5412c9d9d441ef4ee (patch)
tree790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2TowerMessage.cpp
parent37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff)
downloadt2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz
t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip
first pass of T2DLL
Diffstat (limited to '')
-rw-r--r--src/T2DLL/T2TowerMessage.cpp322
1 files changed, 305 insertions, 17 deletions
diff --git a/src/T2DLL/T2TowerMessage.cpp b/src/T2DLL/T2TowerMessage.cpp
index 32b7815..0f6e7a7 100644
--- a/src/T2DLL/T2TowerMessage.cpp
+++ b/src/T2DLL/T2TowerMessage.cpp
@@ -1,61 +1,349 @@
+#include "GlobalFunc.h"
+#include "LArray.h"
+#include "T2Balloon.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, T2TowerDoc*) {
+T2TowerMessage::T2TowerMessage(HINSTANCE inModuleHandle, T2TowerDoc* inDoc) {
+ mDocument = inDoc;
+ _14 = 0;
+ mModuleHandle = inModuleHandle;
+
+ mInfoBarMsgItems = new LArray;
+ mEquipBalloonMessages = new LArray;
+ mObjectBalloonMessages = new LArray;
+
+ mHasCapture = false;
+
+ inDoc->GetTowerMainView()->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&, int, const char*) {
+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*) {
+void T2TowerMessage::SetInfoBarMsg(InfoBarMsgItem* inItem) {
+ CString empty;
+ CString *theString = inItem ? &inItem->mText : &empty;
+ mDocument->towerDoc_vf164(*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&, T2Equip*) {
+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&, T2People*) {
+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&, POINT) {
+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&) {
+void T2TowerMessage::BuildErr(const CString& inText) {
+ POINT otherPt = mDocument->GetTowerMainView()->m7C;
+
+ (new T2Message)->ShowMessage(inText);
}
-void T2TowerMessage::BuildErr(unsigned int, T2EquipDef*) {
+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);
+ }
}
-int T2TowerMessage::GetBuildErrString(unsigned int, CString&) {
+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&, const RECT&) {
+void T2TowerMessage::ObjectBalloonMessage(const CString& inText, const RECT& inRect) {
+ T2TowerMainView *theView = mDocument->GetTowerMainView();
+
+ 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&, int, int) {
+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&, int) {
+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()->GetTowerMainView()->m64;
+
+ 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);
}
-/*virtual*/ void T2TowerMessage::ExecuteSelf(unsigned int, void*) {
+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;
+ }
+ }
+ }
}
-CWnd* T2TowerMessage::FindFloatingWindow(int) {
+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::CancelInfoBarMessage(const CString&) {
+void T2TowerMessage::SetCaptureRect(RECT inRect) {
+ mCaptureRect = inRect;
+ mHasCapture = true;
}
-void T2TowerMessage::PassiveInfoBarMessage(const char*, int, const char*) {
+
+
+InfoBarMsgItem::InfoBarMsgItem(const CString &inText, int inDelay, const char *inSoundID) {
+ mSoundID = "";
+
+ mText = inText;
+ mDelay = inDelay;
+ if (inSoundID)
+ mSoundID = inSoundID;
+ mEndTicks = 0;
}
-void T2TowerMessage::SetCaptureRect(RECT) {
+InfoBarMsgItem::~InfoBarMsgItem() {
}