DialogPDAEditor.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "../../game/game.h"
  23. #include "../../sys/win32/win_local.h"
  24. #include "../../sys/win32/rc/common_resource.h"
  25. #include "../../sys/win32/rc/PDAEditor_resource.h"
  26. #include "../comafx/DialogName.h"
  27. #include "DialogPDAEditor.h"
  28. #ifdef ID_DEBUG_MEMORY
  29. #undef new
  30. #undef DEBUG_NEW
  31. #define DEBUG_NEW new
  32. #endif
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CCDialogPDAEditor dialog
  35. CDialogPDAEditor *g_PDAEditorDialog = NULL;
  36. CDialogPDAEditor::CDialogPDAEditor(CWnd* pParent /*=NULL*/)
  37. : CDialog(CDialogPDAEditor::IDD, pParent)
  38. {
  39. //{{AFX_DATA_INIT(CDialogPDAEditor)
  40. //}}AFX_DATA_INIT
  41. }
  42. void CDialogPDAEditor::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CDialogPDAEditor)
  46. DDX_Control( pDX, IDC_LIST_PDAS, pdaList );
  47. DDX_Control( pDX, IDC_LIST_EMAIL, emailList );
  48. DDX_Control( pDX, IDC_LIST_AUDIO, audioList );
  49. DDX_Control( pDX, IDC_LIST_VIDEO, videoList );
  50. DDX_Text( pDX, IDC_EDIT_FULLNAME, fullName );
  51. DDX_Text( pDX, IDC_EDIT_SHORTNAME, shortName );
  52. DDX_Text( pDX, IDC_EDIT_POST, post );
  53. DDX_Text( pDX, IDC_EDIT_TITLE, title );
  54. DDX_Text( pDX, IDC_EDIT_SECURITY, security );
  55. DDX_Text( pDX, IDC_EDIT_IDNUM, idnum );
  56. DDX_Control( pDX, IDC_BUTTON_SAVE, saveButton );
  57. //}}AFX_DATA_MAP
  58. }
  59. BEGIN_MESSAGE_MAP(CDialogPDAEditor, CDialog)
  60. //{{AFX_MSG_MAP(CDialogPDAEditor)
  61. ON_LBN_SELCHANGE( IDC_LIST_PDAS, OnSelChangePDA )
  62. ON_BN_CLICKED( IDC_BUTTON_SAVE, OnBtnClickedSave )
  63. ON_BN_CLICKED( IDC_BUTTON_RANDOMID, OnBtnClickedRandom )
  64. ON_BN_CLICKED( IDC_BUTTON_PDA_ADD, OnBtnClickedPDAAdd )
  65. ON_BN_CLICKED( IDC_BUTTON_PDA_DEL, OnBtnClickedPDADel )
  66. ON_BN_CLICKED( IDC_BUTTON_EMAIL_ADD, OnBtnClickedEmailAdd )
  67. ON_BN_CLICKED( IDC_BUTTON_EMAIL_EDIT, OnBtnClickedEmailEdit )
  68. ON_BN_CLICKED( IDC_BUTTON_EMAIL_DELETE, OnBtnClickedEmailDel )
  69. ON_BN_CLICKED( IDC_BUTTON_AUDIO_ADD, OnBtnClickedAudioAdd )
  70. ON_BN_CLICKED( IDC_BUTTON_AUDIO_EDIT, OnBtnClickedAudioEdit )
  71. ON_BN_CLICKED( IDC_BUTTON_AUDIO_DELETE, OnBtnClickedAudioDel )
  72. ON_BN_CLICKED( IDC_BUTTON_VIDEO_ADD, OnBtnClickedVideoAdd )
  73. ON_BN_CLICKED( IDC_BUTTON_VIDEO_EDIT, OnBtnClickedVideoEdit )
  74. ON_BN_CLICKED( IDC_BUTTON_VIDEO_DELETE, OnBtnClickedVideoDel )
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CDialogPDAEditor message handlers
  79. void PDAEditorInit( const idDict *spawnArgs ) {
  80. if ( renderSystem->IsFullScreen() ) {
  81. common->Printf( "Cannot run the PDA editor in fullscreen mode.\n"
  82. "Set r_fullscreen to 0 and vid_restart.\n" );
  83. return;
  84. }
  85. if ( g_PDAEditorDialog == NULL ) {
  86. InitAfx();
  87. g_PDAEditorDialog = new CDialogPDAEditor();
  88. }
  89. if ( g_PDAEditorDialog->GetSafeHwnd() == NULL ) {
  90. g_PDAEditorDialog->Create(IDD_DIALOG_PDA_EDITOR);
  91. /*
  92. // FIXME: restore position
  93. CRect rct;
  94. g_PDAEditorDialog->SetWindowPos( NULL, rct.left, rct.top, 0,0, SWP_NOSIZE );
  95. */
  96. }
  97. idKeyInput::ClearStates();
  98. g_PDAEditorDialog->ShowWindow( SW_SHOW );
  99. g_PDAEditorDialog->SetFocus();
  100. if ( spawnArgs ) {
  101. // select PDA based on spawn args
  102. const char *name = spawnArgs->GetString( "pda" );
  103. idDeclPDA *decl = static_cast<idDeclPDA *>( const_cast<idDecl *>( declManager->FindType( DECL_PDA, name ) ) );
  104. // FIXME: select this PDA
  105. }
  106. }
  107. void PDAEditorRun( void ) {
  108. #if _MSC_VER >= 1300
  109. MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!!
  110. #else
  111. MSG *msg = &m_msgCur;
  112. #endif
  113. while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
  114. // pump message
  115. if ( !AfxGetApp()->PumpMessage() ) {
  116. }
  117. }
  118. }
  119. void PDAEditorShutdown( void ) {
  120. delete g_PDAEditorDialog;
  121. g_PDAEditorDialog = NULL;
  122. }
  123. void CDialogPDAEditor::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
  124. CDialog::OnActivate( nState, pWndOther, bMinimized );
  125. if ( nState != WA_INACTIVE ) {
  126. }
  127. }
  128. void CDialogPDAEditor::OnMove( int x, int y ) {
  129. if ( GetSafeHwnd() ) {
  130. CRect rct;
  131. GetWindowRect( rct );
  132. // FIXME: save position
  133. }
  134. CDialog::OnMove( x, y );
  135. }
  136. void CDialogPDAEditor::OnDestroy() {
  137. com_editors &= ~EDITOR_PDA;
  138. return CDialog::OnDestroy();
  139. }
  140. BOOL CDialogPDAEditor::OnInitDialog()
  141. {
  142. CDialog::OnInitDialog();
  143. // Indicate the PDA dialog is opened
  144. com_editors |= EDITOR_PDA;
  145. PopulatePDAList();
  146. return TRUE; // return TRUE unless you set the focus to a control
  147. // EXCEPTION: OCX Property Pages should return FALSE
  148. }
  149. BOOL CDialogPDAEditor::PreTranslateMessage(MSG* pMsg)
  150. {
  151. return CDialog::PreTranslateMessage(pMsg);
  152. }
  153. void CDialogPDAEditor::PopulatePDAList()
  154. {
  155. pdaList.ResetContent();
  156. int i;
  157. int num = declManager->GetNumDecls(DECL_PDA);
  158. for ( i=0; i < num; i++ ) {
  159. const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, i) );
  160. pdaList.AddString( pda->GetName() );
  161. }
  162. }
  163. void CDialogPDAEditor::OnSelChangePDA()
  164. {
  165. int i, num;
  166. int index = pdaList.GetCurSel();
  167. if ( index < 0 ) {
  168. return;
  169. }
  170. const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
  171. if ( !pda ) {
  172. return;
  173. }
  174. CString windowTitle;
  175. windowTitle.Format("PDA Editor - %s", pda->GetName());
  176. idFile *file = fileSystem->OpenFileAppend( pda->GetFileName() );
  177. if ( file ) {
  178. fileSystem->CloseFile(file);
  179. saveButton.EnableWindow( true );
  180. } else {
  181. windowTitle += " [Read Only]";
  182. saveButton.EnableWindow( false );
  183. }
  184. SetWindowText( windowTitle );
  185. emailList.ResetContent();
  186. num = pda->GetNumEmails();
  187. for ( i=0; i < num; i++ ) {
  188. emailList.AddString( pda->GetEmailByIndex( i )->GetSubject() );
  189. }
  190. audioList.ResetContent();
  191. num = pda->GetNumAudios();
  192. for ( i=0; i < num; i++ ) {
  193. audioList.AddString( pda->GetAudioByIndex( i )->GetAudioName() );
  194. }
  195. videoList.ResetContent();
  196. num = pda->GetNumVideos();
  197. for ( i=0; i < num; i++ ) {
  198. videoList.AddString( pda->GetVideoByIndex( i )->GetVideoName() );
  199. }
  200. fullName = pda->GetFullName();
  201. shortName = pda->GetPdaName();
  202. post = pda->GetPost();
  203. title = pda->GetTitle();
  204. security = pda->GetSecurity();
  205. idnum = pda->GetID();
  206. UpdateData( FALSE );
  207. }
  208. void CDialogPDAEditor::OnBtnClickedSave()
  209. {
  210. UpdateData();
  211. int index = pdaList.GetCurSel();
  212. if ( index < 0 ) {
  213. return;
  214. }
  215. const idDeclPDA *pdaConst = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
  216. if ( pdaConst ) {
  217. idDeclPDA *pda = const_cast<idDeclPDA *>(pdaConst);
  218. CString declText = "\n";
  219. declText += "pda ";
  220. declText += pda->GetName();
  221. declText += " {\n";
  222. declText += "\tname \t\t\"" + shortName + "\"\n";
  223. declText += "\tfullname\t\t\"" + fullName + "\"\n";
  224. declText += "\ticon \t\t\"\"\n";
  225. declText += "\tid \t\t\"" + idnum + "\"\n";
  226. declText += "\tpost \t\t\"" + post + "\"\n";
  227. declText += "\ttitle \t\t\"" + title + "\"\n";
  228. declText += "\tsecurity\t\t\"" + security + "\"\n";
  229. for ( int i = 0; i < pda->GetNumEmails(); i++ ) {
  230. declText += "\tpda_email\t\t\"";
  231. declText += pda->GetEmailByIndex(i)->GetName();
  232. declText += "\"\n";
  233. }
  234. for ( int i = 0; i < pda->GetNumAudios(); i++ ) {
  235. declText += "\tpda_audio\t\t\"";
  236. declText += pda->GetAudioByIndex(i)->GetName();
  237. declText += "\"\n";
  238. }
  239. for ( int i = 0; i < pda->GetNumVideos(); i++ ) {
  240. declText += "\tpda_video\t\t\"";
  241. declText += pda->GetVideoByIndex(i)->GetName();
  242. declText += "\"\n";
  243. }
  244. declText += "}";
  245. pda->SetText( declText );
  246. pda->ReplaceSourceFileText();
  247. pda->Invalidate();
  248. }
  249. }
  250. void CDialogPDAEditor::OnBtnClickedRandom()
  251. {
  252. idnum.Format("%d-%02X", 1000+(rand()%8999), (rand()%255));
  253. UpdateData( FALSE );
  254. }
  255. class CDialogPDAAdd : public CDialog
  256. {
  257. public:
  258. CDialogPDAAdd() : CDialog(IDD_DIALOG_PDA_ADD) {}
  259. CString name;
  260. void OnOK() { GetDlgItemText( IDC_EDIT1, name ); CDialog::OnOK(); }
  261. };
  262. void CDialogPDAEditor::OnBtnClickedPDAAdd()
  263. {
  264. CDialogPDAAdd dlg;
  265. if ( dlg.DoModal() == IDOK ) {
  266. dlg.name.MakeLower();
  267. idDecl *decl = declManager->CreateNewDecl( DECL_PDA, dlg.name, "newpdas/" + dlg.name + ".pda" );
  268. decl->ReplaceSourceFileText();
  269. decl->Invalidate();
  270. PopulatePDAList();
  271. pdaList.SelectString( 0, dlg.name );
  272. OnSelChangePDA();
  273. }
  274. }
  275. void CDialogPDAEditor::OnBtnClickedPDADel()
  276. {
  277. }
  278. void CDialogPDAEditor::OnBtnClickedEmailAdd()
  279. {
  280. int index = pdaList.GetCurSel();
  281. if ( index < 0 ) {
  282. return;
  283. }
  284. const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
  285. if ( pda ) {
  286. CString name;
  287. // Search for an unused name
  288. int newIndex = pda->GetNumEmails();
  289. do {
  290. name.Format("%s_email_%d", pda->GetName(), newIndex++);
  291. } while ( declManager->FindType(DECL_EMAIL, name, false) != NULL );
  292. CDialogPDAEditEmail addDlg;
  293. addDlg.SetName(name);
  294. if ( addDlg.DoModal() == IDOK ) {
  295. idDeclEmail *email = static_cast<idDeclEmail *>(declManager->CreateNewDecl(DECL_EMAIL, name, pda->GetFileName()));
  296. email->SetText( addDlg.GetDeclText() );
  297. email->ReplaceSourceFileText();
  298. email->Invalidate();
  299. pda->AddEmail( name );
  300. // Get it again to reparse
  301. const idDeclEmail *emailConst = static_cast<const idDeclEmail *>( declManager->FindType( DECL_EMAIL, name) );
  302. emailList.AddString( emailConst->GetSubject() );
  303. // Save the pda to include this email in the list
  304. // This has a side-effect of saving any other changes, but I don't really care right now
  305. OnBtnClickedSave();
  306. }
  307. }
  308. }
  309. void CDialogPDAEditor::OnBtnClickedEmailEdit()
  310. {
  311. int index = pdaList.GetCurSel();
  312. if ( index < 0 ) {
  313. return;
  314. }
  315. const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
  316. if ( pda ) {
  317. index = emailList.GetCurSel();
  318. if ( index < 0 ) {
  319. return;
  320. }
  321. CDialogPDAEditEmail editDlg;
  322. editDlg.SetEmail( pda->GetEmailByIndex( index ) );
  323. if ( editDlg.DoModal() == IDOK ) {
  324. idDeclEmail *email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );
  325. email->SetText( editDlg.GetDeclText() );
  326. email->ReplaceSourceFileText();
  327. email->Invalidate();
  328. // Get it again to reparse
  329. email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );
  330. emailList.DeleteString( index );
  331. emailList.InsertString( index, email->GetSubject() );
  332. }
  333. }
  334. }
  335. void CDialogPDAEditor::OnBtnClickedEmailDel()
  336. {
  337. }
  338. void CDialogPDAEditor::OnBtnClickedAudioAdd()
  339. {
  340. }
  341. void CDialogPDAEditor::OnBtnClickedAudioEdit()
  342. {
  343. }
  344. void CDialogPDAEditor::OnBtnClickedAudioDel()
  345. {
  346. }
  347. void CDialogPDAEditor::OnBtnClickedVideoAdd()
  348. {
  349. }
  350. void CDialogPDAEditor::OnBtnClickedVideoEdit()
  351. {
  352. }
  353. void CDialogPDAEditor::OnBtnClickedVideoDel()
  354. {
  355. }
  356. CDialogPDAEditEmail::CDialogPDAEditEmail(CWnd* pParent /*=NULL*/)
  357. : CDialog(CDialogPDAEditEmail::IDD, pParent)
  358. {
  359. //{{AFX_DATA_INIT(CDialogPDAEditEmail)
  360. //}}AFX_DATA_INIT
  361. }
  362. void CDialogPDAEditEmail::DoDataExchange(CDataExchange* pDX)
  363. {
  364. CDialog::DoDataExchange(pDX);
  365. //{{AFX_DATA_MAP(CDialogPDAEditEmail)
  366. DDX_Text( pDX, IDC_EDIT_TO, to );
  367. DDX_Text( pDX, IDC_EDIT_FROM, from );
  368. DDX_Text( pDX, IDC_EDIT_DATE, date );
  369. DDX_Text( pDX, IDC_EDIT_SUBJECT, subject );
  370. DDX_Text( pDX, IDC_EDIT_BODY, body );
  371. //}}AFX_DATA_MAP
  372. }
  373. BEGIN_MESSAGE_MAP(CDialogPDAEditEmail, CDialog)
  374. //{{AFX_MSG_MAP(CDialogPDAEditEmail)
  375. //}}AFX_MSG_MAP
  376. END_MESSAGE_MAP()
  377. /////////////////////////////////////////////////////////////////////////////
  378. // CDialogPDAEditor message handlers
  379. BOOL CDialogPDAEditEmail::OnInitDialog()
  380. {
  381. CDialog::OnInitDialog();
  382. SetWindowText( "Editing Email: " + name );
  383. return TRUE; // return TRUE unless you set the focus to a control
  384. // EXCEPTION: OCX Property Pages should return FALSE
  385. }
  386. void CDialogPDAEditEmail::SetName( CString &_name )
  387. {
  388. name = _name;
  389. }
  390. void CDialogPDAEditEmail::SetEmail( const idDeclEmail *email )
  391. {
  392. to = email->GetTo();
  393. from = email->GetFrom();
  394. date = email->GetDate();
  395. subject = email->GetSubject();
  396. body = email->GetBody();
  397. body.Replace("\n", "\r\n");
  398. name = email->GetName();
  399. if ( IsWindow( m_hWnd ) ) {
  400. UpdateData(FALSE);
  401. }
  402. }
  403. CString CDialogPDAEditEmail::GetDeclText()
  404. {
  405. CString mungedBody = body;
  406. mungedBody.Replace("\r\n\r\n", "\\n\\n\"\n\n\"");
  407. mungedBody.Replace("\r\n", "\\n\"\n\"");
  408. CString declText;
  409. declText += "\n";
  410. declText += "email " + name + " {\n";
  411. declText += "\tto \t\t\"" + to + "\"\n";
  412. declText += "\tfrom \t\t\"" + from + "\"\n";
  413. declText += "\tdate \t\t\"" + date + "\"\n";
  414. declText += "\tsubject\t\t\"" + subject + "\"\n";
  415. declText += "\ttext {\n";
  416. declText += "\"" + mungedBody + "\"\n";
  417. declText += "\t}\n";
  418. declText += "}";
  419. return declText;
  420. }