网络游戏建模书的源代码

源代码在线查看: table.cpp

软件大小: 4520 K
上传用户: yyjpu
关键词: 网络游戏 建模 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				// table.cpp : implementation file
				//
				
				#include "stdafx.h"
				#include "..\gamehigh.h"
				#include "..\include\table.h"
				#include "mymemdc.h"
				#include "faceList.h"
				#include "basefunction.h"
				#include "TablePage.h"
				
				#ifdef _DEBUG
				#define new DEBUG_NEW
				#undef THIS_FILE
				static char THIS_FILE[] = __FILE__;
				#endif
				
				/////////////////////////////////////////////////////////////////////////////
				// CTable
				extern CFaceList*	gpFaceList;
				extern CGameHighApp	theApp;
				
				CTable::CTable()
				{
					hHandCur	=NULL;
					lpTable		=NULL;
				
					memset(&rcEmpty, 0, sizeof(RECT));
					rcEmpty.left	=50;
					rcEmpty.top		=50;
					rcEmpty.right	=rcEmpty.left + 50;
					rcEmpty.bottom	=rcEmpty.top  + 50;
				
					memset(rcPosArray, 0, sizeof(RECT) * MAX_TABCONTAIN);
				
					rcPosArray[0].left		=15;
					rcPosArray[0].top		=55;
					rcPosArray[0].right		=rcPosArray[0].left + 32;
					rcPosArray[0].bottom	=rcPosArray[0].top + 32;
				
					rcPosArray[1].left		=58;
					rcPosArray[1].top		=15;
					rcPosArray[1].right		=rcPosArray[1].left	+ 32;
					rcPosArray[1].bottom	=rcPosArray[1].top	+ 32;
				
					rcPosArray[2].left		=105;
					rcPosArray[2].top		=55;
					rcPosArray[2].right		=rcPosArray[2].left + 32;
					rcPosArray[2].bottom	=rcPosArray[2].top + 32;
				
					rcPosArray[3].left		=58;
					rcPosArray[3].top		=100;
					rcPosArray[3].right		=rcPosArray[3].left + 32;
					rcPosArray[3].bottom	=rcPosArray[3].top  + 32;
				
					memset(rcTextArray, 0, sizeof(RECT) * MAX_TABCONTAIN);
				
					rcTextArray[0].left		=5;
					rcTextArray[0].top		=5;
					rcTextArray[0].right	=rcTextArray[0].left + 32;
					rcTextArray[0].bottom	=rcTextArray[0].top  + 32;
				
					rcTextArray[1].left		=110;
					rcTextArray[1].top		=5;
					rcTextArray[1].right	=rcTextArray[1].left + 32;
					rcTextArray[1].bottom	=rcTextArray[1].top  + 32;
				
					rcTextArray[2].left		=110;
					rcTextArray[2].top		=105;
					rcTextArray[2].right	=rcTextArray[2].left + 32;
					rcTextArray[2].bottom	=rcTextArray[2].top  + 32;
				
					rcTextArray[3].left		=5;
					rcTextArray[3].top		=105;
					rcTextArray[3].right	=rcTextArray[3].left + 32;
					rcTextArray[3].bottom	=rcTextArray[3].top  + 32;
				
					uBkIndex		=0;
				
					pTargetWnd		=NULL;
					if(NULL == hHandCur)
					{
						hHandCur	=::LoadCursor(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_MYHAND));
					}
				}
				
				CTable::~CTable()
				{
					SAFE_CHECKPOINTER(hHandCur)
					{
						::DestroyCursor(hHandCur);
						hHandCur	=NULL;
					}
				}
				
				
				BEGIN_MESSAGE_MAP(CTable, CWnd)
					//{{AFX_MSG_MAP(CTable)
					ON_WM_PAINT()
					ON_WM_SETCURSOR()
					ON_WM_MOUSEMOVE()
					ON_WM_CREATE()
					ON_WM_LBUTTONUP()
					ON_WM_LBUTTONDOWN()
					ON_WM_ERASEBKGND()
					//}}AFX_MSG_MAP
				END_MESSAGE_MAP()
				
				
				/////////////////////////////////////////////////////////////////////////////
				// CTable message handlers
				
				BOOL CTable::Create(const POINT& ptStart, CWnd* pParentWnd) 
				{
					RECT	rect;
					memset(&rect, 0, sizeof(rect));
					::memcpy(&rect, &ptStart, sizeof(POINT));
					rect.right	=rect.left	+	TABLE_WIDTH;
					rect.bottom	=rect.top	+	TABLE_HEIGHT;
					DWORD	dwStyle	=WS_CHILD | WS_VISIBLE;
					return CWnd::Create(NULL, NULL, dwStyle, rect, pParentWnd, 0, NULL);
				}
				
				void CTable::OnPaint() 
				{
					CPaintDC dc(this); // device context for painting
				}
				
				void CTable::SetTable(LPGAMEHIGH_TABLE lpTab)
				{
					ASSERT(lpTab);
					SAFE_CHECKPOINTER(lpTab)
					{
						lpTable	=lpTab;
					}
				}
				
				LPGAMEHIGH_TABLE CTable::GetTable()
				{
					return lpTable;
				}
				
				BOOL CTable::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
				{
					// TODO: Add your message handler code here and/or call default
					
					return CWnd::OnSetCursor(pWnd, nHitTest, message);
				}
				
				void CTable::OnMouseMove(UINT nFlags, CPoint point) 
				{
					if(MK_LBUTTON == nFlags)
					{
						::SetCursor(::LoadCursor(NULL, IDC_ARROW));
						return ;
					}
				
					POINT	ptMouse;
					memset(&ptMouse, 0, sizeof(ptMouse));
					::GetCursorPos(&ptMouse);
					
					if(this->GetSafeHwnd() == ::WindowFromPoint(ptMouse))
					{
						RECT	rect;
						memset(&rect, 0, sizeof(rect));
						
						this->GetWindowRect(&rect);
						
						if(::PtInRect(&rect, ptMouse) && !::PtInRect(&rcEmpty, point))
						{
							::SetCursor(hHandCur);
						}
						else
						{
							::SetCursor(::LoadCursor(NULL, IDC_ARROW));
						}
					}
					CWnd::OnMouseMove(nFlags, point);
				}
				
				int CTable::OnCreate(LPCREATESTRUCT lpCreateStruct) 
				{
					if (CWnd::OnCreate(lpCreateStruct) == -1)
						return -1;
					return 0;
				}
				
				void CTable::DrawTable(CDC *pDC)
				{
					ASSERT(pDC);
					if(NULL == pDC)
					{
						return ;
					}
				
					if(NULL == lpTable)
					{
						return ;
					}
				
					if(NULL == gpFaceList)
					{
						return ;
					}
				
					//首先绘画背景颜色
					COLORREF	clrBk	=RGB(18, 153, 145);
					CBrush	m_Brush;
					m_Brush.CreateSolidBrush(clrBk);
					
					RECT	rect;
					memset(&rect, 0, sizeof(RECT));
					this->GetClientRect(&rect);
					SAFE_CHECKWND(pTargetWnd)
					{
						this	  ->ClientToScreen(&rect);
						pTargetWnd->ScreenToClient(&rect);
					}
				
					pDC->FillRect(&rect, &m_Brush);
					m_Brush.DeleteObject();
				
					m_Brush.CreateSolidBrush(RGB(0, 128, 128));
					for(int i=0; i					{
						RECT	rcTemp;
						memset(&rcTemp, 0, sizeof(RECT));
						::CopyRect(&rcTemp, &(rcPosArray[i]));
						SAFE_CHECKWND(pTargetWnd)
						{
							this	  ->ClientToScreen(&rcTemp);
							pTargetWnd->ScreenToClient(&rcTemp);
						}
						pDC->FillRect(&rcTemp, &m_Brush);	
					}
					m_Brush.DeleteObject();
				
					CImageList*	pBkImgList	=gpFaceList->GetBkImgList();
					if(NULL != pBkImgList 
						&& pBkImgList->GetSafeHandle() 
						&& 0 < pBkImgList->GetImageCount())
					{
						RECT	rcTemp;
						memset(&rcTemp, 0, sizeof(RECT));
						::CopyRect(&rcTemp, &(rcEmpty));
						SAFE_CHECKWND(pTargetWnd)
						{
							this	  ->ClientToScreen(&rcTemp);
							pTargetWnd->ScreenToClient(&rcTemp);
						}
				
						HICON	hIcon	=pBkImgList->ExtractIcon(uBkIndex);
						SAFE_CHECKPOINTER(hIcon)
						{
							::DrawIconEx(pDC->GetSafeHdc(), rcTemp.left, rcTemp.top, hIcon, 
								BKICON_SIZE, BKICON_SIZE, 0, NULL, DI_NORMAL); 
							::DestroyIcon(hIcon);
							hIcon	=NULL;
						}
					}
				
					//绘画桌子上的人
					CImageList*	pImgList1	=gpFaceList->GetImageList1();
					if(NULL == pImgList1 ||
						NULL == pImgList1->GetSafeHandle() ||
						0    >= pImgList1->GetImageCount())
						return ;
				
					HICON	hIcon	=pImgList1->ExtractIcon(0);
					SAFE_CHECKPOINTER(hIcon)
					{
						for(i=0; i						{
							if(0 != strlen(lpTable->userStatus[i].userID))
							{
								RECT	rcTemp;
								memset(&rcTemp, 0, sizeof(RECT));
								::CopyRect(&rcTemp, &(rcPosArray[i]));
								SAFE_CHECKWND(pTargetWnd)
								{
									this	  ->ClientToScreen(&rcTemp);
									pTargetWnd->ScreenToClient(&rcTemp);
								}
				
								::DrawIconEx(pDC->GetSafeHdc(), rcTemp.left, rcTemp.top, hIcon, 
									LARGEICON_SIZE, LARGEICON_SIZE, 0, NULL, DI_NORMAL); 
							}
						}
						::DestroyIcon(hIcon);
						hIcon	=NULL;
					}
				
					LOGFONT	lf;
					memset(&lf, 0, sizeof(LOGFONT));
					if(IsWin9x())
					{
						lf.lfHeight	=15;
					}
					else
					{
						lf.lfHeight	=14;
					}
				
					CFont	m_Font;
					m_Font.CreateFontIndirect(&lf);
					CFont*	pOldFont	=pDC->SelectObject(&m_Font);
				
					pDC->SetBkMode(TRANSPARENT);
				
					char buffer[256];
					memset(buffer, 0, sizeof(char) * 256);
					for(i=0; i					{
						RECT	rcTemp;
						memset(&rcTemp, 0, sizeof(RECT));
						::CopyRect(&rcTemp, &(rcTextArray[i]));
						SAFE_CHECKWND(pTargetWnd)
						{
							this	  ->ClientToScreen(&rcTemp);
							pTargetWnd->ScreenToClient(&rcTemp);
						}
				
						memset(buffer, 0, sizeof(char) * 256);
						if(0 != strlen(lpTable->userStatus[i].userName))
						{
							wsprintf(buffer, "%s", lpTable->userStatus[i].userName);
						}
						else 
							if(0 != strlen(lpTable->userStatus[i].userID))
						{
							wsprintf(buffer, "%s", lpTable->userStatus[i].userID);
						}
						
						pDC->DrawText(buffer, &(rcTemp), DT_WORDBREAK);
					}
				
					memset(&rect, 0, sizeof(RECT));
					this->GetClientRect(&rect);
					rect.top	=rect.bottom - 16;
					
					SAFE_CHECKWND(pTargetWnd)
					{
						this		->ClientToScreen(&rect);
						pTargetWnd	->ScreenToClient(&rect);
					}
					
					memset(buffer, 0, sizeof(char) * 256);
					wsprintf(buffer, "- %d -", lpTable->tableID + 1);
					pDC->DrawText(buffer, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
				
					pDC->SelectObject(pOldFont);
					m_Font.DeleteObject();
				}
				
				
				
				void CTable::OnLButtonUp(UINT nFlags, CPoint point) 
				{
						
					CWnd::OnLButtonUp(nFlags, point);
				}
				
				void CTable::OnLButtonDown(UINT nFlags, CPoint point) 
				{
					POINT	ptMouse;
					memset(&ptMouse, 0, sizeof(ptMouse));
					::GetCursorPos(&ptMouse);
					if(this->GetSafeHwnd() != ::WindowFromPoint(ptMouse))
					{
						return ;
					}
					CMainData*	pMainData	=theApp.GetMainData();
					ASSERT(pMainData);
					if(NULL == pMainData)
					{
						return ;
					}
				
					LPGAMEHIGH_TABLE	lpOldTab	=NULL;
					lpOldTab						=pMainData->Attrib_GetMyTable();
					for(int i=0; i<	MAX_TABCONTAIN; i++)
					{
						RECT	rect;
						memset(&rect, 0, sizeof(RECT));
						::CopyRect(&rect, &(rcPosArray[i]));
					
						if(::PtInRect(&rect, point))
						{
							if(NULL != lpTable &&
								0 == strlen(lpTable->userStatus[i].userID))
							{	//用户坐到这张桌子上
				
								CWnd*	pWnd	=this->GetParent();
								SAFE_CHECKWND(pWnd)
								{
									pWnd->PostMessage(WM_TABLE_SITDOWN, (WPARAM)this, i);
								}
								break;
							} // end if(NULL != lpTable
						}//end if ptinrect
					}//end for
				
					CWnd::OnLButtonDown(nFlags, point);
				}
				
				LRESULT CTable::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
				{
					return CWnd::WindowProc(message, wParam, lParam);
				}
				
				BOOL CTable::OnEraseBkgnd(CDC* pDC) 
				{
					return TRUE;
				}
				
				void CTable::SetDrawTargetWnd(CWnd *pWnd)
				{
					SAFE_CHECKWND(pWnd)
					{
						pTargetWnd	=pWnd;
					}
				}
				
				LPRECT CTable::GetTextArray(int nIndex)
				{
					if(nIndex > 0 &&
						nIndex < MAX_TABCONTAIN)
					{
						return &rcTextArray[nIndex];
					}
					return NULL;
				}
							

相关资源