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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 界面--聊天窗口
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-8-27
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "../elem/wnds.h"
  11. #include "UiSkills.h"
  12. #include "UiSysMsgCentre.h"
  13. #include "../../../core/src/coreshell.h"
  14. #include "../UiBase.h"
  15. #include "crtdbg.h"
  16. #include "../UiSoundSetting.h"
  17. #include "../../../Represent/iRepresent/iRepresentShell.h"
  18. extern iRepresentShell* g_pRepresentShell;
  19. extern iCoreShell* g_pCoreShell;
  20. #define  SCHEME_INI_SHEET "技能主窗口.ini"
  21. #define  SCHEME_INI_LIVE "生活技能分页.ini"
  22. #define  SCHEME_INI_FIGHT "战斗技能分页.ini"
  23. #define  SCHEME_INI_FIGHT_SUB_PAGE "战斗技能细分页.ini"
  24. #define SET_NEW_SKILL_TO_IMMED_SKILL_LEVEL_RANGE 9
  25. #define AUTO_SET_IMMED_SKILL_MSG_ID "24"
  26. KUiFightSkillSubPage::KUiFightSkillSubPage()
  27. {
  28. m_nRemainSkillPoint = 0;
  29. // m_nSubPagIndex = 0;
  30. }
  31. //初始化
  32. void KUiFightSkillSubPage::Initialize(/*int nSubPageIndex*/)
  33. {
  34. for (int i = 0; i < FIGHT_SKILL_COUNT_PER_PAGE; i ++)
  35. {
  36. AddChild(&m_FightSkills[i]);
  37. m_FightSkills[i].Celar();
  38. m_FightSkills[i].SetContainerId((int)UOC_SKILL_LIST);
  39. }
  40. // m_nSubPagIndex = nSubPageIndex;
  41. }
  42. //载入界面方案
  43. void KUiFightSkillSubPage::LoadScheme(const char* pScheme)
  44. {
  45. char Buff[128];
  46. KIniFile Ini;
  47. sprintf(Buff, "%s\"SCHEME_INI_FIGHT_SUB_PAGE, pScheme);
  48. if (Ini.Load(Buff))
  49. {
  50. KWndPage::Init(&Ini, "Main");
  51. for (int i = 0; i < FIGHT_SKILL_COUNT_PER_PAGE; i++)
  52. {
  53. sprintf(Buff, "Skill_%d", i);
  54. m_FightSkills[i].Init(&Ini, Buff);
  55. m_FightSkills[i].EnablePickPut(false);
  56. }
  57. Ini.GetInteger("SkillText", "Font", 12, &m_SkillTextParam.nFont);
  58. Ini.GetInteger2("SkillText", "Offset",
  59. (int*)&m_SkillTextParam.Offset.cx, (int*)&m_SkillTextParam.Offset.cy);
  60. Ini.GetString("SkillText", "Color", "", Buff, 16);
  61. m_SkillTextParam.Color = GetColor(Buff);
  62. }
  63. }
  64. //更新升级点数
  65. void KUiFightSkillSubPage::UpdateRemainPoint(int nPoint)
  66. {
  67. m_nRemainSkillPoint = nPoint;
  68. }
  69. //更新升级点数
  70. void KUiFightSkillSubPage::UpdateSkill(KUiSkillData* pSkill, int nIndex)
  71. {
  72. _ASSERT(pSkill && nIndex >= 0 && nIndex < FIGHT_SKILL_COUNT_PER_PAGE);
  73. m_FightSkills[nIndex].HoldObject(pSkill->uGenre, pSkill->uId, pSkill->nLevel, 0);
  74. }
  75. //更新数据
  76. void KUiFightSkillSubPage::UpdateData(KUiSkillData* pSkills)
  77. {
  78. _ASSERT(pSkills);
  79. for (int i = 0; i < FIGHT_SKILL_COUNT_PER_PAGE; i++)
  80. m_FightSkills[i].HoldObject(pSkills[i].uGenre, pSkills[i].uId, pSkills[i].nLevel, 0);
  81. }
  82. //窗口函数
  83. int KUiFightSkillSubPage::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  84. {
  85. if (uMsg == WND_N_LEFT_CLICK_ITEM && uParam && m_nRemainSkillPoint)
  86. {
  87. KUiDraggedObject* pObj = (KUiDraggedObject*)uParam;
  88. if (pObj->uGenre != CGOG_NOTHING)
  89. {
  90. m_nRemainSkillPoint --; // 使用技能点数
  91. g_pCoreShell->OperationRequest(GOI_TONE_UP_SKILL, CGOG_SKILL_FIGHT, pObj->uId);
  92. }
  93. return 0;
  94. }
  95. return KWndPage::WndProc(uMsg, uParam, nParam);
  96. }
  97. //绘制窗口
  98. void KUiFightSkillSubPage::PaintWindow()
  99. {
  100. KWndPage::PaintWindow();
  101. for (int i = 0; i < FIGHT_SKILL_COUNT_PER_PAGE; i++)
  102. {
  103. KUiDraggedObject Obj;
  104. m_FightSkills[i].GetObject(Obj);
  105. if (Obj.uGenre != CGOG_NOTHING)
  106. {
  107. int nLeft, nTop, nWidth, nHeight;
  108. m_FightSkills[i].GetAbsolutePos(&nLeft, &nTop);
  109. m_FightSkills[i].GetSize(&nWidth, &nHeight);
  110. g_pCoreShell->DrawGameObj(CGOG_SKILL_LIVE, Obj.uId, nLeft, nTop, nWidth, nHeight, Obj.DataW);
  111. if (Obj.DataW)
  112. {
  113. char szLevel[8];
  114. int nLen;
  115. itoa(Obj.DataW, szLevel, 10);
  116. nLen = strlen(szLevel);
  117. nLeft += m_SkillTextParam.Offset.cx;
  118. nTop += m_SkillTextParam.Offset.cy;
  119. nLeft += (nWidth - nLen * m_SkillTextParam.nFont / 2) / 2;
  120. g_pRepresentShell->OutputText(m_SkillTextParam.nFont, szLevel, nLen, nLeft, nTop,
  121. m_SkillTextParam.Color, 0);
  122. }
  123. }
  124. }
  125. }
  126. //初始化
  127. void KUiFightSkillSub::Initialize()
  128. {
  129. for (int i = 0; i < FIGHT_SKILL_SUB_PAGE_COUNT; i++)
  130. {
  131. m_SubPages[i].Initialize();
  132. AddPage(&m_SubPages[i], &m_SubPageBtn[i]);
  133. }
  134. }
  135. //载入界面方案
  136. void KUiFightSkillSub::LoadScheme(const char* pScheme)
  137. {
  138. char Buff[128];
  139. KIniFile Ini;
  140. sprintf(Buff, "%s\"SCHEME_INI_FIGHT, pScheme);
  141. if (Ini.Load(Buff))
  142. {
  143. KWndPageSet::Init(&Ini, "Main");
  144. m_oFixPos.x = 0;
  145. m_oFixPos.y = 0;
  146. SetPosition(0, 0);
  147. for (int i = 0; i < FIGHT_SKILL_SUB_PAGE_COUNT; i++)
  148. {
  149. m_SubPages[i].LoadScheme(pScheme);
  150. sprintf(Buff, "SubPageBtn_%d", i);
  151. m_SubPageBtn[i].Init(&Ini, Buff);
  152. }
  153. Show();
  154. }
  155. }
  156. //更新升级点数
  157. void KUiFightSkillSub::UpdateRemainPoint(int nPoint)
  158. {
  159. for (int i = 0; i < FIGHT_SKILL_SUB_PAGE_COUNT; i++)
  160. m_SubPages[i].UpdateRemainPoint(nPoint);
  161. }
  162. //更新技能
  163. void KUiFightSkillSub::UpdateSkill(KUiSkillData* pSkill, int nIndex)
  164. {
  165. _ASSERT(pSkill);
  166. int nPage = nIndex / FIGHT_SKILL_COUNT_PER_PAGE;
  167. nIndex = nIndex % FIGHT_SKILL_COUNT_PER_PAGE;
  168. _ASSERT(nPage >= 0 && nPage < FIGHT_SKILL_SUB_PAGE_COUNT);
  169. m_SubPages[nPage].UpdateSkill(pSkill, nIndex);
  170. }
  171. //更新数据
  172. void KUiFightSkillSub::UpdateData()
  173. {
  174. KUiSkillData Skills[FIGHT_SKILL_COUNT];
  175. g_pCoreShell->GetGameData(GDI_FIGHT_SKILLS, (unsigned int)Skills, 0);
  176. for (int i = 0; i < FIGHT_SKILL_SUB_PAGE_COUNT; i++)
  177. m_SubPages[i].UpdateData(&Skills[i * FIGHT_SKILL_COUNT_PER_PAGE]);
  178. }
  179. //--------------------------------------------------------------------------
  180. // 功能:初始化
  181. //--------------------------------------------------------------------------
  182. void KUiFightSkill::Initialize()
  183. {
  184. m_InternalPad.Initialize();
  185. AddChild(&m_InternalPad);
  186. AddChild(&m_RemainSkillPoint);
  187. }
  188. //--------------------------------------------------------------------------
  189. // 功能:载入窗口的界面方案
  190. //--------------------------------------------------------------------------
  191. void KUiFightSkill::LoadScheme(const char* pScheme)
  192. {
  193. char Buff[128];
  194. KIniFile Ini;
  195. sprintf(Buff, "%s\"SCHEME_INI_FIGHT, pScheme);
  196. if (Ini.Load(Buff))
  197. {
  198. KWndPage::Init(&Ini, "Main");
  199. m_InternalPad.LoadScheme(pScheme);
  200. m_RemainSkillPoint.Init(&Ini, "RemainPoint");
  201. }
  202. }
  203. //--------------------------------------------------------------------------
  204. // 功能:更新数据
  205. //--------------------------------------------------------------------------
  206. void KUiFightSkill::UpdateData()
  207. {
  208. int nRemainSkillPoint = g_pCoreShell->GetGameData(GDI_FIGHT_SKILL_POINT, 0, 0);
  209. m_InternalPad.UpdateRemainPoint(nRemainSkillPoint);
  210. m_RemainSkillPoint.SetIntText(nRemainSkillPoint);
  211. m_InternalPad.UpdateData();
  212. }
  213. //--------------------------------------------------------------------------
  214. // 功能:更新技能
  215. //--------------------------------------------------------------------------
  216. void KUiFightSkill::UpdateSkill(KUiSkillData* pSkill, int nIndex)
  217. {
  218. m_InternalPad.UpdateSkill(pSkill, nIndex);
  219. }
  220. //--------------------------------------------------------------------------
  221. // 功能:更新升级点数
  222. //--------------------------------------------------------------------------
  223. void KUiFightSkill::UpdateRemainPoint(int nPoint)
  224. {
  225. m_RemainSkillPoint.SetIntText(nPoint);
  226. m_InternalPad.UpdateRemainPoint(nPoint);
  227. }
  228. KUiLiveSkill::KUiLiveSkill()
  229. {
  230. m_nRemainSkillPoint = 0;
  231. }
  232. //--------------------------------------------------------------------------
  233. // 功能:初始化
  234. //--------------------------------------------------------------------------
  235. void KUiLiveSkill::Initialize()
  236. {
  237. AddChild(&m_RemainSkillPoint);
  238. for (int i = 0; i < LIVE_SKILL_COUNT; i++)
  239. {
  240. m_LiveSkill[i].Celar();
  241. AddChild(&m_LiveSkill[i]);
  242. m_LiveSkill[i].SetContainerId((int)UOC_SKILL_LIST);
  243. }
  244. }
  245. //--------------------------------------------------------------------------
  246. // 功能:载入窗口的界面方案
  247. //--------------------------------------------------------------------------
  248. void KUiLiveSkill::LoadScheme(const char* pScheme)
  249. {
  250. char Buff[128];
  251. KIniFile Ini;
  252. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_LIVE);
  253. if (Ini.Load(Buff))
  254. {
  255. KWndImage::Init(&Ini, "Main");
  256. m_RemainSkillPoint. Init(&Ini, "RemainPoint");
  257. for (int i = 0; i < LIVE_SKILL_COUNT; i++)
  258. {
  259. sprintf(Buff, "Skill_%d", i);
  260. m_LiveSkill[i].Init(&Ini, Buff);
  261. m_LiveSkill[i].EnablePickPut(false);
  262. }
  263. Ini.GetInteger("SkillText", "Font", 12, &m_SkillTextParam.nFont);
  264. Ini.GetInteger2("SkillText", "Offset",
  265. (int*)&m_SkillTextParam.Offset.cx, (int*)&m_SkillTextParam.Offset.cy);
  266. Ini.GetString("SkillText", "Color", "", Buff, 16);
  267. m_SkillTextParam.Color = GetColor(Buff);
  268. }
  269. }
  270. //--------------------------------------------------------------------------
  271. // 功能:窗口函数
  272. //--------------------------------------------------------------------------
  273. int KUiLiveSkill::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  274. {
  275. if (uMsg == WND_N_LEFT_CLICK_ITEM && uParam && m_nRemainSkillPoint)
  276. {
  277. KUiDraggedObject* pObj = (KUiDraggedObject*)uParam;
  278. if (pObj->uGenre != CGOG_NOTHING)
  279. {
  280. m_nRemainSkillPoint--; // 使用技能点数
  281. g_pCoreShell->OperationRequest(GOI_TONE_UP_SKILL, CGOG_SKILL_LIVE, pObj->uId);
  282. }
  283. return 0;
  284. }
  285. return KWndPage::WndProc(uMsg, uParam, nParam);
  286. }
  287. //--------------------------------------------------------------------------
  288. // 功能:绘制窗口
  289. //--------------------------------------------------------------------------
  290. void KUiLiveSkill::PaintWindow()
  291. {
  292. KWndPage::PaintWindow();
  293. for (int i = 0; i < LIVE_SKILL_COUNT; i++)
  294. {
  295. KUiDraggedObject Obj;
  296. m_LiveSkill[i].GetObject(Obj);
  297. if (Obj.uGenre != CGOG_NOTHING)
  298. {
  299. int nLeft, nTop, nWidth, nHeight;
  300. m_LiveSkill[i].GetAbsolutePos(&nLeft, &nTop);
  301. m_LiveSkill[i].GetSize(&nWidth, &nHeight);
  302. g_pCoreShell->DrawGameObj(CGOG_SKILL_LIVE, Obj.uId, nLeft, nTop, nWidth, nHeight, Obj.DataW);
  303. if (Obj.DataW)
  304. {
  305. char szLevel[8];
  306. int nLen;
  307. itoa(Obj.DataW, szLevel, 10);
  308. nLen = strlen(szLevel);
  309. nLeft += m_SkillTextParam.Offset.cx;
  310. nTop += m_SkillTextParam.Offset.cy;
  311. nLeft += (nWidth - nLen * m_SkillTextParam.nFont / 2) / 2;
  312. g_pRepresentShell->OutputText(m_SkillTextParam.nFont, szLevel, nLen, nLeft, nTop,
  313. m_SkillTextParam.Color, 0);
  314. }
  315. }
  316. }
  317. }
  318. //--------------------------------------------------------------------------
  319. // 功能:更新技能公共数据
  320. //--------------------------------------------------------------------------
  321. void KUiLiveSkill::UpdateBaseData()
  322. {
  323. //从游戏世界获取生活技能数据
  324. KUiPlayerLiveSkillBase Info;
  325. g_pCoreShell->GetGameData(GDI_LIVE_SKILL_BASE, (unsigned int)&Info, 0);
  326. m_RemainSkillPoint.SetIntText(m_nRemainSkillPoint = Info.nRemainPoint);
  327. }
  328. //--------------------------------------------------------------------------
  329. // 功能:更新技能
  330. //--------------------------------------------------------------------------
  331. void KUiLiveSkill::UpdateSkill(KUiSkillData* pSkill, int nIndex)
  332. {
  333. if (pSkill && nIndex >= 0 && nIndex < LIVE_SKILL_COUNT)
  334. {
  335. m_LiveSkill[nIndex].HoldObject(pSkill->uGenre, pSkill->uId, pSkill->nLevel, 0);
  336. }
  337. }
  338. //--------------------------------------------------------------------------
  339. // 功能:更新数据
  340. //--------------------------------------------------------------------------
  341. void KUiLiveSkill::UpdateData()
  342. {
  343. UpdateBaseData();
  344. KUiSkillData Skills[LIVE_SKILL_COUNT];
  345. g_pCoreShell->GetGameData(GDI_LIVE_SKILLS, (unsigned int)Skills, 0);
  346. for (int i = 0; i < LIVE_SKILL_COUNT; i++)
  347. m_LiveSkill[i].HoldObject(Skills[i].uGenre, Skills[i].uId, Skills[i].nLevel, 0);
  348. }
  349. KUiSkills* KUiSkills::m_pSelf = NULL;
  350. //--------------------------------------------------------------------------
  351. // 功能:打开窗口,返回唯一的一个类对象实例
  352. //--------------------------------------------------------------------------
  353. KUiSkills* KUiSkills::OpenWindow()
  354. {
  355. if (m_pSelf == NULL)
  356. {
  357. m_pSelf = new KUiSkills;
  358. if (m_pSelf)
  359. m_pSelf->Initialize();
  360. }
  361. if (m_pSelf)
  362. {
  363. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  364. m_pSelf->m_FightSkillPad.UpdateData();
  365. m_pSelf->m_LiveSkillPad.UpdateData();
  366. m_pSelf->BringToTop();
  367. m_pSelf->Show();
  368. }
  369. return m_pSelf;
  370. }
  371. //--------------------------------------------------------------------------
  372. // 功能:如果窗口正被显示,则返回实例指针
  373. //--------------------------------------------------------------------------
  374. KUiSkills* KUiSkills::GetIfVisible()
  375. {
  376. if (m_pSelf && m_pSelf->IsVisible())
  377. return m_pSelf;
  378. return NULL;
  379. }
  380. //--------------------------------------------------------------------------
  381. // 功能:关闭窗口,同时可以选则是否删除对象实例
  382. //--------------------------------------------------------------------------
  383. void KUiSkills::CloseWindow(bool bDestroy)
  384. {
  385. if (m_pSelf)
  386. {
  387. if (bDestroy == false)
  388. m_pSelf->Hide();
  389. else
  390. {
  391. m_pSelf->Destroy();
  392. m_pSelf = NULL;
  393. }
  394. }
  395. }
  396. //--------------------------------------------------------------------------
  397. // 功能:初始化
  398. //--------------------------------------------------------------------------
  399. void KUiSkills::Initialize()
  400. {
  401. m_FightSkillPad.Initialize();
  402. AddPage(&m_FightSkillPad, &m_FightSkillPadBtn);
  403. m_LiveSkillPad.Initialize();
  404. AddPage(&m_LiveSkillPad, &m_LiveSkillPadBtn);
  405. AddChild(&m_Close);
  406. char Scheme[256];
  407. g_UiBase.GetCurSchemePath(Scheme, 256);
  408. LoadScheme(Scheme);
  409. Wnd_AddWindow(this);
  410. }
  411. //--------------------------------------------------------------------------
  412. // 功能:载入窗口的界面方案
  413. //--------------------------------------------------------------------------
  414. void KUiSkills::LoadScheme(const char* pScheme)
  415. {
  416. char Buff[128];
  417. KIniFile Ini;
  418. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_SHEET);
  419. if (m_pSelf && Ini.Load(Buff))
  420. {
  421. m_pSelf->Init(&Ini, "Main");
  422. m_pSelf->m_FightSkillPadBtn.Init(&Ini, "FightBtn");
  423. m_pSelf->m_LiveSkillPadBtn .Init(&Ini, "LiveBtn");
  424. m_pSelf->m_Close           .Init(&Ini, "CloseBtn");
  425. m_pSelf->m_LiveSkillPad.LoadScheme(pScheme);
  426. m_pSelf->m_FightSkillPad.LoadScheme(pScheme);
  427. }
  428. }
  429. //--------------------------------------------------------------------------
  430. // 功能:更新技能
  431. //--------------------------------------------------------------------------
  432. void KUiSkills::UpdateSkill(KUiSkillData* pSkill, int nIndex)
  433. {
  434. if (pSkill)
  435. {
  436. if (m_pSelf)
  437. {
  438. if (pSkill->uGenre == CGOG_SKILL_LIVE)
  439. m_pSelf->m_LiveSkillPad.UpdateSkill(pSkill, nIndex);
  440. else if (pSkill->uGenre == CGOG_SKILL_FIGHT)
  441. m_pSelf->m_FightSkillPad.UpdateSkill(pSkill, nIndex);
  442. }
  443. if (g_pCoreShell)
  444. {
  445. KUiPlayerAttribute Info;
  446. memset(&Info, 0, sizeof(KUiPlayerAttribute));
  447. g_pCoreShell->GetGameData(GDI_PLAYER_RT_ATTRIBUTE, (unsigned int)&Info, 0);
  448. if (Info.nLevel <= SET_NEW_SKILL_TO_IMMED_SKILL_LEVEL_RANGE)
  449. {
  450. g_pCoreShell->OperationRequest(GOI_SET_IMMDIA_SKILL, (unsigned int)pSkill, 1);
  451. KSystemMessage Msg;
  452. Msg.byConfirmType = SMCT_NONE;
  453. Msg.byParamSize = 0;
  454. Msg.byPriority = 0;
  455. Msg.eType = SMT_NORMAL;
  456. Msg.uReservedForUi = 0;
  457. KIniFile* pIni = g_UiBase.GetCommConfigFile();
  458. if (pIni)
  459. {
  460. if (pIni->GetString("InfoString", AUTO_SET_IMMED_SKILL_MSG_ID,
  461. "", Msg.szMessage, sizeof(Msg.szMessage)))
  462. {
  463. KUiSysMsgCentre::AMessageArrival(&Msg, NULL);
  464. }
  465. g_UiBase.CloseCommConfigFile();
  466. }
  467. }
  468. }
  469. }
  470. }
  471. //--------------------------------------------------------------------------
  472. // 功能:更新战斗技能升级点数
  473. //--------------------------------------------------------------------------
  474. void KUiSkills::UpdateFightRemainPoint(int nPoint)
  475. {
  476. m_FightSkillPad.UpdateRemainPoint(nPoint);
  477. }
  478. //--------------------------------------------------------------------------
  479. // 功能:更新生活技能公共数据
  480. //--------------------------------------------------------------------------
  481. void KUiSkills::UpdateLiveBaseData()
  482. {
  483. m_LiveSkillPad.UpdateBaseData();
  484. }
  485. //窗口函数
  486. int KUiSkills::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  487. {
  488. if (uMsg == WND_N_BUTTON_CLICK && (KWndWindow*)uParam == (KWndWindow*)&m_Close)
  489. {
  490. Hide(); // 关闭装备框
  491. return 0;
  492. }
  493. return KWndPageSet::WndProc(uMsg, uParam, nParam);
  494. }