dlgmpwolpagereply.cpp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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/dlgmpwolpagereply.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 8/26/02 4:31p $*
  29. * *
  30. * $Revision:: 14 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "DlgMPWOLPageReply.h"
  36. #include "DlgMPWOLAddBuddy.h"
  37. #include "DlgMPWOLAddIgnoreEntry.h"
  38. #include "WOLLogonMgr.h"
  39. #include "Resource.h"
  40. #include "consolemode.h"
  41. #include <WWUI\ListCtrl.h>
  42. DlgWOLPageReply* DlgWOLPageReply::_mInstance = NULL;
  43. /******************************************************************************
  44. *
  45. * NAME
  46. * DlgWOLPageReply::DoDialog
  47. *
  48. * DESCRIPTION
  49. * Start page reply dialog. There can only be one page reply dialog present
  50. * at a time therefore if a page reply dialog is already displayed it will
  51. * brought forward.
  52. *
  53. * INPUTS
  54. * NONE
  55. *
  56. * RESULT
  57. * True if dialog created successfully.
  58. *
  59. ******************************************************************************/
  60. bool DlgWOLPageReply::DoDialog(void)
  61. {
  62. DlgWOLPageReply* dialog = _mInstance;
  63. if (dialog == NULL)
  64. {
  65. dialog = new DlgWOLPageReply;
  66. if (dialog)
  67. {
  68. if (dialog->FinalizeCreate())
  69. {
  70. dialog->Start_Dialog();
  71. }
  72. dialog->Release_Ref();
  73. }
  74. }
  75. return (dialog != NULL);
  76. }
  77. /******************************************************************************
  78. *
  79. * NAME
  80. * DlgWOLPageReply::IsOpen
  81. *
  82. * DESCRIPTION
  83. * Default constructor
  84. *
  85. * INPUTS
  86. * NONE
  87. *
  88. * RESULT
  89. * NONE
  90. *
  91. ******************************************************************************/
  92. bool DlgWOLPageReply::IsOpen(void)
  93. {
  94. return (NULL != _mInstance);
  95. }
  96. /******************************************************************************
  97. *
  98. * NAME
  99. * DlgWOLPageReply::DlgWOLPageReply
  100. *
  101. * DESCRIPTION
  102. * Default constructor
  103. *
  104. * INPUTS
  105. * NONE
  106. *
  107. * RESULT
  108. * NONE
  109. *
  110. ******************************************************************************/
  111. DlgWOLPageReply::DlgWOLPageReply(void) :
  112. PopupDialogClass(IDD_MP_WOL_PAGE_REPLY),
  113. mBuddyMgr(NULL)
  114. {
  115. WWDEBUG_SAY(("DlgWOLPageReply Instantiated\n"));
  116. WWASSERT(_mInstance == NULL);
  117. _mInstance = this;
  118. }
  119. /******************************************************************************
  120. *
  121. * NAME
  122. * DlgWOLPageReply::~DlgWOLPageReply
  123. *
  124. * DESCRIPTION
  125. * Destructor
  126. *
  127. * INPUTS
  128. * NONE
  129. *
  130. * RESULT
  131. * NONE
  132. *
  133. ******************************************************************************/
  134. DlgWOLPageReply::~DlgWOLPageReply()
  135. {
  136. WWDEBUG_SAY(("DlgWOLPageReply Destroyed\n"));
  137. if (mBuddyMgr)
  138. {
  139. mBuddyMgr->Release_Ref();
  140. }
  141. _mInstance = NULL;
  142. }
  143. /******************************************************************************
  144. *
  145. * NAME
  146. * DlgWOLPageReply::FinalizeCreate
  147. *
  148. * DESCRIPTION
  149. * Post creation initialization.
  150. *
  151. * INPUTS
  152. * NONE
  153. *
  154. * RESULT
  155. * True if successful
  156. *
  157. ******************************************************************************/
  158. bool DlgWOLPageReply::FinalizeCreate(void)
  159. {
  160. mBuddyMgr = WOLBuddyMgr::GetInstance(false);
  161. return (mBuddyMgr != NULL);
  162. }
  163. /******************************************************************************
  164. *
  165. * NAME
  166. * DlgWOLPageReply::On_Init_Dialog
  167. *
  168. * DESCRIPTION
  169. * One time dialog initialization
  170. *
  171. * INPUTS
  172. * NONE
  173. *
  174. * RESULT
  175. * NONE
  176. *
  177. ******************************************************************************/
  178. void DlgWOLPageReply::On_Init_Dialog(void)
  179. {
  180. // Configure the list control that shows the page messages
  181. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_MESSAGE_LIST);
  182. if (list)
  183. {
  184. list->Add_Column(L"", 1.0F, Vector3(1, 1, 1));
  185. list->Allow_Selection(false);
  186. }
  187. // Enable the invite button if we are in a situation to invite users.
  188. bool canInvite = mBuddyMgr->CanInviteUsers();
  189. Enable_Dlg_Item(IDC_INVITE_BUDDY_BUTTON, canInvite);
  190. Observer<WOLPagedEvent>::NotifyMe(*mBuddyMgr);
  191. PopupDialogClass::On_Init_Dialog();
  192. }
  193. /******************************************************************************
  194. *
  195. * NAME
  196. * DlgWOLPageReply::On_Command
  197. *
  198. * DESCRIPTION
  199. * Handle commands from dialog controls
  200. *
  201. * INPUTS
  202. *
  203. * RESULT
  204. * NONE
  205. *
  206. ******************************************************************************/
  207. void DlgWOLPageReply::On_Command(int ctrlID, int message, DWORD param)
  208. {
  209. switch (ctrlID)
  210. {
  211. case IDC_ADD_BUDDY_BUTTON:
  212. {
  213. MPWolAddBuddyPopupClass* dialog = new MPWolAddBuddyPopupClass;
  214. if (dialog)
  215. {
  216. const WCHAR* pagersName = mBuddyMgr->GetLastPagersName();
  217. dialog->Set_Default_User_Name(pagersName);
  218. dialog->Start_Dialog();
  219. dialog->Release_Ref();
  220. }
  221. break;
  222. }
  223. case IDC_IGNORE_PLAYER_BUTTON:
  224. {
  225. const WCHAR* pagersName = mBuddyMgr->GetLastPagersName();
  226. MPWolAddIgnoreEntry::DoDialog(pagersName);
  227. }
  228. break;
  229. case IDC_INVITE_BUDDY_BUTTON:
  230. {
  231. const WCHAR* pagersName = mBuddyMgr->GetLastPagersName();
  232. mBuddyMgr->InviteUser(pagersName, Get_Dlg_Item_Text(IDC_REPLY_EDIT));
  233. End_Dialog();
  234. }
  235. break;
  236. case IDOK:
  237. case IDC_REPLY_BUTTON:
  238. Send_Reply();
  239. break;
  240. }
  241. PopupDialogClass::On_Command(ctrlID, message, param);
  242. }
  243. /******************************************************************************
  244. *
  245. * NAME
  246. * DlgWOLPageReply::Send_Reply
  247. *
  248. * DESCRIPTION
  249. * Send reply message to the last user who paged.
  250. *
  251. * INPUTS
  252. * NONE
  253. *
  254. * RESULT
  255. * NONE
  256. *
  257. ******************************************************************************/
  258. void DlgWOLPageReply::Send_Reply(void)
  259. {
  260. const WCHAR* pagersName = mBuddyMgr->GetLastPagersName();
  261. if (pagersName && (wcslen(pagersName) > 0))
  262. {
  263. WideStringClass reply(0, true);
  264. reply = Get_Dlg_Item_Text(IDC_REPLY_EDIT);
  265. reply.Trim();
  266. if (reply.Is_Empty() == false)
  267. {
  268. // Send the reply and clear the text
  269. mBuddyMgr->PageUser(pagersName, reply);
  270. // Add this message to the list
  271. WideStringClass name(0, true);
  272. WOLLogonMgr::GetLoginName(name);
  273. Add_Message(name, reply);
  274. }
  275. Set_Dlg_Item_Text(IDC_REPLY_EDIT, L"");
  276. }
  277. }
  278. /******************************************************************************
  279. *
  280. * NAME
  281. * DlgWOLPageReply::Add_Message
  282. *
  283. * DESCRIPTION
  284. * Add a message to the message display area.
  285. *
  286. * INPUTS
  287. * Username - Name of user message is from.
  288. * Message - Message text.
  289. *
  290. * RESULT
  291. * NONE
  292. *
  293. ******************************************************************************/
  294. void DlgWOLPageReply::Add_Message(const WCHAR* username, const WCHAR* message)
  295. {
  296. ListCtrlClass* list = (ListCtrlClass*)Get_Dlg_Item(IDC_MESSAGE_LIST);
  297. if (list)
  298. {
  299. // Build the message
  300. if (username) {
  301. WideStringClass text(255, true);
  302. text.Format(L"%s: %s", username, message);
  303. list->Insert_Entry(list->Get_Entry_Count(), text);
  304. } else {
  305. list->Insert_Entry(list->Get_Entry_Count(), message);
  306. }
  307. // Scroll to the end of the list
  308. list->Scroll_To_End();
  309. }
  310. }
  311. /******************************************************************************
  312. *
  313. * NAME
  314. * DlgWOLPageReply::HandleNotification(WOLPagedEvent)
  315. *
  316. * DESCRIPTION
  317. * Handle page message events.
  318. *
  319. * INPUTS
  320. * Event - Page event.
  321. *
  322. * RESULT
  323. * NONE
  324. *
  325. ******************************************************************************/
  326. void DlgWOLPageReply::HandleNotification(WOLPagedEvent& event)
  327. {
  328. WWOnline::PageMessage* page = event.Subject();
  329. WWASSERT(page && "NULL page in WOLPagedEvent");
  330. const WCHAR* pager = NULL;
  331. if (!ConsoleBox.Is_Exclusive())
  332. {
  333. if (PAGE_RECEIVED == event.GetAction())
  334. {
  335. pager = page->GetPagersName();
  336. }
  337. Add_Message(pager, page->GetPageMessage());
  338. }
  339. }
  340. /******************************************************************************
  341. *
  342. * NAME
  343. * DlgWOLPageReply::On_EditCtrl_Enter_Pressed
  344. *
  345. * DESCRIPTION
  346. * Handle enter key being pressed in edit control. Use this notification
  347. * to send the reply text automatically without requiring the user to click
  348. * the reply button.
  349. *
  350. * INPUTS
  351. *
  352. * RESULT
  353. * NONE
  354. *
  355. ******************************************************************************/
  356. void DlgWOLPageReply::On_EditCtrl_Enter_Pressed(EditCtrlClass* edit, int id)
  357. {
  358. if (IDC_REPLY_EDIT == id)
  359. {
  360. Send_Reply();
  361. }
  362. }