dlgmpwolpagebuddy.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/dlgmpwolpagebuddy.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/12/02 9:35p $*
  29. * *
  30. * $Revision:: 15 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "dlgmpwolpagebuddy.h"
  36. #include "dlgmpwolbuddies.h"
  37. #include "dlgmpwolpagereply.h"
  38. #include "dlgmpwolbuddylistpopup.h"
  39. #include "renegadedialogmgr.h"
  40. //#include "wolbuddymgr.h"
  41. #include "comboboxctrl.h"
  42. ////////////////////////////////////////////////////////////////
  43. //
  44. // MPWolPageBuddyPopupClass
  45. //
  46. ////////////////////////////////////////////////////////////////
  47. MPWolPageBuddyPopupClass::MPWolPageBuddyPopupClass (void) :
  48. PopupDialogClass (IDD_MP_WOL_PAGE_BUDDY),
  49. mBuddyMgr(NULL)
  50. {
  51. mBuddyMgr = WOLBuddyMgr::GetInstance(false);
  52. WWASSERT(mBuddyMgr != NULL);
  53. }
  54. MPWolPageBuddyPopupClass::~MPWolPageBuddyPopupClass(void)
  55. {
  56. if (mBuddyMgr) {
  57. mBuddyMgr->Release_Ref();
  58. }
  59. }
  60. ////////////////////////////////////////////////////////////////
  61. //
  62. // On_Init_Dialog
  63. //
  64. ////////////////////////////////////////////////////////////////
  65. void
  66. MPWolPageBuddyPopupClass::On_Init_Dialog(void)
  67. {
  68. Enable_Dlg_Item(IDC_INVITE_BUDDY_BUTTON, false);
  69. if (mBuddyMgr) {
  70. // Enable the invite button if we are in a situation to invite users.
  71. bool canInvite = mBuddyMgr->CanInviteUsers();
  72. Enable_Dlg_Item(IDC_INVITE_BUDDY_BUTTON, canInvite);
  73. // Get the current buddy list
  74. const WWOnline::UserList& list = mBuddyMgr->GetBuddyList();
  75. const unsigned int count = list.size();
  76. if (count == 0) {
  77. Observer<WOLBuddyMgrEvent>::NotifyMe (*mBuddyMgr);
  78. mBuddyMgr->RefreshBuddyList();
  79. } else {
  80. // Configure the combobox
  81. ComboBoxCtrlClass* combo_box = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_BUDDY_NAME_COMBO);
  82. if (combo_box) {
  83. // Add each buddy to the combobox
  84. for (unsigned int index = 0; index < count; ++index) {
  85. const RefPtr<WWOnline::UserData>& user = list[index];
  86. // Add this buddy if they are currently online
  87. if (user->GetLocation() != WWOnline::USERLOCATION_OFFLINE) {
  88. combo_box->Add_String(user->GetName());
  89. }
  90. }
  91. }
  92. }
  93. }
  94. // The page button is disable until the user enters a message.
  95. Enable_Dlg_Item(IDC_PAGE_BUTTON, false);
  96. // Set message edit to focus
  97. DialogControlClass* ctrl = Get_Dlg_Item(IDC_MESSAGE_EDIT);
  98. if (ctrl) {
  99. ctrl->Set_Focus();
  100. }
  101. PopupDialogClass::On_Init_Dialog();
  102. }
  103. ////////////////////////////////////////////////////////////////
  104. //
  105. // On_Command
  106. //
  107. ////////////////////////////////////////////////////////////////
  108. void
  109. MPWolPageBuddyPopupClass::On_Command(int ctrl_id, int message_id, DWORD param)
  110. {
  111. switch (ctrl_id) {
  112. case IDC_INVITE_BUDDY_BUTTON: {
  113. // Get the name of the user we'll be inviting
  114. WideStringClass user_name = Get_Dlg_Item_Text(IDC_BUDDY_NAME_COMBO);
  115. if (user_name.Is_Empty() == false) {
  116. // Invite the user
  117. if (mBuddyMgr) {
  118. mBuddyMgr->InviteUser(user_name, Get_Dlg_Item_Text(IDC_MESSAGE_EDIT));
  119. }
  120. End_Dialog();
  121. }
  122. break;
  123. }
  124. case IDC_BUDDY_LIST_BUTTON: {
  125. MPWolBuddyListPopupClass* dialog = new MPWolBuddyListPopupClass;
  126. dialog->Set_Observer(this);
  127. dialog->Start_Dialog();
  128. REF_PTR_RELEASE(dialog);
  129. break;
  130. }
  131. case IDC_VIEW_BUDDY_LIST_BUTTON:
  132. MPWolBuddiesMenuClass::Display();
  133. End_Dialog();
  134. break;
  135. case IDC_PAGE_BUTTON:
  136. Send_Page();
  137. break;
  138. }
  139. PopupDialogClass::On_Command(ctrl_id, message_id, param);
  140. }
  141. ////////////////////////////////////////////////////////////////
  142. //
  143. // Send_Page
  144. //
  145. ////////////////////////////////////////////////////////////////
  146. void
  147. MPWolPageBuddyPopupClass::Send_Page(void)
  148. {
  149. // Get the message to send
  150. WideStringClass message(0, true);
  151. message = Get_Dlg_Item_Text(IDC_MESSAGE_EDIT);
  152. message.Trim();
  153. if (message.Is_Empty() == false) {
  154. // Get the name of the user we'll be paging
  155. const WCHAR* username = Get_Dlg_Item_Text(IDC_BUDDY_NAME_COMBO);
  156. if (wcslen(username) > 0) {
  157. // Send the page
  158. if (mBuddyMgr) {
  159. mBuddyMgr->PageUser(username, message);
  160. }
  161. End_Dialog();
  162. }
  163. }
  164. }
  165. ////////////////////////////////////////////////////////////////
  166. //
  167. // Set_Buddy_Name
  168. //
  169. ////////////////////////////////////////////////////////////////
  170. void MPWolPageBuddyPopupClass::Set_Buddy_Name(const WCHAR *user_name)
  171. {
  172. Set_Dlg_Item_Text(IDC_BUDDY_NAME_COMBO, user_name);
  173. }
  174. void MPWolPageBuddyPopupClass::CheckIfCanSendPage(void)
  175. {
  176. // Get the length of the message after leading and trailing whitespace
  177. // has been removed.
  178. WideStringClass message(0, true);
  179. message = Get_Dlg_Item_Text(IDC_MESSAGE_EDIT);
  180. message.Trim();
  181. // Check for a buddy name
  182. WideStringClass username(0, true);
  183. username = Get_Dlg_Item_Text(IDC_BUDDY_NAME_COMBO);
  184. username.Trim();
  185. // If there is a message and user then allow page to be sent.
  186. bool canSend = ((message.Get_Length() > 0) && (username.Get_Length() > 0));
  187. Enable_Dlg_Item(IDC_PAGE_BUTTON, canSend);
  188. }
  189. void MPWolPageBuddyPopupClass::On_ComboBoxCtrl_Edit_Change(ComboBoxCtrlClass* combo, int id)
  190. {
  191. if (IDC_BUDDY_NAME_COMBO == id) {
  192. CheckIfCanSendPage();
  193. }
  194. }
  195. void MPWolPageBuddyPopupClass::On_EditCtrl_Change(EditCtrlClass* edit, int id)
  196. {
  197. if (IDC_MESSAGE_EDIT == id) {
  198. CheckIfCanSendPage();
  199. }
  200. }
  201. void MPWolPageBuddyPopupClass::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit, int id)
  202. {
  203. if (IDC_MESSAGE_EDIT == id && Is_Dlg_Item_Enabled(IDC_PAGE_BUTTON)) {
  204. Send_Page();
  205. }
  206. }
  207. void MPWolPageBuddyPopupClass::HandleNotification(WOLBuddyMgrEvent &event)
  208. {
  209. WOLBuddyMgrAction action = event.GetAction();
  210. if ((BUDDYLIST_CHANGED == action) || (BUDDYINFO_CHANGED == action)) {
  211. // Configure the combobox
  212. ComboBoxCtrlClass* combo_box = (ComboBoxCtrlClass*)Get_Dlg_Item(IDC_BUDDY_NAME_COMBO);
  213. if (combo_box) {
  214. combo_box->Reset_Content();
  215. const WWOnline::UserList& buddies = mBuddyMgr->GetBuddyList();
  216. const unsigned int count = buddies.size();
  217. // Add each buddy to the combobox
  218. for (unsigned int index = 0; index < count; ++index) {
  219. const RefPtr<WWOnline::UserData>& user = buddies[index];
  220. if (user->GetLocation() != WWOnline::USERLOCATION_OFFLINE) {
  221. combo_box->Add_String(user->GetName());
  222. }
  223. }
  224. }
  225. }
  226. }