UiStatus.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 "UiStatus.h"
  12. #include "UiPlayerBar.h"
  13. #include "../ShortcutKey.h"
  14. #include "../UiSoundSetting.h"
  15. #include "../../../core/src/coreshell.h"
  16. #include "../../../core/src/gamedatadef.h"
  17. #include "../UiBase.h"
  18. extern iCoreShell* g_pCoreShell;
  19. #define SCHEME_INI "玩家装备与人物状态.ini"
  20. KUiStatus* KUiStatus::m_pSelf = NULL;
  21. // -------------------------------------------------------------------------
  22. // ---> 建立控件与UIEP_*以及可接纳物品的类型的对应关系
  23. static struct UE_CTRL_MAP
  24. {
  25. int nPosition;
  26. const char* pIniSection;
  27. }CtrlItemMap[_ITEM_COUNT] =
  28. {
  29. { UIEP_HEAD, "Cap" }, //装备-帽子
  30. { UIEP_HAND, "Weapon" }, //装备-武器
  31. { UIEP_NECK, "Necklace" }, //装备-项链
  32. { UIEP_FINESSE, "Bangle" }, //装备-手镯
  33. { UIEP_BODY, "Cloth" }, //装备-衣服
  34. { UIEP_WAIST, "Sash" }, //装备-腰带
  35. { UIEP_FINGER1, "Ring1" }, //装备-戒指
  36. { UIEP_FINGER2, "Ring2" }, //装备-戒指
  37. { UIEP_WAIST_DECOR, "Pendant" }, //装备-腰缀
  38. { UIEP_FOOT, "Shoes" }, //装备-鞋子
  39. { UIEP_HORSE, "Horse" } //装备-马
  40. };
  41. //--------------------------------------------------------------------------
  42. // 功能:如果窗口正被显示,则返回实例指针
  43. //--------------------------------------------------------------------------
  44. KUiStatus* KUiStatus::GetIfVisible()
  45. {
  46. if (m_pSelf && m_pSelf->IsVisible())
  47. return m_pSelf;
  48. return NULL;
  49. }
  50. //--------------------------------------------------------------------------
  51. // 功能:打开窗口,返回唯一的一个类对象实例
  52. //--------------------------------------------------------------------------
  53. KUiStatus* KUiStatus::OpenWindow()
  54. {
  55. if (m_pSelf == NULL)
  56. {
  57. m_pSelf = new KUiStatus;
  58. if (m_pSelf)
  59. m_pSelf->Initialize();
  60. }
  61. if (m_pSelf)
  62. {
  63. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  64. m_pSelf->UpdateData();
  65. m_pSelf->BringToTop();
  66. m_pSelf->Show();
  67. }
  68. return m_pSelf;
  69. }
  70. //--------------------------------------------------------------------------
  71. // 功能:关闭窗口,同时可以选则是否删除对象实例
  72. //--------------------------------------------------------------------------
  73. void KUiStatus::CloseWindow(bool bDestroy)
  74. {
  75. if (m_pSelf)
  76. {
  77. if (bDestroy == false)
  78. m_pSelf->Hide();
  79. else
  80. {
  81. m_pSelf->Destroy();
  82. m_pSelf = NULL;
  83. }
  84. }
  85. }
  86. //--------------------------------------------------------------------------
  87. // 功能:初始化
  88. //--------------------------------------------------------------------------
  89. void KUiStatus::Initialize()
  90. {
  91. AddChild(&m_Agname);
  92. AddChild(&m_Name);
  93. AddChild(&m_Title);
  94. AddChild(&m_Money);
  95. AddChild(&m_Life);
  96. AddChild(&m_Mana);
  97. AddChild(&m_Stamina);
  98. AddChild(&m_Angry);
  99. AddChild(&m_Experience);
  100. AddChild(&m_RemainPoint);
  101. AddChild(&m_Strength);
  102. AddChild(&m_Dexterity);
  103. AddChild(&m_Vitality);
  104. AddChild(&m_Energy);
  105. AddChild(&m_AddStrength);
  106. AddChild(&m_AddDexterity);
  107. AddChild(&m_AddVitality);
  108. AddChild(&m_AddEnergy);
  109. AddChild(&m_LeftDamage);
  110. AddChild(&m_RightDamage);
  111. AddChild(&m_Attack);
  112. AddChild(&m_Defence);
  113. AddChild(&m_MoveSpeed);
  114. AddChild(&m_AttackSpeed);
  115. AddChild(&m_PhyDef);
  116. AddChild(&m_CoolDef);
  117. AddChild(&m_LightDef);
  118. AddChild(&m_FireDef);
  119. AddChild(&m_PoisonDef);
  120. AddChild(&m_Level);
  121. AddChild(&m_StatusDesc);
  122. for (int i = 0; i < _ITEM_COUNT; i ++)
  123. {
  124. m_EquipBox[i].SetObjectGenre(CGOG_ITEM);
  125. AddChild(&m_EquipBox[i]);
  126. m_EquipBox[i].SetContainerId((int)UOC_EQUIPTMENT);
  127. }
  128. AddChild(&m_OpenItemPad);
  129. AddChild(&m_Close);
  130. Wnd_AddWindow(this);
  131. char Scheme[256];
  132. g_UiBase.GetCurSchemePath(Scheme, 256);
  133. LoadScheme(Scheme);
  134. }
  135. //--------------------------------------------------------------------------
  136. // 功能:载入窗口的界面方案
  137. //--------------------------------------------------------------------------
  138. void KUiStatus::LoadScheme(const char* pScheme)
  139. {
  140. if (m_pSelf)
  141. {
  142. char Buff[128];
  143. KIniFile Ini;
  144. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  145. if (Ini.Load(Buff))
  146. m_pSelf->LoadScheme(&Ini);
  147. }
  148. }
  149. //载入界面方案
  150. void KUiStatus::LoadScheme(class KIniFile* pIni)
  151. {
  152. if (g_pCoreShell->GetGameData(GDI_PLAYER_IS_MALE, 0, 0))
  153. Init(pIni, "Male");
  154. else
  155. Init(pIni, "Female");
  156. m_Face    .Init(pIni, "Face");
  157. m_Agname  .Init(pIni, "Agname");
  158. m_Name    .Init(pIni, "Name");
  159. m_Title   .Init(pIni, "Title");
  160. m_Money  .Init(pIni, "Money");
  161. m_Life .Init(pIni, "Life");
  162. m_Mana .Init(pIni, "Mana");
  163. m_Stamina .Init(pIni, "Stamina");
  164. m_Angry .Init(pIni, "Angry");
  165. m_Experience.Init(pIni, "Exp");
  166. m_RemainPoint.Init(pIni, "RemainPoint");
  167. m_Strength   .Init(pIni, "Strength");
  168. m_Dexterity  .Init(pIni, "Dexterity");
  169. m_Vitality   .Init(pIni, "Vitality");
  170. m_Energy     .Init(pIni, "Energy");
  171. m_AddStrength .Init(pIni, "AddStrength");
  172. m_AddDexterity.Init(pIni, "AddDexterity");
  173. m_AddVitality .Init(pIni, "AddVitality");
  174. m_AddEnergy   .Init(pIni, "AddEnergy");
  175. m_LeftDamage .Init(pIni, "LeftDamage");
  176. m_RightDamage.Init(pIni, "RightDamage");
  177. m_Attack     .Init(pIni, "Attack");
  178. m_Defence    .Init(pIni, "Defense");
  179. m_MoveSpeed  .Init(pIni, "MoveSpeed");
  180. m_AttackSpeed.Init(pIni, "AttackSpeed");
  181. m_PhyDef  .Init(pIni, "ResistPhy");
  182. m_CoolDef    .Init(pIni, "ResistCold");
  183. m_LightDef   .Init(pIni, "ResistLighting");
  184. m_FireDef    .Init(pIni, "ResistFire");
  185. m_PoisonDef  .Init(pIni, "ResistPoison");
  186. m_Level  .Init(pIni, "Level");
  187. m_StatusDesc .Init(pIni, "Status");
  188. m_Close  .Init(pIni, "Close");
  189. m_OpenItemPad.Init(pIni, "Item");
  190. for (int i = 0; i < _ITEM_COUNT; i ++)
  191. {
  192. m_EquipBox[i].Init(pIni, CtrlItemMap[i].pIniSection);
  193. }
  194. }
  195. //--------------------------------------------------------------------------
  196. // 功能:窗口函数
  197. //--------------------------------------------------------------------------
  198. int KUiStatus::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  199. {
  200. int nRet = 0;
  201. switch(uMsg)
  202. {
  203. case WND_N_BUTTON_CLICK:
  204. if (uParam == (unsigned int)(KWndWindow*)&m_Close)
  205. Hide();
  206. else if (uParam == (unsigned int)(KWndWindow*)&m_OpenItemPad)
  207. KShortcutKeyCentre::ExcuteScript(SCK_SHORTCUT_ITEMS);
  208. else if (m_nRemainPoint > 0)
  209. {
  210. if (uParam == (unsigned int)(KWndWindow*)&m_AddStrength)
  211. UseRemainPoint(UIPA_STRENGTH);
  212. else if (uParam == (unsigned int)(KWndWindow*)&m_AddDexterity)
  213. UseRemainPoint(UIPA_DEXTERITY);
  214. else if (uParam == (unsigned int)(KWndWindow*)&m_AddVitality)
  215. UseRemainPoint(UIPA_VITALITY);
  216. else if (uParam == (unsigned int)(KWndWindow*)&m_AddEnergy)
  217. UseRemainPoint(UIPA_ENERGY);
  218. }
  219. break;
  220. case WND_N_ITEM_PICKDROP:
  221. if (g_UiBase.IsOperationEnable(UIS_O_MOVE_ITEM))
  222. OnEquiptChanged((ITEM_PICKDROP_PLACE*)uParam, (ITEM_PICKDROP_PLACE*)nParam);
  223. break;
  224. default:
  225. nRet = KWndShowAnimate::WndProc(uMsg, uParam, nParam);
  226. }
  227. return nRet;
  228. }
  229. //--------------------------------------------------------------------------
  230. // 功能:升级某项属性
  231. //--------------------------------------------------------------------------
  232. void KUiStatus::UseRemainPoint(UI_PLAYER_ATTRIBUTE type)
  233. {
  234. g_pCoreShell->OperationRequest(GOI_TONE_UP_ATTRIBUTE, type, 0);
  235. m_nRemainPoint --;
  236. m_RemainPoint.SetIntText(m_nRemainPoint);
  237. m_AddStrength.Enable(m_nRemainPoint);
  238. m_AddDexterity.Enable(m_nRemainPoint);
  239. m_AddVitality.Enable(m_nRemainPoint);
  240. m_AddEnergy.Enable(m_nRemainPoint);
  241. }
  242. //--------------------------------------------------------------------------
  243. // 功能:更新基本数据(人名等不易变数据)
  244. //--------------------------------------------------------------------------
  245. void KUiStatus::UpdateBaseData()
  246. {
  247. KUiPlayerBaseInfo Info;
  248. memset(&Info, 0, sizeof(KUiPlayerBaseInfo));
  249. g_pCoreShell->GetGameData(GDI_PLAYER_BASE_INFO, (int)&Info, 0);
  250. m_Agname.SetText(Info.Agname);
  251. m_Name  .SetText(Info.Name);
  252. m_Title .SetText(Info.Title);
  253. }
  254. void KUiStatus::UpdateRuntimeInfo(KUiPlayerRuntimeInfo* pInfo)
  255. {
  256. if (pInfo)
  257. {
  258. m_Life .Set2IntText(pInfo->nLife, pInfo->nLifeFull, '/');
  259. m_Mana .Set2IntText(pInfo->nMana, pInfo->nManaFull, '/');
  260. m_Stamina .Set2IntText(pInfo->nStamina, pInfo->nStaminaFull, '/');
  261. m_Angry .Set2IntText(pInfo->nAngry, pInfo->nAngryFull, '/');
  262. m_Experience.Set2IntText(pInfo->nExperience, pInfo->nExperienceFull, '/');
  263. //Info.byAction & PA_RIDE
  264. }
  265. }
  266. //--------------------------------------------------------------------------
  267. // 功能:更新数据
  268. //--------------------------------------------------------------------------
  269. void KUiStatus::UpdateData()
  270. {
  271. UpdateAllEquips();
  272. UpdateBaseData();
  273. }
  274. void KUiStatus::UpdateAllEquips()
  275. {
  276. KUiObjAtRegion Equips[_ITEM_COUNT];
  277. int nCount = g_pCoreShell->GetGameData(GDI_EQUIPMENT, (unsigned int)&Equips, 0);
  278. int i;
  279. for (i = 0; i < _ITEM_COUNT; i++)
  280. m_EquipBox[i].Celar();
  281. for (i = 0; i < nCount; i++)
  282. {
  283. if (Equips[i].Obj.uGenre != CGOG_NOTHING)
  284. UpdateEquip(&Equips[i], true);
  285. }
  286. }
  287. void KUiStatus::UpdateRuntimeAttribute(KUiPlayerAttribute* pInfo)
  288. {
  289. if (pInfo)
  290. {
  291. m_Money.SetIntText(pInfo->nMoney);
  292. m_nRemainPoint = pInfo->nBARemainPoint;
  293. m_AddStrength.Enable(m_nRemainPoint);
  294. m_AddDexterity.Enable(m_nRemainPoint);
  295. m_AddVitality.Enable(m_nRemainPoint);
  296. m_AddEnergy.Enable(m_nRemainPoint);
  297. m_RemainPoint.SetIntText(pInfo->nBARemainPoint);
  298. m_Strength   .SetIntText(pInfo->nStrength);
  299. m_Dexterity  .SetIntText(pInfo->nDexterity);
  300. m_Vitality   .SetIntText(pInfo->nVitality);
  301. m_Energy     .SetIntText(pInfo->nEnergy);
  302. m_LeftDamage.Set2IntText(pInfo->nKillMIN,pInfo->nKillMAX,'/');
  303. m_RightDamage.Set2IntText(pInfo->nRightKillMin, pInfo->nRightKillMax, '/');
  304. m_Attack.SetIntText(pInfo->nAttack);
  305. m_Defence.SetIntText(pInfo->nDefence);
  306. m_MoveSpeed.SetIntText(pInfo->nMoveSpeed);
  307. m_AttackSpeed.SetIntText(pInfo->nAttackSpeed);
  308. char TextInfo[32];
  309. sprintf(TextInfo, "%d%%", pInfo->nPhyDef);
  310. m_PhyDef .SetText(TextInfo);
  311. sprintf(TextInfo, "%d%%", pInfo->nCoolDef);
  312. m_CoolDef  .SetText(TextInfo);
  313. sprintf(TextInfo, "%d%%", pInfo->nLightDef);
  314. m_LightDef .SetText(TextInfo);
  315. sprintf(TextInfo, "%d%%", pInfo->nFireDef);
  316. m_FireDef  .SetText(TextInfo);
  317. sprintf(TextInfo, "%d%%", pInfo->nPoisonDef);
  318. m_PoisonDef.SetText(TextInfo);
  319. m_Level.SetIntText(pInfo->nLevel); //等级
  320. m_StatusDesc.SetText(pInfo->StatusDesc);
  321. }
  322. }
  323. //--------------------------------------------------------------------------
  324. // 功能:响应界面操作引起装备的改变
  325. //--------------------------------------------------------------------------
  326. void KUiStatus::OnEquiptChanged(ITEM_PICKDROP_PLACE* pPickPos, ITEM_PICKDROP_PLACE* pDropPos)
  327. {
  328. KUiObjAtContRegion Drop, Pick;
  329. KUiDraggedObject Obj;
  330. KWndWindow* pWnd = NULL;
  331. UISYS_STATUS eStatus = g_UiBase.GetStatus();
  332. if (pPickPos)
  333. {
  334. //_ASSERT(pPickPos->pWnd);
  335. ((KWndObjectBox*)(pPickPos->pWnd))->GetObject(Obj);
  336. Pick.Obj.uGenre = Obj.uGenre;
  337. Pick.Obj.uId = Obj.uId;
  338. Pick.Region.Width = Obj.DataW;
  339. Pick.Region.Height = Obj.DataH;
  340. Pick.Region.h = 0;
  341. Pick.eContainer = UOC_EQUIPTMENT;
  342. pWnd = pPickPos->pWnd;
  343. if (eStatus == UIS_S_TRADE_REPAIR)
  344. {
  345. g_pCoreShell->OperationRequest(GOI_TRADE_NPC_REPAIR,
  346. (unsigned int)(&Pick), 0);
  347. return;
  348. }
  349. else if (eStatus == UIS_S_TRADE_SALE)
  350. {
  351. g_pCoreShell->OperationRequest(GOI_TRADE_NPC_SELL,
  352. (unsigned int)(&Pick), 0);
  353. return;
  354. }
  355. else if (eStatus == UIS_S_TRADE_NPC)
  356. {
  357. return;
  358. }
  359. else if (eStatus == UIS_S_TRADE_BUY)
  360. return;
  361. }
  362. else if (pDropPos)
  363. {
  364. pWnd = pDropPos->pWnd;
  365. }
  366. else
  367. return;
  368. if (pDropPos)
  369. {
  370. Wnd_GetDragObj(&Obj);
  371. Drop.Obj.uGenre = Obj.uGenre;
  372. Drop.Obj.uId = Obj.uId;
  373. Drop.Region.Width = Obj.DataW;
  374. Drop.Region.Height = Obj.DataH;
  375. Drop.Region.h = 0;
  376. Drop.eContainer = UOC_EQUIPTMENT;
  377. }
  378. for (int i = 0; i < _ITEM_COUNT; i++)
  379. {
  380. if (pWnd == (KWndWindow*)&m_EquipBox[i])
  381. {
  382. Drop.Region.v = Pick.Region.v = CtrlItemMap[i].nPosition;
  383. break;
  384. }
  385. }
  386. //_ASSERT(i < _ITEM_COUNT);
  387. g_pCoreShell->OperationRequest(GOI_SWITCH_OBJECT,
  388. pPickPos ? (unsigned int)&Pick : 0,
  389. pDropPos ? (int)&Drop : 0);
  390. }
  391. //--------------------------------------------------------------------------
  392. // 功能:装备变化更新
  393. //--------------------------------------------------------------------------
  394. void KUiStatus::UpdateEquip(KUiObjAtRegion* pEquip, int bAdd)
  395. {
  396. if (pEquip)
  397. {
  398. for (int i = 0; i < _ITEM_COUNT; i++)
  399. {
  400. if (CtrlItemMap[i].nPosition == pEquip->Region.v)
  401. {
  402. if (bAdd)
  403. m_EquipBox[i].HoldObject(pEquip->Obj.uGenre, pEquip->Obj.uId,
  404. pEquip->Region.Width, pEquip->Region.Height);
  405. else
  406. m_EquipBox[i].HoldObject(CGOG_NOTHING, 0, 0, 0);
  407. break;
  408. }
  409. }
  410. }
  411. }