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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 剑侠界面系统基础功能模块
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-7-17
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KWin32Wnd.h"
  9. #include "KIniFile.h"
  10. #include "UiBase.h"
  11. #include "KFilePath.h"
  12. #include "KIme.h"
  13. #include "../../core/src/coreshell.h"
  14. #include "../../core/src/GameDataDef.h"
  15. #include "Elem/MouseHover.h"
  16. #include "Elem/WndShowAnimate.h"
  17. #include "Elem/WndObjContainer.h"
  18. #include "UiCase/UiInformation.h"
  19. #include "UiCase/UiInformation2.h"
  20. #include "UiCase/UiSelColor.h"
  21. #include "UiCase/UiPlayerBar.h"
  22. #include "UiCase/UiStatus.h"
  23. #include "UiCase/UiMiniMap.h"
  24. #include "UiCase/UiMsgCentrePad.h"
  25. //#include "UiCase/UiManage.h"
  26. #include "UiCase/UiOptions.h"
  27. #include "UiCase/UiItem.h"
  28. #include "UiCase/UiSkills.h"
  29. #include "UiCase/UiStoreBox.h"
  30. #include "UiCase/UiChatCentre.h"
  31. #include "UiCase/UiChannelSubscibe.h"
  32. #include "UiCase/UiChatStatus.h"
  33. #include "UiCase/UiTeamManage.h"
  34. #include "Uicase/UiShop.h"
  35. #include "UiCase/UiHeaderControlBar.h"
  36. #include "UiCase/UiSysMsgCentre.h"
  37. #include "UiCase/UiMsgSel.h"
  38. #include "UiCase/UiSelPlayerNearby.h"
  39. #include "UiCase/UiSkillTree.h"
  40. #include "UiCase/UiHelper2.h"
  41. #include "UiChatPhrase.h"
  42. #include "ShortcutKey.h"
  43. #include "Elem/Wnds.h"
  44. #include "Elem/PopupMenu.h"
  45. #include "../../Represent/iRepresent/iRepresentShell.h"
  46. extern iRepresentShell* g_pRepresentShell;
  47. extern iCoreShell*      g_pCoreShell;
  48. #define UI_INFO_FILE_PATH "\Ui" //界面信息文件存放的根目录
  49. #define UI_COMMON_CONFIG_FILE "\Ui\Setting.ini"
  50. #define UI_DEF_CONFIG_FILE "\Ui\DefConfig.Ini"//界面配置纪录文件名
  51. #define UI_PUBLIC_SETTING "公共.ini" //某个界面方案的设定文件
  52. #define UI_USER_DATA_FOLDER "\UserData" //玩家数据的存盘目录位置
  53. #define UI_USER_DATA_TEMP_FOLDER "\UserData\Temp" //玩家数据的临时存盘目录位置
  54. #define UI_COMMON_SETTING_FILE "\UserData\UiCommon.ini"//界面公共设置的文件的名称
  55. #define UI_PRIVATE_SETTING_FILE "UiConfig.ini" //界面个人数据的存储文件
  56. #define THEME_SECTION "Theme"
  57. #define FONT_SECTION "FontList"
  58. const char* $Main = "Main";
  59. KUiBase g_UiBase;
  60. //--------------------------------------------------------------------------
  61. // 功能:构造函数
  62. //--------------------------------------------------------------------------
  63. KUiBase::KUiBase()
  64. {
  65. m_CurScheme[0] = 0;
  66. m_CurSchemePath[0] = 0;
  67. m_UserAccountId[0] = 0;
  68. m_pUiCommSettingFile = NULL; //界面公共设置的文件
  69. m_pUiPrivateSettingFile = NULL; //当前账号的设置文件
  70. m_Status = UIS_S_IDLE;
  71. }
  72. //--------------------------------------------------------------------------
  73. // 功能:析构函数
  74. //--------------------------------------------------------------------------
  75. KUiBase::~KUiBase()
  76. {
  77. }
  78. //--------------------------------------------------------------------------
  79. // 功能:退出函数
  80. //--------------------------------------------------------------------------
  81. void KUiBase::Exit()
  82. {
  83. m_UserAccountId[0] = 0;
  84. CloseCommSettingFile(false);
  85. ClosePrivateSettingFile(false);
  86. CloseCommConfigFile();
  87. }
  88. #ifdef _DEBUG
  89. extern int WND_SHOW_MOUSE_OVER_WND;
  90. #endif
  91. //获得玩家数据的临时存盘目录位置
  92. const char* KUiBase::GetUserTempDataFolder()
  93. {
  94. return UI_USER_DATA_TEMP_FOLDER;
  95. }
  96. //清除玩家数据的临时存盘目录内的全部文件
  97. void KUiBase::CleanTempDataFolder()
  98. {
  99. ClearFolder(UI_USER_DATA_TEMP_FOLDER, false);
  100. }
  101. //清除当前玩家私有数据的存储目录
  102. void KUiBase::ClearFolder(const char* pszFolder, bool bDeleteFolder)
  103. {
  104. char szPathFile[MAX_PATH];
  105. WIN32_FIND_DATA FileData;
  106. HANDLE hFind;
  107. if (pszFolder && pszFolder[0])
  108. {
  109. g_GetFullPath(szPathFile, (char*)pszFolder);
  110. int nLen = strlen(szPathFile) + 1;
  111. strcat(szPathFile, "\*.*");
  112. hFind = FindFirstFile(szPathFile, &FileData);
  113. if(hFind != INVALID_HANDLE_VALUE)
  114. {
  115. do
  116. {
  117. strcpy(szPathFile + nLen, FileData.cFileName);
  118. SetFileAttributes(szPathFile, FILE_ATTRIBUTE_NORMAL);
  119. DeleteFile(szPathFile);
  120. }while(FindNextFile(hFind, &FileData));
  121. FindClose(hFind);
  122. }
  123. if (bDeleteFolder)
  124. {
  125. szPathFile[nLen - 1] = 0;
  126. RemoveDirectory(szPathFile);
  127. }
  128. }
  129. }
  130. //--------------------------------------------------------------------------
  131. // 功能:初始化
  132. //--------------------------------------------------------------------------
  133. int KUiBase::Init()
  134. {
  135. if (g_pIme)
  136. {
  137. g_pIme->DisableLanguageChange();
  138. g_pIme->CloseIME();
  139. g_pIme->TurnOn();
  140. }
  141. KIniFile* pSetting = GetCommSettingFile();
  142. char SchemeName[32] = "";
  143. int nInterval = 20;
  144. if (pSetting)
  145. {
  146. pSetting->GetString("Main", "LastUsedScheme", "", SchemeName, 32);
  147. pSetting->GetInteger("Main", "WndMoveInterval", 20, &nInterval);
  148. #ifdef _DEBUG
  149. int nValue;
  150. pSetting->GetInteger("Main", "ShowDebugFrameText", 0, &nValue);
  151. WND_SHOW_DEBUG_FRAME_TEXT = nValue;
  152. pSetting->GetInteger("Main", "ShowMouseOverWnd", 0, &nValue);
  153. WND_SHOW_MOUSE_OVER_WND = nValue;
  154. #endif
  155. CloseCommSettingFile(false);
  156. }
  157. g_CreatePath(UI_USER_DATA_FOLDER);
  158. g_CreatePath(UI_USER_DATA_TEMP_FOLDER);
  159. KWndShowAnimate::SetInterval(nInterval);
  160. LoadScheme(SchemeName);
  161. return true;
  162. }
  163. //--------------------------------------------------------------------------
  164. // 功能:设置用户账号
  165. //--------------------------------------------------------------------------
  166. void KUiBase::SetUserAccount(char* pszId, char* pszRole)
  167. {
  168. if (pszId == NULL || pszId[0] == 0 || pszRole == NULL || pszRole[0] == 0)
  169. return;
  170. //根据(玩家)名称id获得对应处理过字符串id
  171. {
  172. m_UserAccountId[0] = 0;
  173. unsigned int uID1 =  g_FileName2Id(pszId);
  174. unsigned int uID2 = ~g_FileName2Id(pszRole);
  175. int nLen1 = strlen(pszId);
  176. int nLen2 = strlen(pszRole);
  177. sprintf(m_UserAccountId, "%x%xl%x%x", uID1, nLen1, nLen2, uID2);
  178. }
  179. }
  180. //清除当前玩家私有数据的存储目录
  181. void KUiBase::CleanPrivateDataFolder()
  182. {
  183. char szBuffer[128];
  184. sprintf(szBuffer, "%s\%s", UI_USER_DATA_FOLDER, m_UserAccountId);
  185. ClearFolder(szBuffer, true);
  186. }
  187. //清除当前玩家私有数据的某个文件
  188. void KUiBase::DeletePrivateDataFile(const char* pszFileName)
  189. {
  190. char szBuffer[128], szPathFile[MAX_PATH];
  191. if (pszFileName && pszFileName[0])
  192. {
  193. sprintf(szBuffer, "%s\%s\%s", UI_USER_DATA_FOLDER, m_UserAccountId, pszFileName);
  194. g_GetFullPath(szPathFile, (char*)szBuffer);
  195. SetFileAttributes(szPathFile, FILE_ATTRIBUTE_NORMAL);
  196. DeleteFile(szPathFile);
  197. }
  198. }
  199. //--------------------------------------------------------------------------
  200. // 功能:载入配置纪录,如定制的窗口位置
  201. //--------------------------------------------------------------------------
  202. void CreateBlackListUnit();
  203. void KUiBase::LoadPrivateConfig()
  204. {
  205. CreateBlackListUnit();
  206. KIniFile* pConfigFile = GetPrivateSettingFile();
  207. if (pConfigFile)
  208. {
  209. //----获取窗口方案设定----
  210. char SchemeName[32];
  211. if (pConfigFile->GetString("Main", "Scheme", "", SchemeName, 32))
  212. {
  213. if (SchemeName[0] && LoadScheme(SchemeName))
  214. {
  215. //----逐个窗口载入配置设定----
  216. KUiPlayerBar::LoadPrivateSetting(pConfigFile);
  217. KUiSkillTree::LoadConfig(pConfigFile);
  218. KShortcutKeyCentre::LoadPrivateSetting(pConfigFile);
  219. KUiChatCentre::LoadPrivateSetting(pConfigFile); //在KShortcutKeyCentre之后,因为会有脚本生成Unit
  220. //----逐个窗口载入配置设定结束----
  221. }
  222. }
  223. ClosePrivateSettingFile(false);
  224. }
  225. }
  226. //--------------------------------------------------------------------------
  227. // 功能:存储配置纪录
  228. //--------------------------------------------------------------------------
  229. int KUiBase::SavePrivateConfig()
  230. {
  231. if (m_UserAccountId[0] == 0)
  232. return true;
  233. KIniFile* pConfigFile = GetPrivateSettingFile();
  234. if (pConfigFile)
  235. {
  236. pConfigFile->Clear();
  237. pConfigFile->WriteString("Main", "Scheme", m_CurScheme);
  238. //----逐个窗口保存配置设定----
  239. KUiSkillTree::SaveConfig(pConfigFile);
  240. KUiPlayerBar::SavePrivateSetting(pConfigFile);
  241. KUiChatCentre::SavePrivateSetting(pConfigFile);
  242. KShortcutKeyCentre::SavePrivateSetting(pConfigFile);
  243. //----逐个窗口保存配置设定结束----
  244. ClosePrivateSettingFile(true);
  245. return true;
  246. }
  247. return false;
  248. }
  249. //--------------------------------------------------------------------------
  250. // 功能:获得当前玩家账号在界面系统中的id
  251. //--------------------------------------------------------------------------
  252. int KUiBase::GetUserPrivateDataFolder(char* pBuffer, int nSize)
  253. {
  254. char szBuffer[128];
  255. sprintf(szBuffer, "%s\%s\", UI_USER_DATA_FOLDER, m_UserAccountId);
  256. g_CreatePath(szBuffer);
  257. if (pBuffer && nSize > (int)(strlen(szBuffer)))
  258. {
  259. strcpy(pBuffer, szBuffer);
  260. return true;
  261. }
  262. return false;
  263. }
  264. int g_nWindowNTFlag = false;
  265. static int _KSG_GetWindowVersion()
  266. {  
  267.     g_nWindowNTFlag = (GetVersion() < 0x80000000);
  268.     return true;
  269. }
  270. //--------------------------------------------------------------------------
  271. // 功能:按照某种方案载入界面(Skin)
  272. //--------------------------------------------------------------------------
  273. int KUiBase::LoadScheme(const char* pScheme)
  274. {
  275.     _KSG_GetWindowVersion();
  276. if (pScheme == NULL)
  277. return false;
  278. if (m_CurScheme[0] != 0 && strcmp(pScheme, m_CurScheme) == 0)
  279. return true;
  280. char Buffer[128];
  281. sprintf(Buffer, "%s\"UI_PUBLIC_SETTING, m_CurSchemePath);
  282. if (GetSchemePath(pScheme))
  283. {
  284. int nCount, nId, i;
  285. KIniFile Ini;
  286. char Section[8];
  287. //----卸载字体----
  288. if (g_pRepresentShell && Ini.Load(Buffer) &&
  289. Ini.GetInteger(FONT_SECTION, "Count", 0, &nCount))
  290. {
  291. for (i = 0; i < nCount; i++)
  292. {
  293. itoa(i, Section, 10);
  294. if (Ini.GetInteger(FONT_SECTION, Section, 0, &nId))
  295. g_pRepresentShell->ReleaseAFont(nId);
  296. }
  297. }
  298. sprintf(Buffer, "%s\"UI_PUBLIC_SETTING, m_CurSchemePath);
  299. Ini.Load(Buffer);
  300. //----载入字体----
  301. if (g_pRepresentShell && Ini.GetInteger(FONT_SECTION, "Count", 0, &nCount))
  302. {
  303. for (i = 0; i < nCount; i++)
  304. {
  305. itoa(i, Section, 10);
  306. if (Ini.GetInteger(FONT_SECTION, Section, 0, &nId))
  307. {
  308. strcat(Section, "_File");
  309. if (Ini.GetString(FONT_SECTION, Section, "", Buffer, sizeof(Buffer)) &&
  310. Buffer[0])
  311. {
  312. g_pRepresentShell->CreateAFont(Buffer, CHARACTER_CODE_SET_GBK, nId);
  313. }
  314. }
  315. }
  316. }
  317. //----载入字体结束----
  318. WndObjContainerInit(&Ini);
  319. for (i = CURSOR_NORMAL; i < CURSOR_INDEX_COUNT; i++)
  320. {
  321. itoa(i, Section, 10);
  322.             if (g_nWindowNTFlag)
  323.     Ini.GetString("CursorList", Section, "", Buffer, sizeof(Buffer));
  324.             else    // Win9x
  325.     Ini.GetString("CursorList98", Section, "", Buffer, sizeof(Buffer));
  326. Wnd_LoadCursor(i, Buffer);//载入鼠标指针资源
  327. }
  328. LoadSchemeForEachWnd();
  329. return true;
  330. }
  331. return false;
  332. }
  333. void KUiBase::LoadSchemeForEachWnd()
  334. {
  335. //----逐个窗口界面方案----
  336. KUiPlayerBar::LoadScheme(m_CurSchemePath);
  337. KUiStatus::LoadScheme(m_CurSchemePath);
  338. KUiMsgCentrePad::LoadScheme(m_CurSchemePath);
  339. // KUiManage::LoadScheme(m_CurSchemePath);
  340. KUiOptions::LoadScheme(m_CurSchemePath);
  341. KUiItem::LoadScheme(m_CurSchemePath);
  342. KUiSkills::LoadScheme(m_CurSchemePath);
  343. KUiStoreBox::LoadScheme(m_CurSchemePath);
  344. KUiMsgSel::LoadScheme(m_CurSchemePath);
  345. KUiSelPlayerNearby::LoadScheme(m_CurSchemePath);
  346. KUiChatCentre::LoadScheme(m_CurSchemePath);
  347. KUiChatStatus::LoadScheme(m_CurSchemePath);
  348. KUiTeamManage::LoadScheme(m_CurSchemePath);
  349. KUiHeaderControlBar::LoadScheme(m_CurSchemePath);
  350. KUiShop::LoadScheme(m_CurSchemePath);
  351. KUiSysMsgCentre::LoadScheme(m_CurSchemePath);
  352. KUiMiniMap::LoadScheme(m_CurSchemePath);
  353. g_MouseOver.LoadScheme(m_CurSchemePath);
  354. g_UiInformation.LoadScheme(m_CurSchemePath);
  355. g_UiInformation2.LoadScheme(m_CurSchemePath);
  356. KPopupMenu::LoadTheme(m_CurSchemePath);
  357. KUiSelColor::LoadScheme(m_CurSchemePath);
  358. //----逐个窗口界面方案结束----
  359. }
  360. //--------------------------------------------------------------------------
  361. // 功能:获得当前指定界面方案的目录名,如果未能找到指定的方案,则取第一个
  362. //  方案(默认方案)作为当前方案
  363. // 参数:pScheme --> 指定界面方案名称
  364. //--------------------------------------------------------------------------
  365. int KUiBase::GetSchemePath(const char* pScheme)
  366. {
  367. KIniFile* pIni = NULL;
  368. int nCount;
  369. char Buff[32], Key[32];
  370. if (pScheme == NULL ||
  371. (pIni = GetCommConfigFile()) == NULL)
  372. return false;
  373. pIni->GetInteger(THEME_SECTION, "Count", 0, &nCount);
  374. for (int i = 0; i < nCount; i++)
  375. {
  376. itoa(i, Key, 10);
  377. if (pIni->GetString(THEME_SECTION, Key, "", Buff, 32))
  378. {
  379. if (strcmp(Buff, pScheme) == 0)
  380. {
  381. strcpy(m_CurScheme, pScheme);
  382. strcat(Key, "_Path");
  383. if (pIni->GetString(THEME_SECTION, Key, "", Buff, 32) && Buff[0])
  384. {
  385. sprintf(m_CurSchemePath, "%s\%s", UI_INFO_FILE_PATH, Buff);
  386. CloseCommConfigFile();
  387. return true;
  388. }
  389. }
  390. }
  391. }
  392. if (pIni->GetString(THEME_SECTION, "0", "", m_CurScheme, 32) &&
  393. pIni->GetString(THEME_SECTION, "0_Path", "", Buff, 32) && Buff[0])
  394. {
  395. sprintf(m_CurSchemePath, "%s\%s", UI_INFO_FILE_PATH, Buff);
  396. CloseCommConfigFile();
  397. return true;
  398. }
  399. CloseCommConfigFile();
  400. return false;
  401. }
  402. //--------------------------------------------------------------------------
  403. // 功能:获得界面方案的数目
  404. //--------------------------------------------------------------------------
  405. int KUiBase::SchemeCount()
  406. {
  407. int nCount = 0;
  408. KIniFile* pIni = GetCommConfigFile();
  409. if (pIni)
  410. {
  411. pIni->GetInteger(THEME_SECTION, "Count", 0, &nCount);
  412. if (nCount < 0)
  413. nCount = 0;
  414. CloseCommConfigFile();
  415. }
  416. return nCount;
  417. }
  418. //--------------------------------------------------------------------------
  419. // 功能:获得某个界面方案的名称与路径
  420. // 参数:pName --> 用于获取方案的名称,为指向一个长度不小于的32的缓冲区的指针,或者空指针。
  421. //   pPath --> 用于获取方案的路径,为指向一个长度不小于的32的缓冲区的指针,或者空指针。
  422. //--------------------------------------------------------------------------
  423. int KUiBase::GetScheme(int nIndex, char* pName, char* pPath)
  424. {
  425. KIniFile Ini;
  426. int nCount = 0;
  427. KIniFile* pIni = GetCommConfigFile();
  428. if (pIni)
  429. {
  430. Ini.GetInteger(THEME_SECTION, "Count", 0, &nCount);
  431. if (nIndex >= 0 && nIndex < nCount)
  432. {
  433. char Num[8] = "";
  434. itoa(nIndex, Num, 10);
  435. if (pName)
  436. Ini.GetString(THEME_SECTION, Num, "", pName, 32);
  437. if (pPath)
  438. Ini.GetString(THEME_SECTION, Num, "", pPath, 32);
  439. return true;
  440. }
  441. CloseCommConfigFile();
  442. }
  443. return false;
  444. }
  445. //--------------------------------------------------------------------------
  446. // 功能:获得当前界面方案的路径
  447. //--------------------------------------------------------------------------
  448. int KUiBase::GetCurSchemePath(char* pBuffer, int nSize)
  449. {
  450. if (pBuffer && nSize >= (int)strlen(m_CurSchemePath) + 1)
  451. {
  452. strcpy(pBuffer, m_CurSchemePath);
  453. return true;
  454. }
  455. return false;
  456. }
  457. //--------------------------------------------------------------------------
  458. // 功能:打开保存界面公共设置的文件
  459. //--------------------------------------------------------------------------
  460. KIniFile* KUiBase::GetCommSettingFile()
  461. {
  462. if (m_pUiCommSettingFile == NULL)
  463. {
  464. m_pUiCommSettingFile = new KIniFile;
  465. if (m_pUiCommSettingFile)
  466. m_pUiCommSettingFile->Load((char*)UI_COMMON_SETTING_FILE);
  467. }
  468. return m_pUiCommSettingFile;
  469. }
  470. //--------------------------------------------------------------------------
  471. // 功能:关闭保存界面公共设置的文件
  472. //--------------------------------------------------------------------------
  473. void KUiBase::CloseCommSettingFile(bool bSave)
  474. {
  475. if (m_pUiCommSettingFile)
  476. {
  477. if (bSave)
  478. m_pUiCommSettingFile->Save((char*)UI_COMMON_SETTING_FILE);
  479. delete(m_pUiCommSettingFile);
  480. m_pUiCommSettingFile = NULL;
  481. }
  482. }
  483. KIniFile* KUiBase::GetCommConfigFile()
  484. {
  485. if (m_pUiCommConfigFile == NULL)
  486. {
  487. m_pUiCommConfigFile = new KIniFile;
  488. if (m_pUiCommConfigFile &&
  489. !m_pUiCommConfigFile->Load((char*)UI_COMMON_CONFIG_FILE))
  490. {
  491. delete m_pUiCommConfigFile;
  492. m_pUiCommConfigFile = NULL;
  493. }
  494. }
  495. return m_pUiCommConfigFile;
  496. }
  497. void KUiBase::CloseCommConfigFile()
  498. {
  499. if (m_pUiCommConfigFile)
  500. {
  501. delete(m_pUiCommConfigFile);
  502. m_pUiCommConfigFile = NULL;
  503. }
  504. }
  505. //--------------------------------------------------------------------------
  506. // 功能:打开打开当前账号的设置文件
  507. //--------------------------------------------------------------------------
  508. KIniFile* KUiBase::GetPrivateSettingFile()
  509. {
  510. if (m_pUiPrivateSettingFile == NULL && m_UserAccountId[0])
  511. {
  512. m_pUiPrivateSettingFile = new KIniFile;
  513. if (m_pUiPrivateSettingFile)
  514. {
  515. char FileName[128];
  516. sprintf(FileName, "%s\%s\%s", UI_USER_DATA_FOLDER, m_UserAccountId, UI_PRIVATE_SETTING_FILE);
  517. m_pUiPrivateSettingFile->Load(FileName);
  518. }
  519. }
  520. return m_pUiPrivateSettingFile;
  521. }
  522. //--------------------------------------------------------------------------
  523. // 功能:关闭打开当前账号的设置文件
  524. //--------------------------------------------------------------------------
  525. void KUiBase::ClosePrivateSettingFile(bool bSave)
  526. {
  527. if (m_pUiPrivateSettingFile)
  528. {
  529. if (bSave && m_UserAccountId[0])
  530. {
  531. char FileName[128];
  532. sprintf(FileName, "%s\%s", UI_USER_DATA_FOLDER, m_UserAccountId);
  533. g_CreatePath(FileName);
  534. strcat(FileName, "\");
  535. strcat(FileName, UI_PRIVATE_SETTING_FILE);
  536. m_pUiPrivateSettingFile->Save(FileName);
  537. }
  538. delete(m_pUiPrivateSettingFile);
  539. m_pUiPrivateSettingFile = NULL;
  540. }
  541. }
  542. void KUiBase::SetStatus(UISYS_STATUS eStatus)
  543. {
  544. if (m_Status == eStatus)
  545. return;
  546. m_Status = eStatus;
  547. Wnd_GameSpaceHandleInput(m_Status == UIS_S_IDLE);
  548. SetCurrentCursor();
  549. }
  550. //根据当前状态设置鼠标指针图形
  551. void KUiBase::SetCurrentCursor()
  552. {
  553. int nCursorIndex;
  554. switch(m_Status)
  555. {
  556. case UIS_S_TRADE_PLAYER: //(与Player)交易
  557. case UIS_S_TRADE_NPC: //(与npc)交易
  558. nCursorIndex = CURSOR_NORMAL;
  559. break;
  560. case UIS_S_TRADE_SALE: //(与npc)交易 卖
  561. nCursorIndex = CURSOR_SELL;
  562. break;
  563. case UIS_S_TRADE_BUY: //(与npc)交易 买
  564. nCursorIndex = CURSOR_BUY;
  565. break;
  566. case UIS_S_TRADE_REPAIR: //(与npc)交易 修理
  567. nCursorIndex = CURSOR_REPAIR;
  568. break;
  569. default:
  570. nCursorIndex = CURSOR_NORMAL;
  571. break;
  572. }
  573. Wnd_SwitchCursor(nCursorIndex);
  574. }
  575. int KUiBase::IsOperationEnable(UISYS_OPERATION uOper)
  576. {
  577. int bEnable = false;
  578. switch(uOper)
  579. {
  580. case UIS_O_MOVE_ITEM:
  581. case UIS_O_USE_ITEM:
  582. bEnable = (m_Status == UIS_S_IDLE);
  583. break;
  584. case UIS_O_TRADE_ITEM:
  585. bEnable = (m_Status == UIS_S_TRADE_PLAYER || m_Status == UIS_S_TRADE_NPC ||
  586. m_Status == UIS_S_TRADE_SALE || m_Status == UIS_S_TRADE_BUY);
  587. break;
  588. }
  589. return bEnable;
  590. }
  591. void KUiBase::RegisterEvent(const char* szName, HANDLE hWnd)
  592. {
  593. if (hWnd == 0)
  594. return;
  595. EVENTWNDLIST::iterator i = m_EventWndList.find(szName);
  596. if (i == m_EventWndList.end())
  597. {
  598. m_EventWndList[szName] = hWnd;
  599. }
  600. }
  601. void KUiBase::UnregisterEvent(const char* szName, HANDLE hWnd)
  602. {
  603. if (hWnd == 0)
  604. return;
  605. EVENTWNDLIST::iterator i = m_EventWndList.find(szName);
  606. if (i != m_EventWndList.end() && i->second == hWnd)
  607. {
  608. m_EventWndList.erase(i);
  609. }
  610. }
  611. int KUiBase::NotifyOneEvent(const char* szName, const char* szEvent) //0为已经处理, 不要再处理了, 非0为未处理或错误
  612. {
  613. if (szEvent == NULL || szEvent[0] == 0)
  614. return -1;
  615. EVENTWNDLIST::iterator i = m_EventWndList.find(szName);
  616. if (i == m_EventWndList.end())
  617. return -1;
  618. int nLen = strlen(szEvent) + 1;
  619. int nRet = -1;
  620. if (i->second)
  621. {
  622. COPYDATASTRUCT cp;
  623. cp.dwData = 0;
  624. cp.cbData = nLen;
  625. cp.lpData = (void*)szEvent;
  626. nRet = ::SendMessage((HWND)i->second, WM_COPYDATA, (WPARAM)g_GetMainHWnd(), (LPARAM)&cp);
  627. }
  628. return nRet;
  629. }
  630. int KUiBase::NotifyEvent(const char* szEvent) //0为已经处理, 不要再处理了, 非0为未处理或错误
  631. {
  632. if (szEvent == NULL || szEvent[0] == 0)
  633. return -1;
  634. int nLen = strlen(szEvent) + 1;
  635. int nRet = -1;
  636. EVENTWNDLIST::iterator i = m_EventWndList.begin();
  637. while(i != m_EventWndList.end())
  638. {
  639. if (i->second)
  640. {
  641. COPYDATASTRUCT cp;
  642. cp.dwData = 0;
  643. cp.cbData = nLen;
  644. cp.lpData = (void*)szEvent;
  645. nRet = ::SendMessage((HWND)i->second, WM_COPYDATA, (WPARAM)g_GetMainHWnd(), (LPARAM)&cp);
  646. if (!nRet)
  647. return nRet;
  648. }
  649. i++;
  650. }
  651. return nRet;
  652. }
  653. ///////////////////////////////////////////////////////////////////////////////
  654. int AddinNotify::CreateUnit(const char* Unit)
  655. {
  656. if (Unit && Unit[0])
  657. {
  658. char szEvent[256];
  659. sprintf(szEvent, APP_CREATEUNIT, Unit);
  660. return g_UiBase.NotifyEvent(szEvent);
  661. }
  662. return 1;
  663. }
  664. int AddinNotify::DeleteUnit(const char* Unit)
  665. {
  666. if (Unit && Unit[0])
  667. {
  668. char szEvent[256];
  669. sprintf(szEvent, APP_DELETEUNIT, Unit);
  670. return g_UiBase.NotifyEvent(szEvent);
  671. }
  672. return 1;
  673. }
  674. int AddinNotify::CreateUnitGroup(const char* Unit, const char* Name)
  675. {
  676. if (Unit && Unit[0] && Name)
  677. {
  678. char szEvent[256];
  679. sprintf(szEvent, APP_CREATEUNITGROUP, Unit, Name);
  680. return g_UiBase.NotifyEvent(szEvent);
  681. }
  682. return 1;
  683. }
  684. int AddinNotify::RenameUnitGroup(const char* Unit, const char* Name, const char* NewName, const STRINGLIST& friends)
  685. {
  686. if (Unit && Unit[0] && Name && NewName)
  687. {
  688. char szEvent[512];
  689. int nLen = sprintf(szEvent, APP_RENAMEUNITROUP, Unit, Name, NewName);
  690. return g_UiBase.NotifyEvent(szEvent);
  691. }
  692. return 1;
  693. }
  694. int AddinNotify::DeleteUnitGroup(const char* Unit, const char* Name, const STRINGLIST& friends)
  695. {
  696. if (Unit && Unit[0] && Name)
  697. {
  698. char szEvent[512];
  699. int nLen = sprintf(szEvent, APP_DELETEUNITROUP, Unit, Name);
  700. return g_UiBase.NotifyEvent(szEvent);
  701. }
  702. return 1;
  703. }
  704. int AddinNotify::MoveUnitGroup(const char* Unit, const char* Name, const char* Name2, const STRINGLIST& friends)
  705. {
  706. if (Unit && Unit[0] && Name && Name2)
  707. {
  708. char szEvent[512];
  709. int nLen = sprintf(szEvent, APP_MOVEUNITROUP, Unit, Name, Name2);
  710. return g_UiBase.NotifyEvent(szEvent);
  711. }
  712. return 1;
  713. }
  714. int AddinNotify::CreateUnitMember(const char* Unit, const char* Name, const char* Group)
  715. {
  716. if (Unit && Unit[0] && Name && Group)
  717. {
  718. char szEvent[256];
  719. sprintf(szEvent, APP_CREATEUNITMEMBER, Unit, Name, Group);
  720. return g_UiBase.NotifyEvent(szEvent);
  721. }
  722. return 1;
  723. }
  724. int AddinNotify::DeleteUnitMember(const char* Unit, const char* Name)
  725. {
  726. if (Unit && Unit[0] && Name)
  727. {
  728. char szEvent[256];
  729. sprintf(szEvent, APP_DELETEUNITMEMBER, Unit, Name);
  730. return g_UiBase.NotifyEvent(szEvent);
  731. }
  732. return 1;
  733. }
  734. int AddinNotify::MoveUnitMember(const char* Unit, const char* Name, const char* Group)
  735. {
  736. if (Unit && Unit[0] && Name && Group)
  737. {
  738. char szEvent[256];
  739. sprintf(szEvent, APP_MOVEUNITMEMBER, Unit, Name, Group);
  740. return g_UiBase.NotifyEvent(szEvent);
  741. }
  742. return 1;
  743. }
  744. int AddinNotify::SetUnitMemberStatus(const char* Unit, const char* Name, const char* status)
  745. {
  746. if (Unit && Unit[0] && Name && status)
  747. {
  748. char szEvent[256];
  749. sprintf(szEvent, APP_SETUNITMEMBERSTATUS, Unit, Name, status);
  750. return g_UiBase.NotifyEvent(szEvent);
  751. }
  752. return 1;
  753. }
  754. AddinNotify s_ANotify;
  755. void CreateAddinUnit(const char* UnitName)
  756. {
  757. KUiChatCentre::AddAddinUnit(UnitName, &s_ANotify);
  758. }
  759. void DeleteAddinUnit(const char* UnitName)
  760. {
  761. KUiChatCentre::RemoveAddinUnit(UnitName);
  762. }