diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/T2ToolWindow.cpp | 590 |
1 files changed, 527 insertions, 63 deletions
diff --git a/src/T2DLL/T2ToolWindow.cpp b/src/T2DLL/T2ToolWindow.cpp index 3601077..08ade6c 100644 --- a/src/T2DLL/T2ToolWindow.cpp +++ b/src/T2DLL/T2ToolWindow.cpp @@ -1,102 +1,440 @@ +#include "CT2App.h" +#include "GlobalFunc.h" +#include "T2ImageObj.h" +#include "T2MainWindow.h" +#include "T2TemplatePluginList.h" +#include "T2ToolDef.h" #include "T2ToolWindow.h" +#include "T2TowerDoc.h" +#include "T2WorldDef.h" -/*static*/ CObject* __stdcall T2ToolWindow::CreateObject() { +CObject* PASCAL T2ToolWindow::CreateObject() { +#line 16 + return DEBUG_NEW T2ToolWindow; } +IMPLEMENT_DYNAMIC(T2ToolWindow, CFrameWnd); -/*static*/ CRuntimeClass* __stdcall T2ToolWindow::_GetBaseClass() { -} +T2ToolWindow::T2ToolWindow() { +#line 20 + mToolIconList = DEBUG_NEW T2ToolIconList; -/*virtual*/ CRuntimeClass* T2ToolWindow::GetRuntimeClass() const { -} + mDocument = NULL; + mWorldDef = NULL; + mSel = -1; + mListCtrl = NULL; + mTimerID = 0; -T2ToolWindow::T2ToolWindow() { + for (int i = 0; i < 16; i++) + _D8[i] = NULL; + + _118 = 1; } /*virtual*/ T2ToolWindow::~T2ToolWindow() { + delete mToolIconList; } -/*virtual*/ void T2ToolWindow::SetDocument(T2TowerDoc*) { +/*virtual*/ void T2ToolWindow::SetDocument(T2TowerDoc* inDoc) { + mDocument = inDoc; + mWorldDef = inDoc->mWorldDef; } -/*static*/ const AFX_MSGMAP* __stdcall T2ToolWindow::_GetBaseMessageMap() { -} +BEGIN_MESSAGE_MAP(T2ToolWindow, CFrameWnd) + ON_WM_QUERYNEWPALETTE() + ON_WM_ERASEBKGND() + ON_WM_CREATE() + ON_WM_LBUTTONDOWN() + ON_WM_LBUTTONUP() + ON_WM_MOUSEMOVE() + ON_WM_LBUTTONDBLCLK() + ON_WM_TIMER() + ON_WM_DESTROY() + ON_WM_CLOSE() +END_MESSAGE_MAP() -/*virtual*/ const AFX_MSGMAP* T2ToolWindow::GetMessageMap() const { -} +afx_msg BOOL T2ToolWindow::OnQueryNewPalette() { + if (!mDocument || !mDocument->mWorldDef) + return CFrameWnd::OnQueryNewPalette(); -int T2ToolWindow::OnQueryNewPalette() { + CDC *pDC = GetDC(); + pDC->SaveDC(); + pDC->SelectPalette(mDocument->mWorldDef->GetPalette(), false); + pDC->RealizePalette(); + pDC->RestoreDC(-1); + ReleaseDC(pDC); + return true; } -int T2ToolWindow::OnCreate(CREATESTRUCTA*) { +afx_msg int T2ToolWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) { + if (CFrameWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + return OnCreateProc(lpCreateStruct); } /*virtual*/ int T2ToolWindow::GetSel() { + return mSel; } -/*virtual*/ void T2ToolWindow::SetSel(int) { +/*virtual*/ void T2ToolWindow::SetSel(int inID) { + if (SearchID(inID)) + SelChange(inID); } -/*virtual*/ CString* T2ToolWindow::GetIconName(int) { +/*virtual*/ CString* T2ToolWindow::GetIconName(int inID) { + static CString defaultName = ""; + + POSITION pos = SearchID(inID); + if (!pos) + return &defaultName; + + return &mToolIconList->GetAt(pos)->mName; } -/*virtual*/ T2TemplatePlugin* T2ToolWindow::GetIconPlugin(int) { +/*virtual*/ T2TemplatePlugin* T2ToolWindow::GetIconPlugin(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return NULL; + + return mToolIconList->GetAt(pos)->mPlugin; } -/*virtual*/ unsigned long T2ToolWindow::GetIconOption(int) { +/*virtual*/ DWORD T2ToolWindow::GetIconOption(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return 0; + + return mToolIconList->GetAt(pos)->mOption; } -/*virtual*/ unsigned int T2ToolWindow::GetIconValiation(int) { +/*virtual*/ unsigned int T2ToolWindow::GetIconValiation(int inID) { + POSITION pos = SearchID(inID); + if (!pos) + return 0; + + return mToolIconList->GetAt(pos)->mValiation; } -/*virtual*/ void T2ToolWindow::AddIcon(const char*, char*, unsigned int, unsigned long, T2ToolDef*, int, unsigned short, T2ToolCallback*) { +/*virtual*/ void T2ToolWindow::AddIcon(const char* inName, char* inStr2, unsigned int inValiation, DWORD inOption, T2ToolDef* inToolDef, int inFld18, unsigned short inSomeMask, T2ToolCallback* inToolCallback) { + T2ToolIconItem *theToolIconItem; + POSITION position = mToolIconList->GetHeadPosition(); + while (position) { + theToolIconItem = mToolIconList->GetNext(position); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return; + } + +#line 145 + T2ToolIconItem *theItem = DEBUG_NEW T2ToolIconItem; + theItem->mID = AssignNewID(); + theItem->mName = inName; + theItem->mValiation = inValiation; + theItem->mOption = inOption; + theItem->m18 = inFld18; + theItem->m1C = inSomeMask; + theItem->mToolCallback = inToolCallback; + theItem->mToolDef = inToolDef; + + unsigned short mask = 1; + if (mDocument->mViewMode == ViewMode_1) + mask = 2; + + if (inSomeMask & mask) + theItem->m30 = 1; + else + theItem->m30 = 0; + + if (inStr2) + theItem->m2C = inStr2; + + if (RefreshItem(theItem)) { + mToolIconList->AddTail(theItem); + ListUpdated(); + } } -/*virtual*/ void T2ToolWindow::AddIcon(const char*, unsigned short, char*, T2ToolCallback*) { +/*virtual*/ void T2ToolWindow::AddIcon(const char* inName, unsigned short inSomeMask, char* inStr2, T2ToolCallback* inToolCallback) { + AddIcon(inName, inStr2, 0, 0, NULL, 0, inSomeMask, inToolCallback); } -/*virtual*/ void T2ToolWindow::RemoveIcon(const char*, unsigned int) { +/*virtual*/ void T2ToolWindow::RemoveIcon(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION prevPos; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + prevPos = pos; + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { + RemoveItem(prevPos); + mToolIconList->RemoveAt(prevPos); + delete theToolIconItem; + ListUpdated(); + break; + } + } } /*virtual*/ void T2ToolWindow::RemoveAll() { + delete mToolIconList; +#line 204 + mToolIconList = DEBUG_NEW T2ToolIconList; + + ListUpdated(); + SelChange(1); } -/*virtual*/ int T2ToolWindow::GetID(const char*, unsigned int) { +/*virtual*/ int T2ToolWindow::GetID(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return theToolIconItem->mID; + } + + return -1; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(const char*, unsigned int) { +/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(const char* inName, unsigned int inValiation) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) + return theToolIconItem; + } + + return NULL; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(int) { +/*virtual*/ T2ToolIconItem* T2ToolWindow::GetItem(int inID) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mID == inID) + return theToolIconItem; + } + + return NULL; } /*virtual*/ void T2ToolWindow::Refresh() { -} + POSITION pos = mToolIconList->GetHeadPosition(); + while (pos) { + while (pos) { + T2ToolIconItem *theToolIconItem = mToolIconList->GetNext(pos); + if (!RefreshItem(theToolIconItem)) { + pos = mToolIconList->GetHeadPosition(); + break; + } + } + } -/*virtual*/ int T2ToolWindow::RefreshItem(T2ToolIconItem*) { + Updated(); } -/*virtual*/ T2TemplatePlugin* T2ToolWindow::SearchPlugin(T2TemplatePluginList*, CString&) { -} +/*virtual*/ BOOL T2ToolWindow::RefreshItem(T2ToolIconItem* inItem) { +#line 269 + _ASSERT(mWorldDef != NULL); + _ASSERT(mDocument != NULL); -/*virtual*/ POSITION T2ToolWindow::SearchID(int) { -} + inItem->mPlugin = NULL; -/*virtual*/ int T2ToolWindow::AssignNewID() { -} + if (mDocument->mTenantTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mTenantTemplates, inItem->mName); -/*virtual*/ void T2ToolWindow::RemoveItem(POSITION) { -} + if (!inItem->mPlugin && mDocument->mMoverTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mMoverTemplates, inItem->mName); -/*virtual*/ void T2ToolWindow::SelChange(int) { + if (!inItem->mPlugin && mDocument->mOuterObjTemplates) + inItem->mPlugin = SearchPlugin(mDocument->mOuterObjTemplates, inItem->mName); + + if (!inItem->mPlugin && mWorldDef->m1D0->FindObject(inItem->mName) != -1) + inItem->mPlugin = mWorldDef; + + if (!inItem->mPlugin) { + POSITION pos = mToolIconList->Find(inItem); + if (pos) { + RemoveItem(pos); + mToolIconList->RemoveAt(pos); + } + delete inItem; + return false; + } + + return true; } -/*virtual*/ int T2ToolWindow::EnableIcon(const char*, unsigned int, int) { +/*virtual*/ T2TemplatePlugin* T2ToolWindow::SearchPlugin(T2TemplatePluginList* inList, CString& inName) { + LArrayIterator iterator(*inList); + T2TemplatePlugin *thePlugin; + + while (iterator.Next(&thePlugin)) { + if (thePlugin->mStr48 == inName) + return thePlugin; + } + + return NULL; } -/*virtual*/ void T2ToolWindow::EnableIcon(int) { +/*virtual*/ POSITION T2ToolWindow::SearchID(int inID) { + T2ToolIconItem *theToolIconItem; + POSITION prevPos; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + prevPos = pos; + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mID == inID) + return prevPos; + } + + return NULL; } -/*virtual*/ T2ToolIconItem* T2ToolWindow::EnableIcon(unsigned short) { +/*virtual*/ int T2ToolWindow::AssignNewID() { + for (int id = 0; id < 10000; id++) { + if (!SearchID(id)) + return id; + } + + return -1; +} + +/*virtual*/ void T2ToolWindow::RemoveItem(POSITION inPos) { +#line 334 + _ASSERT(inPos != NULL); + + T2ToolIconItem *theToolIconItem = mToolIconList->GetAt(inPos); + if (theToolIconItem->mID == mSel) { + theToolIconItem = mToolIconList->GetAt(mToolIconList->GetHeadPosition()); + ListUpdated(); + SelChange(theToolIconItem->mID); + } +} + +/*virtual*/ void T2ToolWindow::SelChange(int inID) { + mSel = inID; + Updated(); +} + +/*virtual*/ BOOL T2ToolWindow::EnableIcon(const char* inName, unsigned int inValiation, BOOL inFlag) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (theToolIconItem->mName == inName && theToolIconItem->mValiation == inValiation) { + if (inFlag) + theToolIconItem->mEnableCount--; + else + theToolIconItem->mEnableCount++; + RedrawButton(); + return true; + } + } + + return false; +} + +/*virtual*/ void T2ToolWindow::EnableIcon(BOOL inFlag) { + T2ToolIconItem *theToolIconItem; + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + if (inFlag) { + if (theToolIconItem->mEnableCount) + theToolIconItem->mEnableCount--; + } else { + theToolIconItem->mEnableCount++; + } + } + + RedrawButton(); +} + +/*virtual*/ T2ToolIconItem* T2ToolWindow::EnableIcon(unsigned short inMask) { + T2ToolIconItem *theToolIconItem; + T2ToolIconItem *oldSelectedItem = NULL; + T2ToolIconItem *selectedItem = NULL; + + POSITION pos = mToolIconList->GetHeadPosition(); + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + unsigned int flag = 0; + if (theToolIconItem->m1C & inMask) + flag = 1; + theToolIconItem->m30 = flag; + + if (theToolIconItem->m24) { + if (theToolIconItem->mOption == 4 || theToolIconItem->mOption == 0) { + _D8[_118] = theToolIconItem; + if (!flag) + oldSelectedItem = theToolIconItem; + } + } + } + + for (unsigned short what = 1; what < 16; what++) { + if ((what & inMask) && _D8[what]) { + theToolIconItem = _D8[what]; + if (theToolIconItem->mOption == 4 || theToolIconItem->mOption == 0) { + if (theToolIconItem->m30 && !theToolIconItem->m18) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + if (oldSelectedItem) { + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + } + } + } + } + } + + if (oldSelectedItem && oldSelectedItem->mOption == 4) { + pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->m30 && theToolIconItem->mOption == 4 && !theToolIconItem->m18) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + break; + } + } + } + + if (oldSelectedItem) { + pos = mToolIconList->GetHeadPosition(); + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + if (theToolIconItem->m30 && theToolIconItem->mOption == 0) { + theToolIconItem->m24 = true; + selectedItem = theToolIconItem; + oldSelectedItem->m24 = false; + oldSelectedItem = NULL; + break; + } + } + } + + if (selectedItem) + SelChange(selectedItem->mID); + + RedrawButton(); + Updated(); + _118 = inMask & 0xF; + + return selectedItem; } /*virtual*/ void T2ToolWindow::RedrawButton() { @@ -106,85 +444,211 @@ int T2ToolWindow::OnCreate(CREATESTRUCTA*) { } /*virtual*/ void T2ToolWindow::ListUpdated() { + if (mListCtrl) { + mListCtrl->DeleteAllItems(); + + POSITION pos = mToolIconList->GetHeadPosition(); + T2ToolIconItem *theToolIconItem; + int row = 0; + CString text; + + while (pos) { + theToolIconItem = mToolIconList->GetNext(pos); + + mListCtrl->InsertItem(row, theToolIconItem->mName); + + text.Format("%d", theToolIconItem->mValiation); + mListCtrl->SetItemText(row, 1, text); + + text.Format("%d", theToolIconItem->mID); + mListCtrl->SetItemText(row, 2, text); + + mListCtrl->SetItemText(row, 3, theToolIconItem->mPlugin->mStr48); + + mListCtrl->SetItemData(row, (DWORD) theToolIconItem->mID); + + row++; + } + } } -void T2ToolWindow::StartTimer(unsigned int) { +void T2ToolWindow::StartTimer(UINT inDelay) { + if (mTimerID) + KillTimer(mTimerID); + + mTimerID = SetTimer(1, inDelay, NULL); } void T2ToolWindow::StopTimer() { -} + if (mTimerID) + KillTimer(mTimerID); -int T2ToolWindow::OnEraseBkgnd(CDC*) { + mTimerID = 0; } -void T2ToolWindow::OnLButtonDown(unsigned int, CPoint) { +afx_msg BOOL T2ToolWindow::OnEraseBkgnd(CDC* pDC) { + return OnEraseBkgndProc(pDC); } -void T2ToolWindow::OnLButtonUp(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnLButtonDown(UINT nFlags, CPoint point) { + OnLButtonDownProc(nFlags, point); } -void T2ToolWindow::OnMouseMove(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnLButtonUp(UINT nFlags, CPoint point) { + OnLButtonUpProc(nFlags, point); } -void T2ToolWindow::OnLButtonDblClk(unsigned int, CPoint) { -} +afx_msg void T2ToolWindow::OnMouseMove(UINT nFlags, CPoint point) { + CWinApp *theApp = AfxGetApp(); + HCURSOR cursor = theApp->LoadStandardCursor(IDC_ARROW); + if (cursor) + SetCursor(cursor); -void T2ToolWindow::OnTimer(unsigned int) { + OnMouseMoveProc(nFlags, point); } -void T2ToolWindow::OnSize(unsigned int, int, int) { +afx_msg void T2ToolWindow::OnLButtonDblClk(UINT nFlags, CPoint point) { + OnLButtonDblClkProc(nFlags, point); } -void T2ToolWindow::OnDestroy() { -} +afx_msg void T2ToolWindow::OnTimer(UINT nIDEvent) { + if (nIDEvent == 1) + OnTimerProc(nIDEvent); -/*virtual*/ int T2ToolWindow::OnCreateProc(CREATESTRUCTA*) { + CWnd::OnTimer(nIDEvent); } -/*virtual*/ int T2ToolWindow::OnEraseBkgndProc(CDC*) { +afx_msg void T2ToolWindow::OnSize(UINT nType, int cx, int cy) { + OnSizeProc(nType, cx, cy); + ListUpdated(); } -/*virtual*/ void T2ToolWindow::OnLButtonDownProc(unsigned int, CPoint) { +afx_msg void T2ToolWindow::OnDestroy() { + StopTimer(); + + if (mListCtrl) { + mListCtrl->DestroyWindow(); + delete mListCtrl; + } + + if (gT2App->mMainWindow) + gT2App->mMainWindow->mToolWindow = NULL; + + CFrameWnd::OnDestroy(); } -/*virtual*/ void T2ToolWindow::OnLButtonUpProc(unsigned int, CPoint) { +/*virtual*/ int T2ToolWindow::OnCreateProc(LPCREATESTRUCT lpCreateStruct) { + CRect listArea; + listArea.SetRect(0, 0, 300, 400); + + CRect windowArea, clientArea; + GetWindowRect(windowArea); + GetClientRect(clientArea); + + SetWindowPos( + NULL, + 0, + 100, + listArea.Width() + windowArea.Width() - clientArea.Width(), + listArea.Height() + windowArea.Height() - clientArea.Height(), + SWP_NOZORDER + ); + +#line 615 + mListCtrl = DEBUG_NEW CListCtrl; + + mListCtrl->Create( + LVS_REPORT | LVS_SINGLESEL | WS_VSCROLL | WS_VISIBLE | WS_CHILD, + listArea, + this, + 100 + ); + + mListCtrl->InsertColumn(0, "Name", LVCFMT_LEFT, 100); + mListCtrl->InsertColumn(1, "Val", LVCFMT_LEFT, 40); + mListCtrl->InsertColumn(2, "ID", LVCFMT_LEFT, 40); + mListCtrl->InsertColumn(3, "Plugin", LVCFMT_LEFT, 120); + + Updated(); + + return 0; } -/*virtual*/ void T2ToolWindow::OnMouseMoveProc(unsigned int, CPoint) { +/*virtual*/ BOOL T2ToolWindow::OnEraseBkgndProc(CDC* pDC) { + return CFrameWnd::OnEraseBkgnd(pDC); } -/*virtual*/ void T2ToolWindow::OnLButtonDblClkProc(unsigned int, CPoint) { +/*virtual*/ void T2ToolWindow::OnLButtonDownProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonDown(nFlags, point); } -/*virtual*/ void T2ToolWindow::OnTimerProc(unsigned int) { +/*virtual*/ void T2ToolWindow::OnLButtonUpProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonUp(nFlags, point); } -/*virtual*/ void T2ToolWindow::OnSizeProc(unsigned int, int, int) { +/*virtual*/ void T2ToolWindow::OnMouseMoveProc(UINT nFlags, CPoint point) { + CWnd::OnMouseMove(nFlags, point); } -void T2ToolWindow::OnClose() { +/*virtual*/ void T2ToolWindow::OnLButtonDblClkProc(UINT nFlags, CPoint point) { + CWnd::OnLButtonDblClk(nFlags, point); } -/*virtual*/ int T2ToolWindow::OnNotify(unsigned int, long, long*) { +/*virtual*/ void T2ToolWindow::OnTimerProc(UINT nIDEvent) { } -/*static*/ const CRuntimeClass T2ToolWindow::classT2ToolWindow { +/*virtual*/ void T2ToolWindow::OnSizeProc(UINT nType, int cx, int cy) { } -/*static*/ const AFX_MSGMAP T2ToolWindow::messageMap { +afx_msg void T2ToolWindow::OnClose() { + if (!mDocument) + return; + + mDocument->towerDoc_vf198(2); } -/*static*/ const AFX_MSGMAP_ENTRY* const T2ToolWindow::_messageEntries { +/*virtual*/ BOOL T2ToolWindow::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { + if (wParam == 100 && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && mListCtrl->GetSelectedCount() == 1) { + int row, count; + + count = mListCtrl->GetItemCount(); + for (row = 0; row < count; row++) { + if (mListCtrl->GetItemState(row, LVIS_SELECTED)) + break; + } + + SelChange(row); + } + + return CWnd::OnNotify(wParam, lParam, pResult); } + + T2ToolIconItem::T2ToolIconItem() { + mPlugin = NULL; + mName = ""; + mValiation = 0; + mOption = 0; + mID = -1; + m24 = false; + mEnableCount = 0; + m30 = 1; } /*virtual*/ T2ToolIconItem::~T2ToolIconItem() { } + + T2ToolIconList::T2ToolIconList() { } /*virtual*/ T2ToolIconList::~T2ToolIconList() { + T2ToolIconItem *theToolIconItem; + POSITION pos = GetHeadPosition(); + while (pos) { + theToolIconItem = GetNext(pos); + delete theToolIconItem; + } } |