dlgmpwolchat.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/dlgmpwolchat.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/25/02 5:02p $*
  29. * *
  30. * $Revision:: 38 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "DlgMPWOLChat.h"
  36. #include "RenegadeDialogMgr.h"
  37. #include "WOLLocaleMgr.h"
  38. #include "DlgMessageBox.h"
  39. #include <WOLAPI\ChatDefs.h>
  40. #include <WWOnline\WOLChannel.h>
  41. #include <WWUI\StyleMgr.h>
  42. #include <WWUI\DialogMgr.h>
  43. #include <WWUI\EditCtrl.h>
  44. #include <WWUI\Listctrl.h>
  45. #include <WWUI\MenuEntryCtrl.h>
  46. #include <WWUI\ShortcutBarCtrl.h>
  47. #include <WW3D2\Render2D.h>
  48. #include "String_IDs.h"
  49. #include <WWTranslateDB\TranslateDB.h>
  50. using namespace WWOnline;
  51. ////////////////////////////////////////////////////////////////
  52. // Local constants
  53. ////////////////////////////////////////////////////////////////
  54. static const Vector3 PRIVATE_COLOR (0.35F, 0.8F, 1.0F);
  55. static const Vector3 EMOT_COLOR (0.1F, 0.75F, 0.0F);
  56. static const Vector3 SQUELCHED_COLOR (0.5F, 0.5F, 0.5F);
  57. static const Vector3 SYSOP_COLOR (1.0F, 1.0F, 1.0F);
  58. ////////////////////////////////////////////////////////////////
  59. // Static member initialization
  60. ////////////////////////////////////////////////////////////////
  61. MPWolChatMenuClass* MPWolChatMenuClass::_TheInstance = NULL;
  62. ////////////////////////////////////////////////////////////////
  63. //
  64. // MPWolChatMenuClass
  65. //
  66. ////////////////////////////////////////////////////////////////
  67. MPWolChatMenuClass::MPWolChatMenuClass (void) :
  68. MenuDialogClass (IDD_MP_WOL_CHAT),
  69. mChatMgr(NULL),
  70. mLobbyListChanged(false),
  71. mLobbyChanged(false),
  72. mUserInListChanged(false),
  73. mUserOutListChanged(false),
  74. mMessageListChanged(false)
  75. {
  76. WWDEBUG_SAY(("MPWolChatMenuClass instantiated\n"));
  77. WWASSERT (_TheInstance == NULL);
  78. _TheInstance = this;
  79. }
  80. ////////////////////////////////////////////////////////////////
  81. //
  82. // ~MPWolChatMenuClass
  83. //
  84. ////////////////////////////////////////////////////////////////
  85. MPWolChatMenuClass::~MPWolChatMenuClass (void)
  86. {
  87. WWDEBUG_SAY(("MPWolChatMenuClass destroyed\n"));
  88. _TheInstance = NULL;
  89. }
  90. ////////////////////////////////////////////////////////////////
  91. //
  92. // On_Init_Dialog
  93. //
  94. ////////////////////////////////////////////////////////////////
  95. void MPWolChatMenuClass::On_Init_Dialog(void)
  96. {
  97. // Configure the shortcut bar
  98. ShortcutBarCtrlClass* bar = (ShortcutBarCtrlClass*)Get_Dlg_Item(IDC_SHORTCUT_BAR);
  99. if (bar) {
  100. bar->Add_Button(IDC_MP_SHORTCUT_GAMELIST, TRANSLATE(IDS_MENU_TEXT365));
  101. bar->Add_Button(IDC_MP_SHORTCUT_BUDDIES, TRANSLATE(IDS_MP_SHORTCUT_BUDDIES));
  102. bar->Add_Button(IDC_MP_SHORTCUT_PAGE_BUDDY, TRANSLATE(IDS_MP_SHORTCUT_PAGE_BUDDY));
  103. bar->Add_Button(IDC_MP_SHORTCUT_INTERNET_OPTIONS, TRANSLATE(IDS_INTERNET_OPTIONS));
  104. bar->Add_Button(IDC_MP_SHORTCUT_NEWS, TRANSLATE(IDS_MP_SHORTCUT_NEWS));
  105. bar->Add_Button(IDC_MP_SHORTCUT_CLANS, TRANSLATE(IDS_MP_SHORTCUT_CLANS));
  106. bar->Add_Button(IDC_MP_SHORTCUT_RANKINGS, TRANSLATE(IDS_MP_SHORTCUT_RANKINGS));
  107. bar->Add_Button(IDC_MP_SHORTCUT_NET_STATUS, TRANSLATE(IDS_MP_SHORTCUT_NET_STATUS));
  108. }
  109. // Configure the lobby list ctrl
  110. ListCtrlClass* list_ctrl = (ListCtrlClass*)Get_Dlg_Item(IDC_LOBBY_LIST_CTRL);
  111. if (list_ctrl) {
  112. list_ctrl->Set_Wants_Focus(false);
  113. // Lobby name column
  114. list_ctrl->Add_Column(L"", 0.8F, Vector3 (1, 1, 1));
  115. // Lobby user count column
  116. list_ctrl->Add_Column(L"", 0.2F, Vector3 (1, 1, 1));
  117. }
  118. // Configure the user list ctrl
  119. list_ctrl = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  120. if (list_ctrl) {
  121. list_ctrl->Allow_Multiple_Selection(true);
  122. list_ctrl->Allow_NoSelection(true);
  123. list_ctrl->Set_Wants_Focus(false);
  124. // User flags column
  125. list_ctrl->Add_Column(L"", .15F, Vector3 (1, 1, 1));
  126. // Username column
  127. list_ctrl->Add_Column(L"", .50F, Vector3 (1, 1, 1));
  128. // User clan column
  129. list_ctrl->Add_Column(L"", .35F, Vector3 (1, 1, 1));
  130. }
  131. // Configure the message list ctrl
  132. list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_MESSAGE_LIST_CTRL);
  133. if (list_ctrl) {
  134. list_ctrl->Add_Column (L"", 1.0F, Vector3 (1, 1, 1));
  135. list_ctrl->Allow_Selection(false);
  136. list_ctrl->Set_Wants_Focus(false);
  137. }
  138. // Get Chat Manager
  139. mChatMgr = WOLChatMgr::GetInstance(true);
  140. if (mChatMgr) {
  141. mChatMgr->Start();
  142. Observer<WOLChatMgrEvent>::NotifyMe(*mChatMgr);
  143. mChatMgr->RefreshLobbyList();
  144. }
  145. RefPtr<Session> wolSession = Session::GetInstance(false);
  146. if (wolSession.IsValid()) {
  147. Observer<UserEvent>::NotifyMe(*wolSession);
  148. }
  149. MenuDialogClass::On_Init_Dialog ();
  150. return ;
  151. }
  152. ////////////////////////////////////////////////////////////////
  153. //
  154. // On_Command
  155. //
  156. ////////////////////////////////////////////////////////////////
  157. void MPWolChatMenuClass::On_Command(int ctrl_id, int message_id, DWORD param)
  158. {
  159. switch (ctrl_id) {
  160. case IDC_MENU_BACK_BUTTON:
  161. mChatMgr->LeaveLobby();
  162. break;
  163. case IDC_EMOT_MESSAGE_BUTTON:
  164. Send_Message(true);
  165. break;
  166. case IDC_SQUELCH_BUTTON:
  167. Toggle_Squelch();
  168. break;
  169. case IDC_REFRESH_BUTTON:
  170. mChatMgr->RefreshLobbyList();
  171. break;
  172. }
  173. MenuDialogClass::On_Command (ctrl_id, message_id, param);
  174. Set_Focus_To_Chat_Edit_Ctrl();
  175. return ;
  176. }
  177. ////////////////////////////////////////////////////////////////
  178. //
  179. // On_Destroy
  180. //
  181. ////////////////////////////////////////////////////////////////
  182. void MPWolChatMenuClass::On_Destroy(void)
  183. {
  184. Observer<WOLChatMgrEvent>::StopObserving();
  185. if (mChatMgr) {
  186. mChatMgr->Stop();
  187. mChatMgr->Release_Ref();
  188. mChatMgr = NULL;
  189. }
  190. MenuDialogClass::On_Destroy ();
  191. return ;
  192. }
  193. ////////////////////////////////////////////////////////////////
  194. //
  195. // On_Frame_Update
  196. //
  197. ////////////////////////////////////////////////////////////////
  198. void MPWolChatMenuClass::On_Frame_Update(void)
  199. {
  200. MenuDialogClass::On_Frame_Update();
  201. // Do we need to update the lobby list?
  202. if (mLobbyListChanged) {
  203. Refresh_Lobby_List();
  204. }
  205. // Do we need to change the text of the current lobby control?
  206. if (mLobbyChanged) {
  207. Update_Current_Channel();
  208. }
  209. // Do we need to add users to the player list?
  210. if (mUserInListChanged) {
  211. Add_Users();
  212. }
  213. // Do we need to remove users from the player list?
  214. if (mUserOutListChanged) {
  215. Remove_Users();
  216. }
  217. // Do we need to update the message list?
  218. if (mMessageListChanged) {
  219. Refresh_Message_List();
  220. }
  221. }
  222. void MPWolChatMenuClass::On_Last_Menu_Ending(void)
  223. {
  224. // If this is the last menu the bring up the internet game main menu.
  225. RenegadeDialogMgrClass::Goto_Location(RenegadeDialogMgrClass::LOC_INTERNET_MAIN);
  226. }
  227. ////////////////////////////////////////////////////////////////
  228. //
  229. // Refresh_Lobby_List
  230. //
  231. ////////////////////////////////////////////////////////////////
  232. void MPWolChatMenuClass::Refresh_Lobby_List(void)
  233. {
  234. // Remember that we've gotten this data
  235. mLobbyListChanged = false;
  236. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_LOBBY_LIST_CTRL);
  237. if (list) {
  238. // Remove existing lobby names
  239. list->Delete_All_Entries();
  240. // Add the new lobbies
  241. const LobbyList& lobbyList = mChatMgr->GetLobbyList();
  242. if (lobbyList.empty()) {
  243. DlgMsgBox::DoDialog(TRANSLATE(IDS_MENU_SERVER_MESSAGE_TITLE), TRANSLATE(IDS_MENU_NO_CHAT_AVAIL));
  244. End_Dialog();
  245. return;
  246. }
  247. LobbyList::const_iterator iter = lobbyList.begin();
  248. while (iter != lobbyList.end()) {
  249. const RefPtr<ChannelData>& lobby = (*iter);
  250. WideStringClass lobbyName(64, true);
  251. mChatMgr->GetLobbyDisplayName(lobby, lobbyName);
  252. int listIndex = list->Insert_Entry(list->Get_Entry_Count(), lobbyName);
  253. if (listIndex >= -1) {
  254. // Associate the channel with this lobby entry
  255. const ChannelData* channel = lobby.ReferencedObject();
  256. list->Set_Entry_Data(listIndex, 0, (uint32)channel);
  257. UpdateLobbyUserCount(list, listIndex);
  258. }
  259. iter++;
  260. }
  261. // Select either the current lobby we are joined to or the first
  262. // lobby in the list.
  263. RefPtr<ChannelData> lobby = mChatMgr->GetCurrentLobby();
  264. if (!lobby.IsValid() && (list->Get_Entry_Count() > 0)) {
  265. lobby = (ChannelData*)list->Get_Entry_Data(0, 0);
  266. mChatMgr->JoinLobby(lobby);
  267. }
  268. SelectLobbyFromChannel(lobby);
  269. }
  270. }
  271. void MPWolChatMenuClass::UpdateLobbyUserCount(ListCtrlClass* list, int listIndex)
  272. {
  273. if (list && (listIndex >= 0)) {
  274. const ChannelData* channel = (const ChannelData*)list->Get_Entry_Data(listIndex, 0);
  275. if (channel) {
  276. WideStringClass countText(0, true);
  277. countText.Format(L"(%u)", channel->GetCurrentUsers());
  278. list->Set_Entry_Text(listIndex, 1, countText);
  279. }
  280. }
  281. }
  282. void MPWolChatMenuClass::UpdateCurrentLobbyUserCount(void)
  283. {
  284. RefPtr<ChannelData> lobby = mChatMgr->GetCurrentLobby();
  285. if (lobby.IsValid()) {
  286. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_LOBBY_LIST_CTRL);
  287. if (list) {
  288. const int count = list->Get_Entry_Count();
  289. for (int listIndex = 0; listIndex < count; ++listIndex) {
  290. const ChannelData* channel = (const ChannelData*)list->Get_Entry_Data(listIndex, 0);
  291. if (channel && (lobby.ReferencedObject() == channel)) {
  292. UpdateLobbyUserCount(list, listIndex);
  293. return;
  294. }
  295. }
  296. }
  297. }
  298. }
  299. void MPWolChatMenuClass::SelectLobbyFromChannel(const RefPtr<ChannelData>& channel)
  300. {
  301. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_LOBBY_LIST_CTRL);
  302. if (list) {
  303. if (channel.IsValid()) {
  304. WideStringClass displayName(0, true);
  305. mChatMgr->GetLobbyDisplayName(channel, displayName);
  306. int index = list->Find_Entry(0, displayName);
  307. if (index >= 0) {
  308. list->Set_Curr_Sel(index);
  309. }
  310. } else {
  311. list->Set_Curr_Sel(-1);
  312. }
  313. }
  314. }
  315. ////////////////////////////////////////////////////////////////
  316. //
  317. // Add_Users
  318. //
  319. ////////////////////////////////////////////////////////////////
  320. void MPWolChatMenuClass::Add_Users(void)
  321. {
  322. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  323. if (list) {
  324. // Loop over all the users
  325. const UserList& userList = mChatMgr->GetUserInList();
  326. const unsigned int count = userList.size();
  327. for (unsigned int index = 0; index < count; ++index) {
  328. const RefPtr<UserData>& user = userList[index];
  329. // Add the user to the list control
  330. int itemIndex = list->Find_Entry(1, user->GetName());
  331. if (itemIndex == -1) {
  332. itemIndex = list->Insert_Entry(list->Get_Entry_Count(), L"");
  333. }
  334. if (itemIndex != -1) {
  335. list->Set_Entry_Text(itemIndex, 1, user->GetName());
  336. Update_User_Status(list, itemIndex, user);
  337. }
  338. }
  339. // Update the message color in the edit control
  340. Update_Message_Color();
  341. }
  342. UpdateCurrentLobbyUserCount();
  343. mChatMgr->ClearUserInList();
  344. mUserInListChanged = false;
  345. }
  346. ////////////////////////////////////////////////////////////////
  347. //
  348. // Remove_Users
  349. //
  350. ////////////////////////////////////////////////////////////////
  351. void MPWolChatMenuClass::Remove_Users(void)
  352. {
  353. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  354. if (list) {
  355. // Loop over all the users
  356. const UserList& userList = mChatMgr->GetUserOutList();
  357. const unsigned int count = userList.size();
  358. for (unsigned int index = 0; index < count; ++index) {
  359. const RefPtr<UserData>& user = userList[index];
  360. WWASSERT(user.IsValid() && "Invalid user in userlist from WOLChatMgr");
  361. if (user.IsValid()) {
  362. int sel = list->Find_Entry(1, user->GetName());
  363. if (sel != -1) {
  364. list->Delete_Entry(sel);
  365. }
  366. }
  367. }
  368. // Update the message color in the edit control
  369. Update_Message_Color();
  370. }
  371. UpdateCurrentLobbyUserCount();
  372. mChatMgr->ClearUserOutList();
  373. mUserOutListChanged = false;
  374. }
  375. ////////////////////////////////////////////////////////////////
  376. //
  377. // Refresh_Message_List
  378. //
  379. ////////////////////////////////////////////////////////////////
  380. void MPWolChatMenuClass::Refresh_Message_List(void)
  381. {
  382. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_MESSAGE_LIST_CTRL);
  383. if (list) {
  384. const ChatMessageList& messageList = mChatMgr->GetMessageList();
  385. // Loop over all the messages
  386. int count = messageList.size();
  387. for (int index = 0; index < count; index ++) {
  388. const ChatMessage& message = messageList[index];
  389. // Build the string
  390. WideStringClass text(255, true);
  391. const WideStringClass& sender = message.GetSendersName();
  392. const WCHAR* msg = message.GetMessage();
  393. if (sender.Is_Empty() == false) {
  394. if (message.IsAction()) {
  395. text.Format(L"%s %s", (const WCHAR*)sender, msg);
  396. } else {
  397. text.Format(L"%s: %s", (const WCHAR*)sender, msg);
  398. }
  399. msg = text;
  400. }
  401. // Add the message to the list control
  402. int entryCount = list->Get_Entry_Count();
  403. int itemIndex = list->Insert_Entry(entryCount + index, msg);
  404. if (itemIndex != -1) {
  405. // Now, color the message as necessary
  406. if (message.IsPrivate()) {
  407. list->Set_Entry_Color(itemIndex, 0, PRIVATE_COLOR);
  408. } else if (message.IsAction()) {
  409. list->Set_Entry_Color(itemIndex, 0, EMOT_COLOR);
  410. } else if (message.IsSenderChannelOwner()) {
  411. list->Set_Entry_Color(itemIndex, 0, SYSOP_COLOR);
  412. }
  413. }
  414. // Start deleting text after 1000 lines of messages
  415. if (entryCount > 1000) {
  416. list->Delete_Entry(0);
  417. }
  418. }
  419. // Force-scroll the control to the end of the list
  420. if (list->Has_Focus() == false) {
  421. list->Scroll_To_End();
  422. }
  423. }
  424. mChatMgr->ClearMessageList();
  425. mMessageListChanged = false;
  426. }
  427. ////////////////////////////////////////////////////////////////
  428. //
  429. // Add_Message
  430. //
  431. ////////////////////////////////////////////////////////////////
  432. void MPWolChatMenuClass::Add_Message(const WCHAR* text)
  433. {
  434. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_MESSAGE_LIST_CTRL);
  435. if (list) {
  436. // Add the message to the list control
  437. int entryCount = list->Get_Entry_Count();
  438. list->Insert_Entry(entryCount, text);
  439. // Start deleting text after 1000 lines of messages
  440. if (entryCount > 1000) {
  441. list->Delete_Entry(0);
  442. }
  443. // Force-scroll the control to the end of the list
  444. if (list->Has_Focus() == false) {
  445. list->Scroll_To_End();
  446. }
  447. }
  448. }
  449. ////////////////////////////////////////////////////////////////
  450. //
  451. // Set_Focus_To_Chat_Edit_Ctrl
  452. //
  453. ////////////////////////////////////////////////////////////////
  454. void MPWolChatMenuClass::Set_Focus_To_Chat_Edit_Ctrl(void)
  455. {
  456. // Return focus to the chat edit control.
  457. DialogControlClass* ctrl = Get_Dlg_Item(IDC_CHAT_EDIT);
  458. if (ctrl) {
  459. ctrl->Set_Focus();
  460. }
  461. }
  462. ////////////////////////////////////////////////////////////////
  463. //
  464. // On_ListCtrl_Sel_Change
  465. //
  466. ////////////////////////////////////////////////////////////////
  467. void MPWolChatMenuClass::On_ListCtrl_Sel_Change(ListCtrlClass* list, int id, int oldSel, int newSel)
  468. {
  469. if (IDC_LOBBY_LIST_CTRL == id) {
  470. if (newSel >= 0) {
  471. // Join the lobby associated with the entry
  472. const RefPtr<ChannelData> lobby = (ChannelData*)list->Get_Entry_Data(newSel, 0);
  473. if (lobby.IsValid()) {
  474. mChatMgr->JoinLobby(lobby);
  475. }
  476. }
  477. } else if (IDC_PLAYERS_LIST_CTRL == id) {
  478. Update_Message_Color();
  479. }
  480. }
  481. ////////////////////////////////////////////////////////////////
  482. //
  483. // On_ListCtrl_Mouse_Over
  484. //
  485. ////////////////////////////////////////////////////////////////
  486. void MPWolChatMenuClass::On_ListCtrl_Mouse_Over(ListCtrlClass* list, int id, int index)
  487. {
  488. if (IDC_PLAYERS_LIST_CTRL == id) {
  489. WideStringClass userinfo(0, true);
  490. if (index >= 0) {
  491. const WCHAR* name = list->Get_Entry_Text(index, 1);
  492. userinfo += name;
  493. const RefPtr<UserData> user = mChatMgr->FindUser(name);
  494. if (user.IsValid()) {
  495. RefPtr<SquadData> clan = user->GetSquad();
  496. if (clan.IsValid())
  497. {
  498. userinfo += L" : ";
  499. userinfo += clan->GetName();
  500. }
  501. userinfo += L" : ";
  502. userinfo += WolLocaleMgrClass::Get_Locale_String(user->GetLocale());
  503. }
  504. }
  505. Set_Dlg_Item_Text(IDC_USERINFO, userinfo);
  506. }
  507. }
  508. ////////////////////////////////////////////////////////////////
  509. //
  510. // On_EditCtrl_Enter_Pressed
  511. //
  512. ////////////////////////////////////////////////////////////////
  513. void MPWolChatMenuClass::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit_ctrl, int ctrl_id)
  514. {
  515. if (IDC_CHAT_EDIT == ctrl_id) {
  516. Send_Message(false);
  517. }
  518. return ;
  519. }
  520. ////////////////////////////////////////////////////////////////
  521. //
  522. // Update_Message_Color
  523. //
  524. ////////////////////////////////////////////////////////////////
  525. void MPWolChatMenuClass::Update_Message_Color(void)
  526. {
  527. ListCtrlClass *list_ctrl = (ListCtrlClass *)Get_Dlg_Item (IDC_PLAYERS_LIST_CTRL);
  528. EditCtrlClass *edit_ctrl = (EditCtrlClass *)Get_Dlg_Item (IDC_CHAT_EDIT);
  529. if (list_ctrl == NULL || edit_ctrl == NULL) {
  530. return ;
  531. }
  532. // Reset the color as necessary depending on the selection
  533. // state of the user list
  534. if (list_ctrl->Get_First_Selected () == -1) {
  535. // Set the default color
  536. Vector3 default_color;
  537. INT32_TO_VRGB (StyleMgrClass::Get_Text_Color (), default_color);
  538. edit_ctrl->Set_Text_Color (default_color);
  539. } else {
  540. // Set the private message color
  541. edit_ctrl->Set_Text_Color (PRIVATE_COLOR);
  542. }
  543. return ;
  544. }
  545. ////////////////////////////////////////////////////////////////
  546. //
  547. // Send_Message
  548. //
  549. ////////////////////////////////////////////////////////////////
  550. void MPWolChatMenuClass::Send_Message(bool is_emot)
  551. {
  552. // Get the message text
  553. WideStringClass message(0, true);
  554. message = Get_Dlg_Item_Text(IDC_CHAT_EDIT);
  555. message.Trim();
  556. if (message.Is_Empty()) {
  557. return;
  558. }
  559. // If the user has players selected then send the message as private.
  560. ListCtrlClass* list_ctrl = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  561. if (list_ctrl && (list_ctrl->Get_First_Selected() >= 0)) {
  562. UserList users;
  563. int index = list_ctrl->Get_First_Selected();
  564. while (index != -1) {
  565. const WCHAR* name = list_ctrl->Get_Entry_Text(index, 1);
  566. const RefPtr<UserData> user = mChatMgr->FindUser(name);
  567. if (user.IsValid()) {
  568. users.push_back(user);
  569. }
  570. index = list_ctrl->Get_Next_Selected(index);
  571. }
  572. mChatMgr->SendPrivateMessage(users, message, is_emot);
  573. } else {
  574. mChatMgr->SendPublicMessage(message, is_emot);
  575. }
  576. // Clear the edit control
  577. Set_Dlg_Item_Text(IDC_CHAT_EDIT, L"");
  578. }
  579. ////////////////////////////////////////////////////////////////
  580. //
  581. // Toggle_Squelch
  582. //
  583. ////////////////////////////////////////////////////////////////
  584. void MPWolChatMenuClass::Toggle_Squelch(void)
  585. {
  586. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  587. if (list) {
  588. // Loop over the selected users
  589. int index = list->Get_First_Selected();
  590. while (index != -1) {
  591. const WCHAR* userName = list->Get_Entry_Text(index, 1);
  592. const RefPtr<UserData>& user = mChatMgr->FindUser(userName);
  593. // If the user is valid and it is not a channel owner and it is
  594. // not the current user then allow squelching.
  595. if (user.IsValid() && !user->IsChannelOwner() && !user->IsMe()) {
  596. // Toggle the users squelch
  597. bool squelched = user->IsSquelched();
  598. mChatMgr->SquelchUser(user, !squelched);
  599. Update_User_Status(list, index, user);
  600. }
  601. index = list->Get_Next_Selected(index);
  602. }
  603. }
  604. }
  605. ////////////////////////////////////////////////////////////////
  606. //
  607. // Update_User_Status
  608. //
  609. ////////////////////////////////////////////////////////////////
  610. void MPWolChatMenuClass::Update_User_Status(ListCtrlClass* list, int index, const RefPtr<UserData>& user)
  611. {
  612. WWASSERT(list);
  613. WWASSERT(user.IsValid());
  614. list->Reset_Icons(index, 0);
  615. // Update the entry based on the user's flags
  616. if (user->IsSquelched()) {
  617. list->Set_Entry_Color(index, 1, SQUELCHED_COLOR);
  618. }
  619. if (user->IsChannelOwner()) {
  620. list->Set_Entry_Color(index, 1, SYSOP_COLOR);
  621. list->Add_Icon(index, 0, "mul_ccop4.tga");
  622. } else {
  623. // Set the default color
  624. Vector3 default_color;
  625. INT32_TO_VRGB(StyleMgrClass::Get_Text_Color(), default_color);
  626. list->Set_Entry_Color(index, 1, default_color);
  627. }
  628. // Set there clan information
  629. RefPtr<SquadData> clan = user->GetSquad();
  630. if (clan.IsValid()) {
  631. WideStringClass clanAbbr(0, true);
  632. clanAbbr.Format(L"[%S]", clan->GetAbbr());
  633. list->Set_Entry_Text(index, 2, clanAbbr);
  634. } else {
  635. list->Set_Entry_Text(index, 2, L"");
  636. }
  637. }
  638. ////////////////////////////////////////////////////////////////
  639. //
  640. // Update_Current_Channel
  641. //
  642. ////////////////////////////////////////////////////////////////
  643. void MPWolChatMenuClass::Update_Current_Channel(void)
  644. {
  645. Refresh_Lobby_List();
  646. ListCtrlClass* list_ctrl = (ListCtrlClass*)Get_Dlg_Item (IDC_PLAYERS_LIST_CTRL);
  647. if (list_ctrl == NULL) {
  648. return ;
  649. }
  650. // Reset the player list
  651. list_ctrl->Delete_All_Entries ();
  652. // Update the current lobby text
  653. mLobbyChanged = false;
  654. return ;
  655. }
  656. ////////////////////////////////////////////////////////////////
  657. //
  658. // Display
  659. //
  660. ////////////////////////////////////////////////////////////////
  661. void MPWolChatMenuClass::DoDialog(const RefPtr<ChannelData>& channel)
  662. {
  663. // Create the dialog if necessary, otherwise simply bring it to the front
  664. if (_TheInstance == NULL) {
  665. MPWolChatMenuClass* dialog = new MPWolChatMenuClass;
  666. if (dialog) {
  667. dialog->Start_Dialog();
  668. dialog->Release_Ref();
  669. }
  670. } else {
  671. if (_TheInstance->Is_Active_Menu() == false) {
  672. DialogMgrClass::Rollback(_TheInstance);
  673. }
  674. }
  675. if (channel.IsValid() && _TheInstance) {
  676. WOLChatMgr* chat = WOLChatMgr::GetInstance(false);
  677. if (chat) {
  678. chat->JoinLobby(channel);
  679. chat->Release_Ref();
  680. }
  681. _TheInstance->SelectLobbyFromChannel(channel);
  682. }
  683. }
  684. ////////////////////////////////////////////////////////////////
  685. //
  686. // HandleNotification(WOLChatMgrEvent)
  687. //
  688. ////////////////////////////////////////////////////////////////
  689. void MPWolChatMenuClass::HandleNotification(WOLChatMgrEvent& event)
  690. {
  691. switch (event) {
  692. case LobbyListChanged:
  693. mLobbyListChanged = true;
  694. break;
  695. case LobbyChanged:
  696. mLobbyChanged = true;
  697. break;
  698. case UserInListChanged:
  699. mUserInListChanged = true;
  700. break;
  701. case UserOutListChanged:
  702. mUserOutListChanged = true;
  703. break;
  704. case MessageListChanged:
  705. mMessageListChanged = true;
  706. break;
  707. case KickedFromChannel:
  708. DlgMsgBox::DoDialog(TRANSLATE(IDS_MENU_SERVER_MESSAGE_TITLE), TRANSLATE(IDS_MENU_WOL_KICK_USER_MESSAGE));
  709. End_Dialog();
  710. break;
  711. case BannedFromChannel:
  712. DlgMsgBox::DoDialog(TRANSLATE(IDS_MENU_SERVER_MESSAGE_TITLE), TRANSLATE(IDS_MENU_WOL_BAN_USER_MESSAGE));
  713. End_Dialog();
  714. break;
  715. default:
  716. break;
  717. }
  718. }
  719. ////////////////////////////////////////////////////////////////
  720. //
  721. // HandleNotification(UserEvent)
  722. //
  723. ////////////////////////////////////////////////////////////////
  724. void MPWolChatMenuClass::HandleNotification(UserEvent& userEvent)
  725. {
  726. UserEvent::Event event = userEvent.GetEvent();
  727. if ((UserEvent::SquadInfo == event) || (UserEvent::NewData == event)) {
  728. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_PLAYERS_LIST_CTRL);
  729. const RefPtr<UserData>& user = userEvent.Subject();
  730. if (list && user.IsValid()) {
  731. int index = list->Find_Entry(1, user->GetName());
  732. if (index != -1) {
  733. Update_User_Status(list, index, user);
  734. }
  735. }
  736. }
  737. }