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

模拟服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #define WRITESTRLENTH 50
  3. CMirMsgBox3D::CMirMsgBox3D()
  4. {
  5. m_bCanMove = TRUE;
  6. m_bFocused = FALSE;
  7. }
  8. CMirMsgBox3D::~CMirMsgBox3D()
  9. {
  10. }
  11. BOOL CMirMsgBox3D::Load(CWHWilImageData* pxImage)
  12. {
  13. CMirMsgBox::Load(pxImage);
  14. m_pxWndImage = pxImage;
  15. D3DWILTextr_Invalidate(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX1);
  16. D3DWILTextr_DestroyTexture(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX1);
  17. pxImage->NewSetIndex(_WNDIMGINDX_MSGBOX1);
  18. D3DWILTextr_CreateEmptyTexture(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX1,pxImage->m_lpstNewCurrWilImageInfo->shWidth,
  19. pxImage->m_lpstNewCurrWilImageInfo->shHeight,(WORD*)pxImage->m_pbCurrImage,D3DTEXTR_TRANSPARENTBLACK);
  20. D3DWILTextr_Invalidate(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX2);
  21. D3DWILTextr_DestroyTexture(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX2);
  22. pxImage->NewSetIndex(_WNDIMGINDX_MSGBOX2);
  23. D3DWILTextr_CreateEmptyTexture(pxImage->m_szWilFileName,_WNDIMGINDX_MSGBOX2,pxImage->m_lpstNewCurrWilImageInfo->shWidth,
  24. pxImage->m_lpstNewCurrWilImageInfo->shHeight,(WORD*)pxImage->m_pbCurrImage,D3DTEXTR_TRANSPARENTBLACK);
  25. return TRUE;
  26. }
  27. BOOL CMirMsgBox3D::CreateWnd(CWHWilImageData* pxWndImage, BOOL bCanMove, INT nStartX, INT nStartY, INT nWidth, INT nHeight)
  28. {
  29. m_nID = _WND_ID_MESSAGEBOX;
  30. m_pxWndImage = pxWndImage;
  31. m_bCanMove = bCanMove;
  32. Load(pxWndImage);
  33. m_pxWndImage->NewSetIndex(_WNDIMGINDX_MSGBOX1);
  34. SetRect(&m_rcImgWnd, nStartX, nStartY, 
  35. nStartX+m_pxWndImage->m_lpstNewCurrWilImageInfo->shWidth,
  36. nStartY+m_pxWndImage->m_lpstNewCurrWilImageInfo->shHeight);
  37. ( ! nWidth )  ? m_nWidth = m_rcImgWnd.right -m_rcImgWnd.left: m_nWidth  = nWidth;
  38. ( ! nHeight ) ? m_nHeight =m_rcImgWnd.bottom-m_rcImgWnd.top : m_nHeight = nHeight;
  39. SetRect(&m_rcWnd, nStartX, nStartY, nStartX+m_nWidth, nStartY+m_nHeight);
  40.   D3DVECTOR vNorm(0, 0, -1);
  41.     m_avMagic[0]  = D3DVERTEX(D3DVECTOR(-0.5f, 0.5f, 0), vNorm, 0, 0);
  42.     m_avMagic[1]  = D3DVERTEX(D3DVECTOR(-0.5f,-0.5f, 0), vNorm, 0, 1);
  43.     m_avMagic[2]  = D3DVERTEX(D3DVECTOR( 0.5f, 0.5f, 0), vNorm, 1, 0);
  44.     m_avMagic[3]  = D3DVERTEX(D3DVECTOR( 0.5f,-0.5f, 0), vNorm, 1, 1);
  45. return FALSE;
  46. }
  47. BOOL CMirMsgBox3D::ShowMessageBox(CHAR* szMgs,INT nType,INT nImgIndex) // Show Message box with Initialization
  48. {
  49. m_nFrameImgIdx = (nType&128) ? _WNDIMGINDX_MSGBOX2:_WNDIMGINDX_MSGBOX1;
  50. D3DWILTextr_Invalidate(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx);
  51. D3DWILTextr_Restore(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx, g_xMainWnd.Get3DDevice());
  52. CMirMsgBox::ShowMessageBox(szMgs,nType,nImgIndex);
  53. m_bActive = TRUE;
  54. return TRUE;
  55. }
  56. BOOL CMirMsgBox3D::HideMessageBox(VOID) // Hide Message box
  57. {
  58. m_bActive = FALSE;
  59. return FALSE;
  60. }
  61. BOOL CMirMsgBox3D::DestoryMessageBox(VOID) // DestoryMessage box
  62. {
  63. m_bActive = FALSE;
  64. m_bInited = FALSE;
  65. m_bSet = FALSE;
  66. m_xMsg.ClearAllNodes();
  67. return TRUE;
  68. }
  69. BOOL CMirMsgBox3D::OnKeyDown(WPARAM wParam,LPARAM lParam)
  70. {
  71. return TRUE;
  72. }
  73. BOOL CMirMsgBox3D::RenderMessageBox(INT nLoopTIme)
  74. {
  75. INT nCount;
  76. RenderBox();
  77. if(m_bActive&&m_bInited&&m_bSet)
  78. {
  79. // 柳楼 嘛绢具 且锭父 嘛阑巴
  80. // 嘛阑 捞固瘤 康开 犬牢
  81. POINT xTxtPos;
  82. m_xBoxPos.x = m_rcWnd.left;
  83. m_xBoxPos.y = m_rcWnd.top;
  84. nCount = m_xMsg.GetCounter();
  85. m_xMsg.MoveCurrentToTop();
  86. xTxtPos.x = m_xBoxPos.x +24;
  87. switch(nCount)
  88. {
  89. case 1: // 嘛阑 临捞 1俺 挥老锭
  90. {
  91. xTxtPos.y = 68;
  92. INT n = strlen(m_szMsg);
  93. if(n<WRITESTRLENTH)
  94. {
  95. xTxtPos.x= xTxtPos.x + (WRITESTRLENTH-n)*2;
  96. }
  97. break;
  98. }
  99. case 2: // 嘛阑 临捞 2俺 老锭
  100. {
  101. xTxtPos.y = 61;
  102. break;
  103. }
  104. case 3: // 嘛阑 临捞 3俺 老锭
  105. {
  106. xTxtPos.y = 54;
  107. break;
  108. }
  109. case 4: // 嘛阑 临捞 4俺 老锭
  110. {
  111. xTxtPos.y = 47;
  112. break;
  113. }
  114. case 5: // 嘛阑 临捞 5俺 老锭
  115. {
  116. xTxtPos.y = 40;
  117. break;
  118. }
  119. case 6: // 嘛阑 临捞 6俺 老锭
  120. {
  121. xTxtPos.y = 33;
  122. break;
  123. }
  124. default: // 嘛阑 临捞 7俺 捞惑老 版快
  125. {
  126. xTxtPos.y = 26;
  127. break;
  128. }
  129. }
  130. for(int i = 0 ; i < nCount ; i++)
  131. {
  132. g_xMainWnd.PutsHan(NULL,xTxtPos.x,m_xBoxPos.y+xTxtPos.y,RGB(255,255,255),RGB(0,0,0),*m_xMsg.GetCurrentData());
  133. xTxtPos.y = xTxtPos.y + 16;
  134. m_xMsg.MoveNextNode();
  135. }
  136. // Draw Button
  137. switch(m_nType)
  138. {
  139. case MSG_BTN_YESNO:
  140. case MSG_BTN_YESNO|MSG_EDITEXIST:
  141. {
  142. m_nStart=1;
  143. m_nEnd = 3;
  144. m_xMsgBtn[1].ChangeRect(m_xBoxPos.x+78,m_xBoxPos.y+134);
  145. m_xMsgBtn[2].ChangeRect(m_xBoxPos.x+210,m_xBoxPos.y+134);
  146. break;
  147. }
  148. case MSG_BTN_YESNOCANCLE:
  149. case MSG_BTN_YESNOCANCLE|MSG_EDITEXIST:
  150. {
  151. m_nStart=1;
  152. m_nEnd = 4;
  153. m_xMsgBtn[1].ChangeRect(m_xBoxPos.x+54,m_xBoxPos.y+134);
  154. m_xMsgBtn[2].ChangeRect(m_xBoxPos.x+144,m_xBoxPos.y+134);
  155. m_xMsgBtn[3].ChangeRect(m_xBoxPos.x+234,m_xBoxPos.y+134);
  156. break;
  157. }
  158. case MSG_BTN_OK:
  159. {
  160. m_nStart=0;
  161. m_nEnd = 1;
  162. m_xMsgBtn[0].ChangeRect(m_xBoxPos.x+144,m_xBoxPos.y+134);
  163. break;
  164. }
  165. case MSG_BTN_OK|MSG_EDITEXIST:
  166. default:
  167. {
  168. m_nStart=0;
  169. m_nEnd = 1;
  170. m_xMsgBtn[0].ChangeRect(m_xBoxPos.x+260,m_xBoxPos.y+134);
  171. break;
  172. }
  173. }
  174. for(i = m_nStart; i< m_nEnd; i++)
  175. {
  176. m_xMsgBtn[i].ShowGameBtn();
  177. }
  178. return FALSE;
  179. }
  180. return TRUE;
  181. }
  182. BOOL CMirMsgBox3D::RenderBox(VOID)
  183. {
  184. if ( m_bActive )
  185. {
  186. if ( g_xMainWnd.Get3DDevice() )
  187. {
  188. D3DVECTOR vTrans;
  189. D3DMATRIX matTrans;
  190. D3DMATRIX matScale;
  191. D3DMATRIX matWorld;
  192. D3DMATRIX matWorldOriginal;
  193. D3DMATERIAL7 mtrl;
  194. if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene()))
  195. {
  196. g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  197. m_pxWndImage->NewSetIndex(m_nFrameImgIdx);
  198. vTrans.x = (FLOAT)m_rcWnd.left+(FLOAT)(m_rcImgWnd.right-m_rcImgWnd.left)/2-400;
  199. vTrans.y = (FLOAT)-m_rcWnd.top-(FLOAT)(m_rcImgWnd.bottom-m_rcImgWnd.top)/2+300;
  200. vTrans.z = 0;
  201. D3DUtil_SetTranslateMatrix(matTrans, vTrans);
  202. D3DUtil_SetScaleMatrix(matScale, (FLOAT)m_rcImgWnd.right-m_rcImgWnd.left, (FLOAT)m_rcImgWnd.bottom-m_rcImgWnd.top, 0.0f);
  203. D3DMath_MatrixMultiply(matWorld, matScale, matTrans);
  204. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorld);
  205. if ( m_bFocused )
  206. {
  207. g_xMainWnd.Get3DDevice()->SetTexture(0, D3DWILTextr_GetSurface(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx));
  208. D3DUtil_InitMaterial(mtrl, 
  209.  (FLOAT)255/255.0f,
  210.  (FLOAT)255/255.0f, 
  211.  (FLOAT)255/255.0f);
  212. mtrl.diffuse.a = 200/255.0f;
  213. g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
  214. }
  215. else
  216. {
  217. g_xMainWnd.Get3DDevice()->SetTexture(0, D3DWILTextr_GetSurface(m_pxWndImage->m_szWilFileName, m_nFrameImgIdx));
  218. D3DUtil_InitMaterial(mtrl,
  219.  (FLOAT)255/255.0f,
  220.  (FLOAT)255/255.0f,
  221.  (FLOAT)255/255.0f);
  222. mtrl.diffuse.a = 170/255.0f;
  223. g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
  224. }
  225. g_xMainWnd.Get3DDevice()->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
  226. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
  227. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
  228. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE);
  229. g_xMainWnd.Get3DDevice()->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
  230. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE);
  231. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
  232. g_xMainWnd.Get3DDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_VERTEX, m_avMagic, 4, NULL);
  233. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);
  234. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
  235. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND , D3DBLEND_ONE);
  236. g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
  237. g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);
  238. g_xMainWnd.Get3DDevice()->EndScene();
  239. }
  240. }
  241. }
  242. return TRUE;
  243. }
  244. VOID CMirMsgBox3D::MoveWnd(POINT ptMouse) // Move Window
  245. {
  246. if ( m_bActive && m_bFocused && m_bCanMove )
  247. {
  248. SetRect(&m_rcWnd, ptMouse.x-m_bGrabbedMousePos.x, ptMouse.y-m_bGrabbedMousePos.y,
  249. ptMouse.x-m_bGrabbedMousePos.x+m_nWidth, ptMouse.y-m_bGrabbedMousePos.y+m_nHeight);
  250. }
  251. }
  252. HRESULT CMirMsgBox3D::OnButtonDown(POINT tpMouse) // Button Down
  253. {
  254. if(CMirMsgBox::OnButtonDown(tpMouse)==1) return 0;
  255. if(IsInRect(tpMouse.x,tpMouse.y,m_rcWnd))
  256. {
  257. m_bFocused = TRUE;
  258. if ( m_bActive && m_bFocused && m_bCanMove ) // Get the gaps between Mouse and Window
  259. {
  260. m_bGrabbedMousePos.x = tpMouse.x - m_rcWnd.left;
  261. m_bGrabbedMousePos.y = tpMouse.y - m_rcWnd.top;
  262. }
  263. }
  264. return 0;
  265. }
  266. HRESULT CMirMsgBox3D::OnButtonUp(POINT tpMouse) // Button Up
  267. {
  268. m_bFocused = FALSE;
  269. return CMirMsgBox::OnButtonUp(tpMouse);
  270. }