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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--组队管理界面
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-9-2
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "../elem/wnds.h"
  11. #include "UiTeamManage.h"
  12. #include "UiInformation.h"
  13. #include "UiPlayerBar.h"
  14. #include "../UiSoundSetting.h"
  15. #include "../../../core/src/CoreShell.h"
  16. #include "../UiBase.h"
  17. #include <crtdbg.h>
  18. extern iCoreShell* g_pCoreShell;
  19. #define MANAGE_INI_TEAM  "队伍管理.ini"
  20. KUiTeamManage* KUiTeamManage::m_pSelf = NULL;
  21. //--------------------------------------------------------------------------
  22. // 功能:构造函数 
  23. //--------------------------------------------------------------------------
  24. KUiTeamManage::KUiTeamManage()
  25. {
  26. memset(&m_Info, 0, sizeof(KUiPlayerTeam));
  27. m_pPlayersList = NULL;
  28. m_pNearbyPlayersList = NULL;
  29. // m_pNearbyTeamsList = NULL;
  30. }
  31. //--------------------------------------------------------------------------
  32. // 功能:如果窗口正被显示,则返回实例指针
  33. //--------------------------------------------------------------------------
  34. KUiTeamManage* KUiTeamManage::GetIfVisible()
  35. {
  36. if (m_pSelf && m_pSelf->IsVisible())
  37. return m_pSelf;
  38. return NULL;
  39. }
  40. //--------------------------------------------------------------------------
  41. // 功能:打开窗口,返回唯一的一个类对象实例
  42. //--------------------------------------------------------------------------
  43. KUiTeamManage* KUiTeamManage::OpenWindow()
  44. {
  45. if (m_pSelf == NULL)
  46. {
  47. m_pSelf = new KUiTeamManage;
  48. if (m_pSelf)
  49. m_pSelf->Initialize();
  50. }
  51. if (m_pSelf)
  52. {
  53. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  54. m_pSelf->UpdateData(NULL);
  55. m_pSelf->BringToTop();
  56. m_pSelf->Show();
  57. }
  58. return m_pSelf;
  59. }
  60. //--------------------------------------------------------------------------
  61. // 功能:关闭窗口,同时可以选则是否删除对象实例
  62. //--------------------------------------------------------------------------
  63. void KUiTeamManage::CloseWindow()
  64. {
  65. if (m_pSelf)
  66. {
  67. m_pSelf->Clear();
  68. m_pSelf->Destroy();
  69. m_pSelf = NULL;
  70. }
  71. }
  72. //--------------------------------------------------------------------------
  73. // 功能:初始化
  74. //--------------------------------------------------------------------------
  75. void KUiTeamManage::Initialize()
  76. {
  77. AddChild(&m_LeaderAbility);
  78. // AddChild(&m_NearbyPlayerTab);
  79. // AddChild(&m_NearbyTeamTab);
  80. AddChild(&m_TeamMember);
  81. AddChild(&m_NearbyList);
  82. AddChild(&m_MemberScroll);
  83. AddChild(&m_NearbyScroll);
  84. AddChild(&m_btnInvite);
  85. AddChild(&m_btnKick);
  86. // AddChild(&m_btnApplyJoin);
  87. AddChild(&m_btnAppoint);
  88. AddChild(&m_btnLeave);
  89. AddChild(&m_btnDismiss);
  90. AddChild(&m_btnRefresh);
  91. AddChild(&m_btnCloseTeam);
  92. AddChild(&m_btnCancel);
  93. m_TeamMember.SetScrollbar(&m_MemberScroll);
  94. m_NearbyList.SetScrollbar(&m_NearbyScroll);
  95. m_MemberScroll.Enable(false);
  96. m_NearbyScroll.Enable(false);
  97. // m_btnApplyJoin.Hide();
  98. char Scheme[256];
  99. g_UiBase.GetCurSchemePath(Scheme, 256);
  100. LoadScheme(Scheme);
  101. // m_NearbyPlayerTab.CheckButton(true);
  102. // m_NearbyTeamTab.CheckButton(false);
  103. Wnd_AddWindow(this);
  104. }
  105. //--------------------------------------------------------------------------
  106. // 功能:载入窗口的界面方案
  107. //--------------------------------------------------------------------------
  108. void KUiTeamManage::LoadScheme(class KIniFile* pSetting)
  109. {
  110. _ASSERT(pSetting);
  111. Init(pSetting, "Main");
  112. m_LeaderAbility .Init(pSetting, "LeaderAbility");
  113. // m_NearbyPlayerTab.Init(pSetting, "NearbyPlayerTab");
  114. // m_NearbyTeamTab .Init(pSetting, "NearbyTeamTab");
  115. m_TeamMember .Init(pSetting, "MemberList");
  116. m_NearbyList .Init(pSetting, "NearbyList");
  117. m_MemberScroll .Init(pSetting, "MemberScroll");
  118. m_NearbyScroll .Init(pSetting, "NearbyScroll");
  119. m_btnInvite .Init(pSetting, "Invite");
  120. m_btnKick .Init(pSetting, "Kick");
  121. // m_btnApplyJoin .Init(pSetting, "ApplyJoin");
  122. m_btnAppoint .Init(pSetting, "Appoint");
  123. m_btnLeave .Init(pSetting, "Leave");
  124. m_btnDismiss .Init(pSetting, "Dismiss");
  125. m_btnRefresh .Init(pSetting, "Refresh");
  126. m_btnCloseTeam .Init(pSetting, "CloseTeam");
  127. m_btnCancel .Init(pSetting, "Cancel");
  128. }
  129. //载入界面方案
  130. void KUiTeamManage::LoadScheme(const char* pScheme)
  131. {
  132. if (m_pSelf && pScheme)
  133. {
  134. char Buff[128];
  135. KIniFile Ini;
  136. sprintf(Buff, "%s\%s", pScheme, MANAGE_INI_TEAM);
  137. if (Ini.Load(Buff))
  138. m_pSelf->LoadScheme(&Ini);
  139. }
  140. }
  141. //--------------------------------------------------------------------------
  142. // 功能:窗口函数
  143. //--------------------------------------------------------------------------
  144. int KUiTeamManage::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  145. {
  146. switch(uMsg)
  147. {
  148. case WND_N_BUTTON_CLICK:
  149. if (uParam == (unsigned int)(KWndWindow*)&m_btnInvite)
  150. OnInvite();
  151. else if (uParam == (unsigned int)(KWndWindow*)&m_btnKick)
  152. OnKick();
  153. // else if (uParam == (unsigned int)(KWndWindow*)&m_btnApplyJoin)
  154. // OnApplyJoin();
  155. if (uParam == (unsigned int)(KWndWindow*)&m_btnAppoint)
  156. OnAppoint();
  157. else if (uParam == (unsigned int)(KWndWindow*)&m_btnLeave ||
  158. uParam == (unsigned int)(KWndWindow*)&m_btnDismiss)
  159. OnLeave();
  160. else if (uParam == (unsigned int)(KWndWindow*)&m_btnRefresh)
  161. OnRefresh();
  162. // else if (uParam == (unsigned int)(KWndWindow*)&m_NearbyPlayerTab)
  163. // SwitchNearbyMode(true);
  164. // else if (uParam == (unsigned int)(KWndWindow*)&m_NearbyTeamTab)
  165. // SwitchNearbyMode(false);
  166. else if (uParam == (unsigned int)(KWndWindow*)&m_btnCloseTeam)
  167. g_pCoreShell->TeamOperation(TEAM_OI_CLOSE, 0, nParam);
  168. else if (uParam == (unsigned int)(KWndWindow*)&m_btnCancel)
  169. CloseWindow();
  170. break;
  171. case WND_N_LIST_ITEM_SEL:
  172. if (uParam == (unsigned int)(KWndWindow*)&m_TeamMember)
  173. OnSelTeamMember(nParam);
  174. else if (uParam == (unsigned int)(KWndWindow*)&m_NearbyList)
  175. OnSelNearby(nParam);
  176. break;
  177. case WND_N_SCORLLBAR_POS_CHANGED:
  178. if (uParam == (unsigned int)(KWndWindow*)&m_MemberScroll)
  179. m_TeamMember.SetTopItemIndex(nParam);
  180. else if (uParam == (unsigned int)(KWndWindow*)&m_NearbyScroll)
  181. m_NearbyList.SetTopItemIndex(nParam);
  182. break;
  183. default:
  184. return KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  185. }
  186. return 0;
  187. }
  188. void KUiTeamManage::OnSelTeamMember(int nItem)
  189. {
  190. bool bEnable = false;
  191. const char* pcszSelfName = KUiPlayerBar::SelfName();
  192. if (m_Info.bTeamLeader && pcszSelfName && nItem >= 0)
  193. {
  194. bEnable = (strcmp(pcszSelfName, m_pPlayersList[nItem].Name) != 0);
  195. }
  196. m_btnKick.Enable(bEnable);
  197. m_btnAppoint.Enable(bEnable);
  198. }
  199. void KUiTeamManage::OnSelNearby(int nItem)
  200. {
  201. bool bEnable = false;
  202. // if (m_NearbyPlayerTab.IsButtonChecked())
  203. {
  204. if (nItem >= 0 &&
  205. ((m_Info.cNumMember && m_Info.bTeamLeader) || m_Info.cNumMember == 0))
  206. {
  207. bEnable = true;
  208. }
  209. m_btnInvite.Enable(bEnable);
  210. }
  211. // else if (m_NearbyTeamTab.IsButtonChecked())
  212. // {
  213. // if (nItem >= 0 && m_Info.cNumMember == 0)
  214. // bEnable = true;
  215. // m_btnApplyJoin.Enable(bEnable);
  216. // }
  217. }
  218. void KUiTeamManage::Clear()
  219. {
  220. m_TeamMember.SetContent(0, 0, 0, 0);
  221. m_NearbyList.SetContent(0, 0, 0, 0);
  222. m_btnInvite.Enable(false);
  223. m_btnKick.Enable(false);
  224. // m_btnApplyJoin.Enable(false);
  225. m_btnAppoint.Enable(false);
  226. m_btnLeave.Enable(false);
  227. m_btnDismiss.Enable(false);
  228. m_btnCloseTeam.CheckButton(false);
  229. memset(&m_Info, 0, sizeof(KUiPlayerTeam));
  230. if (m_pPlayersList)
  231. {
  232. free(m_pPlayersList);
  233. m_pPlayersList = NULL;
  234. }
  235. if (m_pNearbyPlayersList)
  236. {
  237. free (m_pNearbyPlayersList);
  238. m_pNearbyPlayersList = NULL;
  239. }
  240. // if (m_pNearbyTeamsList)
  241. // {
  242. // free (m_pNearbyTeamsList);
  243. // m_pNearbyTeamsList = NULL;
  244. // }
  245. }
  246. //--------------------------------------------------------------------------
  247. // 功能:更新队伍信息
  248. //--------------------------------------------------------------------------
  249. void KUiTeamManage::UpdateData(KUiPlayerTeam* pInfo)
  250. {
  251. Clear();
  252. KUiPlayerLeaderShip LeaderShip;
  253. memset(&LeaderShip, 0, sizeof(KUiPlayerLeaderShip));
  254. g_pCoreShell->GetGameData(GDI_PLAYER_LEADERSHIP,
  255. (unsigned int)&LeaderShip, 0);
  256. m_LeaderAbility.SetIntText(LeaderShip.nLeaderShipLevel);
  257. if (pInfo)
  258. m_Info = *pInfo;
  259. else if (!g_pCoreShell->TeamOperation(TEAM_OI_GD_INFO, (unsigned int)&m_Info, 0))
  260. {
  261. memset(&m_Info, 0, sizeof(m_Info));
  262. }
  263. if (m_Info.bTeamLeader)
  264. {
  265. m_btnCloseTeam.CheckButton(m_Info.bOpened);
  266. m_btnDismiss.Show();
  267. m_btnDismiss.Enable(true);
  268. m_btnLeave.Hide();
  269. }
  270. else
  271. {
  272. m_btnLeave.Show();
  273. m_btnLeave.Enable(m_Info.cNumMember > 0);
  274. m_btnDismiss.Hide();
  275. }
  276. if (m_Info.cNumMember > 0)
  277. {
  278. m_pPlayersList = (KUiPlayerItem*)malloc(sizeof(KUiPlayerItem) * (m_Info.cNumMember));
  279. if (m_pPlayersList)
  280. {
  281. int nCount = g_pCoreShell->TeamOperation(TEAM_OI_GD_MEMBER_LIST,
  282. (unsigned int)m_pPlayersList, m_Info.cNumMember);
  283. _ASSERT(nCount == m_Info.cNumMember);
  284. m_TeamMember.SetContent((unsigned char*)m_pPlayersList, m_Info.cNumMember, sizeof(KUiPlayerItem),
  285. ((char*)&m_pPlayersList->Name - (char*)m_pPlayersList));
  286. }
  287. else
  288. {
  289. m_Info.cNumMember = 0;
  290. }
  291. }
  292. OnRefresh();
  293. }
  294. /*void KUiTeamManage::SwitchNearbyMode(bool bNearbyPlayer)
  295. {
  296. m_NearbyPlayerTab.CheckButton(bNearbyPlayer);
  297. m_NearbyTeamTab.CheckButton(!bNearbyPlayer);
  298. if (bNearbyPlayer)
  299. {
  300. m_btnKick.Show();
  301. m_btnApplyJoin.Hide();
  302. }
  303. else
  304. {
  305. m_btnInvite.Enable(false);
  306. m_btnKick.Hide();
  307. m_btnApplyJoin.Show();
  308. }
  309. OnRefresh();
  310. }*/
  311. //--------------------------------------------------------------------------
  312. // 功能:更新周围队伍的列表
  313. //--------------------------------------------------------------------------
  314. /*void KUiTeamManage::UpdateNearbyTeams(KUiTeamItem* pList, int nCount)
  315. {
  316. if (m_pSelf == NULL)
  317. return;
  318. if (m_pSelf->m_NearbyTeamTab.IsButtonChecked())
  319. {
  320. m_pSelf->m_NearbyList.SetContent(NULL, 0, 0, 0);
  321. if (m_pSelf->m_pNearbyTeamsList)
  322. {
  323. free (m_pSelf->m_pNearbyTeamsList);
  324. m_pSelf->m_pNearbyTeamsList = NULL;
  325. }
  326. if (pList && nCount)
  327. {
  328. m_pSelf->m_pNearbyTeamsList = (KUiTeamItem*)malloc(sizeof(KUiTeamItem) * nCount);
  329. if (m_pSelf->m_pNearbyTeamsList)
  330. {
  331. memcpy(m_pSelf->m_pNearbyTeamsList, pList, sizeof(KUiTeamItem) * nCount);
  332. m_pSelf->m_NearbyList.SetContent((unsigned char*)m_pSelf->m_pNearbyTeamsList,
  333. nCount, sizeof(KUiTeamItem), (int)&(((KUiTeamItem*)0)->Leader.Name));
  334. }
  335. }
  336. }
  337. }
  338. */
  339. //--------------------------------------------------------------------------
  340. // 功能:任命队长
  341. //--------------------------------------------------------------------------
  342. void KUiTeamManage::OnAppoint()
  343. {
  344. int nCurSel = m_TeamMember.GetCurSel();
  345. if (nCurSel >= 0)
  346. g_pCoreShell->TeamOperation(TEAM_OI_APPOINT, (unsigned int)&m_pPlayersList[nCurSel], 0);
  347. }
  348. //--------------------------------------------------------------------------
  349. // 功能:踢除
  350. //--------------------------------------------------------------------------
  351. void KUiTeamManage::OnKick()
  352. {
  353. int nCurSel = m_TeamMember.GetCurSel();
  354. if (nCurSel >= 0)
  355. g_pCoreShell->TeamOperation(TEAM_OI_KICK, (unsigned int)&m_pPlayersList[nCurSel], 0);
  356. }
  357. //--------------------------------------------------------------------------
  358. // 功能:申请加入
  359. //--------------------------------------------------------------------------
  360. /*void KUiTeamManage::OnApplyJoin()
  361. {
  362. int nCurSel = m_NearbyList.GetCurSel();
  363. if (nCurSel >= 0)
  364. {
  365. g_pCoreShell->OperationRequest(GOI_TEAM_APPLY,
  366. (unsigned int)&m_pNearbyTeamsList[nCurSel], 0);
  367. }
  368. }*/
  369. //--------------------------------------------------------------------------
  370. // 功能:邀请
  371. //--------------------------------------------------------------------------
  372. void KUiTeamManage::OnInvite()
  373. {
  374. int nCurSel = m_NearbyList.GetCurSel();
  375. if (nCurSel >= 0)
  376. {
  377. if (m_Info.cNumMember == 0)
  378. g_pCoreShell->TeamOperation(TEAM_OI_CREATE, 0, 0);
  379. g_pCoreShell->TeamOperation(TEAM_OI_INVITE, (unsigned int)(&m_pNearbyPlayersList[nCurSel]), 0);
  380. }
  381. }
  382. void KUiTeamManage::OnRefresh()
  383. {
  384. m_NearbyList.SetContent(NULL, 0, 0, 0);
  385. if (m_pNearbyPlayersList)
  386. {
  387. free (m_pNearbyPlayersList);
  388. m_pNearbyPlayersList = NULL;
  389. }
  390. // if (m_pNearbyTeamsList)
  391. // {
  392. // free (m_pNearbyTeamsList);
  393. // m_pNearbyTeamsList = NULL;
  394. // }
  395. // if (m_NearbyPlayerTab.IsButtonChecked())
  396. {
  397. int nCount = g_pCoreShell->GetGameData(GDI_NEARBY_IDLE_PLAYER_LIST, 0, 0);
  398. if (nCount)
  399. {
  400. m_pNearbyPlayersList = (KUiPlayerItem*)malloc(sizeof(KUiPlayerItem) * nCount);
  401. if (m_pNearbyPlayersList)
  402. {
  403. g_pCoreShell->GetGameData(GDI_NEARBY_IDLE_PLAYER_LIST, (unsigned int)m_pNearbyPlayersList, nCount);
  404. m_NearbyList.SetContent((unsigned char*)m_pNearbyPlayersList, nCount,
  405. sizeof(KUiPlayerItem), ((char*)&m_pNearbyPlayersList->Name - (char*)m_pNearbyPlayersList));
  406. }
  407. }
  408. }
  409. // else
  410. // {
  411. // g_pCoreShell->OperationRequest(GOI_TEAM_COLLECT_NEARBY_LIST, 0, 0);
  412. // }
  413. }
  414. //--------------------------------------------------------------------------
  415. // 功能:离开
  416. //--------------------------------------------------------------------------
  417. void KUiTeamManage::OnLeave()
  418. {
  419. g_pCoreShell->TeamOperation(TEAM_OI_LEAVE, 0, 0);
  420. }