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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--申请队伍界面
  3. // Copyright : Kingsoft 2003
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2003-2-26
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../elem/wnds.h"
  10. #include "../Elem/WndMessage.h"
  11. #include "../UiBase.h"
  12. #include "UiTeamApply.h"
  13. #include "../UiSoundSetting.h"
  14. #include "../../../core/src/gamedatadef.h"
  15. #include "../../../core/src/CoreShell.h"
  16. extern iCoreShell* g_pCoreShell;
  17. #define SCHEME_INI "加入组队.ini"
  18. KUiTeamApply* KUiTeamApply::m_pSelf = NULL;
  19. //--------------------------------------------------------------------------
  20. // 功能:如果窗口正被显示,则返回实例指针
  21. //--------------------------------------------------------------------------
  22. KUiTeamApply* KUiTeamApply::GetIfVisible()
  23. {
  24. if (m_pSelf && m_pSelf->IsVisible())
  25. return m_pSelf;
  26. return NULL;
  27. }
  28. KUiTeamApply::KUiTeamApply()
  29. {
  30. m_pDataList = NULL;
  31. m_nCount = 0;
  32. }
  33. KUiTeamApply::~KUiTeamApply()
  34. {
  35. Clear();
  36. }
  37. //--------------------------------------------------------------------------
  38. // 功能:打开窗口,返回唯一的一个类对象实例
  39. //--------------------------------------------------------------------------
  40. KUiTeamApply* KUiTeamApply::OpenWindow()
  41. {
  42. if (m_pSelf == NULL)
  43. {
  44. m_pSelf = new KUiTeamApply;
  45. if (m_pSelf)
  46. m_pSelf->Initialize();
  47. }
  48. if (m_pSelf)
  49. {
  50. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  51. m_pSelf->m_RefuseBtn.CheckButton(
  52. g_pCoreShell->GetGameData(GDI_TEAM_REFUSE_INVITE_STATUS, 0, 0));
  53. g_pCoreShell->OperationRequest(GOI_TEAM_COLLECT_NEARBY_LIST, 0, 0);
  54. m_pSelf->BringToTop();
  55. m_pSelf->Show();
  56. }
  57. return m_pSelf;
  58. }
  59. //初始化
  60. void KUiTeamApply::Initialize()
  61. {
  62. AddChild(&m_RefuseBtn);
  63. AddChild(&m_ApplyBtn);
  64. AddChild(&m_NewBtn);
  65. AddChild(&m_CloseBtn);
  66. AddChild(&m_TeamList);
  67. AddChild(&m_ListScroll);
  68. AddChild(&m_RefreshBtn);
  69. m_TeamList.SetScrollbar(&m_ListScroll);
  70. Wnd_AddWindow(this);
  71. char Scheme[256];
  72. g_UiBase.GetCurSchemePath(Scheme, 256);
  73. LoadScheme(Scheme);
  74. }
  75. //--------------------------------------------------------------------------
  76. // 功能:关闭窗口,同时可以选则是否删除对象实例
  77. //--------------------------------------------------------------------------
  78. void KUiTeamApply::CloseWindow()
  79. {
  80. if (m_pSelf)
  81. {
  82. m_pSelf->Destroy();
  83. m_pSelf = NULL;
  84. }
  85. }
  86. void KUiTeamApply::LoadScheme(const char* pScheme)
  87. {
  88. if (m_pSelf)
  89. {
  90. char Buff[128];
  91. KIniFile Ini;
  92. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  93. if (Ini.Load(Buff))
  94. {
  95. m_pSelf->Init(&Ini, "Main");
  96. m_pSelf->m_RefuseBtn .Init(&Ini, "RefuseBtn");
  97. m_pSelf->m_ApplyBtn  .Init(&Ini, "ApplyBtn");
  98. m_pSelf->m_NewBtn    .Init(&Ini, "NewBtn");
  99. m_pSelf->m_CloseBtn  .Init(&Ini, "CloseBtn");
  100. m_pSelf->m_RefreshBtn.Init(&Ini, "RefreshBtn");
  101. m_pSelf->m_TeamList .Init(&Ini, "TeamList");
  102. m_pSelf->m_ListScroll.Init(&Ini, "Scroll");
  103. }
  104. }
  105. }
  106. //自己新建立队伍
  107. void KUiTeamApply::OnNewTeam()
  108. {
  109. g_pCoreShell->OperationRequest(GOI_TEAM_NEW, 0, 0);
  110. CloseWindow();
  111. }
  112. //窗口函数
  113. int KUiTeamApply::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  114. {
  115. int nRet = 0;
  116. switch(uMsg)
  117. {
  118. case WND_N_BUTTON_CLICK:
  119. if (uParam == (unsigned int)(KWndWindow*)&m_NewBtn)
  120. {
  121. OnNewTeam();
  122. }
  123. else if (uParam == (unsigned int)(KWndWindow*)&m_RefuseBtn)
  124. {
  125. g_pCoreShell->OperationRequest(GOI_TRAM_REFUSE_INVITE, 0, nParam);
  126. m_ApplyBtn.Enable(!nParam);
  127. }
  128. else if (uParam == (unsigned int)(KWndWindow*)&m_ApplyBtn)
  129. OnApply();
  130. else if (uParam == (unsigned int)(KWndWindow*)&m_CloseBtn)
  131. CloseWindow();
  132. else if (uParam == (unsigned int)(KWndWindow*)&m_RefreshBtn)
  133. {
  134. g_pCoreShell->OperationRequest(GOI_TEAM_COLLECT_NEARBY_LIST, 0, 0);
  135. }
  136. break;
  137. case WND_N_SCORLLBAR_POS_CHANGED:
  138. if (uParam == (unsigned int)(KWndWindow*)&m_ListScroll)
  139. m_TeamList.SetTopItemIndex(nParam);
  140. break;
  141. default:
  142. nRet = KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  143. }
  144. return nRet;
  145. }
  146. void KUiTeamApply::UpdateData(KUiTeamItem* pList, int nCount)
  147. {
  148. if (m_pSelf == NULL)
  149. return;
  150. m_pSelf->Clear();
  151. if (pList && nCount)
  152. {
  153. m_pSelf->m_pDataList = (KUiTeamItem*)malloc(sizeof(KUiTeamItem) * nCount);
  154. if (m_pSelf->m_pDataList)
  155. {
  156. memcpy(m_pSelf->m_pDataList, pList, sizeof(KUiTeamItem) * nCount);
  157. m_pSelf->m_nCount = nCount;
  158. m_pSelf->m_TeamList.SetContent((unsigned char*)m_pSelf->m_pDataList, nCount, sizeof(KUiPlayerItem),
  159. (char*)&(m_pSelf->m_pDataList->Leader.Name) - (char*)m_pSelf->m_pDataList);
  160. nCount = m_pSelf->m_TeamList.GetVisibleItemCount();
  161. }
  162. }
  163. int bRefused = m_pSelf->m_RefuseBtn.IsButtonChecked();
  164. m_pSelf->m_ApplyBtn.Enable(!bRefused);
  165. }
  166. void KUiTeamApply::OnApply()
  167. {
  168. int nSel = m_TeamList.GetCurSel();
  169. if (nSel >= 0 && nSel < m_nCount)
  170. {
  171. g_pCoreShell->OperationRequest(GOI_TEAM_APPLY,
  172. (unsigned int)&m_pDataList[nSel], 0);
  173. CloseWindow();
  174. }
  175. }
  176. void KUiTeamApply::Clear()
  177. {
  178. m_TeamList.SetContent(0, 0, 0, 0);
  179. if (m_pDataList)
  180. {
  181. free(m_pDataList);
  182. m_pDataList = NULL;
  183. }
  184. m_nCount = 0;
  185. }