// MenuGroup.cpp: implementation of the CMenuGroup class. // ////////////////////////////////////////////////////////////////////// #include "MenuGroup.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMenuGroup::CMenuGroup(int x,int y,int cols,int rows, UINT uiImgs,UINT uiCont,HINSTANCE hInstance){ ix=x; iy=y; icols=cols; irows=rows; uiImages=uiImgs; uiContent=uiCont; iLastClicked=0; (GameEngine::GetEngine()->GetMenuOpen())?bClosed=false:bClosed=true; bMouseDown=false; pMenuItems=new CMenuItem*[cols*rows+1]; pMenuItems[0]=new CMenuItem(uiImgs,hInstance); pMenuItems[0]->SetPosition(x,y); pMenuItems[0]->SetContent(0); int nextX=x; int nextY=y+pMenuItems[0]->GetHeight(); for(int i=0;iSetPosition(nextX,nextY); nextY+=pMenuItems[i*rows+j+1]->GetHeight(); pMenuItems[i*rows+j+1]->SetContent(uiContent+i*rows+j); } nextX+=pMenuItems[i*rows+rows]->GetWidth(); nextY=y+pMenuItems[0]->GetHeight(); } } CMenuGroup::~CMenuGroup() { delete[] pMenuItems; } void CMenuGroup::MouseButtonDown(int x, int y, BOOL bLeft){ //pMenuItems[0]->MouseButtonDown BOOL bDownInside=false; if(!bClosed){ for(int i=1;i<=icols*irows;i++){ pMenuItems[i]->MouseButtonDown(x,y,bLeft); if(!bDownInside){ bDownInside=pMenuItems[i]->JustDown(); } } bMouseDown=true; GameEngine::GetEngine()->SetManuMouseDown(true); } if(!bMouseDown){ pMenuItems[0]->MouseButtonDown(x,y,bLeft); if(pMenuItems[0]->JustDown()){ if(bClosed){ bClosed=false; GameEngine::GetEngine()->SetManuOpen(true); GameEngine::GetEngine()->WhoOpenedMenu(uiImages); } else{ bClosed=true; bMouseDown=false; GameEngine::GetEngine()->SetManuOpen(false); GameEngine::GetEngine()->SetManuMouseDown(false); MouseMove(x,y); } bDownInside=true; bMouseDown=true; GameEngine::GetEngine()->SetManuMouseDown(true); } } /* CHAR szText[64]; wsprintf(szText, "Time 2 show %d",GameEngine::GetEngine()->GetMenuMouseDown()); MessageBox(GameEngine::GetEngine()->GetWindow(), szText, TEXT("Brainiac"),MB_OK);*/ if(!bClosed &&!bDownInside) GameEngine::GetEngine()->SetManuOpen(false); if(!bDownInside){ bMouseDown=false; //GameEngine::GetEngine()->SetManuMouseDown(false); bClosed=true; MouseMove(x,y); } if(GameEngine::GetEngine()->WhoOpenedMenu()!=uiImages){ bClosed=true; MouseMove(x,y); bMouseDown=false; } } void CMenuGroup::MouseButtonUp(int x, int y, BOOL bLeft){ if(GameEngine::GetEngine()->WhoOpenedMenu()!=uiImages){ bClosed=true; bMouseDown=false; MouseMove(x,y); return; } if(!bClosed){ for(int i=1;i<=icols*irows;i++){ pMenuItems[i]->MouseButtonUp(x,y,bLeft); if(pMenuItems[i]->JustClicked()){ bMouseDown=false; GameEngine::GetEngine()->SetManuMouseDown(false); bClosed=true; MouseMove(x,y); //to update GameEngine::GetEngine()->SetManuOpen(false); pMenuItems[i]->NotNowClicked(); iLastClicked=i; } } bMouseDown=false; GameEngine::GetEngine()->SetManuMouseDown(false); } } void CMenuGroup::MouseMove(int x, int y){ if(bClosed){ pMenuItems[0]->MouseMove(x,y); if(GameEngine::GetEngine()->GetMenuOpen() && pMenuItems[0]->JustTouched()){ bClosed=false; GameEngine::GetEngine()->WhoOpenedMenu(uiImages); pMenuItems[0]->MouseButtonDown(x,y,true); if(GameEngine::GetEngine()->GetMenuMouseDown()){ /*TCHAR szText[64]; wsprintf(szText, "Time 2 show"); MessageBox(GameEngine::GetEngine()->GetWindow(), szText, TEXT("Brainiac"),MB_OK); */ bMouseDown=true; } } } else{ for(int i=1;i<=icols*irows;i++){ if(bMouseDown){ pMenuItems[i]->MouseButtonDown(x,y,true); } else pMenuItems[i]->MouseMove(x,y); } } if(GameEngine::GetEngine()->WhoOpenedMenu()!=uiImages){ bClosed=true; bMouseDown=false; return; } } void CMenuGroup::DrawScreen(HDC hDC){ pMenuItems[0]->DrawScreen(hDC); if(!bClosed){ for(int i=1;i<=icols*irows;i++){ pMenuItems[i]->DrawScreen(hDC); } } }