SelectChr.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:8k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #define CHR_ANI_COUNT 21
  3. #define ANIMATION_TICK 200
  4. #define BLEND_TICK 50
  5. CSelectChr::CSelectChr()
  6. {
  7. m_nRenderState = 0;
  8. m_nAnimationCount = 0;
  9. m_nRoll = 0;
  10. m_nBlend = -999;
  11. m_fIsButtonDown = FALSE;
  12. }
  13. CSelectChr::~CSelectChr()
  14. {
  15. if(m_pBtn!=NULL)
  16. {
  17. delete[] m_pBtn;
  18. }
  19. }
  20. VOID CSelectChr::Create(CWHWilImageData* pxImage,CPDLList<CHRINFO>* pxList, CPDLList<CHRRECT>* pxrcList,INT nChrCount)
  21. {
  22. INT nLoop;
  23. // Buttons
  24. BUTTONINFO CharProcBtnInfo[] ={
  25. { IMG_IDX_SELECT_CREATE, SELECT_CHAR_NEW_BTN_POS_X, SELECT_CHAR_NEW_BTN_POS_Y, 0, 0}, // Create New Charector Button
  26. { IMG_IDX_SELECT_DELETE, SELECT_CHAR_ERASE_BTN_POS_X, SELECT_CHAR_ERASE_BTN_POS_Y, 0, 0}, // Erase Charector Button
  27. { IMG_IDX_SELECT_EXIT, SELECT_CHAR_EXIT_BTN_POS_X, SELECT_CHAR_EXIT_BTN_POS_Y, 0, 0}, // Exit Button
  28. { IMG_IDX_SELECT_START, SELECT_CHAR_START_BTN_POS_X, SELECT_CHAR_START_BTN_POS_Y, 0, 0}, // Start Button
  29. };
  30. m_pBtn = new CMirButton*[sizeof(CharProcBtnInfo)/sizeof(BUTTONINFO)];
  31. m_pxImage = pxImage;
  32. m_pxSList = pxList;
  33. m_pxrcList = pxrcList;
  34. m_nChrCount = nChrCount;
  35. m_xLightFog.Init(RGB(125,125,125));
  36. for( nLoop = 0 ; nLoop < (sizeof(CharProcBtnInfo)/sizeof(BUTTONINFO)) ; nLoop++)
  37. {
  38. m_pBtn[nLoop] = new CMirButton;
  39. m_pxImage->NewSetIndex(CharProcBtnInfo[nLoop].nID);
  40. CharProcBtnInfo[nLoop].right = m_pxImage->m_lpstNewCurrWilImageInfo->shWidth;
  41. CharProcBtnInfo[nLoop].bottom = m_pxImage->m_lpstNewCurrWilImageInfo->shHeight;
  42. m_pBtn[nLoop]->SetBtn(&CharProcBtnInfo[nLoop]);
  43. }
  44. }
  45. VOID CSelectChr::OpenWnd(VOID)
  46. {
  47. m_fIsActive = TRUE;
  48. m_nRenderState = 9;
  49. m_nBlend = 100;
  50. }
  51. HRESULT CSelectChr::OnKeyDown(WPARAM wParam, LPARAM lParam)
  52. {
  53. return 0;
  54. }
  55. HRESULT CSelectChr::OnButtonDown(WPARAM wParam, LPARAM lParam)
  56. {
  57. if(m_fIsActive)
  58. for (int i = ID_SEL_CHR_NEW_BTN; i <= ID_SEL_CHR_START_BTN; i++)
  59. {
  60. if (IsInRect(m_pBtn[i]->m_Rect,LOWORD(lParam), HIWORD(lParam)))
  61. {
  62. m_pBtn[i]->m_nState = BUTTON_STATE_DOWN;
  63. m_fIsButtonDown = TRUE;
  64. }
  65. else
  66. m_pBtn[i]->m_nState = BUTTON_STATE_UP;
  67. }
  68. return 0;
  69. }
  70. HRESULT CSelectChr::OnButtonDown(POINT ptMouse)
  71. {
  72. m_fIsButtonDown = TRUE;
  73. return 0;
  74. }
  75. HRESULT CSelectChr::OnButtonUp(WPARAM wParam, LPARAM lParam)
  76. {
  77. INT i;
  78. int Px,Py;
  79. if(m_fIsActive)
  80. {
  81. for(i = ID_SEL_CHR_NEW_BTN; i <= ID_SEL_CHR_START_BTN; i++)
  82. { m_pBtn[i]->m_nState = BUTTON_STATE_UP;
  83. if (IsInRect(m_pBtn[i]->m_Rect,LOWORD(lParam), HIWORD(lParam)))
  84. { switch(i)
  85. {
  86. case ID_SEL_CHR_NEW_BTN:
  87. {
  88. if(m_nChrCount<3)
  89. { m_nBlend = 0;
  90. m_nRenderState = 1;
  91. return RETURN_SELECT_NEW_BTN;
  92. }
  93. else
  94. return RETURN_SELECT_NEW_ERR;
  95. break;
  96. }
  97. case ID_SEL_CHR_DEL_BTN:
  98. {
  99. if(m_nChrCount!=0)
  100. {
  101. return RETURN_SELECT_DEL_BTN;
  102. }
  103. else
  104. return RETURN_SELECT_DEL_ERR;
  105. break;
  106. }
  107. case ID_SEL_CHR_EXIT_BTN:
  108. {
  109. SendMessage(g_xMainWnd.GetSafehWnd(), WM_DESTROY, NULL, NULL);
  110. return 0L;
  111. }
  112. case ID_SEL_CHR_START_BTN:
  113. {
  114. if(m_nSelectChr != SELECT_NONE)
  115. { m_nBlend = 0;
  116. m_pxSList->MoveCurrentToTop();
  117. m_pxSList->MoveNode(m_nSelectChr);
  118. g_xClientSocket.OnSelChar(m_pxSList->GetCurrentData()->ChrName);
  119. return RETURN_SELECT_START_BTN;
  120. }
  121. else
  122. {
  123. return RETURN_SELECT_START_ERR;
  124. }
  125. break;
  126. }
  127. }
  128. }
  129. }
  130. m_pxrcList->MoveCurrentToTop();
  131. m_pxSList->MoveCurrentToTop();
  132. for(i=0; i < m_pxrcList->ListLength(); i++)
  133. {
  134. Px = m_pxrcList->GetCurrentData()->nLeft - LOWORD(lParam);
  135. Py = m_pxrcList->GetCurrentData()->nTop - HIWORD(lParam);
  136. if(Px < 0 && ((Px +m_pxrcList->GetCurrentData()->nWidth)>0))
  137. {
  138. if(Py<0 && ((Py+m_pxrcList->GetCurrentData()->nHeight)>0))
  139. {
  140. m_nSelectChr = i;
  141. }
  142. }
  143. m_pxrcList->MoveNextNode();
  144. }
  145. }
  146. m_fIsButtonDown = FALSE;
  147. return 0;
  148. }
  149. HRESULT CSelectChr::OnButtonUp(POINT ptMouse)
  150. {
  151. return 0;
  152. }
  153. LRESULT CSelectChr::OnMouseMove(WPARAM wParam, LPARAM lParam)
  154. {
  155. INT i;
  156. BOOL fOnButton = FALSE;
  157. if(m_fIsActive&&(!m_fIsButtonDown))
  158. {
  159. for (i = ID_SEL_CHR_NEW_BTN; i <= ID_SEL_CHR_START_BTN; i++)
  160. {
  161. if (IsInRect(m_pBtn[i]->m_Rect,LOWORD(lParam), HIWORD(lParam)))
  162. {
  163. m_pBtn[i]->m_nState = BUTTON_STATE_DOWN;
  164. fOnButton = TRUE;
  165. }
  166. else
  167. m_pBtn[i]->m_nState = BUTTON_STATE_UP;
  168. }
  169. /* if(fOnButton)
  170. {
  171. HCURSOR hCursor;
  172. hCursor = LoadCursor(g_xMainWnd.GetSafehInstance(),MAKEINTRESOURCE(IDC_HAND1));
  173. SetCursor(hCursor);
  174. DestroyCursor(hCursor); 
  175. }
  176. else
  177. g_xMainWnd.OnSetCursor(IDC_ARROW);
  178. */
  179. }
  180. return 0;
  181. }
  182. VOID CSelectChr::Render(INT nLoopTime)
  183. {
  184. static DWORD dwTicks = 0;
  185. int i;
  186. INT nPx,nPy;
  187. POINT ptPos[] = { 
  188. {310,310}, // One
  189. {300,270}, // Two-One
  190. {360,310}, // Two-Two
  191. {250,270}, // Three-One
  192. {320,310}, // Three-Two
  193. {390,340} 
  194. };// Three-Three
  195. if(m_fIsActive)
  196. {
  197. m_xLightFog.ClearSavedLightColor();
  198. for (i = ID_SEL_CHR_NEW_BTN; i <= ID_SEL_CHR_START_BTN ; i++) // 窜眠 烙矫
  199. {
  200. if(m_pBtn[i]->m_nState==BUTTON_STATE_DOWN) // Draw Button when Button state is Downed..
  201. {
  202. m_pxImage->NewSetIndex(m_pBtn[i]->m_nButtonID);
  203. g_xMainWnd.DrawWithImageForComp(m_pBtn[i]->m_Rect.left, m_pBtn[i]->m_Rect.top,
  204. m_pxImage->m_lpstNewCurrWilImageInfo->shWidth,
  205. m_pxImage->m_lpstNewCurrWilImageInfo->shHeight
  206. , (WORD*)(m_pxImage->m_pbCurrImage));
  207. }
  208. }
  209. dwTicks +=nLoopTime;
  210. if(dwTicks > BLEND_TICK)
  211. {
  212. m_nBlend = m_nBlend +((m_nRenderState != 0)? dwTicks / BLEND_TICK *(m_nRenderState != 9 ? 1 : -1): 0);
  213. m_nRoll = (m_nRoll+ 2)%100;
  214. if(dwTicks > ANIMATION_TICK)
  215. {
  216. m_nAnimationCount++;
  217. m_nAnimationCount%=CHR_ANI_COUNT;
  218. dwTicks = 0;
  219. }
  220. }
  221. m_pxSList->MoveCurrentToTop();
  222. for( i = 0 ; i < m_nChrCount ; i ++)
  223. {
  224. // Draw Person
  225. m_pxImage->NewSetIndex(IDX_IMG_MALE_WAR 
  226. + (m_pxSList->GetCurrentData()->Gender) * 60
  227. + (m_pxSList->GetCurrentData()->Class) * 120 
  228. + ((i == m_nSelectChr) ? m_nAnimationCount : 0)) ;
  229. nPx = ptPos[i + m_nChrCount - 1].x + m_pxImage->m_lpstNewCurrWilImageInfo->shPX;
  230. nPy = ptPos[i + m_nChrCount - 1].y + m_pxImage->m_lpstNewCurrWilImageInfo->shPY;
  231. g_xMainWnd.DrawWithABlendCompDataWithBackBuffer(nPx,nPy
  232. ,m_pxImage->m_lpstNewCurrWilImageInfo->shWidth,m_pxImage->m_lpstNewCurrWilImageInfo->shHeight
  233. ,(WORD*)(m_pxImage->m_pbCurrImage),640,480,0xffff,0xffff,((m_nBlend>=0)? m_nBlend : 0));
  234. // Draw Fire
  235. if(i == m_nSelectChr)
  236. {
  237. m_pxImage->NewSetIndex(IDX_IMG_MALE_WAR_FIRE 
  238. + (m_pxSList->GetCurrentData()->Gender) * 60
  239. + (m_pxSList->GetCurrentData()->Class) * 120 
  240. + (m_nAnimationCount)) ;
  241. nPx = ptPos[i + m_nChrCount - 1].x + m_pxImage->m_lpstNewCurrWilImageInfo->shPX;
  242. nPy = ptPos[i + m_nChrCount - 1].y + m_pxImage->m_lpstNewCurrWilImageInfo->shPY;
  243. g_xMainWnd.DrawWithABlendCompDataWithBackBuffer(nPx,nPy
  244. ,m_pxImage->m_lpstNewCurrWilImageInfo->shWidth,m_pxImage->m_lpstNewCurrWilImageInfo->shHeight
  245. ,(WORD*)(m_pxImage->m_pbCurrImage),640,480,0xffff,0x1f1f,((m_nBlend>=0)? m_nBlend : 50));
  246. INT nTemp = (INT)(125.0f * sin((m_nRoll/10)));
  247. m_xLightFog.SetLightRadiusWithCircle(nPx+100,nPy+100,((m_nBlend>=0) ? 5 - ((m_nBlend)/20) : 5),125 + nTemp,255 + nTemp,255 + nTemp);
  248. }
  249. m_pxSList->MoveNextNode();
  250. }
  251. m_xLightFog.ShowLightFog();
  252. ShowChrInfo();
  253. if((m_nBlend>=100 && m_nRenderState!=9)||(m_nBlend<=0 && m_nRenderState==9))
  254. {
  255. m_nBlend = -1;
  256. m_nRenderState = m_nRenderState + 10;
  257. }
  258. }
  259. }
  260. VOID CSelectChr::ShowChrInfo(VOID)
  261. {
  262. char ChrName[20];
  263. char ChrLev[3];
  264. if(m_nChrCount!=0)
  265. {
  266. m_pxSList->MoveCurrentToTop();
  267. m_pxSList->MoveNode(m_nSelectChr);
  268. strcpy(ChrName,m_pxSList->GetCurrentData()->ChrName);
  269. strcpy(g_szCharName,m_pxSList->GetCurrentData()->ChrName);
  270. itoa(m_pxSList->GetCurrentData()->Level,ChrLev,10);
  271. g_xMainWnd.PutsHan(NULL,m_PosName.x,m_PosName.y,RGB(255,255,255),RGB(0,0,0),ChrName);
  272. }
  273. }
  274. VOID CSelectChr::CloseWnd(VOID)
  275. {
  276. m_fIsActive = FALSE;
  277. }