tablepage.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:10k
源码类别:
游戏
开发平台:
Visual C++
- // tablepage.cpp : implementation file
- //
- #include "stdafx.h"
- #include "..gamehigh.h"
- #include "..includetablepage.h"
- #include "MainData.h"
- #include "macros.h"
- #include "mymemdc.h"
- extern CGameHighApp theApp;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTablePage
- IMPLEMENT_DYNCREATE(CTablePage, CView)
- CTablePage::CTablePage()
- {
- dwCurRoomID =0;
- memset(pTableArray, 0, sizeof(CTable*) * MAX_TABLE);
- lpTabArray =NULL;
- }
- CTablePage::~CTablePage()
- {
- SAFE_DELETE_ARRAY(lpTabArray);
- for(int i= 0; i< MAX_TABLE; i++)
- {
- SAFE_CHECKPOINTER(pTableArray[i])
- {
- SAFE_CHECKWND(pTableArray[i])
- {
- pTableArray[i]->DestroyWindow();
- }
- SAFE_DELETE(pTableArray[i]);
- }
- }
- }
- BEGIN_MESSAGE_MAP(CTablePage, CView)
- //{{AFX_MSG_MAP(CTablePage)
- ON_WM_CREATE()
- ON_WM_VSCROLL()
- ON_WM_ERASEBKGND()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTablePage drawing
- void CTablePage::OnDraw(CDC* pDC)
- {
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- this->GetClientRect(&rect);
- CMyMemDC memdc(pDC, rect);
- CBrush m_Brush;
- m_Brush.CreateSolidBrush(RGB(16, 154, 148));
- memdc->FillRect(&rect, &m_Brush);
- int nRowCount =15;
- int nColCount =3;
- for(int i=0; i< nRowCount; i++)
- {
- for(int j=0; j< nColCount; j++)
- {
- SAFE_CHECKWND(pTableArray[i])
- {
- RECT rcWnd;
- memset(&rcWnd, 0, sizeof(RECT));
- pTableArray[i * nColCount + j]->GetWindowRect(&rcWnd);
- this->ScreenToClient(&rcWnd);
- POINT ptLeft;
- memset(&ptLeft, 0, sizeof(POINT));
- ptLeft.x =rcWnd.left;
- ptLeft.y =rcWnd.top;
- POINT ptRight;
- memset(&ptRight, 0, sizeof(POINT));
- ptRight.x =rcWnd.right;
- ptRight.y =rcWnd.bottom;
- if(::PtInRect(&rect, ptLeft) ||
- ::PtInRect(&rect, ptRight))
- {
- pTableArray[i * nColCount + j]->DrawTable(&memdc);
- }
- }
- }//end for j
- }//end for i
- }
- /////////////////////////////////////////////////////////////////////////////
- // CTablePage diagnostics
- #ifdef _DEBUG
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CTablePage message handlers
- int CTablePage::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- this->SetScrollRange(SB_VERT, 0, TABLE_HEIGHT * 15);
- int nRowCount =15;
- int nColCount =3;
- for(int i=0; i< nRowCount; i++)
- {
- for(int j=0; j< nColCount; j++)
- {
- CTable* pTable =new CTable();
- ASSERT(pTable);
- if(NULL != pTable)
- {
- POINT ptStart;
- memset(&ptStart, 0, sizeof(POINT));
- ptStart.x =j * TABLE_WIDTH;
- ptStart.y =i * TABLE_HEIGHT;
- pTable->Create(ptStart, this);
- pTable->ModifyStyleEx(NULL, WS_EX_TRANSPARENT, 0);
- pTableArray[i * nColCount + j] =pTable;
- pTableArray[i * nColCount + j]->SetDrawTargetWnd(this);
- }
- }
- }
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- m_StartButton.Create("开始", WS_VISIBLE | WS_CHILD, rect, this, START_BUTTONID);
- m_StartButton.ShowWindow(SW_HIDE);
- return 0;
- }
- void CTablePage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- SCROLLINFO si;
- GetScrollInfo(SB_VERT,&si);
- int nPageHeight =TABLE_HEIGHT;
- switch (nSBCode)
- {
- case SB_BOTTOM:
- si.nPos =TABLE_HEIGHT * 15;
- break;
- case SB_ENDSCROLL:
- return;
- case SB_LINEDOWN:
- si.nPos++;
- break;
- case SB_LINEUP:
- si.nPos--;
- break;
- case SB_PAGEDOWN:
- si.nPos+=nPageHeight;
- break;
- case SB_PAGEUP:
- si.nPos-=nPageHeight;
- break;
- case SB_THUMBPOSITION:
- si.nPos = nPos;
- break;
- case SB_THUMBTRACK:
- si.nPos = nPos;
- break; ;
- case SB_TOP:
- si.nPos =0;
- break;
- default:
- ASSERT(FALSE);
- }
- SetScrollInfo(SB_VERT,&si);
- CalcTablePos();
- // CView::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- BOOL CTablePage::CalcTablePos()
- {
- SCROLLINFO si;
- GetScrollInfo(SB_VERT,&si);
- int nZeroPoint =si.nPos;
- int nRowCount =15;
- int nColCount =3;
- for(int i=0; i< nRowCount; i++)
- {
- for(int j=0; j< nColCount; j++)
- {
- SAFE_CHECKWND(pTableArray[i])
- {
- POINT ptStart;
- memset(&ptStart, 0, sizeof(POINT));
- ptStart.x =j * TABLE_WIDTH;
- ptStart.y =i * TABLE_HEIGHT - nZeroPoint;
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- rect.left =ptStart.x;
- rect.top =ptStart.y;
- rect.right =rect.left + TABLE_WIDTH;
- rect.bottom =rect.top + TABLE_HEIGHT;
- pTableArray[i * nColCount + j]->MoveWindow(&rect, FALSE);
- }
- }//end for j
- }//end for i
- //移动按钮
- CMainData* pMainData =theApp.GetMainData();
- ASSERT(pMainData);
- if(NULL == pMainData)
- {
- return TRUE;
- }
- LPGAMEHIGH_TABLE lpTab =pMainData->Attrib_GetMyTable();
- int nPos =pMainData->Attrib_GetMyPos();
- if(NULL != lpTab &&
- -1 != nPos)
- {
- CTable* pTable =FindTable(lpTab);
- CButton* pButton =&m_StartButton;
- SAFE_CHECKWND(pButton)
- {
- LPRECT lprc =pTable->GetTextArray(nPos);
- RECT rcButton;
- memset(&rcButton, 0, sizeof(RECT));
- ::CopyRect(&rcButton, lprc);
- rcButton.bottom =rcButton.top + 22;
- rcButton.right =rcButton.left + 38;
- pTable->ClientToScreen(&rcButton);
- this->ScreenToClient(&rcButton);
- pButton->MoveWindow(&rcButton);
- }
- }
- this->Invalidate();
- return TRUE;
- }
- void CTablePage::SetRoomID(DWORD dwRoomID)
- {
- dwRoomID =dwRoomID;
- SAFE_CHECKWND(this)
- {
- CMainData* pMainData =theApp.GetMainData();
- SAFE_CHECKPOINTER(pMainData)
- {
- SAFE_DELETE_ARRAY(lpTabArray);
- int nCount =0;
- pMainData->Async_GameHigh_LoadTableFromRoom(dwRoomID, lpTabArray, nCount);
- if(nCount != MAX_TABLE)
- {
- ASSERT(NULL);
- return ;
- }
- SAFE_CHECKPOINTER(lpTabArray)
- {
- for(int i=0; i<nCount; i++)
- {
- pTableArray[i]->SetTable(&lpTabArray[i]);
- }
- }//end SAFE_CHECKPOINTER
- } //end SAFE_CHECKPOINTER
- }//end SAFE_CHECKWND
- }
- void CTablePage::RefreshTable(LPGAMEHIGH_TABLE lpTab)
- {
- ASSERT(lpTab);
- if(NULL == lpTab)
- return ;
- CTable* pTable =FindTable(lpTab);
- SAFE_CHECKWND(pTable)
- {
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- pTable->GetWindowRect(&rect);
- this->ScreenToClient(&rect);
- this->InvalidateRect(&rect);
- }
- }
- CTable* CTablePage::FindTable(LPGAMEHIGH_TABLE lpTab)
- {
- ASSERT(lpTab);
- if(NULL == lpTab)
- return NULL;
- for(int i=0; i<MAX_TABLE; i++)
- {
- if(lpTab == pTableArray[i]->GetTable())
- {
- return pTableArray[i];
- }
- }
- return NULL;
- }
- BOOL CTablePage::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- BOOL CTablePage::AutoJoin()
- {
- CMainData* pMainData =theApp.GetMainData();
- if(NULL == pMainData)
- return FALSE;
- SAFE_CHECKPOINTER(pMainData->Attrib_GetMyTable())
- { //用户已经坐在桌子上了.
- return FALSE;
- }
- //优先法则的确定,要人数未满4人,但人越多为准
- return FALSE;
- }
- LRESULT CTablePage::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- CMainData* pMainData =theApp.GetMainData();
- if(NULL == pMainData)
- {
- return CView::WindowProc(message, wParam, lParam);
- }
- switch(message)
- {
- case WM_TABLE_SITDOWN:
- {
- OnTableSitDown(wParam, lParam);
- }
- break;
- case WM_COMMAND:
- {
- if(HIWORD(wParam) == BN_CLICKED &&
- START_BUTTONID == LOWORD(wParam))
- {
- CButton* pButton =&m_StartButton;
- SAFE_CHECKWND(pButton)
- {
- pButton->ShowWindow(SW_HIDE);
- //Start JQ
- DWORD nDllIndex =dwCurRoomID / 1000;
- HMODULE hMoudal =NULL;
- switch(nDllIndex)
- {
- case 0:
- {
- hMoudal =theApp.hJQLib;
- }
- break;
- default:
- break;
- }
- #ifdef _DEBUG //debug code
- LPGAMEHIGH_TABLE lpTable =pMainData->Attrib_GetMyTable();
- #else //release
- SAFE_CHECKPOINTER(hMoudal)
- {
- STARTMODUAL startModual =(STARTMODUAL)::GetProcAddress(hMoudal, "StartModual");
- SAFE_CHECKPOINTER(startModual)
- {
- startModual(pMainData->Attrib_GetMyTable(), pMainData->Attrib_GetMyID());
- }
- }
- #endif
- } //end safe_checkwnd(pbutton);
- }//end if highword
- }//end case
- break;
- default:
- break;
- }
- return CView::WindowProc(message, wParam, lParam);
- }
- void CTablePage::OnTableSitDown(WPARAM wParam, LPARAM lParam)
- {
- CTable* pTable =(CTable*)wParam;
- SAFE_CHECKFALSEWND(pTable)
- {
- return ;
- }
- CMainData* pMainData =theApp.GetMainData();
- ASSERT(pMainData);
- if(NULL == pMainData)
- {
- return ;
- }
- //先清除旧的状态
- LPGAMEHIGH_TABLE lpOldTab =NULL;
- lpOldTab =pMainData->Attrib_GetMyTable();
- SAFE_CHECKPOINTER(lpOldTab)
- {
- pMainData->Implemen_StandUp(lpOldTab);
- SAFE_CHECKWND(this)
- {
- this->RefreshTable(lpOldTab);
- }
- }
- //设置自已的状态
- LPGAMEHIGH_TABLE lpTable =pTable->GetTable();
- if(NULL == lpTable)
- {
- return ;
- }
- strcpy(lpTable->userStatus[lParam].userID, pMainData->Attrib_GetMyID());
- LPGAMEHIGH_USERINFO lpinfo =pMainData->Attrib_GetMyInfo();
- SAFE_CHECKPOINTER(lpinfo)
- {
- strcpy(lpTable->userStatus[lParam].userName, lpinfo->userName);
- }
- pMainData->Attrib_SetMyTable(lpTable);
- //m_StartButton
- CButton* pButton =&m_StartButton;
- SAFE_CHECKWND(pButton)
- {
- LPRECT lprc =pTable->GetTextArray(lParam);
- RECT rcButton;
- memset(&rcButton, 0, sizeof(RECT));
- ::CopyRect(&rcButton, lprc);
- rcButton.bottom =rcButton.top + 22;
- rcButton.right =rcButton.left + 38;
- pTable->ClientToScreen(&rcButton);
- this->ScreenToClient(&rcButton);
- pButton->MoveWindow(&rcButton);
- pButton->ShowWindow(SW_SHOW);
- pButton->BringWindowToTop();
- }
- //刷新窗口区
- RECT rcWnd;
- memset(&rcWnd, 0, sizeof(RECT));
- pTable->GetWindowRect(&rcWnd);
- this->ScreenToClient(&rcWnd);
- this->InvalidateRect(&rcWnd);
- }
- void CTablePage::OnMouseMove(UINT nFlags, CPoint point)
- {
- CView::OnMouseMove(nFlags, point);
- }