tablepage.cpp
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:10k
源码类别:

游戏

开发平台:

Visual C++

  1. // tablepage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "..gamehigh.h"
  5. #include "..includetablepage.h"
  6. #include "MainData.h"
  7. #include "macros.h"
  8. #include "mymemdc.h"
  9. extern CGameHighApp theApp;
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CTablePage
  17. IMPLEMENT_DYNCREATE(CTablePage, CView)
  18. CTablePage::CTablePage()
  19. {
  20. dwCurRoomID =0;
  21. memset(pTableArray, 0, sizeof(CTable*) * MAX_TABLE);
  22. lpTabArray =NULL;
  23. }
  24. CTablePage::~CTablePage()
  25. {
  26. SAFE_DELETE_ARRAY(lpTabArray);
  27. for(int i= 0; i< MAX_TABLE; i++)
  28. {
  29. SAFE_CHECKPOINTER(pTableArray[i])
  30. {
  31. SAFE_CHECKWND(pTableArray[i])
  32. {
  33. pTableArray[i]->DestroyWindow();
  34. }
  35. SAFE_DELETE(pTableArray[i]);
  36. }
  37. }
  38. }
  39. BEGIN_MESSAGE_MAP(CTablePage, CView)
  40. //{{AFX_MSG_MAP(CTablePage)
  41. ON_WM_CREATE()
  42. ON_WM_VSCROLL()
  43. ON_WM_ERASEBKGND()
  44. ON_WM_MOUSEMOVE()
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CTablePage drawing
  49. void CTablePage::OnDraw(CDC* pDC)
  50. {
  51. RECT rect;
  52. memset(&rect, 0, sizeof(RECT));
  53. this->GetClientRect(&rect);
  54. CMyMemDC memdc(pDC, rect);
  55. CBrush m_Brush;
  56. m_Brush.CreateSolidBrush(RGB(16, 154, 148));
  57. memdc->FillRect(&rect, &m_Brush);
  58. int nRowCount =15;
  59. int nColCount =3;
  60. for(int i=0; i< nRowCount; i++)
  61. {
  62. for(int j=0; j< nColCount; j++)
  63. {
  64. SAFE_CHECKWND(pTableArray[i])
  65. {
  66. RECT rcWnd;
  67. memset(&rcWnd, 0, sizeof(RECT));
  68. pTableArray[i * nColCount + j]->GetWindowRect(&rcWnd);
  69. this->ScreenToClient(&rcWnd);
  70. POINT ptLeft;
  71. memset(&ptLeft, 0, sizeof(POINT));
  72. ptLeft.x =rcWnd.left;
  73. ptLeft.y =rcWnd.top;
  74. POINT ptRight;
  75. memset(&ptRight, 0, sizeof(POINT));
  76. ptRight.x =rcWnd.right;
  77. ptRight.y =rcWnd.bottom;
  78. if(::PtInRect(&rect, ptLeft) ||
  79. ::PtInRect(&rect, ptRight))
  80. {
  81. pTableArray[i * nColCount + j]->DrawTable(&memdc);
  82. }
  83. }
  84. }//end for j
  85. }//end for i
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CTablePage diagnostics
  89. #ifdef _DEBUG
  90. #endif //_DEBUG
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CTablePage message handlers
  93. int CTablePage::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  94. {
  95. if (CView::OnCreate(lpCreateStruct) == -1)
  96. return -1;
  97. this->SetScrollRange(SB_VERT, 0, TABLE_HEIGHT * 15);
  98. int nRowCount =15;
  99. int nColCount =3;
  100. for(int i=0; i< nRowCount; i++)
  101. {
  102. for(int j=0; j< nColCount; j++)
  103. {
  104. CTable* pTable =new CTable();
  105. ASSERT(pTable);
  106. if(NULL != pTable)
  107. {
  108. POINT ptStart;
  109. memset(&ptStart, 0, sizeof(POINT));
  110. ptStart.x =j * TABLE_WIDTH;
  111. ptStart.y =i * TABLE_HEIGHT;
  112. pTable->Create(ptStart, this);
  113. pTable->ModifyStyleEx(NULL, WS_EX_TRANSPARENT, 0);
  114. pTableArray[i * nColCount + j] =pTable;
  115. pTableArray[i * nColCount + j]->SetDrawTargetWnd(this);
  116. }
  117. }
  118. }
  119. RECT rect;
  120. memset(&rect, 0, sizeof(RECT));
  121. m_StartButton.Create("开始", WS_VISIBLE | WS_CHILD, rect, this, START_BUTTONID);
  122. m_StartButton.ShowWindow(SW_HIDE);
  123. return 0;
  124. }
  125. void CTablePage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  126. {
  127. SCROLLINFO si;
  128. GetScrollInfo(SB_VERT,&si);
  129. int nPageHeight =TABLE_HEIGHT;
  130. switch (nSBCode)
  131. {
  132. case SB_BOTTOM:
  133. si.nPos =TABLE_HEIGHT * 15;
  134. break;
  135. case SB_ENDSCROLL:
  136. return;
  137. case SB_LINEDOWN:
  138. si.nPos++;
  139. break;
  140. case SB_LINEUP:
  141. si.nPos--;
  142. break;
  143. case SB_PAGEDOWN:
  144. si.nPos+=nPageHeight;
  145. break;
  146. case SB_PAGEUP:
  147. si.nPos-=nPageHeight;
  148. break;
  149. case SB_THUMBPOSITION:
  150. si.nPos = nPos;
  151. break;
  152. case SB_THUMBTRACK:
  153. si.nPos = nPos;
  154. break; ;
  155. case SB_TOP:
  156. si.nPos =0;
  157. break;
  158. default:
  159. ASSERT(FALSE);
  160. }
  161. SetScrollInfo(SB_VERT,&si);
  162. CalcTablePos();
  163. // CView::OnVScroll(nSBCode, nPos, pScrollBar);
  164. }
  165. BOOL CTablePage::CalcTablePos()
  166. {
  167. SCROLLINFO si;
  168. GetScrollInfo(SB_VERT,&si);
  169. int nZeroPoint =si.nPos;
  170. int nRowCount =15;
  171. int nColCount =3;
  172. for(int i=0; i< nRowCount; i++)
  173. {
  174. for(int j=0; j< nColCount; j++)
  175. {
  176. SAFE_CHECKWND(pTableArray[i])
  177. {
  178. POINT ptStart;
  179. memset(&ptStart, 0, sizeof(POINT));
  180. ptStart.x =j * TABLE_WIDTH;
  181. ptStart.y =i * TABLE_HEIGHT - nZeroPoint;
  182. RECT rect;
  183. memset(&rect, 0, sizeof(RECT));
  184. rect.left =ptStart.x;
  185. rect.top =ptStart.y;
  186. rect.right =rect.left + TABLE_WIDTH;
  187. rect.bottom =rect.top + TABLE_HEIGHT;
  188. pTableArray[i * nColCount + j]->MoveWindow(&rect, FALSE);
  189. }
  190. }//end for j
  191. }//end for i
  192. //移动按钮
  193. CMainData* pMainData =theApp.GetMainData();
  194. ASSERT(pMainData);
  195. if(NULL == pMainData)
  196. {
  197. return TRUE;
  198. }
  199. LPGAMEHIGH_TABLE lpTab =pMainData->Attrib_GetMyTable();
  200. int nPos =pMainData->Attrib_GetMyPos();
  201. if(NULL != lpTab &&
  202. -1  != nPos)
  203. {
  204. CTable* pTable =FindTable(lpTab);
  205. CButton* pButton =&m_StartButton;
  206. SAFE_CHECKWND(pButton)
  207. {
  208. LPRECT lprc =pTable->GetTextArray(nPos);
  209. RECT rcButton;
  210. memset(&rcButton, 0, sizeof(RECT));
  211. ::CopyRect(&rcButton, lprc);
  212. rcButton.bottom =rcButton.top    + 22;
  213. rcButton.right =rcButton.left  + 38;
  214. pTable->ClientToScreen(&rcButton);
  215. this->ScreenToClient(&rcButton);
  216. pButton->MoveWindow(&rcButton);
  217. }
  218. }
  219. this->Invalidate();
  220. return TRUE;
  221. }
  222. void CTablePage::SetRoomID(DWORD dwRoomID)
  223. {
  224. dwRoomID =dwRoomID;
  225. SAFE_CHECKWND(this)
  226. {
  227. CMainData* pMainData =theApp.GetMainData();
  228. SAFE_CHECKPOINTER(pMainData)
  229. {
  230. SAFE_DELETE_ARRAY(lpTabArray);
  231. int nCount =0;
  232. pMainData->Async_GameHigh_LoadTableFromRoom(dwRoomID, lpTabArray, nCount);
  233. if(nCount != MAX_TABLE)
  234. {
  235. ASSERT(NULL);
  236. return ;
  237. }
  238. SAFE_CHECKPOINTER(lpTabArray)
  239. {
  240. for(int i=0; i<nCount; i++)
  241. {
  242. pTableArray[i]->SetTable(&lpTabArray[i]);
  243. }
  244. }//end SAFE_CHECKPOINTER
  245. } //end SAFE_CHECKPOINTER
  246. }//end SAFE_CHECKWND
  247. }
  248. void CTablePage::RefreshTable(LPGAMEHIGH_TABLE lpTab)
  249. {
  250. ASSERT(lpTab);
  251. if(NULL == lpTab)
  252. return ;
  253. CTable* pTable =FindTable(lpTab);
  254. SAFE_CHECKWND(pTable)
  255. {
  256. RECT rect;
  257. memset(&rect, 0, sizeof(RECT));
  258. pTable->GetWindowRect(&rect);
  259. this->ScreenToClient(&rect);
  260. this->InvalidateRect(&rect);
  261. }
  262. }
  263. CTable* CTablePage::FindTable(LPGAMEHIGH_TABLE lpTab)
  264. {
  265. ASSERT(lpTab);
  266. if(NULL == lpTab)
  267. return NULL;
  268. for(int i=0; i<MAX_TABLE; i++)
  269. {
  270. if(lpTab == pTableArray[i]->GetTable())
  271. {
  272. return pTableArray[i];
  273. }
  274. }
  275. return NULL;
  276. }
  277. BOOL CTablePage::OnEraseBkgnd(CDC* pDC) 
  278. {
  279. return TRUE;
  280. }
  281. BOOL CTablePage::AutoJoin()
  282. {
  283. CMainData* pMainData =theApp.GetMainData();
  284. if(NULL == pMainData)
  285. return FALSE;
  286. SAFE_CHECKPOINTER(pMainData->Attrib_GetMyTable())
  287. { //用户已经坐在桌子上了.
  288. return FALSE;
  289. }
  290. //优先法则的确定,要人数未满4人,但人越多为准
  291. return FALSE;
  292. }
  293. LRESULT CTablePage::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  294. {
  295. CMainData* pMainData =theApp.GetMainData();
  296. if(NULL == pMainData)
  297. {
  298. return CView::WindowProc(message, wParam, lParam);
  299. }
  300. switch(message)
  301. {
  302. case WM_TABLE_SITDOWN:
  303. {
  304. OnTableSitDown(wParam, lParam);
  305. }
  306. break;
  307. case WM_COMMAND:
  308. {
  309. if(HIWORD(wParam) == BN_CLICKED && 
  310. START_BUTTONID == LOWORD(wParam))
  311. {
  312. CButton* pButton =&m_StartButton;
  313. SAFE_CHECKWND(pButton)
  314. {
  315. pButton->ShowWindow(SW_HIDE);
  316. //Start JQ
  317. DWORD nDllIndex =dwCurRoomID / 1000;
  318. HMODULE hMoudal =NULL;
  319. switch(nDllIndex)
  320. {
  321. case 0:
  322. {
  323. hMoudal =theApp.hJQLib;
  324. }
  325. break;
  326. default:
  327. break;
  328. }
  329. #ifdef _DEBUG //debug code
  330. LPGAMEHIGH_TABLE lpTable =pMainData->Attrib_GetMyTable();
  331. #else //release
  332. SAFE_CHECKPOINTER(hMoudal)
  333. {
  334. STARTMODUAL startModual =(STARTMODUAL)::GetProcAddress(hMoudal, "StartModual");
  335. SAFE_CHECKPOINTER(startModual)
  336. {
  337. startModual(pMainData->Attrib_GetMyTable(), pMainData->Attrib_GetMyID());
  338. }
  339. }
  340. #endif
  341. } //end safe_checkwnd(pbutton);
  342. }//end if highword
  343. }//end case
  344. break;
  345. default:
  346. break;
  347. }
  348. return CView::WindowProc(message, wParam, lParam);
  349. }
  350. void CTablePage::OnTableSitDown(WPARAM wParam, LPARAM lParam)
  351. {
  352. CTable* pTable =(CTable*)wParam;
  353. SAFE_CHECKFALSEWND(pTable)
  354. {
  355. return ;
  356. }
  357. CMainData* pMainData =theApp.GetMainData();
  358. ASSERT(pMainData);
  359. if(NULL == pMainData)
  360. {
  361. return ;
  362. }
  363. //先清除旧的状态
  364. LPGAMEHIGH_TABLE lpOldTab =NULL;
  365. lpOldTab =pMainData->Attrib_GetMyTable();
  366. SAFE_CHECKPOINTER(lpOldTab)
  367. {
  368. pMainData->Implemen_StandUp(lpOldTab);
  369. SAFE_CHECKWND(this)
  370. {
  371. this->RefreshTable(lpOldTab);
  372. }
  373. }
  374. //设置自已的状态
  375. LPGAMEHIGH_TABLE lpTable =pTable->GetTable();
  376. if(NULL == lpTable)
  377. {
  378. return ;
  379. }
  380. strcpy(lpTable->userStatus[lParam].userID, pMainData->Attrib_GetMyID());
  381. LPGAMEHIGH_USERINFO lpinfo =pMainData->Attrib_GetMyInfo();
  382. SAFE_CHECKPOINTER(lpinfo)
  383. {
  384. strcpy(lpTable->userStatus[lParam].userName, lpinfo->userName);
  385. }
  386. pMainData->Attrib_SetMyTable(lpTable);
  387. //m_StartButton
  388. CButton* pButton =&m_StartButton;
  389. SAFE_CHECKWND(pButton)
  390. {
  391. LPRECT lprc =pTable->GetTextArray(lParam);
  392. RECT rcButton;
  393. memset(&rcButton, 0, sizeof(RECT));
  394. ::CopyRect(&rcButton, lprc);
  395. rcButton.bottom =rcButton.top    + 22;
  396. rcButton.right =rcButton.left  + 38;
  397. pTable->ClientToScreen(&rcButton);
  398. this->ScreenToClient(&rcButton);
  399. pButton->MoveWindow(&rcButton);
  400. pButton->ShowWindow(SW_SHOW);
  401. pButton->BringWindowToTop();
  402. }
  403. //刷新窗口区
  404. RECT rcWnd;
  405. memset(&rcWnd, 0, sizeof(RECT));
  406. pTable->GetWindowRect(&rcWnd);
  407. this->ScreenToClient(&rcWnd);
  408. this->InvalidateRect(&rcWnd);
  409. }
  410. void CTablePage::OnMouseMove(UINT nFlags, CPoint point) 
  411. {
  412. CView::OnMouseMove(nFlags, point);
  413. }