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

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 遊戲窗口的接口
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-9-18
  6. ------------------------------------------------------------------------------------------
  7. 向无数抗日先烈。致敬!倡议9.18全国鸣警报。
  8. *****************************************************************************************/
  9. #include "KWin32.h"
  10. #include "Windows.h"
  11. #include "../Elem/WndMessage.h"
  12. #include "../../../core/Src/CoreShell.h"
  13. #include "../../../core/Src/GameDataDef.h"
  14. #include "UiGame.h"
  15. #include "memory.h"
  16. #include "UiPlayerBar.h"
  17. #include "UiChatCentre.h"
  18. #include "UiFaceSelector.h"
  19. #include "UiTongManager.h"
  20. #include "../UiChatPhrase.h"
  21. #include "../Elem/PopupMenu.h"
  22. #include "../../../Engine/src/Text.h"
  23. #include "../../../core/Src/KPlayerMenuState.h"
  24. #include "../Elem/Wnds.h"
  25. #include "../ShortcutKey.h"
  26. #include "CommCtrl.h"
  27. extern iCoreShell* g_pCoreShell;
  28. extern KUiChatPhrase    g_UiChatPhrase;
  29. KUiGameSpace g_WndGameSpace;
  30. #define SEL_ACTION_MENU 1
  31. #define SEL_EMOTE_MENU 2
  32. //--------------------------------------------------------------------------
  33. // 功能:输入处理消息以及一些特定窗口消息的响应
  34. //--------------------------------------------------------------------------
  35. int KUiGameSpace::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  36. {
  37. bool bDefault = true;
  38. int nKind = -1;
  39. switch(uMsg)
  40. {
  41. case WM_LBUTTONDOWN:
  42. case WM_RBUTTONDOWN:
  43. {
  44. int nModifier = 0;
  45. if (uParam & MK_CONTROL)
  46. nModifier |= HOTKEYF_CONTROL;
  47. if (uParam & MK_SHIFT)
  48. nModifier |= HOTKEYF_SHIFT;
  49. if (GetKeyState(VK_MENU) & 0x8000)
  50. nModifier |= HOTKEYF_ALT;
  51. if (KShortcutKeyCentre::HandleMouseInput(uMsg == WM_LBUTTONDOWN ? VK_LBUTTON : VK_RBUTTON, nModifier, LOWORD(nParam), HIWORD(nParam)))
  52. bDefault = false;
  53. }
  54. break;
  55. case WM_LBUTTONDBLCLK:
  56. case WM_RBUTTONDBLCLK:
  57. {
  58. int nModifier = 0;
  59. if (uParam & MK_CONTROL)
  60. nModifier |= HOTKEYF_CONTROL;
  61. if (uParam & MK_SHIFT)
  62. nModifier |= HOTKEYF_SHIFT;
  63. if (GetKeyState(VK_MENU) & 0x8000)
  64. nModifier |= HOTKEYF_ALT;
  65. if (KShortcutKeyCentre::HandleMouseInput(uMsg == WM_LBUTTONDBLCLK ? VK_LDBUTTON : VK_RDBUTTON, nModifier, LOWORD(nParam), HIWORD(nParam)))
  66. bDefault = false;
  67. }
  68. break;
  69. case WND_M_MENUITEM_SELECTED:
  70. if (uParam == (unsigned int)(KWndWindow*)this)
  71. {
  72. if (HIWORD(nParam) == SEL_ACTION_MENU && short(LOWORD(nParam)) >= 0)
  73. {
  74. ProcessPeople(&m_SelectPlayer, LOWORD(nParam));
  75. bDefault = false;
  76. }
  77. if (HIWORD(nParam) == SEL_EMOTE_MENU && short(LOWORD(nParam)) >= 0)
  78. {
  79. ProcessEmote(m_SelectPlayer.Name, "", LOWORD(nParam));
  80. bDefault = false;
  81. }
  82. }
  83. break;
  84. case WM_MOUSEMOVE:
  85. case WM_MOUSEHOVER:
  86. if (uParam & MK_LBUTTON)
  87. {
  88. if (g_pCoreShell)
  89. g_pCoreShell->GotoWhere(LOWORD(nParam), HIWORD(nParam), 0);
  90. }
  91. else if (uParam & MK_RBUTTON)
  92. {
  93. KShortcutKeyCentre::HandleMouseInput(0, VK_RBUTTON, LOWORD(nParam), HIWORD(nParam));
  94. }
  95. OnMouseMoveCursor(LOWORD(nParam), HIWORD(nParam));
  96. bDefault = false;
  97. break;
  98. case WM_MOUSEWHEEL:
  99. if (g_pCoreShell)
  100. {
  101. int zDelta = short(HIWORD(uParam));
  102. int nPos = (-zDelta / WHEEL_DELTA);
  103. if (nPos > 0)
  104. g_pCoreShell->Turn(0);
  105. else if (nPos < 0)
  106. g_pCoreShell->Turn(1);
  107. }
  108. break;
  109. default:
  110. break;
  111. }
  112. if (bDefault && g_pCoreShell)
  113. g_pCoreShell->ProcessInput(uMsg, uParam, nParam);
  114. return 0;
  115. }
  116. //--------------------------------------------------------------------------
  117. // 功能:绘制游戏世界
  118. //--------------------------------------------------------------------------
  119. void KUiGameSpace::PaintWindow()
  120. {
  121. g_pCoreShell->DrawGameSpace();
  122. }
  123. void KUiGameSpace::OnMouseMoveCursor(int x, int y)
  124. {
  125. if (g_pCoreShell == NULL)
  126. return;
  127. KUiPlayerItem SelectPlayer;
  128. int nKind = -1;
  129. int nObjectIdx = -1;
  130. if (g_pCoreShell->FindSelectNPC(x, y, relation_all, true, &SelectPlayer, nKind))
  131. {
  132. if (nKind == kind_dialoger)
  133. Wnd_SwitchCursor(MOUSE_CURSOR_DIALOG);
  134. else if (g_pCoreShell->GetNPCRelation(SelectPlayer.nIndex) == relation_enemy)
  135. Wnd_SwitchCursor(MOUSE_CURSOR_FIGHT);
  136. else
  137. Wnd_SwitchCursor(MOUSE_CURSOR_NORMAL);
  138. }
  139. else if (g_pCoreShell->FindSelectObject(x, y, true, nObjectIdx, nKind))
  140. {
  141. if (nKind == Obj_Kind_MapObj)
  142. Wnd_SwitchCursor(MOUSE_CURSOR_DIALOG);
  143. else if (nKind == Obj_Kind_Item || nKind == Obj_Kind_Money)
  144. Wnd_SwitchCursor(MOUSE_CURSOR_PICK);
  145. else if (nKind == Obj_Kind_Prop)
  146. Wnd_SwitchCursor(MOUSE_CURSOR_USE);
  147. else if (nKind == Obj_Kind_Box)
  148. Wnd_SwitchCursor(CURSOR_POINT_TO_OBJ_NPC);
  149. }
  150. else
  151. Wnd_SwitchCursor(MOUSE_CURSOR_NORMAL);
  152. }
  153. void AddBlackList(const char* strName, const char* strGroup);
  154. void ProcessPeople(KUiPlayerItem* pDest, int nAction)
  155. {
  156. if (pDest == NULL || pDest->Name[0] == 0)
  157. return;
  158. switch(nAction)
  159. {
  160. case ACTION_JOINTEAM: //要用nIndex
  161. if (g_pCoreShell && pDest->nData == PLAYER_MENU_STATE_TEAMOPEN && pDest->nIndex != -1)
  162. g_pCoreShell->ApplyAddTeam(pDest);
  163. break;
  164. case ACTION_TRADE: //要用nIndex
  165. if (g_pCoreShell && pDest->nData == PLAYER_MENU_STATE_TRADEOPEN && pDest->nIndex != -1)
  166. g_pCoreShell->TradeApplyStart(pDest);
  167. break;
  168. case ACTION_CHAT: //要用Name
  169. KUiPlayerBar::InputNameMsg(false, pDest->Name, true);
  170. break;
  171. case ACTION_REVENGE: //要用uId
  172. if (g_pCoreShell && pDest->uId != 0)
  173. g_pCoreShell->OperationRequest(GOI_REVENGE_SOMEONE, (unsigned int)pDest, 0);
  174. break;
  175. case ACTION_MAKEFRIEND: //要用Name
  176. if (g_pCoreShell && !KUiChatCentre::IsMyFriend(pDest->Name))
  177. g_pCoreShell->OperationRequest(GOI_CHAT_FRIEND_ADD, (unsigned int)pDest, 0);
  178. break;
  179. case ACTION_INVITETEAM: //要用uId
  180. if (g_pCoreShell && pDest->uId != 0)
  181. {
  182. KUiPlayerTeam TeamInfo;
  183. TeamInfo.cNumMember = 0;
  184. g_pCoreShell->TeamOperation(TEAM_OI_GD_INFO, (unsigned int)&TeamInfo, 0);
  185. if (TeamInfo.cNumMember == 0)
  186. g_pCoreShell->TeamOperation(TEAM_OI_CREATE, 0, 0);
  187. g_pCoreShell->TeamOperation(TEAM_OI_INVITE, (unsigned int)pDest, 0);
  188. }
  189. break;
  190. case ACTION_FOLLOW: //要用nIndex
  191. if (g_pCoreShell && pDest->nIndex != -1)
  192. g_pCoreShell->OperationRequest(GOI_FOLLOW_SOMEONE, (unsigned int)pDest, 0);
  193. break;
  194. case ACTION_VIEWITEM: //要用uId
  195. if (g_pCoreShell && pDest->uId != 0)
  196. g_pCoreShell->OperationRequest(GOI_VIEW_PLAYERITEM, (unsigned int)pDest->uId, 0);
  197. break;
  198. case ACTION_BLACKLIST: //要用Name
  199. AddBlackList(pDest->Name, "");
  200. break;
  201. case ACTION_TONG:
  202. KUiTongManager::OpenWindow(pDest->Name);
  203. break;
  204. }
  205. }
  206. void ProcessEmote(char* szDest, char *szDestChannel, int nEmoteIndex)
  207. {
  208. if (g_pCoreShell && szDest)
  209. {
  210. KUiPlayerBaseInfo MyInfo;
  211. char szBuff[256];
  212. int nStringLen, nChannelIndex, nDestChannel;
  213. nDestChannel = KUiMsgCentrePad::GetChannelIndex(szDestChannel);
  214. if(nDestChannel == -1)
  215. {
  216. nChannelIndex = KUiPlayerBar::GetCurChannel();
  217. }
  218. else
  219. {
  220. nChannelIndex = nDestChannel;
  221. }
  222. if(nChannelIndex != -1)
  223. {
  224. int nChannelCount = KUiMsgCentrePad::GetChannelCount();
  225. int nChannelID    = KUiMsgCentrePad::GetChannelID(nChannelIndex);
  226. //开始获取和转换字串
  227. g_pCoreShell->GetGameData(GDI_PLAYER_BASE_INFO, (unsigned int)&MyInfo, 0);
  228.         if(szDest[0])
  229.             nStringLen = g_UiChatPhrase.GetEmote(nEmoteIndex, szBuff, sizeof(szBuff));
  230.     else
  231.     nStringLen = g_UiChatPhrase.GetEmote(nEmoteIndex, szBuff, sizeof(szBuff), 1);
  232. //获取和转换字串玩了
  233. //发出去
  234. if(KUiPlayerBar::IsCanSendMessage(szBuff, nStringLen, szDest, nChannelID))
  235. {
  236. char szBuffConverted[256];
  237. nStringLen = KUiFaceSelector::ConvertFaceText(szBuffConverted, szBuff, nStringLen);
  238. nStringLen = g_UiChatPhrase.ConvertEmoteString(szBuffConverted, nStringLen, MyInfo.Name, szDest);
  239.      if(nChannelIndex >= nChannelCount)
  240.     {
  241. if (szDest[0])
  242. {
  243.          KUiPlayerBar::OnSendSomeoneMessage(szDest, szBuffConverted, nStringLen);
  244. int nIndex = KUiPlayerBar::AddRecentPlayer(szDest);
  245. KUiPlayerBar::SetCurrentChannel(nIndex);
  246. }
  247.     }
  248. else
  249. {
  250. KUiPlayerBar::OnSendChannelMessage(nChannelID, szBuffConverted, nStringLen);
  251. }
  252. ///////////////////////////////////////////
  253. }
  254. /////////////////////////////
  255. }
  256. ////////////////////
  257. }
  258. /////////////////
  259. }
  260. char g_ActionName[][32] = 
  261. {
  262. "聊天",
  263. "好友",
  264. "交易",
  265. "入队",
  266. "组队",
  267. "跟随",
  268. "仇杀",
  269. "装备",
  270. "黑名单",
  271. "帮会",
  272. };
  273. bool IsInBlackName(char* strName);
  274. void PopUpContextPeopleMenu(const KUiPlayerItem& SelectPlayer, int x, int y)
  275. {
  276. if (SelectPlayer.Name[0] == 0)
  277. return;
  278. if (KUiPlayerBar::IsSelfName((char*)SelectPlayer.Name))
  279. return;
  280. int nbIsRecruit = g_pCoreShell->TongOperation(GTOI_TONG_IS_RECRUIT, (unsigned int)&SelectPlayer, 0);
  281. int nActionDataCount = sizeof(g_ActionName) / 32;
  282. KPopupMenuData* pMenuData = (KPopupMenuData*)malloc(MENU_DATA_SIZE(nActionDataCount));
  283. if (pMenuData == NULL)
  284. return;
  285. KPopupMenu::InitMenuData(pMenuData, nActionDataCount);
  286. pMenuData->usMenuFlag |= PM_F_AUTO_DEL_WHEN_HIDE;
  287. pMenuData->usMenuFlag &= ~PM_F_HAVE_HEAD_TAIL_IMG;
  288. KUiPlayerTeam TeamInfo;
  289. TeamInfo.nCaptainPower = 0;
  290. g_pCoreShell->TeamOperation(TEAM_OI_GD_INFO, (unsigned int)&TeamInfo, 0);
  291. int nMenuCount = 0;
  292. int i;
  293. pMenuData->nItemHeight = 0;
  294. for (i = 0; i < nActionDataCount; i++)
  295. {
  296. if ((i == ACTION_JOINTEAM && SelectPlayer.nIndex != -1 && SelectPlayer.nData == PLAYER_MENU_STATE_TEAMOPEN) || //"申请入队", 对方未打开队伍时不能加入
  297. (i == ACTION_TRADE && SelectPlayer.nIndex != -1 && SelectPlayer.nData == PLAYER_MENU_STATE_TRADEOPEN) || //"交易物品", 对方未打开交易时不能加入
  298. (i == ACTION_MAKEFRIEND && !KUiChatCentre::IsMyFriend((char*)SelectPlayer.Name)) || //"加为好友", 对方已是我的好友时不能再邀请
  299. (i == ACTION_INVITETEAM && SelectPlayer.uId != 0 && TeamInfo.nCaptainPower > 0) || //"邀请加入", 队伍不可以加人了就不能邀请加入
  300. (i == ACTION_FOLLOW && SelectPlayer.nIndex != -1) ||
  301. (i == ACTION_REVENGE && SelectPlayer.uId != 0) ||
  302. (i == ACTION_VIEWITEM && SelectPlayer.uId != 0) ||
  303. (i == ACTION_TONG && SelectPlayer.nIndex != -1 && nbIsRecruit) ||
  304. (i == ACTION_BLACKLIST && !IsInBlackName((char*)SelectPlayer.Name)) ||
  305. (i == ACTION_CHAT)
  306. )
  307. {
  308. strcpy(pMenuData->Items[nMenuCount].szData, g_ActionName[i]);
  309. pMenuData->Items[nMenuCount].uDataLen = strlen(g_ActionName[i]);
  310. pMenuData->Items[nMenuCount].uID = i;
  311. nMenuCount++;
  312. }
  313. }
  314. pMenuData->nNumItem = nMenuCount;
  315. pMenuData->nX = x;
  316. pMenuData->nY = y;
  317. g_WndGameSpace.m_SelectPlayer = SelectPlayer;
  318. KPopupMenu::Popup(pMenuData, &g_WndGameSpace, SEL_ACTION_MENU);
  319. }
  320. void PopUpContextEmoteMenu(char* szDest, int x, int y)
  321. {
  322. if (szDest == NULL || szDest[0] == 0)
  323. return;
  324. if (KUiPlayerBar::IsSelfName(szDest))
  325. return;
  326. int nEmoteCount = g_UiChatPhrase.GetEmoteCount((KUiChatPhrase::EMOTE_TYPE)(1));
  327. KPopupMenuData* pMenuData = (KPopupMenuData*)malloc(MENU_DATA_SIZE(nEmoteCount));
  328. if (pMenuData == NULL)
  329. {
  330. return;
  331. }
  332. KPopupMenu::InitMenuData(pMenuData, nEmoteCount);
  333. pMenuData->usMenuFlag |= PM_F_AUTO_DEL_WHEN_HIDE;
  334. pMenuData->usMenuFlag &= ~PM_F_HAVE_HEAD_TAIL_IMG;
  335. int i, nBuffLen;
  336. char szBuff[128];
  337. pMenuData->nItemHeight = 0;
  338. for (i = 0; i < nEmoteCount; i++)
  339. {
  340. nBuffLen = g_UiChatPhrase.GetMenuEmoteName(i, szBuff, sizeof(szBuff));
  341. memcpy(pMenuData->Items[i].szData, szBuff, nBuffLen);
  342. pMenuData->Items[i].uDataLen = nBuffLen;
  343. pMenuData->Items[i].uID = i;
  344. }
  345. pMenuData->nNumItem = nEmoteCount;
  346. pMenuData->nX = x;
  347. pMenuData->nY = y;
  348. strncpy(g_WndGameSpace.m_SelectPlayer.Name, szDest, 32);
  349. g_WndGameSpace.m_SelectPlayer.nIndex = -1;
  350. g_WndGameSpace.m_SelectPlayer.uId = 0;
  351. g_WndGameSpace.m_SelectPlayer.Name[31] = 0;
  352. KPopupMenu::Popup(pMenuData, &g_WndGameSpace, SEL_EMOTE_MENU);
  353. }