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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--聊天窗口
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-8-27
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "../Elem/Wnds.h"
  11. #include "UiFriendInterview.h"
  12. #include "UiSysMsgCentre.h"
  13. #include "UiSelColor.h"
  14. #include <crtdbg.h>
  15. #include "../UiSoundSetting.h"
  16. #include "../../../core/src/coreshell.h"
  17. #include "../../../core/src/GameDataDef.h"
  18. #include "../../../Engine/src/Text.h"
  19. #include "../../../Represent/iRepresent/iRepresentShell.h"
  20. #include "../../../Engine/src/Text.h"
  21. #include "../UiBase.h"
  22. #include "UiMsgCentrePad.h"
  23. extern iCoreShell* g_pCoreShell;
  24. extern iRepresentShell* g_pRepresentShell;
  25. KUiFriendInterview* KUiFriendInterview::m_pFirstSelf = NULL;
  26. #define SCHEME_INI "你一句我一句聊天.ini"
  27. #define SEL_COLOR_MENU 1
  28. char KUiFriendInterview::m_szSelfName[32] = "";
  29. int KUiFriendInterview::m_nSelfNameLen = 0;
  30. unsigned int KUiFriendInterview::m_uLastTextColor = 0x00000000;
  31. //--------------------------------------------------------------------------
  32. // 功能:打开窗口,返回唯一的一个类对象实例
  33. //--------------------------------------------------------------------------
  34. KUiFriendInterview* KUiFriendInterview::OpenWindow(KUiPlayerItem* pFriend)
  35. {
  36. KUiFriendInterview* pWnd = NULL;
  37. if (pFriend)
  38. {
  39. pWnd = FindWindow(pFriend, true);
  40. if (pWnd)
  41. {
  42. pWnd->BringToTop();
  43. pWnd->Show();
  44. }
  45. }
  46. return pWnd;
  47. }
  48. void KUiFriendInterview::CloneTheme(KUiFriendInterview* pCopy)
  49. {
  50. _ASSERT(pCopy);
  51. Clone(pCopy);
  52. m_MsgList .Clone(&(pCopy->m_MsgList));
  53. m_MsgScroll .Clone(&(pCopy->m_MsgScroll));
  54. m_InputWnd  .Clone(&(pCopy->m_InputWnd));
  55. m_SendBtn .Clone(&(pCopy->m_SendBtn));
  56. m_ColorBtn .Clone(&(pCopy->m_ColorBtn));
  57. m_CloseBtn .Clone(&(pCopy->m_CloseBtn));
  58. m_FaceBtn .Clone(&(pCopy->m_FaceBtn));
  59. m_FriendName.Clone(&(pCopy->m_FriendName));
  60. pCopy->m_SelfTextColor.Color_dw = m_SelfTextColor.Color_dw;
  61. pCopy->m_InputWnd.SetColor(m_SelfTextColor.Color_dw);
  62. }
  63. //--------------------------------------------------------------------------
  64. // 功能:构造函数
  65. //--------------------------------------------------------------------------
  66. KUiFriendInterview::KUiFriendInterview()
  67. {
  68. m_pNextSelf = NULL;
  69. m_SelfTextColor.Color_dw = 0x00000000;
  70. memset(&m_FriendData, 0, sizeof(KUiPlayerItem));
  71. }
  72. KUiFriendInterview::~KUiFriendInterview()
  73. {
  74. if (m_pFirstSelf == NULL)
  75. {
  76. KIniFile* pSetting = g_UiBase.GetPrivateSettingFile();
  77. if (pSetting)
  78. {
  79. char szColor[16];
  80. m_SelfTextColor.Color_dw = m_uLastTextColor;
  81. sprintf(szColor, "%d,%d,%d", m_SelfTextColor.Color_b.r,
  82. m_SelfTextColor.Color_b.g, m_SelfTextColor.Color_b.b);
  83. pSetting->WriteString("UiConfig", "ChatColor", szColor);
  84. g_UiBase.ClosePrivateSettingFile(true);
  85. }
  86. }
  87. }
  88. int KUiFriendInterview::DoesHaveVisibleWnd()
  89. {
  90. KUiFriendInterview* pWnd = m_pFirstSelf;
  91. while (pWnd)
  92. {
  93. if (pWnd->IsVisible())
  94. return true;
  95. pWnd = pWnd->m_pNextSelf;
  96. }
  97. return false;
  98. }
  99. //--------------------------------------------------------------------------
  100. // 功能:关闭窗口,同时可以选则是否删除对象实例
  101. //--------------------------------------------------------------------------
  102. void KUiFriendInterview::CloseWindow()
  103. {
  104. while (m_pFirstSelf)
  105. {
  106. KUiFriendInterview* pWnd = m_pFirstSelf;
  107. m_pFirstSelf = m_pFirstSelf->m_pNextSelf;
  108. pWnd->Destroy();
  109. }
  110. }
  111. void KUiFriendInterview::CloseSelf()
  112. {
  113. if (this == m_pFirstSelf)
  114. {
  115. m_pFirstSelf = this->m_pNextSelf;
  116. }
  117. else
  118. {
  119. KUiFriendInterview* pWnd = m_pFirstSelf;
  120. while(pWnd)
  121. {
  122. if (pWnd->m_pNextSelf == this)
  123. {
  124. pWnd->m_pNextSelf = this->m_pNextSelf;
  125. break;
  126. }
  127. pWnd = pWnd->m_pNextSelf;
  128. }
  129. }
  130. Destroy();
  131. }
  132. KUiFriendInterview* KUiFriendInterview::FindWindow(KUiPlayerItem* pFriend, bool bCreate)
  133. {
  134. KUiFriendInterview *pWnd = NULL, *pPreWnd = NULL;
  135. if (pFriend)
  136. {
  137. pWnd = m_pFirstSelf;
  138. while(pWnd)
  139. {
  140. if (strcmp(pWnd->m_FriendData.Name, pFriend->Name) == 0 &&
  141. pWnd->m_FriendData.uId == pFriend->uId)
  142. {
  143. break;
  144. }
  145. else if (pWnd->IsRecyclable())
  146. {
  147. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  148. pWnd->SetFriendData(pFriend);
  149. break;
  150. }
  151. pPreWnd = pWnd;
  152. pWnd = pWnd->m_pNextSelf;
  153. }
  154. }
  155. if (pWnd && pPreWnd)
  156. {
  157. pPreWnd->m_pNextSelf = pWnd->m_pNextSelf;
  158. pWnd->m_pNextSelf = m_pFirstSelf;
  159. m_pFirstSelf = pWnd;
  160. }
  161. if (pWnd == NULL)
  162. {
  163. pWnd = new KUiFriendInterview;
  164. if (pWnd)
  165. {
  166. pWnd->Initialize();
  167. if (m_pFirstSelf)
  168. {
  169. m_pFirstSelf->CloneTheme(pWnd);
  170. pWnd->m_pNextSelf = m_pFirstSelf;
  171. m_pFirstSelf = pWnd;
  172. }
  173. else
  174. {
  175. m_pFirstSelf = pWnd;
  176. LoadScheme(NULL);
  177. }
  178. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  179. pWnd->SetFriendData(pFriend);
  180. }
  181. }
  182. return pWnd;
  183. }
  184. void KUiFriendInterview::SetFriendData(KUiPlayerItem* pFriend)
  185. {
  186. if (pFriend)
  187. {
  188. m_FriendData = *pFriend;
  189. m_FriendName.SetText(pFriend->Name);
  190. }
  191. }
  192. //--------------------------------------------------------------------------
  193. // 功能:初始化
  194. //--------------------------------------------------------------------------
  195. int KUiFriendInterview::Initialize()
  196. {
  197. AddChild(&m_MsgList);
  198. AddChild(&m_MsgScroll);
  199. m_MsgList.SetScrollbar(&m_MsgScroll);
  200. AddChild(&m_InputWnd);
  201. AddChild(&m_SendBtn);
  202. AddChild(&m_ColorBtn);
  203. AddChild(&m_CloseBtn);
  204. AddChild(&m_FaceBtn);
  205. AddChild(&m_FriendName);
  206. m_Style &= ~WND_S_VISIBLE;
  207. Wnd_AddWindow(this);
  208. return true;
  209. }
  210. //--------------------------------------------------------------------------
  211. // 功能:载入窗口的界面方案
  212. //--------------------------------------------------------------------------
  213. void KUiFriendInterview::LoadScheme(const char* pScheme)
  214. {
  215. if (m_pFirstSelf == NULL)
  216. return;
  217. if (pScheme == NULL)
  218. {
  219. char Scheme[128];
  220. g_UiBase.GetCurSchemePath(Scheme, 256);
  221. pScheme = Scheme;
  222. }
  223. KUiPlayerBaseInfo Info;
  224. memset(&Info, 0, sizeof(KUiPlayerBaseInfo));
  225. if (g_pCoreShell)
  226. {
  227. g_pCoreShell->GetGameData(GDI_PLAYER_BASE_INFO, (int)&Info, 0);
  228. SetSelfName(Info.Name);
  229. }
  230. char Buff[128];
  231. KIniFile Ini;
  232. sprintf(Buff, "%s\"SCHEME_INI, pScheme);
  233. if (Ini.Load(Buff))
  234. {
  235. m_pFirstSelf->Init(&Ini, "Main");
  236. m_pFirstSelf->m_MsgList .Init(&Ini, "MsgList");
  237. m_pFirstSelf->m_MsgScroll.Init(&Ini, "MsgScroll");
  238. m_pFirstSelf->m_InputWnd.Init(&Ini, "Input");
  239. m_pFirstSelf->m_SendBtn.Init(&Ini, "SendBtn");
  240. m_pFirstSelf->m_ColorBtn.Init(&Ini, "ColorBtn");
  241. m_pFirstSelf->m_CloseBtn.Init(&Ini, "CloseBtn");
  242. m_pFirstSelf->m_FaceBtn.Init(&Ini, "FaceBtn");
  243. m_pFirstSelf->m_FriendName.Init(&Ini, "FriendName");
  244. Ini.GetString("MsgList", "MsgColor", "0,0,0", Buff, sizeof(Buff));
  245. m_uLastTextColor = (::GetColor(Buff) & 0xFFFFFF);
  246. }
  247. KIniFile* pSetting = g_UiBase.GetPrivateSettingFile();
  248. if (pSetting)
  249. {
  250. if (pSetting->GetString("UiConfig", "ChatColor", "0,0,0", Buff, sizeof(Buff)))
  251. m_uLastTextColor = (::GetColor(Buff) & 0xFFFFFF);
  252. g_UiBase.ClosePrivateSettingFile(false);
  253. }
  254. m_pFirstSelf->m_SelfTextColor.Color_dw = m_uLastTextColor;
  255. m_pFirstSelf->m_InputWnd.SetColor(m_uLastTextColor);
  256. KUiFriendInterview* pWnd = m_pFirstSelf->m_pNextSelf;
  257. while(pWnd)
  258. {
  259. m_pFirstSelf->CloneTheme(pWnd);
  260. pWnd = pWnd->m_pNextSelf;
  261. }
  262. }
  263. //--------------------------------------------------------------------------
  264. // 功能:窗口函数
  265. //--------------------------------------------------------------------------
  266. int KUiFriendInterview::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  267. {
  268. int nRet = 0;
  269. switch(uMsg)
  270. {
  271. case WND_N_BUTTON_CLICK:
  272. if (uParam == (unsigned int)(KWndWindow*)&m_SendBtn)
  273. OnSend();
  274. else if (uParam == (unsigned int)(KWndWindow*)&m_CloseBtn)
  275. CloseSelf();
  276. else if (uParam == (unsigned int)(KWndWindow*)&m_FaceBtn)
  277. PopupFaceMenu();
  278. else if (uParam == (unsigned int)(KWndWindow*)&m_ColorBtn)
  279. {
  280. int x, y, nWidth;
  281. m_ColorBtn.GetAbsolutePos(&x, &y);
  282. m_ColorBtn.GetSize(&nWidth, NULL);
  283. KUiSelColor::PopupMenu((KWndWindow*)this, SEL_COLOR_MENU, x, y, nWidth);
  284. }
  285. break;
  286. case WND_N_EDIT_SPECIAL_KEY_DOWN: //文本编辑窗口获得回车按键操作
  287. if (nParam == VK_RETURN)
  288. {
  289. OnSend();
  290. nRet = 1;
  291. }
  292. break;
  293. case WND_N_SCORLLBAR_POS_CHANGED:
  294. if (uParam == (unsigned int)(KWndWindow*)&m_MsgScroll)
  295. m_MsgList.SetFirstShowLine(nParam);
  296. break;
  297. case WND_M_MENUITEM_SELECTED:
  298. if (uParam == (unsigned int)(KWndWindow*)this)
  299. {
  300. if (HIWORD(nParam) == SEL_COLOR_MENU && short(LOWORD(nParam)) >= 0)
  301. {
  302. m_SelfTextColor.Color_dw = KUiSelColor::GetColor(LOWORD(nParam));
  303. m_uLastTextColor = m_SelfTextColor.Color_dw;
  304. m_InputWnd.SetColor(m_SelfTextColor.Color_dw);
  305. }
  306. }
  307. break;
  308. default:
  309. nRet =  KWndImage::WndProc(uMsg, uParam, nParam);
  310. }
  311. return nRet;
  312. }
  313. void KUiFriendInterview::PopupFaceMenu()
  314. {
  315. }
  316. int KUiFriendInterview::IsRecyclable()
  317. {
  318. return (IsVisible() == 0 && m_MsgList.GetMsgCount() == 0);
  319. }
  320. void KUiFriendInterview::PaintWindow()
  321. {
  322. KWndImage::PaintWindow();
  323. int nWidth, nHeight;
  324. KRUShadow Shadow;
  325. m_ColorBtn.GetSize(&nWidth, &nHeight);
  326. m_ColorBtn.GetAbsolutePos(&Shadow.oPosition.nX, &Shadow.oPosition.nY);
  327. Shadow.oEndPos.nX = Shadow.oPosition.nX + nWidth;
  328. Shadow.oEndPos.nY = Shadow.oPosition.nY + nHeight;
  329. Shadow.Color.Color_dw = m_SelfTextColor.Color_dw;
  330. g_pRepresentShell->DrawPrimitives(1, &Shadow, RU_T_SHADOW, true);
  331. }
  332. //--------------------------------------------------------------------------
  333. // 功能:响应点击发送按钮
  334. //--------------------------------------------------------------------------
  335. void KUiFriendInterview::OnSend()
  336. {
  337. char szBuffer[300];
  338. KUiChatMessage Msg;
  339. Msg.uColor = m_SelfTextColor.Color_dw;
  340. Msg.nContentLen = m_InputWnd.GetText(&Msg.szContent[0], sizeof(Msg.szContent), true);
  341. if (Msg.nContentLen)
  342. {
  343. memcpy(szBuffer, m_szSelfName, m_nSelfNameLen);
  344. szBuffer[m_nSelfNameLen] = ':';
  345. szBuffer[m_nSelfNameLen + 1] = KTC_ENTER;
  346. szBuffer[m_nSelfNameLen + 2] = KTC_COLOR;
  347. szBuffer[m_nSelfNameLen + 3] = m_SelfTextColor.Color_b.r;
  348. szBuffer[m_nSelfNameLen + 4] = m_SelfTextColor.Color_b.g;
  349. szBuffer[m_nSelfNameLen + 5] = m_SelfTextColor.Color_b.b;
  350. int nLen = m_nSelfNameLen + 6;
  351. memcpy(&szBuffer[nLen], Msg.szContent, Msg.nContentLen);
  352. nLen += Msg.nContentLen;
  353. m_MsgList.AddOneMessage(szBuffer, nLen);
  354. m_InputWnd.ClearText();
  355. g_pCoreShell->OperationRequest(GOI_CHAT_WORDS_TO_FRIEND,
  356. (unsigned int)(&Msg), (int)(&m_FriendData));
  357. }
  358. }
  359. void KUiFriendInterview::SetSelfName(const char* pszSelfName)
  360. {
  361. if (pszSelfName)
  362. {
  363. m_nSelfNameLen = strlen(pszSelfName);
  364. if (m_nSelfNameLen < 32)
  365. {
  366. strcpy(m_szSelfName, pszSelfName);
  367. }
  368. else
  369. {
  370. strcpy(m_szSelfName, "[self]");
  371. m_nSelfNameLen = strlen(m_szSelfName);
  372. }
  373. }
  374. }