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

模拟服务器

开发平台:

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 "UiTeamNew.h"
  13. #include <crtdbg.h>
  14. #include "../../../core/src/coreshell.h"
  15. extern iCoreShell* g_pCoreShell;
  16. #define TEAM_NAME_LEN_MAX 20
  17. #define TEAM_NAME_LEN_MIN 4
  18. #define SCHEME_INI "新建队伍.ini"
  19. KUiTeamNew* KUiTeamNew::m_pSelf = NULL;
  20. //--------------------------------------------------------------------------
  21. // 功能:如果窗口正被显示,则返回实例指针
  22. //--------------------------------------------------------------------------
  23. KUiTeamNew* KUiTeamNew::GetIfVisible()
  24. {
  25. if (m_pSelf && m_pSelf->IsVisible())
  26. return m_pSelf;
  27. return NULL;
  28. }
  29. //--------------------------------------------------------------------------
  30. // 功能:打开窗口,返回唯一的一个类对象实例
  31. //--------------------------------------------------------------------------
  32. KUiTeamNew* KUiTeamNew::OpenWindow()
  33. {
  34. if (m_pSelf == NULL)
  35. {
  36. m_pSelf = new KUiTeamNew;
  37. if (m_pSelf)
  38. m_pSelf->Initialize();
  39. }
  40. if (m_pSelf)
  41. {
  42. m_pSelf->BringToTop();
  43. Wnd_SetExclusive(m_pSelf);
  44. Wnd_SetFocusWnd(&m_pSelf->m_TeamName);
  45. m_pSelf->Show();
  46. }
  47. return m_pSelf;
  48. }
  49. //初始化
  50. void KUiTeamNew::Initialize()
  51. {
  52. AddChild(&m_TeamName);
  53. AddChild(&m_OkBtn);
  54. AddChild(&m_CancelBtn);
  55. Wnd_AddWindow(this);
  56. char Scheme[256];
  57. g_UiBase.GetCurSchemePath(Scheme, 256);
  58. LoadScheme(Scheme);
  59. }
  60. //--------------------------------------------------------------------------
  61. // 功能:关闭窗口,同时可以选则是否删除对象实例
  62. //--------------------------------------------------------------------------
  63. void KUiTeamNew::CloseWindow()
  64. {
  65. if (m_pSelf)
  66. {
  67. Wnd_ReleaseExclusive(m_pSelf);
  68. m_pSelf->Destroy();
  69. m_pSelf = NULL;
  70. }
  71. }
  72. void KUiTeamNew::LoadScheme(const char* pScheme)
  73. {
  74. char Buff[128];
  75. KIniFile Ini;
  76. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  77. if (Ini.Load(Buff))
  78. {
  79. Init(&Ini, "Main");
  80. m_TeamName .Init(&Ini, "TeamName");
  81. m_OkBtn .Init(&Ini, "OkBtn");
  82. m_CancelBtn .Init(&Ini, "CancelBtn");
  83. }
  84. }
  85. //窗口函数
  86. int KUiTeamNew::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  87. {
  88. int nRet = 0;
  89. switch(uMsg)
  90. {
  91. case WND_N_BUTTON_CLICK:
  92. if (uParam == (unsigned int)(KWndWindow*)&m_OkBtn)
  93. OnOk();
  94. else if (uParam == (unsigned int)(KWndWindow*)&m_CancelBtn)
  95. CloseWindow();
  96. break;
  97. case WND_N_EDIT_SPECIAL_KEY_DOWN:
  98. if (nParam == VK_RETURN)
  99. {
  100. if (uParam == (unsigned int)(KWndWindow*)&m_TeamName)
  101. OnOk();
  102. }
  103. else if (nParam == VK_ESCAPE)
  104. {
  105. CloseWindow();
  106. nRet = 1;
  107. }
  108. break;
  109. default:
  110. nRet = KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  111. }
  112. return nRet;
  113. }
  114. void KUiTeamNew::OnOk()
  115. {
  116. char Name[32];
  117. if (!CheckInput(Name))
  118. return;
  119. g_pCoreShell->OperationRequest(GOI_TEAM_NEW, (unsigned int)Name, 0);
  120. CloseWindow();
  121. }
  122. bool KUiTeamNew::CheckInput(char* pName)
  123. {
  124. _ASSERT(pName);
  125. int nLen = m_TeamName.GetText(pName, 32);
  126. if (nLen >= TEAM_NAME_LEN_MIN && nLen <= TEAM_NAME_LEN_MAX)
  127. {
  128. return true;
  129. }
  130. // UIMessageBox("★毛主席★说:密码和账号不能太短也不能太长,要不革命会失败!", this);
  131. return false;
  132. }