2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 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.
24 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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../../game/game.h"
33 #include "../../sys/win32/win_local.h"
34 #include "../../sys/win32/rc/common_resource.h"
35 #include "../../sys/win32/rc/PDAEditor_resource.h"
36 #include "../comafx/DialogName.h"
38 #include "DialogPDAEditor.h"
40 #ifdef ID_DEBUG_MEMORY
46 /////////////////////////////////////////////////////////////////////////////
47 // CCDialogPDAEditor dialog
48 CDialogPDAEditor *g_PDAEditorDialog = NULL;
51 CDialogPDAEditor::CDialogPDAEditor(CWnd* pParent /*=NULL*/)
52 : CDialog(CDialogPDAEditor::IDD, pParent)
54 //{{AFX_DATA_INIT(CDialogPDAEditor)
59 void CDialogPDAEditor::DoDataExchange(CDataExchange* pDX)
61 CDialog::DoDataExchange(pDX);
62 //{{AFX_DATA_MAP(CDialogPDAEditor)
63 DDX_Control( pDX, IDC_LIST_PDAS, pdaList );
64 DDX_Control( pDX, IDC_LIST_EMAIL, emailList );
65 DDX_Control( pDX, IDC_LIST_AUDIO, audioList );
66 DDX_Control( pDX, IDC_LIST_VIDEO, videoList );
68 DDX_Text( pDX, IDC_EDIT_FULLNAME, fullName );
69 DDX_Text( pDX, IDC_EDIT_SHORTNAME, shortName );
70 DDX_Text( pDX, IDC_EDIT_POST, post );
71 DDX_Text( pDX, IDC_EDIT_TITLE, title );
72 DDX_Text( pDX, IDC_EDIT_SECURITY, security );
73 DDX_Text( pDX, IDC_EDIT_IDNUM, idnum );
75 DDX_Control( pDX, IDC_BUTTON_SAVE, saveButton );
80 BEGIN_MESSAGE_MAP(CDialogPDAEditor, CDialog)
81 //{{AFX_MSG_MAP(CDialogPDAEditor)
82 ON_LBN_SELCHANGE( IDC_LIST_PDAS, OnSelChangePDA )
83 ON_BN_CLICKED( IDC_BUTTON_SAVE, OnBtnClickedSave )
84 ON_BN_CLICKED( IDC_BUTTON_RANDOMID, OnBtnClickedRandom )
85 ON_BN_CLICKED( IDC_BUTTON_PDA_ADD, OnBtnClickedPDAAdd )
86 ON_BN_CLICKED( IDC_BUTTON_PDA_DEL, OnBtnClickedPDADel )
87 ON_BN_CLICKED( IDC_BUTTON_EMAIL_ADD, OnBtnClickedEmailAdd )
88 ON_BN_CLICKED( IDC_BUTTON_EMAIL_EDIT, OnBtnClickedEmailEdit )
89 ON_BN_CLICKED( IDC_BUTTON_EMAIL_DELETE, OnBtnClickedEmailDel )
90 ON_BN_CLICKED( IDC_BUTTON_AUDIO_ADD, OnBtnClickedAudioAdd )
91 ON_BN_CLICKED( IDC_BUTTON_AUDIO_EDIT, OnBtnClickedAudioEdit )
92 ON_BN_CLICKED( IDC_BUTTON_AUDIO_DELETE, OnBtnClickedAudioDel )
93 ON_BN_CLICKED( IDC_BUTTON_VIDEO_ADD, OnBtnClickedVideoAdd )
94 ON_BN_CLICKED( IDC_BUTTON_VIDEO_EDIT, OnBtnClickedVideoEdit )
95 ON_BN_CLICKED( IDC_BUTTON_VIDEO_DELETE, OnBtnClickedVideoDel )
99 /////////////////////////////////////////////////////////////////////////////
100 // CDialogPDAEditor message handlers
102 void PDAEditorInit( const idDict *spawnArgs ) {
104 if ( renderSystem->IsFullScreen() ) {
105 common->Printf( "Cannot run the PDA editor in fullscreen mode.\n"
106 "Set r_fullscreen to 0 and vid_restart.\n" );
110 if ( g_PDAEditorDialog == NULL ) {
112 g_PDAEditorDialog = new CDialogPDAEditor();
115 if ( g_PDAEditorDialog->GetSafeHwnd() == NULL ) {
116 g_PDAEditorDialog->Create(IDD_DIALOG_PDA_EDITOR);
118 // FIXME: restore position
120 g_PDAEditorDialog->SetWindowPos( NULL, rct.left, rct.top, 0,0, SWP_NOSIZE );
124 idKeyInput::ClearStates();
126 g_PDAEditorDialog->ShowWindow( SW_SHOW );
127 g_PDAEditorDialog->SetFocus();
130 // select PDA based on spawn args
131 const char *name = spawnArgs->GetString( "pda" );
132 idDeclPDA *decl = static_cast<idDeclPDA *>( const_cast<idDecl *>( declManager->FindType( DECL_PDA, name ) ) );
133 // FIXME: select this PDA
137 void PDAEditorRun( void ) {
139 MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!!
141 MSG *msg = &m_msgCur;
144 while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
146 if ( !AfxGetApp()->PumpMessage() ) {
151 void PDAEditorShutdown( void ) {
152 delete g_PDAEditorDialog;
153 g_PDAEditorDialog = NULL;
156 void CDialogPDAEditor::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
157 CDialog::OnActivate( nState, pWndOther, bMinimized );
158 if ( nState != WA_INACTIVE ) {
162 void CDialogPDAEditor::OnMove( int x, int y ) {
163 if ( GetSafeHwnd() ) {
165 GetWindowRect( rct );
166 // FIXME: save position
168 CDialog::OnMove( x, y );
171 void CDialogPDAEditor::OnDestroy() {
173 com_editors &= ~EDITOR_PDA;
175 return CDialog::OnDestroy();
178 BOOL CDialogPDAEditor::OnInitDialog()
180 CDialog::OnInitDialog();
182 // Indicate the PDA dialog is opened
183 com_editors |= EDITOR_PDA;
187 return TRUE; // return TRUE unless you set the focus to a control
188 // EXCEPTION: OCX Property Pages should return FALSE
191 BOOL CDialogPDAEditor::PreTranslateMessage(MSG* pMsg)
193 return CDialog::PreTranslateMessage(pMsg);
196 void CDialogPDAEditor::PopulatePDAList()
198 pdaList.ResetContent();
201 int num = declManager->GetNumDecls(DECL_PDA);
202 for ( i=0; i < num; i++ ) {
203 const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, i) );
204 pdaList.AddString( pda->GetName() );
208 void CDialogPDAEditor::OnSelChangePDA()
212 int index = pdaList.GetCurSel();
217 const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
223 windowTitle.Format("PDA Editor - %s", pda->GetName());
225 idFile *file = fileSystem->OpenFileAppend( pda->GetFileName() );
227 fileSystem->CloseFile(file);
228 saveButton.EnableWindow( true );
230 windowTitle += " [Read Only]";
231 saveButton.EnableWindow( false );
234 SetWindowText( windowTitle );
236 emailList.ResetContent();
237 num = pda->GetNumEmails();
238 for ( i=0; i < num; i++ ) {
239 emailList.AddString( pda->GetEmailByIndex( i )->GetSubject() );
242 audioList.ResetContent();
243 num = pda->GetNumAudios();
244 for ( i=0; i < num; i++ ) {
245 audioList.AddString( pda->GetAudioByIndex( i )->GetAudioName() );
248 videoList.ResetContent();
249 num = pda->GetNumVideos();
250 for ( i=0; i < num; i++ ) {
251 videoList.AddString( pda->GetVideoByIndex( i )->GetVideoName() );
254 fullName = pda->GetFullName();
255 shortName = pda->GetPdaName();
256 post = pda->GetPost();
257 title = pda->GetTitle();
258 security = pda->GetSecurity();
259 idnum = pda->GetID();
264 void CDialogPDAEditor::OnBtnClickedSave()
268 int index = pdaList.GetCurSel();
273 const idDeclPDA *pdaConst = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
275 idDeclPDA *pda = const_cast<idDeclPDA *>(pdaConst);
277 CString declText = "\n";
279 declText += pda->GetName();
282 declText += "\tname \t\t\"" + shortName + "\"\n";
283 declText += "\tfullname\t\t\"" + fullName + "\"\n";
284 declText += "\ticon \t\t\"\"\n";
285 declText += "\tid \t\t\"" + idnum + "\"\n";
286 declText += "\tpost \t\t\"" + post + "\"\n";
287 declText += "\ttitle \t\t\"" + title + "\"\n";
288 declText += "\tsecurity\t\t\"" + security + "\"\n";
290 for ( int i = 0; i < pda->GetNumEmails(); i++ ) {
291 declText += "\tpda_email\t\t\"";
292 declText += pda->GetEmailByIndex(i)->GetName();
296 for ( int i = 0; i < pda->GetNumAudios(); i++ ) {
297 declText += "\tpda_audio\t\t\"";
298 declText += pda->GetAudioByIndex(i)->GetName();
302 for ( int i = 0; i < pda->GetNumVideos(); i++ ) {
303 declText += "\tpda_video\t\t\"";
304 declText += pda->GetVideoByIndex(i)->GetName();
310 pda->SetText( declText );
311 pda->ReplaceSourceFileText();
316 void CDialogPDAEditor::OnBtnClickedRandom()
318 idnum.Format("%d-%02X", 1000+(rand()%8999), (rand()%255));
322 class CDialogPDAAdd : public CDialog
325 CDialogPDAAdd() : CDialog(IDD_DIALOG_PDA_ADD) {}
327 void OnOK() { GetDlgItemText( IDC_EDIT1, name ); CDialog::OnOK(); }
330 void CDialogPDAEditor::OnBtnClickedPDAAdd()
333 if ( dlg.DoModal() == IDOK ) {
334 dlg.name.MakeLower();
335 idDecl *decl = declManager->CreateNewDecl( DECL_PDA, dlg.name, "newpdas/" + dlg.name + ".pda" );
336 decl->ReplaceSourceFileText();
339 pdaList.SelectString( 0, dlg.name );
344 void CDialogPDAEditor::OnBtnClickedPDADel()
348 void CDialogPDAEditor::OnBtnClickedEmailAdd()
350 int index = pdaList.GetCurSel();
354 const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
359 // Search for an unused name
360 int newIndex = pda->GetNumEmails();
362 name.Format("%s_email_%d", pda->GetName(), newIndex++);
363 } while ( declManager->FindType(DECL_EMAIL, name, false) != NULL );
365 CDialogPDAEditEmail addDlg;
366 addDlg.SetName(name);
367 if ( addDlg.DoModal() == IDOK ) {
368 idDeclEmail *email = static_cast<idDeclEmail *>(declManager->CreateNewDecl(DECL_EMAIL, name, pda->GetFileName()));
369 email->SetText( addDlg.GetDeclText() );
370 email->ReplaceSourceFileText();
373 pda->AddEmail( name );
375 // Get it again to reparse
376 const idDeclEmail *emailConst = static_cast<const idDeclEmail *>( declManager->FindType( DECL_EMAIL, name) );
377 emailList.AddString( emailConst->GetSubject() );
379 // Save the pda to include this email in the list
380 // This has a side-effect of saving any other changes, but I don't really care right now
386 void CDialogPDAEditor::OnBtnClickedEmailEdit()
388 int index = pdaList.GetCurSel();
392 const idDeclPDA *pda = dynamic_cast<const idDeclPDA *>( declManager->DeclByIndex(DECL_PDA, index) );
395 index = emailList.GetCurSel();
400 CDialogPDAEditEmail editDlg;
401 editDlg.SetEmail( pda->GetEmailByIndex( index ) );
402 if ( editDlg.DoModal() == IDOK ) {
403 idDeclEmail *email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );
404 email->SetText( editDlg.GetDeclText() );
405 email->ReplaceSourceFileText();
408 // Get it again to reparse
409 email = const_cast<idDeclEmail *>( pda->GetEmailByIndex( index ) );
411 emailList.DeleteString( index );
412 emailList.InsertString( index, email->GetSubject() );
417 void CDialogPDAEditor::OnBtnClickedEmailDel()
421 void CDialogPDAEditor::OnBtnClickedAudioAdd()
425 void CDialogPDAEditor::OnBtnClickedAudioEdit()
429 void CDialogPDAEditor::OnBtnClickedAudioDel()
433 void CDialogPDAEditor::OnBtnClickedVideoAdd()
437 void CDialogPDAEditor::OnBtnClickedVideoEdit()
441 void CDialogPDAEditor::OnBtnClickedVideoDel()
448 CDialogPDAEditEmail::CDialogPDAEditEmail(CWnd* pParent /*=NULL*/)
449 : CDialog(CDialogPDAEditEmail::IDD, pParent)
451 //{{AFX_DATA_INIT(CDialogPDAEditEmail)
456 void CDialogPDAEditEmail::DoDataExchange(CDataExchange* pDX)
458 CDialog::DoDataExchange(pDX);
459 //{{AFX_DATA_MAP(CDialogPDAEditEmail)
460 DDX_Text( pDX, IDC_EDIT_TO, to );
461 DDX_Text( pDX, IDC_EDIT_FROM, from );
462 DDX_Text( pDX, IDC_EDIT_DATE, date );
463 DDX_Text( pDX, IDC_EDIT_SUBJECT, subject );
464 DDX_Text( pDX, IDC_EDIT_BODY, body );
469 BEGIN_MESSAGE_MAP(CDialogPDAEditEmail, CDialog)
470 //{{AFX_MSG_MAP(CDialogPDAEditEmail)
474 /////////////////////////////////////////////////////////////////////////////
475 // CDialogPDAEditor message handlers
477 BOOL CDialogPDAEditEmail::OnInitDialog()
479 CDialog::OnInitDialog();
481 SetWindowText( "Editing Email: " + name );
483 return TRUE; // return TRUE unless you set the focus to a control
484 // EXCEPTION: OCX Property Pages should return FALSE
487 void CDialogPDAEditEmail::SetName( CString &_name )
492 void CDialogPDAEditEmail::SetEmail( const idDeclEmail *email )
495 from = email->GetFrom();
496 date = email->GetDate();
497 subject = email->GetSubject();
498 body = email->GetBody();
499 body.Replace("\n", "\r\n");
501 name = email->GetName();
503 if ( IsWindow( m_hWnd ) ) {
508 CString CDialogPDAEditEmail::GetDeclText()
510 CString mungedBody = body;
511 mungedBody.Replace("\r\n\r\n", "\\n\\n\"\n\n\"");
512 mungedBody.Replace("\r\n", "\\n\"\n\"");
516 declText += "email " + name + " {\n";
517 declText += "\tto \t\t\"" + to + "\"\n";
518 declText += "\tfrom \t\t\"" + from + "\"\n";
519 declText += "\tdate \t\t\"" + date + "\"\n";
520 declText += "\tsubject\t\t\"" + subject + "\"\n";
521 declText += "\ttext {\n";
522 declText += "\"" + mungedBody + "\"\n";