UiSysMsgCentre.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:23k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--系统消息中心
  3. // Copyright : Kingsoft 2003
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2003-4-15
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/Wnds.h"
  10. #include "../Elem/WndMessage.h"
  11. #include "UiSysMsgCentre.h"
  12. #include "UiMsgCentrePad.h"
  13. #include "UiInformation.h"
  14. #include "UiStatus.h"
  15. #include "UiSkills.h"
  16. #include "UiTeamManage.h"
  17. #include "UiPlayerBar.h"
  18. #include "UiInit.h"
  19. #include "UiConnectInfo.h"
  20. #include "../UiBase.h"
  21. #include "UiReconnect.h"
  22. #include "../../../core/src/MsgGenreDef.h"
  23. #include "../../../Engine/Src/Text.h"
  24. #include "../../../Represent/iRepresent/iRepresentShell.h"
  25. #include "../../../core/src/coreshell.h"
  26. #include "../UiShell.h"
  27. #include <crtdbg.h>
  28. #include "UiChatCentre.h"
  29. #include "KTongProtocol.h"
  30. extern iCoreShell* g_pCoreShell;
  31. extern iRepresentShell* g_pRepresentShell;
  32. #define SCHEME_INI "系统消息.ini"
  33. #define SYSTEM_MSG_SENDER_NAME "公告"
  34. #define MSG_LIST_EXPAND_STEP 4
  35. #define POPUP_MOVE_INTERVAL_DEF 20
  36. #define MSG_DISAPPEAR_INTERVAL_DEF 30000
  37. #define POPUP_MOVE_SPEED 24
  38. #define LAST_MOVEMENT_POS -1
  39. #define MAX_MSG_IN_RECYCLE_HEAP 10
  40. #define MSG_RENASCENCE "你已经身受重伤!"
  41. #define MSG_BACK_TO_TOWN "回城休养"
  42. #define POP_UP_TIME uReservedForUi
  43. KUiSysMsgCentre* KUiSysMsgCentre::m_pSelf = NULL;
  44. //--------------------------------------------------------------------------
  45. // 功能:构造函数
  46. //--------------------------------------------------------------------------
  47. KUiSysMsgCentre::KUiSysMsgCentre()
  48. {
  49. m_SysMsgParam.cChatPrefixLen = 0;
  50. m_SysMsgParam.eGenre = MSG_G_CHAT;
  51. m_SysMsgParam.nMsgLength = 0;
  52. strcpy(m_SysMsgParam.szName, SYSTEM_MSG_SENDER_NAME);
  53. m_nPopupMsgDestX = 0;
  54. m_nPopupMsgX = LAST_MOVEMENT_POS;
  55. m_nPopupMsgDestIndex = 0;
  56. memset(&m_MsgHeap, 0, sizeof(m_MsgHeap));
  57. memset(&m_MsgIcon, 0, sizeof(m_MsgIcon));
  58. memset(&m_nMsgIconFrame, 0, sizeof(m_nMsgIconFrame));
  59. m_pHandlingMsg = NULL;
  60. m_bShowMsgText = false;
  61. m_uMoveInterval = POPUP_MOVE_INTERVAL_DEF;
  62. m_uDisappearInterval = MSG_DISAPPEAR_INTERVAL_DEF;
  63. }
  64. KUiSysMsgCentre::~KUiSysMsgCentre()
  65. {
  66. Clear();
  67. }
  68. //--------------------------------------------------------------------------
  69. // 功能:打开窗口,返回唯一的一个类对象实例
  70. //--------------------------------------------------------------------------
  71. KUiSysMsgCentre* KUiSysMsgCentre::OpenWindow()
  72. {
  73. if (m_pSelf == NULL)
  74. {
  75. m_pSelf = new KUiSysMsgCentre;
  76. if (m_pSelf)
  77. m_pSelf->Initialize();
  78. }
  79. if (m_pSelf)
  80. m_pSelf->Show();
  81. return m_pSelf;
  82. }
  83. //--------------------------------------------------------------------------
  84. // 功能:初始化
  85. //--------------------------------------------------------------------------
  86. void KUiSysMsgCentre::Initialize()
  87. {
  88. AddChild(&m_MsgTextWnd);
  89. for (int i = 0; i < MAX_SYS_MSG_TYPE; i++)
  90. AddChild(&m_MsgIconBtn[i]);
  91. m_Style &= ~WND_S_VISIBLE;
  92. char Scheme[128];
  93. g_UiBase.GetCurSchemePath(Scheme, 256);
  94. LoadScheme(Scheme);
  95. KIniFile* pSetting = g_UiBase.GetCommConfigFile();
  96. if (pSetting)
  97. {
  98. pSetting->GetInteger("Main", "SysMsgMoveInterval", POPUP_MOVE_INTERVAL_DEF, (int*)(&m_uMoveInterval));
  99. pSetting->GetInteger("Main", "SysMsgDisappearInterval", MSG_DISAPPEAR_INTERVAL_DEF, (int*)(&m_uDisappearInterval));
  100. g_UiBase.CloseCommConfigFile();
  101. }
  102. else
  103. m_uMoveInterval = POPUP_MOVE_INTERVAL_DEF;
  104. Wnd_AddWindow(this, WL_TOPMOST);
  105. }
  106. //--------------------------------------------------------------------------
  107. // 功能:关闭窗口
  108. //--------------------------------------------------------------------------
  109. void KUiSysMsgCentre::CloseWindow()
  110. {
  111. if (m_pSelf)
  112. {
  113. m_pSelf->Clear();
  114. m_pSelf->Destroy();
  115. m_pSelf = NULL;
  116. }
  117. }
  118. //--------------------------------------------------------------------------
  119. // 功能:载入窗口的界面方案
  120. //--------------------------------------------------------------------------
  121. void KUiSysMsgCentre::LoadScheme(const char* pScheme)
  122. {
  123. if (m_pSelf)
  124. {
  125. char szBuf[128];
  126. KIniFile Ini;
  127. sprintf(szBuf, "%s\%s", pScheme, SCHEME_INI);
  128. if (Ini.Load(szBuf))
  129. m_pSelf->LoadScheme(&Ini);
  130. }
  131. }
  132. //--------------------------------------------------------------------------
  133. // 功能:载入窗口的界面方案
  134. //--------------------------------------------------------------------------
  135. void KUiSysMsgCentre::LoadScheme(KIniFile* pIni)
  136. {
  137. KWndWindow::Init(pIni, "Main");
  138. m_MsgTextWnd .Init(pIni, "MsgText");
  139. char szBuf[16];
  140. for (int i = 0; i < MAX_SYS_MSG_TYPE; i++)
  141. {
  142. sprintf(szBuf, "MsgIcon_%d", i + 1);
  143. m_MsgIconBtn[i].Init(pIni, szBuf);
  144. m_MsgIconBtn[i].SetImage(ISI_T_SPR, "");
  145. // m_MsgIconBtn[i].m_Image.szImage[0] = 0;
  146. // m_MsgIconBtn[i].m_Image.uImage = 0;
  147. m_MsgIcon[i].Color.Color_b.a = 255;
  148. m_MsgIcon[i].nFlipTime = 0;
  149. m_MsgIcon[i].nInterval = 0;
  150. m_MsgIcon[i].nNumFrames = 0;
  151. m_MsgIcon[i].nType = ISI_T_SPR;
  152. m_MsgIcon[i].bRenderStyle = IMAGE_RENDER_STYLE_ALPHA;
  153. m_MsgIcon[i].uImage = 0;
  154. m_MsgIcon[i].nISPosition = IMAGE_IS_POSITION_INIT;
  155. pIni->GetString (szBuf, "Image", "" , m_MsgIcon[i].szImage, sizeof(m_MsgIcon[i].szImage));
  156. int nValue;
  157. pIni->GetInteger(szBuf, "Frame", 0, &nValue);
  158. m_MsgIcon[i].nFrame = m_nMsgIconFrame[i] = nValue;
  159. }
  160. pIni->GetString("Main", "NormalMsgColor", "255,255,255", szBuf, sizeof(szBuf));
  161. unsigned int uColor = GetColor(szBuf);
  162. m_SysMsgParam.cChatPrefix[0] = KTC_COLOR;
  163. m_SysMsgParam.cChatPrefix[1] = (uColor >> 16) & 0xff;
  164. m_SysMsgParam.cChatPrefix[2] = (uColor >> 8) & 0xff;
  165. m_SysMsgParam.cChatPrefix[3] = uColor & 0xff;
  166. m_SysMsgParam.cChatPrefixLen = 4;
  167. }
  168. //--------------------------------------------------------------------------
  169. // 功能:窗口函数
  170. //--------------------------------------------------------------------------
  171. int KUiSysMsgCentre::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  172. {
  173. int i, nRet = 0;
  174. switch(uMsg)
  175. {
  176. case WND_N_BUTTON_MR_DOWN:
  177. case WND_N_BUTTON_CLICK:
  178. for (i = 0; i < MAX_SYS_MSG_TYPE; i++)
  179. {
  180. if (uParam == (unsigned int)(KWndWindow*)&m_MsgIconBtn[i])
  181. {
  182. DeleteMsgInHeap(i, 0, (uMsg == WND_N_BUTTON_MR_DOWN), true);
  183. break;
  184. }
  185. }
  186. break;
  187. case WND_N_MOUSE_ENTER_CHILD:
  188. for (i = 0; i < MAX_SYS_MSG_TYPE; i++)
  189. {
  190. if (uParam == (unsigned int)(KWndWindow*)&m_MsgIconBtn[i])
  191. {
  192. m_MsgTextWnd.SetText("", 0);
  193. if (m_MsgHeap[i].nNumValid)
  194. {
  195. m_MsgTextWnd.SetText(m_MsgHeap[i].pMsgList[0]->szMessage);
  196. m_bShowMsgText = true;
  197. }
  198. break;
  199. }
  200. }
  201. break;
  202. case WND_N_MOUSE_LEAVE_CHILD:
  203. m_MsgTextWnd.SetText("", 0);
  204. m_bShowMsgText = false;
  205. break;
  206. case WND_M_OTHER_WORK_RESULT:
  207. OnConfirmOperFinished(uParam, nParam);
  208. break;
  209. default:
  210. nRet = KWndWindow::WndProc(uMsg, uParam, nParam);
  211. break;
  212. }
  213. return nRet;
  214. }
  215. //响应操作结束,玩家已经做出选择。
  216. void KUiSysMsgCentre::OnConfirmOperFinished(unsigned int uParam, int nSelAction)
  217. {
  218. //_ASSERT(m_pHandlingMsg);
  219. KUiPlayerItem* pPlayer = NULL;
  220. switch(uParam)
  221. {
  222. case SMCT_UI_RENASCENCE: //选择重生
  223. g_pCoreShell->OperationRequest(GOI_PLAYER_RENASCENCE, 0, nSelAction);//nSelAction=0:原地重生, nSelAction=1:回城
  224. break;
  225. case SMCT_UI_TEAM_INVITE: //答应或拒绝加入队伍的邀请
  226. if (m_pHandlingMsg)
  227. {
  228. //_ASSERT(m_pHandlingMsg->byParamSize >= sizeof(KUiPlayerItem))
  229. pPlayer = (KUiPlayerItem*)(&m_pHandlingMsg[1]);
  230. g_pCoreShell->TeamOperation(TEAM_OI_INVITE_RESPONSE,
  231. (unsigned int)pPlayer, (nSelAction == 0)); //nSelAction=0:答应, nSelAction=1:拒绝
  232. }
  233. break;
  234. case SMCT_UI_TEAM_APPLY: //答应或拒绝加入队伍的申请,
  235. if (m_pHandlingMsg)
  236. {
  237. //_ASSERT(m_pHandlingMsg->byParamSize >= sizeof(KUiPlayerItem))
  238. pPlayer = (KUiPlayerItem*)(&m_pHandlingMsg[1]);
  239. g_pCoreShell->TeamOperation(TEAM_OI_APPLY_RESPONSE,
  240. (unsigned int)pPlayer, (nSelAction == 0)); //nSelAction=0:答应, nSelAction=1:拒绝
  241. }
  242. break;
  243. case SMCT_UI_FRIEND_INVITE: //批准或拒绝别人加自己为好友
  244. if (m_pHandlingMsg)
  245. {
  246. //_ASSERT(m_pHandlingMsg->byParamSize >= sizeof(KUiPlayerItem));
  247. pPlayer = (KUiPlayerItem*)(&m_pHandlingMsg[1]);
  248. g_pCoreShell->OperationRequest(GOI_CHAT_FRIEND_INVITE,
  249. (unsigned int)pPlayer, (nSelAction == 0)); //nSelAction=0:答应, nSelAction=1:拒绝
  250. if (nSelAction == 0)
  251. {
  252. int nUnit = KUiChatCentre::FindUnitIndexByRoleNameAtServerUnit(pPlayer->Name);
  253. if (nUnit >= 0)
  254. {
  255. KUiChatCentre::DeleteFriend(nUnit, pPlayer->Name, false);
  256. }
  257. KUiChatCentre::AddFriendInfo(0, pPlayer->Name, "");
  258. KUiChatCentre::FriendStatus(0, pPlayer->Name, stateOnline);
  259. }
  260. }
  261. break;
  262. case SMCT_UI_TRADE:
  263. if (m_pHandlingMsg)
  264. {
  265. //_ASSERT(m_pHandlingMsg->byParamSize >= sizeof(KUiPlayerItem));
  266. pPlayer = (KUiPlayerItem*)(&m_pHandlingMsg[1]);
  267. g_pCoreShell->OperationRequest(GOI_TRADE_INVITE_RESPONSE,
  268. (unsigned int)pPlayer, (nSelAction == 0)); //nSelAction=0:答应, nSelAction=1:拒绝
  269. }
  270. break;
  271. case SMCT_UI_TONG_JOIN_APPLY:
  272. if (m_pHandlingMsg)
  273. {
  274. //_ASSERT(m_pHandlingMsg->byParamSize >= sizeof(KUiPlayerItem))
  275. pPlayer = (KUiPlayerItem*)(&m_pHandlingMsg[1]);
  276. g_pCoreShell->TongOperation(GTOI_TONG_JOIN_REPLY,
  277. (unsigned int)pPlayer, (nSelAction == 0)); //nSelAction=0:答应, nSelAction=1:拒绝
  278. }
  279. break;
  280. }
  281. if (m_pHandlingMsg)
  282. {
  283. if (m_MsgHeap[RECYCLE_MSG_HEAP_INDEX].nNumValid >= MAX_MSG_IN_RECYCLE_HEAP ||
  284. !AddAMsgToHeap(m_pHandlingMsg, RECYCLE_MSG_HEAP_INDEX, false))
  285. {
  286. free(m_pHandlingMsg);
  287. }
  288. m_pHandlingMsg = NULL;
  289. }
  290. }
  291. //判断一个点是否在窗口范围内,传入的是绝对坐标
  292. int KUiSysMsgCentre::PtInWindow(int x, int y)
  293. {
  294. if (KWndWindow::PtInWindow(x, y))
  295. {
  296. for (int i = 0; i < MAX_SYS_MSG_TYPE; i++)
  297. {
  298. if (m_MsgHeap[i].nNumValid && m_MsgIconBtn[i].PtInWindow(x, y))
  299. return (i + 1);
  300. }
  301. }
  302. return 0;
  303. }
  304. void KUiSysMsgCentre::Breathe()
  305. {
  306. //让超时的消息消失
  307. int i, j;
  308. for (i = 0; i < MAX_SYS_MSG_TYPE; i++)
  309. {
  310. if (m_MsgHeap[i].nNumValid == 0)
  311. break;
  312. for (j = m_MsgHeap[i].nNumValid - 1;  j >= 0; j--)
  313. {
  314. KSystemMessage* pMsg = m_MsgHeap[i].pMsgList[j];
  315. if (pMsg->byConfirmType == SMCT_CLICK &&
  316. IR_IsTimePassed(m_uDisappearInterval * pMsg->byPriority + m_uDisappearInterval, pMsg->uReservedForUi))
  317. {
  318. DeleteMsgInHeap(i, j, true, false);
  319. }
  320. }
  321. }
  322. //移动正在弹出消息
  323. if (m_MsgHeap[POPUPING_MSG_HEAP_INDEX].nNumValid)
  324. {
  325. if (IR_IsTimePassed(m_uMoveInterval, m_uLastMovementTime))
  326. {
  327. m_nPopupMsgX -= POPUP_MOVE_SPEED;
  328. if (m_nPopupMsgX <= m_nPopupMsgDestX)
  329. MovePopupedMsgToHeap();
  330. }
  331. }
  332. }
  333. bool KUiSysMsgCentre::AMessageArrival(KSystemMessage* pMsg, void* pParam)
  334. {
  335. if (pMsg == NULL || m_pSelf == NULL || 
  336. (pMsg->byParamSize != 0 && pParam == NULL))
  337. return false;
  338. if (pMsg->eType == SMT_NORMAL)
  339. {
  340. KUiMsgCentrePad::SystemMessageArrival(pMsg->szMessage, strlen(pMsg->szMessage)); // 加入一条消息
  341. return true;
  342. }
  343. if (pMsg->byConfirmType == SMCT_UI_RENASCENCE) //重生
  344. {
  345. UIMessageBox(MSG_RENASCENCE, m_pSelf, MSG_BACK_TO_TOWN, NULL, SMCT_UI_RENASCENCE);
  346. return true;
  347. }
  348. //过滤相同的消息
  349. if (pMsg->byConfirmType != SMCT_MSG_BOX)
  350. {
  351. if (m_pSelf->FilterSameMsg(pMsg, pParam))
  352. return true;
  353. }
  354. KSystemMessage* pCloneMsg = m_pSelf->GetAMsgSpace(pMsg->byParamSize);
  355. if (pCloneMsg)
  356. {
  357. memcpy(pCloneMsg, pMsg, sizeof(KSystemMessage) - sizeof(pMsg->byParamSize));
  358. if (pMsg->byParamSize && pParam)
  359. memcpy(&pCloneMsg[1], pParam, pMsg->byParamSize);
  360. if (m_pSelf->AddAMsgToHeap(pCloneMsg, POPUPING_MSG_HEAP_INDEX, false))
  361. {
  362. pCloneMsg->POP_UP_TIME = IR_GetCurrentTime();
  363. if (m_pSelf->m_MsgHeap[POPUPING_MSG_HEAP_INDEX].nNumValid == 1)
  364. m_pSelf->SetPopupMsgDest();
  365. return true;
  366. }
  367. free(pCloneMsg);
  368. pCloneMsg = NULL;
  369. }
  370. return false;
  371. }
  372. bool KUiSysMsgCentre::FilterSameMsg(KSystemMessage* pMsg, void* pParam)
  373. {
  374. //_ASSERT(pMsg);
  375. int j;
  376. SYS_MSG_HEAP* pHeap = &m_MsgHeap[POPUPING_MSG_HEAP_INDEX];
  377. if (pHeap->nNumValid)
  378. {
  379. for (j = pHeap->nNumValid - 1; j >= 0; j--)
  380. {
  381. KSystemMessage* pHeapMsg = pHeap->pMsgList[j];
  382. if (pMsg->eType == pHeapMsg->eType &&
  383. pMsg->byConfirmType == pHeapMsg->byConfirmType &&
  384. pMsg->byPriority == pHeapMsg->byPriority &&
  385. pMsg->byParamSize <= pHeapMsg->byParamSize &&
  386. strcmp(pMsg->szMessage, pHeapMsg->szMessage) == 0)
  387. {
  388. if (pMsg->byParamSize == 0 ||
  389. memcmp(pParam, &pHeapMsg[1], pMsg->byParamSize) == 0)
  390. {
  391. return true;
  392. }
  393. }
  394. }
  395. }
  396. for (int nIndex = 0; nIndex < MAX_SYS_MSG_TYPE; nIndex++)
  397. {
  398. pHeap = &m_MsgHeap[nIndex];
  399. if (pHeap->nNumValid == 0)
  400. break;
  401. if (pHeap->pMsgList[0]->eType != pMsg->eType)
  402. continue;
  403. for (int j = pHeap->nNumValid - 1; j >= 0; j--)
  404. {
  405. KSystemMessage* pHeapMsg = pHeap->pMsgList[j];
  406. if (pMsg->byConfirmType == pHeapMsg->byConfirmType &&
  407. pMsg->byPriority == pHeapMsg->byPriority &&
  408. pMsg->byParamSize <= pHeapMsg->byParamSize &&
  409. strcmp(pMsg->szMessage, pHeapMsg->szMessage) == 0)
  410. {
  411. if (pMsg->byParamSize == 0 ||
  412. memcmp(pParam, &pHeapMsg[1], pMsg->byParamSize) == 0)
  413. {
  414. return true;
  415. }
  416. }
  417. }
  418. }
  419. return false;
  420. }
  421. void KUiSysMsgCentre::Clear()
  422. {
  423. for (int i = 0; i < MAX_SYS_MSG_TYPE + 2; i++)
  424. {
  425. SYS_MSG_HEAP* pHeap = &m_MsgHeap[i];
  426. if (pHeap->pMsgList)
  427. {
  428. for (int j = 0; j < pHeap->nNumValid; j++)
  429. {
  430. if (pHeap->pMsgList[j])
  431. free(pHeap->pMsgList[j]);
  432. }
  433. free(pHeap->pMsgList);
  434. pHeap->pMsgList = NULL;
  435. pHeap->nNumValid = 0;
  436. pHeap->nListSpace = 0;
  437. }
  438. }
  439. m_nPopupMsgX = LAST_MOVEMENT_POS;
  440. m_nPopupMsgDestIndex = 0;
  441. }
  442. KSystemMessage* KUiSysMsgCentre::GetAMsgSpace(int nParamSize)
  443. {
  444. KSystemMessage* pMsgSpace = NULL;
  445. SYS_MSG_HEAP* pHeap = &m_MsgHeap[RECYCLE_MSG_HEAP_INDEX];
  446. if (pHeap->nNumValid)
  447. {
  448. pHeap->nNumValid--;
  449. for (int i = pHeap->nNumValid; i >= 0; i--)
  450. {
  451. if (pHeap->pMsgList[i]->byParamSize >= nParamSize)
  452. {
  453. pMsgSpace = pHeap->pMsgList[i];
  454. for (; i < pHeap->nNumValid; i++)
  455. pHeap->pMsgList[i] = pHeap->pMsgList[i + 1];
  456. break;
  457. }
  458. }
  459. if (pMsgSpace == NULL)
  460. {
  461. free(pHeap->pMsgList[pHeap->nNumValid]);
  462. pHeap->pMsgList[pHeap->nNumValid] = NULL;
  463. }
  464. }
  465. if (pMsgSpace == NULL)
  466. {
  467. pMsgSpace = (KSystemMessage*)malloc(sizeof(KSystemMessage) + nParamSize);
  468. pMsgSpace->byParamSize = nParamSize;
  469. }
  470. return pMsgSpace;
  471. }
  472. void KUiSysMsgCentre::SetPopupMsgDest()
  473. {
  474. if (m_MsgHeap[POPUPING_MSG_HEAP_INDEX].nNumValid)
  475. {
  476. unsigned char ePopupType = m_MsgHeap[POPUPING_MSG_HEAP_INDEX].pMsgList[0]->eType;
  477. for (m_nPopupMsgDestIndex = 0; m_nPopupMsgDestIndex < MAX_SYS_MSG_TYPE;
  478. m_nPopupMsgDestIndex++)
  479. {
  480. if (m_MsgHeap[m_nPopupMsgDestIndex].nNumValid == 0 ||
  481. m_MsgHeap[m_nPopupMsgDestIndex].pMsgList[0]->eType == ePopupType)
  482. {
  483. break;
  484. }
  485. }
  486. // _ASSERT(m_nPopupMsgDestIndex < MAX_SYS_MSG_TYPE);
  487. int y;
  488. m_MsgIconBtn[m_nPopupMsgDestIndex].GetPosition(&m_nPopupMsgDestX, &y);
  489. m_nPopupMsgDestX += m_nAbsoluteLeft;
  490. if (m_nPopupMsgX == LAST_MOVEMENT_POS)
  491. {
  492. Wnd_GetScreenSize(m_nPopupMsgX, m_nPopupMsgY);
  493. m_nPopupMsgY = y + m_nAbsoluteTop;
  494. }
  495. }
  496. }
  497. void KUiSysMsgCentre::ConfirmMsg(KSystemMessage* pMsg, bool bImmedDel)
  498. {
  499. if (pMsg == NULL)
  500. return;
  501. KUiPlayerItem* pPlayer = NULL;
  502. unsigned int uSelMsgId = 0;
  503. char szBuf[128] = "";
  504. const char *pFirstBtnText = NULL, *pSecBtnText = NULL;
  505. unsigned char byConfirmType = pMsg->byConfirmType;
  506. switch(byConfirmType)
  507. {
  508. case SMCT_MSG_BOX:
  509. if (bImmedDel == false)
  510. UIMessageBox(pMsg->szMessage);
  511. break;
  512. case SMCT_UI_ATTRIBUTE: //打开属性页面
  513. if (bImmedDel == false)
  514. KUiStatus::OpenWindow();
  515. break;
  516. case SMCT_UI_SKILLS: //打开技能页面
  517. if (bImmedDel == false)
  518. KUiSkills::OpenWindow();
  519. break;
  520. case SMCT_UI_ATTRIBUTE_SKILLS:
  521. if (bImmedDel == false)
  522. {
  523. KUiStatus::OpenWindow();
  524. KUiSkills::OpenWindow();
  525. }
  526. break;
  527. case SMCT_UI_TEAM: //打开队伍管理面板
  528. if (bImmedDel == false)
  529. KUiTeamManage::OpenWindow();
  530. break;
  531. case SMCT_UI_TEAM_INVITE: //答应或拒绝加入队伍的邀请
  532. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  533. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  534. sprintf(szBuf, "%s邀请你加入他的队伍", pPlayer->Name);
  535. pFirstBtnText = "同意";
  536. pSecBtnText = "拒绝";
  537. _ASSERT(m_pHandlingMsg == NULL);
  538. m_pHandlingMsg = pMsg;
  539. pMsg = NULL;
  540. break;
  541. case SMCT_UI_TEAM_APPLY: //答应或拒绝加入队伍的申请
  542. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  543. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  544. sprintf(szBuf, "%s申请加入你的队伍", pPlayer->Name);
  545. pFirstBtnText = "同意";
  546. pSecBtnText = "拒绝";
  547. _ASSERT(m_pHandlingMsg == NULL);
  548. m_pHandlingMsg = pMsg;
  549. pMsg = NULL;
  550. break;
  551. case SMCT_UI_INTERVIEW: //打开聊天对话界面
  552. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  553. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  554. KUiPlayerBar::InputNameMsg(false, pPlayer->Name, true);
  555. //KUiFriendInterview::OpenWindow((KUiPlayerItem*)(&pMsg[1]));
  556. break;
  557. case SMCT_UI_FRIEND_INVITE: //批准或拒绝别人加自己为好友
  558. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  559. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  560. sprintf(szBuf, "%s希望与你成为好友", pPlayer->Name);
  561. pFirstBtnText = "同意";
  562. pSecBtnText = "拒绝";
  563. _ASSERT(m_pHandlingMsg == NULL);
  564. m_pHandlingMsg = pMsg;
  565. pMsg = NULL;
  566. break;
  567. case SMCT_UI_TRADE:
  568. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  569. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  570. sprintf(szBuf, "%s希望与你交易", pPlayer->Name);
  571. pFirstBtnText = "同意";
  572. pSecBtnText = "拒绝";
  573. _ASSERT(m_pHandlingMsg == NULL);
  574. m_pHandlingMsg = pMsg;
  575. pMsg = NULL;
  576. break;
  577. case SMCT_UI_TONG_JOIN_APPLY:
  578. _ASSERT (pMsg->byParamSize >= sizeof(KUiPlayerItem));
  579. pPlayer = (KUiPlayerItem*)(&pMsg[1]);
  580. sprintf(szBuf, "%s希望申请加入你的帮会", pPlayer->Name);
  581. pFirstBtnText = "同意";
  582. pSecBtnText = "拒绝";
  583. _ASSERT(m_pHandlingMsg == NULL);
  584. m_pHandlingMsg = pMsg;
  585. pMsg = NULL;
  586. break;
  587. }
  588. if (szBuf[0])
  589. UIMessageBox(szBuf, this, pFirstBtnText, pSecBtnText, byConfirmType);
  590. if (pMsg &&
  591. (m_MsgHeap[RECYCLE_MSG_HEAP_INDEX].nNumValid >= MAX_MSG_IN_RECYCLE_HEAP ||
  592. !AddAMsgToHeap(pMsg, RECYCLE_MSG_HEAP_INDEX, false)))
  593. {
  594. free(pMsg);
  595. }
  596. }
  597. void KUiSysMsgCentre::DeleteMsgInHeap(int nHeapIndex, int nMsgIndex, bool bImmedDel, bool bTobeConfirm)
  598. {
  599. int i;
  600. //_ASSERT(nHeapIndex >= 0 && nHeapIndex <= POPUPING_MSG_HEAP_INDEX);
  601. SYS_MSG_HEAP* pHeap = &m_MsgHeap[nHeapIndex];
  602. if (nMsgIndex >= 0 && nMsgIndex < pHeap->nNumValid)
  603. {
  604. if (bTobeConfirm)
  605. {
  606. ConfirmMsg(pHeap->pMsgList[nMsgIndex], bImmedDel);
  607. }
  608. else if (m_MsgHeap[RECYCLE_MSG_HEAP_INDEX].nNumValid >= MAX_MSG_IN_RECYCLE_HEAP ||
  609. !AddAMsgToHeap(pHeap->pMsgList[nMsgIndex], RECYCLE_MSG_HEAP_INDEX, false))
  610. {
  611. free(pHeap->pMsgList[nMsgIndex]);
  612. }
  613. pHeap->nNumValid--;
  614. for (i = nMsgIndex; i < pHeap->nNumValid; i++)
  615. {
  616. pHeap->pMsgList[i] = pHeap->pMsgList[i + 1];
  617. }
  618. pHeap->pMsgList[pHeap->nNumValid] = NULL;
  619. if (pHeap->nNumValid)
  620. {
  621. m_MsgTextWnd.SetText(pHeap->pMsgList[0]->szMessage);
  622. }
  623. else
  624. {
  625. SYS_MSG_HEAP temp;
  626. temp = *pHeap;
  627. for (; nHeapIndex < MAX_SYS_MSG_TYPE - 1; nHeapIndex ++)
  628. {
  629. if (pHeap[1].nNumValid == 0)
  630. break;
  631. *pHeap = pHeap[1];
  632. pHeap++;
  633. }
  634. *pHeap = temp;
  635. SetPopupMsgDest();
  636. m_MsgTextWnd.SetText("");
  637. m_bShowMsgText = false;
  638. }
  639. }
  640. }
  641. void KUiSysMsgCentre::MovePopupedMsgToHeap()
  642. {
  643. int i;
  644. SYS_MSG_HEAP* pHeap = &m_MsgHeap[POPUPING_MSG_HEAP_INDEX];
  645. if (pHeap->nNumValid)
  646. {
  647. m_nPopupMsgX = LAST_MOVEMENT_POS;
  648. KSystemMessage* pMsg = pHeap->pMsgList[0];
  649. pHeap->nNumValid--;
  650. for (i = 0; i < pHeap->nNumValid; i++)
  651. {
  652. pHeap->pMsgList[i] = pHeap->pMsgList[i + 1];
  653. }
  654. pHeap->pMsgList[pHeap->nNumValid] = NULL;
  655. if (!AddAMsgToHeap(pMsg, m_nPopupMsgDestIndex, true))
  656. free (pMsg);
  657. pMsg = NULL;
  658. if (pHeap->nNumValid)
  659. SetPopupMsgDest();
  660. }
  661. }
  662. bool KUiSysMsgCentre::AddAMsgToHeap(KSystemMessage* pMsg, int nHeapIndex, bool bSort)
  663. {
  664. //_ASSERT(pMsg);
  665. //_ASSERT(nHeapIndex >= 0 && nHeapIndex <= RECYCLE_MSG_HEAP_INDEX);
  666. SYS_MSG_HEAP* pHeap = &m_MsgHeap[nHeapIndex];
  667. if (pHeap->nNumValid == pHeap->nListSpace)
  668. {
  669. KSystemMessage** pNewList = (KSystemMessage**)realloc(pHeap->pMsgList,
  670. sizeof(KSystemMessage*) * (pHeap->nListSpace + MSG_LIST_EXPAND_STEP));
  671. if (pNewList)
  672. {
  673. memset(&pNewList[pHeap->nNumValid], 0, sizeof(KSystemMessage*) * MSG_LIST_EXPAND_STEP);
  674. pHeap->pMsgList = pNewList;
  675. pHeap->nListSpace += MSG_LIST_EXPAND_STEP;
  676. }
  677. else
  678. {
  679. return false;
  680. }
  681. }
  682. int nIndex = pHeap->nNumValid;
  683. if (bSort)
  684. {
  685. for (nIndex--; nIndex >= 0; nIndex--)
  686. {
  687. if (pHeap->pMsgList[nIndex]->byPriority > pMsg->byPriority)
  688. {
  689. break;
  690. }
  691. pHeap->pMsgList[nIndex + 1] = pHeap->pMsgList[nIndex];
  692. }
  693. nIndex ++;
  694. }
  695. pHeap->pMsgList[nIndex] = pMsg;
  696. pHeap->nNumValid++;
  697. return true;
  698. }
  699. //绘制窗口
  700. void KUiSysMsgCentre::PaintWindow()
  701. {
  702. KWndWindow::PaintWindow();
  703. unsigned char eType;
  704. int  nFrame, i;
  705. bool bAlreadyChangeFrame = false;
  706. if (m_bShowMsgText)
  707. {
  708. KRUShadow Shadow;
  709. m_MsgTextWnd.GetPosition(&Shadow.oPosition.nX, &Shadow.oPosition.nY);
  710. Shadow.oPosition.nX += m_nAbsoluteLeft;
  711. Shadow.oPosition.nY += m_nAbsoluteTop;
  712. Shadow.oPosition.nZ = 0;
  713. m_MsgTextWnd.GetSize(&Shadow.oEndPos.nX, &Shadow.oEndPos.nY);
  714. Shadow.oEndPos.nX += Shadow.oPosition.nX;
  715. Shadow.oEndPos.nY += Shadow.oPosition.nY;
  716. Shadow.Color.Color_dw = 0x10000000;
  717. g_pRepresentShell->DrawPrimitives(1, &Shadow, RU_T_SHADOW, true);
  718. }
  719. for (i = 0; i < MAX_SYS_MSG_TYPE; i++)
  720. {
  721. if (m_MsgHeap[i].nNumValid == 0)
  722. break;
  723. eType = m_MsgHeap[i].pMsgList[0]->eType - 1;
  724. m_MsgIconBtn[i].GetPosition(&m_MsgIcon[eType].oPosition.nX, 
  725. &m_MsgIcon[eType].oPosition.nY);
  726. m_MsgIcon[eType].oPosition.nX += m_nAbsoluteLeft;
  727. m_MsgIcon[eType].oPosition.nY += m_nAbsoluteTop;
  728. if (m_MsgHeap[i].pMsgList[0]->byConfirmType != SMCT_CLICK)
  729. {
  730. if (i == m_nPopupMsgDestIndex)
  731. bAlreadyChangeFrame = true;
  732. IR_NextFrame(m_MsgIcon[eType]);
  733. g_pRepresentShell->DrawPrimitives(1, &m_MsgIcon[eType], RU_T_IMAGE, true);
  734. }
  735. else
  736. {
  737. nFrame = m_MsgIcon[eType].nFrame;
  738. m_MsgIcon[eType].nFrame = m_nMsgIconFrame[eType];
  739. g_pRepresentShell->DrawPrimitives(1, &m_MsgIcon[eType], RU_T_IMAGE, true);
  740. m_MsgIcon[eType].nFrame = nFrame;
  741. }
  742. }
  743. if (m_MsgHeap[POPUPING_MSG_HEAP_INDEX].nNumValid)
  744. {
  745. eType = m_MsgHeap[POPUPING_MSG_HEAP_INDEX].pMsgList[0]->eType - 1;
  746. m_MsgIcon[eType].oPosition.nX = m_nPopupMsgX;
  747. m_MsgIcon[eType].oPosition.nY = m_nPopupMsgY;
  748. g_pRepresentShell->DrawPrimitives(1, &m_MsgIcon[eType], RU_T_IMAGE, true);
  749. if (m_MsgHeap[POPUPING_MSG_HEAP_INDEX].pMsgList[0]->byConfirmType != SMCT_CLICK)
  750. {
  751. if (bAlreadyChangeFrame == false)
  752. IR_NextFrame(m_MsgIcon[eType]);
  753. g_pRepresentShell->DrawPrimitives(1, &m_MsgIcon[eType], RU_T_IMAGE, true);
  754. }
  755. else
  756. {
  757. nFrame = m_MsgIcon[eType].nFrame;
  758. m_MsgIcon[eType].nFrame = m_nMsgIconFrame[eType];
  759. g_pRepresentShell->DrawPrimitives(1, &m_MsgIcon[eType], RU_T_IMAGE, true);
  760. m_MsgIcon[eType].nFrame = nFrame;
  761. }
  762. }
  763. }