DlgMap.cpp
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:7k
源码类别:

外挂编程

开发平台:

Visual C++

  1. // DlgMap.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ROA.h"
  5. #include "DlgMap.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define SCALE_MIN 0.125
  12. #define SCALE_MAX 1
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDlgMap dialog
  15. CDlgMap::CDlgMap(CWnd* pParent /*=NULL*/)
  16. : CDialog(CDlgMap::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CDlgMap)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. m_dScale = 1.0f;
  22. }
  23. void CDlgMap::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CDlgMap)
  27. // NOTE: the ClassWizard will add DDX and DDV calls here
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CDlgMap, CDialog)
  31. //{{AFX_MSG_MAP(CDlgMap)
  32. ON_WM_PAINT()
  33. ON_BN_CLICKED(IDC_BTN_ZOOMOUT, OnBtnZoomout)
  34. ON_BN_CLICKED(IDC_BTN_ZOOMIN, OnBtnZoomin)
  35. ON_WM_ERASEBKGND()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDlgMap message handlers
  40. void CDlgMap::OnPaint() 
  41. {
  42. CPaintDC dc(this); // device context for painting
  43. // TODO: Add your message handler code here
  44. CBitmap bitmap;
  45. CSize szShow;
  46. CRect rectClient;
  47. // refreshReq.bMap = false;
  48. if(you.pntPos.x == 0 && you.pntPos.y == 0)
  49. return;
  50. CBrush bshYou, bshPlayer, bshMonster, bshPortal, bshItem,*brushOld;
  51. int i;
  52. bshYou.CreateSolidBrush(RGB(255, 0, 0));
  53. bshPlayer.CreateSolidBrush(RGB(0, 0, 255));
  54. bshMonster.CreateSolidBrush(RGB(255, 255, 0));
  55. bshPortal.CreateSolidBrush(RGB(255, 0, 255));
  56. bshItem.CreateSolidBrush(RGB(0, 255, 0));
  57. GetWindowRect(&rectClient);
  58. szShow.cx = rectClient.Width();
  59. szShow.cy = rectClient.Height();
  60. double X = you.pntTo.x;
  61. double Y = you.pntTo.y;
  62. int nRadius = 3;
  63. CRect rectPaste;
  64. double dXPaste, dYPaste;
  65. double dXScale = (double)szShow.cx/field.m_szField.cx/m_dScale;
  66. double dYScale = (double)szShow.cy/field.m_szField.cy/m_dScale;
  67. // Draw backgound
  68. Y = field.m_szField.cy - Y;
  69. dXPaste = (double)field.m_szField.cx*m_dScale/2;
  70. dYPaste = (double)field.m_szField.cy*m_dScale/2;
  71. rectPaste.SetRect((long)(X - dXPaste),
  72.   (long)(Y - dYPaste),
  73.   (long)(X + dXPaste),
  74.   (long)(Y + dYPaste));
  75. if(rectPaste.top < 0)
  76. rectPaste.OffsetRect(0, -rectPaste.top);
  77. if(rectPaste.left < 0)
  78. rectPaste.OffsetRect(-rectPaste.left, 0);
  79. if(rectPaste.bottom > field.m_szField.cy)
  80. rectPaste.OffsetRect(0, field.m_szField.cy - rectPaste.bottom);
  81. if(rectPaste.right > field.m_szField.cx)
  82. rectPaste.OffsetRect(field.m_szField.cx - rectPaste.right, 0);
  83. dc.StretchBlt(0, 0, szShow.cx, szShow.cy, &field.m_dcField, rectPaste.left, rectPaste.top, rectPaste.Width(), rectPaste.Height(), SRCCOPY);
  84. // Draw you
  85. CRect rectYou;
  86. CPoint pntYou;
  87. pntYou.x = (long)(X - rectPaste.left);
  88. pntYou.y = (long)(Y - rectPaste.top);
  89. pntYou.x = (long)(dXScale * pntYou.x);
  90. pntYou.y = (long)(dYScale * pntYou.y);
  91. rectYou.SetRect(pntYou.x-nRadius, pntYou.y-nRadius, pntYou.x+nRadius, pntYou.y+nRadius);
  92. brushOld = dc.SelectObject(&bshYou);
  93. dc.Ellipse(rectYou);
  94. //Draw monsters
  95. CRect rectMon;
  96. CPoint pntMon;
  97. dc.SelectObject(&bshMonster);
  98. for(i=0; i<monsters.GetSize(); i++)
  99. {
  100. X = monsters[i].pntTo.x;
  101. Y = monsters[i].pntTo.y;
  102. Y = field.m_szField.cy - Y;
  103. pntMon.x = (long)(X - rectPaste.left);
  104. pntMon.y = (long)(Y - rectPaste.top);
  105. pntMon.x = (long)(dXScale * pntMon.x);
  106. pntMon.y = (long)(dYScale * pntMon.y);
  107. rectMon.SetRect(pntMon.x-nRadius, pntMon.y-nRadius, pntMon.x+nRadius, pntMon.y+nRadius);
  108. dc.Ellipse(rectMon);
  109. int nModeOld = dc.SetBkMode(TRANSPARENT);
  110. rectMon.InflateRect(30, 10);
  111. CFont font, *pOld;
  112. font.CreatePointFont(90, "Courier New");
  113. pOld = dc.SelectObject(&font);
  114. dc.DrawText(monsters[i].cName, rectMon, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  115. dc.SetBkMode(nModeOld);
  116. dc.SelectObject(pOld);
  117. // test
  118. /* pos pos1, pos2, *posp;
  119. pos_list *poslist;
  120. pos1.x = (WORD)you.pntTo.x;
  121. pos1.y = (WORD)you.pntTo.y;
  122. pos2.x = (WORD)monsters[i].pntTo.x;
  123. pos2.y = (WORD)monsters[i].pntTo.y;
  124. poslist = (pos_list*)new char[sizeof(pos)*300+sizeof(int)];
  125. DWORD session = (*CalcPath_init)(poslist, (char*)field.m_byFields, field.m_szField.cx, field.m_szField.cy, 
  126. &pos1, &pos2, 100);
  127. BOOL bFail= (*CalcPath_pathStep)(session);
  128. if(!bFail)
  129. {
  130. posp = (pos*)(((char*)poslist)+4);
  131. for(int j=0; j<poslist->size; j++)
  132. {
  133. X = posp[j].x;
  134. Y = posp[j].y;
  135. Y = field.m_szField.cy - Y;
  136. pntMon.x = (long)(X - rectPaste.left);
  137. pntMon.y = (long)(Y - rectPaste.top);
  138. pntMon.x = (long)(dXScale * pntMon.x);
  139. pntMon.y = (long)(dYScale * pntMon.y);
  140. dc.SetPixel(pntMon.x, pntMon.y, RGB(0, 0, 0));
  141. }
  142. }
  143. (*CalcPath_destory)(session);
  144. delete poslist;
  145. */ }
  146. //Draw players
  147. CRect rectPlayer;
  148. CPoint pntPlayer;
  149. dc.SelectObject(&bshPlayer);
  150. for(i=0; i<players.GetSize(); i++)
  151. {
  152. X = players[i].pntTo.x;
  153. Y = players[i].pntTo.y;
  154. Y = field.m_szField.cy - Y;
  155. pntPlayer.x = (long)(X - rectPaste.left);
  156. pntPlayer.y = (long)(Y - rectPaste.top);
  157. pntPlayer.x = (long)(dXScale * pntPlayer.x);
  158. pntPlayer.y = (long)(dYScale * pntPlayer.y);
  159. rectPlayer.SetRect(pntPlayer.x-nRadius, pntPlayer.y-nRadius, pntPlayer.x+nRadius, pntPlayer.y+nRadius);
  160. dc.Ellipse(rectPlayer);
  161. }
  162. //Draw portals
  163. CRect rectPortal;
  164. CPoint pntPortal;
  165. dc.SelectObject(&bshPortal);
  166. for(i=0; i<portals.GetSize(); i++)
  167. {
  168. X = portals[i].pntPos.x;
  169. Y = portals[i].pntPos.y;
  170. Y = field.m_szField.cy - Y;
  171. pntPortal.x = (long)(X - rectPaste.left);
  172. pntPortal.y = (long)(Y - rectPaste.top);
  173. pntPortal.x = (long)(dXScale * pntPortal.x);
  174. pntPortal.y = (long)(dYScale * pntPortal.y);
  175. rectPortal.SetRect(pntPortal.x-nRadius*2, pntPortal.y-nRadius*2, pntPortal.x+nRadius*2, pntPortal.y+nRadius*2);
  176. dc.Ellipse(rectPortal);
  177. }
  178. //Draw items
  179. CRect rectItem;
  180. CPoint pntItem;
  181. dc.SelectObject(&bshItem);
  182. for(i=0; i<items.GetSize(); i++)
  183. {
  184. X = items[i].pntPos.x;
  185. Y = items[i].pntPos.y;
  186. Y = field.m_szField.cy - Y;
  187. pntItem.x = (long)(X - rectPaste.left);
  188. pntItem.y = (long)(Y - rectPaste.top);
  189. pntItem.x = (long)(dXScale * pntItem.x);
  190. pntItem.y = (long)(dYScale * pntItem.y);
  191. rectItem.SetRect(pntItem.x-nRadius, pntItem.y-nRadius, pntItem.x+nRadius, pntItem.y+nRadius);
  192. dc.Ellipse(rectItem);
  193. }
  194. // Draw finished
  195. dc.SelectObject(brushOld);
  196. bshYou.DeleteObject();
  197. bshPlayer.DeleteObject();
  198. bshMonster.DeleteObject();
  199. bshPortal.DeleteObject();
  200. bshItem.DeleteObject();
  201. }
  202. void CDlgMap::OnBtnZoomout() 
  203. {
  204. m_dScale /= 2.0;
  205. if(m_dScale < SCALE_MIN)
  206. m_dScale = SCALE_MIN;
  207. RedrawWindow();
  208. }
  209. void CDlgMap::OnBtnZoomin() 
  210. {
  211. m_dScale *= 2.0;
  212. if(m_dScale > SCALE_MAX)
  213. m_dScale = SCALE_MAX;
  214. RedrawWindow();
  215. }
  216. BOOL CDlgMap::OnEraseBkgnd( CDC* pDC )
  217. {
  218. if(!field.m_bLoaded)
  219. {
  220. CRect rect;
  221. CWnd::OnEraseBkgnd(pDC);
  222. GetClientRect(&rect);
  223. int nModeOld = pDC->SetBkMode(TRANSPARENT);
  224. pDC->DrawText("NO MAP", rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
  225. pDC->SetBkMode(nModeOld);
  226. }
  227. return(false);
  228. }