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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--消息窗口
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-8-14
  6. ------------------------------------------------------------------------------------------
  7. *****************************************************************************************/
  8. #include "KWin32.h"
  9. #include "KIniFile.h"
  10. #include "../Elem/Wnds.h"
  11. #include "../Elem/WndMessage.h"
  12. #include "UiInformation2.h"
  13. #include "../../../core/src/coreshell.h"
  14. #include "../../core/src/GameDataDef.h"
  15. #include "../UiSoundSetting.h"
  16. extern iCoreShell* g_pCoreShell;
  17. #define SCHEME_INI "提示2.ini"
  18. KUiInformation2 g_UiInformation2;
  19. void UIMessageBox2(const char* pMsg, int nMsgLen, const char* pBtnLabel,
  20.    KWndWindow* pCaller, unsigned int uParam)
  21. {
  22. if (pCaller && (unsigned int)pCaller != WND_GAMESPACE)
  23. pCaller->Enable(false);
  24. g_UiInformation2.Show(pMsg, nMsgLen, pBtnLabel, pCaller, uParam);
  25. }
  26. //--------------------------------------------------------------------------
  27. // 功能:构造函数
  28. //--------------------------------------------------------------------------
  29. KUiInformation2::KUiInformation2()
  30. {
  31. m_pCallerWnd = NULL;
  32. m_pWordDataList = NULL;
  33. m_nNumWordData = 0;
  34. m_nCurrentWord = 0;
  35. }
  36. //显示对话内容
  37. void KUiInformation2::SpeakWords(KUiInformationParam* pWordDataList, int nCount)
  38. {
  39. if (pWordDataList == NULL || nCount <= 0)
  40. return;
  41. KUiInformationParam* pNewList = (KUiInformationParam*)malloc(sizeof(KUiInformationParam) *(nCount + m_nNumWordData - m_nCurrentWord));
  42. if (pNewList == NULL)
  43. return;
  44. if (m_nNumWordData > m_nCurrentWord)
  45. {
  46. memcpy(pNewList, m_pWordDataList, sizeof(KUiInformationParam) * (m_nNumWordData - m_nCurrentWord));
  47. m_nCurrentWord = m_nNumWordData - m_nCurrentWord;
  48. }
  49. else
  50. m_nCurrentWord = 0;
  51. memcpy(&pNewList[m_nCurrentWord], pWordDataList, sizeof(KUiInformationParam) * nCount);
  52. m_nNumWordData = m_nCurrentWord + nCount;
  53. if (m_pWordDataList)
  54. free(m_pWordDataList);
  55. m_pWordDataList = pNewList;
  56. if (IsVisible() == false)
  57. {
  58. KWndWindow* pCaller = m_pWordDataList->bNeedConfirmNotify ? ((KWndWindow*)WND_GAMESPACE) : 0;
  59. Show(m_pWordDataList->sInformation, m_pWordDataList->nInforLen,
  60. m_pWordDataList->sConfirmText, pCaller, 0);
  61. m_nCurrentWord ++;
  62. }
  63. }
  64. //--------------------------------------------------------------------------
  65. // 功能:初始化
  66. //--------------------------------------------------------------------------
  67. void KUiInformation2::Initialize()
  68. {
  69. m_pCallerWnd = NULL;
  70. AddChild(&m_Information);
  71. AddChild(&m_OKBtn);
  72. m_Style &= ~WND_S_VISIBLE;
  73. Wnd_AddWindow(this, WL_TOPMOST);
  74. }
  75. //--------------------------------------------------------------------------
  76. // 功能:载入窗口的界面方案
  77. //--------------------------------------------------------------------------
  78. void KUiInformation2::LoadScheme(const char* pScheme)
  79. {
  80. char Buff[128];
  81. KIniFile Ini;
  82. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  83. if (Ini.Load(Buff))
  84. {
  85. KWndShowAnimate::Init(&Ini, "Main");
  86. m_Information .Init(&Ini, "Info");
  87. m_OKBtn.Init(&Ini, "OK");
  88. }
  89. }
  90. //--------------------------------------------------------------------------
  91. // 功能:显示窗口
  92. //--------------------------------------------------------------------------
  93. void KUiInformation2::Show(const char* pInformation, int nInforLen, const char* pBtnLabel,
  94. KWndWindow* pCallerWnd, unsigned int uParam)
  95. {
  96. if (pInformation)
  97. {
  98. m_pCallerWnd = pCallerWnd;
  99. m_uCallerParam = uParam;
  100. m_Information.SetText(pInformation, nInforLen);
  101. /* if (pBtnLabel == NULL)
  102. m_OKBtn.Hide();
  103. else
  104. {
  105. m_OKBtn.SetText(pBtnLabel, -1);
  106. m_OKBtn.Show();
  107. }*/
  108. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  109. BringToTop();
  110. KWndShowAnimate::Show();
  111. Wnd_SetExclusive((KWndWindow*)this);
  112. }
  113. }
  114. //--------------------------------------------------------------------------
  115. // 功能:隐藏窗口
  116. //--------------------------------------------------------------------------
  117. void KUiInformation2::Hide()
  118. {
  119. if (m_pCallerWnd)
  120. {
  121. if ((unsigned int)m_pCallerWnd == WND_GAMESPACE)
  122. g_pCoreShell->OperationRequest(GOI_INFORMATION_CONFIRM_NOTIFY, 0, 0);
  123. else
  124. {
  125. m_pCallerWnd->Enable(true);
  126. m_pCallerWnd->WndProc(WND_M_OTHER_WORK_RESULT, m_uCallerParam, 0);
  127. }
  128. m_pCallerWnd = NULL;
  129. }
  130. Wnd_ReleaseExclusive((KWndWindow*)this);
  131. if (m_nCurrentWord < m_nNumWordData)
  132. {
  133. KWndWindow* pCaller = m_pWordDataList[m_nCurrentWord].bNeedConfirmNotify ?
  134. ((KWndWindow*)WND_GAMESPACE) : 0;
  135. Show(m_pWordDataList[m_nCurrentWord].sInformation,
  136. m_pWordDataList[m_nCurrentWord].nInforLen,
  137. m_pWordDataList[m_nCurrentWord].sConfirmText, pCaller, 0);
  138. m_nCurrentWord ++;
  139. }
  140. else
  141. KWndShowAnimate::Hide();
  142. if (m_pWordDataList && m_nCurrentWord >= m_nNumWordData)
  143. {
  144. m_nNumWordData = 0;
  145. m_nCurrentWord = 0;
  146. free(m_pWordDataList);
  147. m_pWordDataList = NULL;
  148. }
  149. }
  150. //--------------------------------------------------------------------------
  151. // 功能:窗口函数
  152. //--------------------------------------------------------------------------
  153. int KUiInformation2::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  154. {
  155. int nRet = 0;
  156. switch(uMsg)
  157. {
  158. case WND_N_BUTTON_CLICK:
  159. case WM_LBUTTONDOWN:
  160. // if (uParam == (unsigned int)(KWndWindow*)&m_OKBtn)
  161. Hide();
  162. break;
  163. case WM_KEYDOWN:
  164. if (uParam  == VK_RETURN || uParam == VK_SPACE)
  165. {
  166. Hide();
  167. nRet = true;
  168. }
  169. else if (uParam == VK_ESCAPE)
  170. {
  171. while (m_pCallerWnd == NULL && IsVisible())
  172. Hide();
  173. Hide();
  174. nRet = true;
  175. }
  176. break;
  177. default:
  178. nRet = KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  179. break;
  180. }
  181. return nRet;
  182. }
  183. //关闭窗口,不通知调用窗口
  184. void KUiInformation2::Close()
  185. {
  186. Wnd_ReleaseExclusive((KWndWindow*)this);
  187. KWndShowAnimate::Hide();
  188. if (m_pWordDataList)
  189. {
  190. free(m_pWordDataList);
  191. m_pWordDataList = NULL;
  192. }
  193. m_nNumWordData = 0;
  194. m_nCurrentWord = 0;
  195. }
  196. KUiInformation2::~KUiInformation2()
  197. {
  198. Close();
  199. }