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

模拟服务器

开发平台:

C/C++

  1. // -------------------------------------------------------------------------
  2. // 文件名 : UiNewPlayer2.cpp
  3. // 创建者 : 彭建波
  4. // 创建时间 : 2002-9-10 14:25:24
  5. // 功能描述 : 角色新建界面-2
  6. //
  7. // -------------------------------------------------------------------------
  8. #include "KWin32.h"
  9. #include "KIniFile.h"
  10. #include "../Elem/WndMessage.h"
  11. #include "../Elem/Wnds.h"
  12. #include "UiNewPlayer2.h"
  13. #include "UiNewPlayer.h"
  14. #include "UiInformation.h"
  15. #include "UiSelPlayer.h"
  16. #include "UiMsgCentrePad.h"
  17. #include "../UiShell.h"
  18. #include "../../Login/Login.h"
  19. #include "../UiBase.h"
  20. #include "../../../core/src/gamedatadef.h"
  21. #define SCHEME_INI_NEWPLAYER2  "新建角色选属性.ini"
  22. #define countof(array) (sizeof(array)/sizeof(array[0]))
  23. #define LOGIN_CANCEL_OPER 1
  24. KUiNewPlayer2*  KUiNewPlayer2::m_pSelf=NULL;
  25. typedef struct tagPROPTYPEINFO
  26. {
  27. OBJ_ATTRIBYTE_TYPE type; //类型
  28. KWndButton* pBtn;
  29. char propertyShow[128]; //属性说明
  30. }PROPTYPEINFO;
  31. // 建一张属性类型与属性说明相对应的表,避免出现大的switch-case,并且有利于以后的增减。
  32. static PROPTYPEINFO propTypeInfoTable[] = 
  33. {
  34. {series_metal, 0, "金的属性说明!"},
  35. {series_wood, 0, "木的属性说明!"},
  36. {series_water, 0, "水的属性说明!"},
  37. {series_fire, 0, "火的属性说明!"},
  38. {series_earth, 0, "土的属性说明!"},
  39. };
  40. KUiNewPlayer2::KUiNewPlayer2()
  41. {
  42. memset(&m_Info, 0, sizeof(m_Info));
  43. m_Info.Attribute = series_metal;
  44. propTypeInfoTable[0].pBtn = &m_Gold;
  45. propTypeInfoTable[1].pBtn = &m_Wood;
  46. propTypeInfoTable[2].pBtn = &m_Water;
  47. propTypeInfoTable[3].pBtn = &m_Fire;
  48. propTypeInfoTable[4].pBtn = &m_Earth;
  49. m_bCreating = false;
  50. }
  51. KUiNewPlayer2::~KUiNewPlayer2()
  52. {
  53. for (int i = 0; i < countof(propTypeInfoTable); i++)
  54. propTypeInfoTable[i].pBtn = 0;
  55. }
  56. //--------------------------------------------------------------------------
  57. // 功能:打开窗口,返回唯一的一个类对象实例
  58. //--------------------------------------------------------------------------
  59. KUiNewPlayer2* KUiNewPlayer2::OpenWindow(const char* pName, int bMale)
  60. {
  61. if (m_pSelf == NULL && pName)
  62. {
  63. m_pSelf = new KUiNewPlayer2;
  64. if (m_pSelf)
  65. m_pSelf->Initialize();
  66. }
  67. if (m_pSelf)
  68. {
  69. m_pSelf->Show();
  70. strcpy(m_pSelf->m_Info.Name, pName);
  71. m_pSelf->m_Info.Gender = bMale ? OBJ_G_MALE : OBJ_G_FEMALE;
  72. m_pSelf->UpdateProperty();
  73. }
  74. return m_pSelf;
  75. }
  76. void KUiNewPlayer2::Initialize()
  77. {
  78. AddChild(&m_PropertyShow);
  79. AddChild(&m_Gold);
  80. AddChild(&m_Wood);
  81. AddChild(&m_Water);
  82. AddChild(&m_Fire);
  83. AddChild(&m_Earth);
  84. AddChild(&m_OK);
  85. AddChild(&m_Cancel);
  86. char Scheme[256];
  87. g_UiBase.GetCurSchemePath(Scheme, 256);
  88. m_pSelf->LoadScheme(Scheme);
  89. Wnd_AddWindow(this, WL_TOPMOST);
  90. }
  91. //--------------------------------------------------------------------------
  92. // 功能:关闭窗口,同时可以选则是否删除对象实例
  93. //--------------------------------------------------------------------------
  94. void KUiNewPlayer2::CloseWindow(bool bDestroy)
  95. {
  96. if (m_pSelf)
  97. {
  98. if (m_pSelf->m_bCreating)
  99. {
  100. KSelSavedCharacter* pTool = KLogin::GetCharacterModule();
  101. if(pTool)
  102. pTool->CancelOperaton();
  103. m_pSelf->m_bCreating = false;
  104. }
  105. if (bDestroy == false)
  106. m_pSelf->Hide();
  107. else
  108. {
  109. m_pSelf->Destroy();
  110. m_pSelf = NULL;
  111. }
  112. }
  113. }
  114. //--------------------------------------------------------------------------
  115. // 功能:载入窗口的界面方案
  116. //--------------------------------------------------------------------------
  117. void KUiNewPlayer2::LoadScheme(const char* pScheme)
  118. {
  119. char Buff[128];
  120. KIniFile Ini;
  121. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_NEWPLAYER2);
  122. if (Ini.Load(Buff))
  123. {
  124. Init(&Ini, "Main");
  125. m_PropertyShow. Init(&Ini, "PropertyShow");
  126. m_Gold. Init(&Ini, "Gold");
  127. m_Wood. Init(&Ini, "Wood");
  128. m_Water. Init(&Ini, "Water");
  129. m_Fire. Init(&Ini, "Fire");
  130. m_Earth. Init(&Ini, "Earth");
  131. m_OK. Init(&Ini, "OK");
  132. m_Cancel. Init(&Ini, "Cancel");
  133. }
  134. }
  135. //--------------------------------------------------------------------------
  136. // 功能:窗口消息函数
  137. //--------------------------------------------------------------------------
  138. int KUiNewPlayer2::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  139. {
  140. int nRet = 0;
  141. switch(uMsg)
  142. {
  143. case WND_N_BUTTON_CLICK:
  144. OnClickButton((KWndWindow*)uParam);
  145. break;
  146. case WM_KEYDOWN:
  147. if (uParam == VK_ESCAPE)
  148. {
  149. OnCancel();
  150. nRet = 1;
  151. }
  152. else if (uParam == VK_RETURN)
  153. {
  154. OnOk();
  155. nRet = 1;
  156. }
  157. break;
  158. case WND_M_OTHER_WORK_RESULT:
  159. if (uParam == LOGIN_CANCEL_OPER)
  160. {
  161. g_NetConnectAgent.SendUndispatchedToGameSpace(false);
  162. KSelSavedCharacter* pTool = KLogin::GetCharacterModule();
  163. if (pTool)
  164. pTool->CancelOperaton();
  165. OnCancel();
  166. }
  167. break;
  168. default:
  169. nRet = KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  170. }
  171. return nRet;
  172. }
  173. //--------------------------------------------------------------------------
  174. // 功能:返回“角色新建界面-1”
  175. //--------------------------------------------------------------------------
  176. void KUiNewPlayer2::OnCancel()
  177. {
  178. CloseWindow(false);
  179. KUiNewPlayer::OpenWindow();
  180. }
  181. //--------------------------------------------------------------------------
  182. // 功能:完成,要发请求新建角色消息了
  183. //--------------------------------------------------------------------------
  184. void KUiNewPlayer2::OnOk()
  185. {
  186. if (m_bCreating == false)
  187. {
  188. KSelSavedCharacter* pTool = KLogin::GetCharacterModule();
  189. if(pTool)
  190. {
  191. m_bCreating = true;
  192. g_NetConnectAgent.SendUndispatchedToGameSpace(true);
  193. pTool->NewCharacter(&m_Info);
  194. UIMessageBox("正在新建角色...请稍候。", this, "取消", 0, LOGIN_CANCEL_OPER);
  195. KUiMsgCentrePad::OpenWindow();
  196. KUiMsgCentrePad::CloseWindow(false);
  197. }
  198. }
  199. }
  200. // -------------------------------------------------------------------------
  201. // 功能 : 窗口的持续行为
  202. // -------------------------------------------------------------------------
  203. void KUiNewPlayer2::Breathe()
  204. {
  205. if (m_bCreating)
  206. {
  207. KSelSavedCharacter* pTool = KLogin::GetCharacterModule();
  208. if (pTool)
  209. {
  210. int nResult = pTool->GetLastActionResult();
  211. switch(nResult)
  212. {
  213. case SSC_R_START_GAME:
  214. m_bCreating = false;
  215. UiCloseMessageBox();
  216. CloseWindow(true);
  217. KUiSelPlayer::CloseWindow(true);
  218. UiStartGame();
  219. break;
  220. }
  221. }
  222. }
  223. }
  224. //--------------------------------------------------------------------------
  225. // 功能:响应点击按钮
  226. //--------------------------------------------------------------------------
  227. void KUiNewPlayer2::OnClickButton(KWndWindow* pWnd)
  228. {
  229. if (pWnd == (KWndWindow*)&m_OK)
  230. OnOk();
  231. else if (pWnd == (KWndWindow*)&m_Cancel)
  232. OnCancel();
  233. else if (pWnd == (KWndWindow*)&m_Gold)
  234. {
  235. m_Info.Attribute = series_metal;
  236. UpdateProperty();
  237. }
  238. else if (pWnd == (KWndWindow*)&m_Wood)
  239. {
  240. m_Info.Attribute = series_wood;
  241. UpdateProperty();
  242. }
  243. else if (pWnd == (KWndWindow*)&m_Water)
  244. {
  245. m_Info.Attribute = series_water;
  246. UpdateProperty();
  247. }
  248. else if (pWnd == (KWndWindow*)&m_Fire)
  249. {
  250. m_Info.Attribute = series_fire;
  251. UpdateProperty();
  252. }
  253. else if (pWnd == (KWndWindow*)&m_Earth)
  254. {
  255. m_Info.Attribute = series_earth;
  256. UpdateProperty();
  257. }
  258. }
  259. //--------------------------------------------------------------------------
  260. // 功能:更新属性说明
  261. //--------------------------------------------------------------------------
  262. void KUiNewPlayer2::UpdateProperty()
  263. {
  264. int nSize = countof(propTypeInfoTable);
  265. for (int i = 0; i < nSize; i++)
  266. {
  267. if (propTypeInfoTable[i].type == m_Info.Attribute)
  268. {
  269. m_PropertyShow.SetText(propTypeInfoTable[i].propertyShow);
  270. propTypeInfoTable[i].pBtn->CheckButton(true);
  271. }
  272. else
  273. propTypeInfoTable[i].pBtn->CheckButton(false);
  274. }
  275. }