/[pcsx2_0.9.7]/trunk/pcsx2/gui/MainMenuClicks.cpp
ViewVC logotype

Contents of /trunk/pcsx2/gui/MainMenuClicks.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 15615 byte(s)
re-commit (had local access denied errors when committing)
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17
18 #include "CDVD/CDVD.h"
19 #include "GS.h"
20
21 #include "MainFrame.h"
22 #include "IsoDropTarget.h"
23
24 #include "Dialogs/ModalPopups.h"
25 #include "Dialogs/ConfigurationDialog.h"
26 #include "Dialogs/LogOptionsDialog.h"
27
28 #include "Utilities/IniInterface.h"
29
30 using namespace Dialogs;
31
32 void MainEmuFrame::SaveEmuOptions()
33 {
34 if (wxConfigBase* conf = GetAppConfig())
35 {
36 IniSaver saver(*conf);
37 g_Conf->EmuOptions.LoadSave(saver);
38 }
39 }
40
41 void MainEmuFrame::Menu_SysSettings_Click(wxCommandEvent &event)
42 {
43 AppOpenDialog<SysConfigDialog>( this );
44 }
45
46 void MainEmuFrame::Menu_McdSettings_Click(wxCommandEvent &event)
47 {
48 AppOpenDialog<McdConfigDialog>( this );
49 }
50
51 void MainEmuFrame::Menu_GameDatabase_Click(wxCommandEvent &event)
52 {
53 AppOpenDialog<GameDatabaseDialog>( this );
54 }
55
56 void MainEmuFrame::Menu_WindowSettings_Click(wxCommandEvent &event)
57 {
58 wxCommandEvent evt( pxEvt_SetSettingsPage );
59 evt.SetString( L"GS Window" );
60 AppOpenDialog<SysConfigDialog>( this )->GetEventHandler()->ProcessEvent( evt );
61 }
62
63 void MainEmuFrame::Menu_GSSettings_Click(wxCommandEvent &event)
64 {
65 wxCommandEvent evt( pxEvt_SetSettingsPage );
66 evt.SetString( L"GS" );
67 AppOpenDialog<SysConfigDialog>( this )->GetEventHandler()->ProcessEvent( evt );
68 }
69
70 void MainEmuFrame::Menu_SelectPluginsBios_Click(wxCommandEvent &event)
71 {
72 AppOpenDialog<ComponentsConfigDialog>( this );
73 }
74
75 void MainEmuFrame::Menu_Language_Click(wxCommandEvent &event)
76 {
77 //AppOpenDialog<InterfaceConfigDialog>( this );
78 InterfaceConfigDialog(this).ShowModal();
79 }
80
81 static void WipeSettings()
82 {
83 wxGetApp().CleanupRestartable();
84 wxGetApp().CleanupResources();
85
86 wxRemoveFile( GetSettingsFilename() );
87
88 // FIXME: wxRmdir doesn't seem to work here for some reason (possible file sharing issue
89 // with a plugin that leaves a file handle dangling maybe?). But deleting the inis folder
90 // manually from explorer does work. Can't think of a good work-around at the moment. --air
91
92 //wxRmdir( GetSettingsFolder().ToString() );
93
94 wxGetApp().GetRecentIsoManager().Clear();
95 g_Conf = new AppConfig();
96 sMainFrame.RemoveCdvdMenu();
97 }
98
99 void MainEmuFrame::RemoveCdvdMenu()
100 {
101 if( wxMenuItem* item = m_menuCDVD.FindItem(MenuId_IsoSelector) )
102 m_menuCDVD.Remove( item );
103 }
104
105 void MainEmuFrame::Menu_ResetAllSettings_Click(wxCommandEvent &event)
106 {
107 if( IsBeingDeleted() || m_RestartEmuOnDelete ) return;
108
109 {
110 ScopedCoreThreadPopup suspender;
111 if( !Msgbox::OkCancel( pxsFmt(
112 pxE( "!Notice:DeleteSettings",
113 L"This command clears %s settings and allows you to re-run the First-Time Wizard. You will need to "
114 L"manually restart %s after this operation.\n\n"
115 L"WARNING!! Click OK to delete *ALL* settings for %s and force-close the app, losing any current emulation progress. Are you absolutely sure?"
116 L"\n\n(note: settings for plugins are unaffected)"
117 ), pxGetAppName().c_str(), pxGetAppName().c_str(), pxGetAppName().c_str() ),
118 _("Reset all settings?") ) )
119 {
120 suspender.AllowResume();
121 return;
122 }
123 }
124
125 WipeSettings();
126 wxGetApp().PostMenuAction( MenuId_Exit );
127 }
128
129 // Return values:
130 // wxID_CANCEL - User canceled the action outright.
131 // wxID_RESET - User wants to reset the emu in addition to swap discs
132 // (anything else) - Standard swap, no reset. (hotswap!)
133 wxWindowID SwapOrReset_Iso( wxWindow* owner, IScopedCoreThread& core_control, const wxString& isoFilename, const wxString& descpart1 )
134 {
135 wxWindowID result = wxID_CANCEL;
136
137 if( (g_Conf->CdvdSource == CDVDsrc_Iso) && (isoFilename == g_Conf->CurrentIso) )
138 {
139 core_control.AllowResume();
140 return result;
141 }
142
143 if( SysHasValidState() )
144 {
145 core_control.DisallowResume();
146 wxDialogWithHelpers dialog( owner, _("Confirm ISO image change") );
147
148 dialog += dialog.Heading(descpart1);
149 dialog += dialog.GetCharHeight();
150 dialog += dialog.Text(isoFilename);
151 dialog += dialog.GetCharHeight();
152 dialog += dialog.Heading(_("Do you want to swap discs or boot the new image (via system reset)?"));
153
154 result = pxIssueConfirmation( dialog, MsgButtons().Reset().Cancel().Custom(_("Swap Disc"), "swap"), L"DragDrop.BootSwapIso" );
155 if( result == wxID_CANCEL )
156 {
157 core_control.AllowResume();
158 return result;
159 }
160 }
161
162 SysUpdateIsoSrcFile( isoFilename );
163 if( result == wxID_RESET )
164 {
165 core_control.DisallowResume();
166 sApp.SysExecute( CDVDsrc_Iso );
167 }
168 else
169 {
170 Console.Indent().WriteLn( "HotSwapping to new ISO src image!" );
171 g_Conf->CdvdSource = CDVDsrc_Iso;
172 //CoreThread.ChangeCdvdSource();
173 core_control.AllowResume();
174 }
175
176 return result;
177 }
178
179 wxWindowID SwapOrReset_CdvdSrc( wxWindow* owner, CDVD_SourceType newsrc )
180 {
181 if(newsrc == g_Conf->CdvdSource) return wxID_CANCEL;
182 wxWindowID result = wxID_CANCEL;
183 ScopedCoreThreadPopup core;
184
185 if( SysHasValidState() )
186 {
187 wxDialogWithHelpers dialog( owner, _("Confirm CDVD source change") );
188
189 wxString changeMsg;
190 changeMsg.Printf(_("You've selected to switch the CDVD source from %s to %s."),
191 CDVD_SourceLabels[g_Conf->CdvdSource], CDVD_SourceLabels[newsrc] );
192
193 dialog += dialog.Heading(changeMsg + L"\n\n" +
194 _("Do you want to swap discs or boot the new image (system reset)?")
195 );
196
197 result = pxIssueConfirmation( dialog, MsgButtons().Reset().Cancel().Custom(_("Swap Disc"), "swap"), L"DragDrop.BootSwapIso" );
198
199 if( result == wxID_CANCEL )
200 {
201 core.AllowResume();
202 sMainFrame.UpdateIsoSrcSelection();
203 return result;
204 }
205 }
206
207 CDVD_SourceType oldsrc = g_Conf->CdvdSource;
208 g_Conf->CdvdSource = newsrc;
209
210 if( result != wxID_RESET )
211 {
212 Console.Indent().WriteLn( L"(CdvdSource) HotSwapping CDVD source types from %s to %s.", CDVD_SourceLabels[oldsrc], CDVD_SourceLabels[newsrc] );
213 //CoreThread.ChangeCdvdSource();
214 sMainFrame.UpdateIsoSrcSelection();
215 core.AllowResume();
216 }
217 else
218 {
219 core.DisallowResume();
220 sApp.SysExecute( g_Conf->CdvdSource );
221 }
222
223 return result;
224 }
225
226 static wxString JoinFiletypes( const wxChar** src )
227 {
228 wxString dest;
229 while( *src != NULL )
230 {
231 if( *src[0] == 0 ) continue;
232 if( !dest.IsEmpty() )
233 dest += L";";
234
235 dest += pxsFmt(L"*.%s", *src);
236
237 if (wxFileName::IsCaseSensitive())
238 {
239 // omgosh! the filesystem is CaSE SeNSiTiVE!!
240 dest += pxsFmt(L";*.%s", *src).ToUpper();
241 }
242
243 ++src;
244 }
245
246 return dest;
247 }
248
249 // Returns FALSE if the user canceled the action.
250 bool MainEmuFrame::_DoSelectIsoBrowser( wxString& result )
251 {
252 static const wxChar* isoSupportedTypes[] =
253 {
254 L"iso", L"mdf", L"nrg", L"bin", L"img", NULL
255 };
256
257 const wxString isoSupportedLabel( JoinString(isoSupportedTypes, L" ") );
258 const wxString isoSupportedList( JoinFiletypes(isoSupportedTypes) );
259
260 wxArrayString isoFilterTypes;
261
262 isoFilterTypes.Add(pxsFmt(_("All Supported (%s)"), (isoSupportedLabel + L" .dump").c_str()));
263 isoFilterTypes.Add(isoSupportedList + L";*.dump");
264
265 isoFilterTypes.Add(pxsFmt(_("Disc Images (%s)"), isoSupportedLabel.c_str() ));
266 isoFilterTypes.Add(isoSupportedList);
267
268 isoFilterTypes.Add(pxsFmt(_("Blockdumps (%s)"), L".dump" ));
269 isoFilterTypes.Add(L"*.dump");
270
271 isoFilterTypes.Add(_("All Files (*.*)"));
272 isoFilterTypes.Add(L"*.*");
273
274 wxFileDialog ctrl( this, _("Select CDVD source iso..."), g_Conf->Folders.RunIso.ToString(), wxEmptyString,
275 JoinString(isoFilterTypes, L"|"), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
276
277 if( ctrl.ShowModal() != wxID_CANCEL )
278 {
279 result = ctrl.GetPath();
280 g_Conf->Folders.RunIso = wxFileName( result ).GetPath();
281 return true;
282 }
283
284 return false;
285 }
286
287 bool MainEmuFrame::_DoSelectELFBrowser()
288 {
289 static const wxChar* elfFilterType = L"ELF Files (.elf)|*.elf;*.ELF";
290
291 wxFileDialog ctrl( this, _("Select ELF file..."), g_Conf->Folders.RunELF.ToString(), wxEmptyString,
292 (wxString)elfFilterType + L"|" + _("All Files (*.*)") + L"|*.*", wxFD_OPEN | wxFD_FILE_MUST_EXIST );
293
294 if( ctrl.ShowModal() != wxID_CANCEL )
295 {
296 g_Conf->Folders.RunELF = wxFileName( ctrl.GetPath() ).GetPath();
297 g_Conf->CurrentELF = ctrl.GetPath();
298 return true;
299 }
300
301 return false;
302 }
303
304 void MainEmuFrame::_DoBootCdvd()
305 {
306 ScopedCoreThreadPause paused_core;
307
308 if( g_Conf->CdvdSource == CDVDsrc_Iso )
309 {
310 bool selector = g_Conf->CurrentIso.IsEmpty();
311
312 if( !selector && !wxFileExists(g_Conf->CurrentIso) )
313 {
314 // User has an iso selected from a previous run, but it doesn't exist anymore.
315 // Issue a courtesy popup and then an Iso Selector to choose a new one.
316
317 wxDialogWithHelpers dialog( this, _("ISO file not found!") );
318 dialog += dialog.Heading(
319 _("An error occurred while trying to open the file:\n\n") + g_Conf->CurrentIso + L"\n\n" +
320 _("Error: The configured ISO file does not exist. Click OK to select a new ISO source for CDVD.")
321 );
322
323 pxIssueConfirmation( dialog, MsgButtons().OK() );
324
325 selector = true;
326 }
327
328 if( selector )
329 {
330 wxString result;
331 if( !_DoSelectIsoBrowser( result ) )
332 {
333 paused_core.AllowResume();
334 return;
335 }
336
337 SysUpdateIsoSrcFile( result );
338 }
339 }
340
341 if( SysHasValidState() )
342 {
343 wxDialogWithHelpers dialog( this, _("Confirm PS2 Reset") );
344 dialog += dialog.Heading( GetMsg_ConfirmSysReset() );
345 bool confirmed = (pxIssueConfirmation( dialog, MsgButtons().Yes().Cancel(), L"BootCdvd.ConfirmReset" ) != wxID_CANCEL);
346
347 if( !confirmed )
348 {
349 paused_core.AllowResume();
350 return;
351 }
352 }
353
354 sApp.SysExecute( g_Conf->CdvdSource );
355 }
356
357 void MainEmuFrame::Menu_CdvdSource_Click( wxCommandEvent &event )
358 {
359 CDVD_SourceType newsrc = CDVDsrc_NoDisc;
360
361 switch( event.GetId() )
362 {
363 case MenuId_Src_Iso: newsrc = CDVDsrc_Iso; break;
364 case MenuId_Src_Plugin: newsrc = CDVDsrc_Plugin; break;
365 case MenuId_Src_NoDisc: newsrc = CDVDsrc_NoDisc; break;
366 jNO_DEFAULT
367 }
368
369 SwapOrReset_CdvdSrc(this, newsrc);
370 }
371
372 void MainEmuFrame::Menu_BootCdvd_Click( wxCommandEvent &event )
373 {
374 g_Conf->EmuOptions.UseBOOT2Injection = false;
375 _DoBootCdvd();
376 }
377
378 void MainEmuFrame::Menu_BootCdvd2_Click( wxCommandEvent &event )
379 {
380 g_Conf->EmuOptions.UseBOOT2Injection = true;
381 _DoBootCdvd();
382 }
383
384 wxString GetMsg_IsoImageChanged()
385 {
386 return _("You have selected the following ISO image into PCSX2:\n\n");
387 }
388
389 void MainEmuFrame::Menu_IsoBrowse_Click( wxCommandEvent &event )
390 {
391 ScopedCoreThreadPopup core;
392 wxString isofile;
393
394 if( !_DoSelectIsoBrowser(isofile) )
395 {
396 core.AllowResume();
397 return;
398 }
399
400 SwapOrReset_Iso(this, core, isofile, GetMsg_IsoImageChanged());
401 AppSaveSettings(); // save the new iso selection; update menus!
402 }
403
404 void MainEmuFrame::Menu_MultitapToggle_Click( wxCommandEvent& )
405 {
406 g_Conf->EmuOptions.MultitapPort0_Enabled = GetMenuBar()->IsChecked( MenuId_Config_Multitap0Toggle );
407 g_Conf->EmuOptions.MultitapPort1_Enabled = GetMenuBar()->IsChecked( MenuId_Config_Multitap1Toggle );
408 AppApplySettings();
409 SaveEmuOptions();
410
411 //evt.Skip();
412 }
413
414 void MainEmuFrame::Menu_EnablePatches_Click( wxCommandEvent& )
415 {
416 g_Conf->EmuOptions.EnablePatches = GetMenuBar()->IsChecked( MenuId_EnablePatches );
417 SaveEmuOptions();
418 }
419
420 void MainEmuFrame::Menu_EnableCheats_Click( wxCommandEvent& )
421 {
422 g_Conf->EmuOptions.EnableCheats = GetMenuBar()->IsChecked( MenuId_EnableCheats );
423 SaveEmuOptions();
424 }
425
426 void MainEmuFrame::Menu_EnableHostFs_Click( wxCommandEvent& )
427 {
428 g_Conf->EmuOptions.HostFs = GetMenuBar()->IsChecked( MenuId_EnableHostFs );
429 SaveEmuOptions();
430 }
431
432 void MainEmuFrame::Menu_OpenELF_Click(wxCommandEvent&)
433 {
434 ScopedCoreThreadClose stopped_core;
435 if( _DoSelectELFBrowser() )
436 {
437 g_Conf->EmuOptions.UseBOOT2Injection = true;
438 sApp.SysExecute( g_Conf->CdvdSource, g_Conf->CurrentELF );
439 }
440
441 stopped_core.AllowResume();
442 }
443
444 void MainEmuFrame::Menu_LoadStates_Click(wxCommandEvent &event)
445 {
446 States_SetCurrentSlot( event.GetId() - MenuId_State_Load01 - 1 );
447 States_DefrostCurrentSlot();
448 }
449
450 void MainEmuFrame::Menu_SaveStates_Click(wxCommandEvent &event)
451 {
452 States_SetCurrentSlot( event.GetId() - MenuId_State_Save01 - 1 );
453 States_FreezeCurrentSlot();
454 }
455
456 void MainEmuFrame::Menu_LoadStateOther_Click(wxCommandEvent &event)
457 {
458 Console.WriteLn("If this were hooked up, it would load a savestate file.");
459 }
460
461 void MainEmuFrame::Menu_SaveStateOther_Click(wxCommandEvent &event)
462 {
463 Console.WriteLn("If this were hooked up, it would save a savestate file.");
464 }
465
466 void MainEmuFrame::Menu_Exit_Click(wxCommandEvent &event)
467 {
468 Close();
469 }
470
471 class SysExecEvent_ToggleSuspend : public SysExecEvent
472 {
473 public:
474 virtual ~SysExecEvent_ToggleSuspend() throw() {}
475
476 wxString GetEventName() const { return L"ToggleSuspendResume"; }
477
478 protected:
479 void InvokeEvent()
480 {
481 if( CoreThread.IsOpen() )
482 CoreThread.Suspend();
483 else
484 CoreThread.Resume();
485 }
486 };
487
488 void MainEmuFrame::Menu_SuspendResume_Click(wxCommandEvent &event)
489 {
490 if( !SysHasValidState() ) return;
491
492 // Disable the menu item. The state of the menu is indeterminate until the core thread
493 // has responded (it updates status after the plugins are loaded and emulation has
494 // engaged successfully).
495
496 EnableMenuItem( MenuId_Sys_SuspendResume, false );
497 GetSysExecutorThread().PostEvent( new SysExecEvent_ToggleSuspend() );
498 }
499
500 void MainEmuFrame::Menu_SysReset_Click(wxCommandEvent &event)
501 {
502 UI_DisableSysReset();
503 sApp.SysExecute();
504 }
505
506 void MainEmuFrame::Menu_SysShutdown_Click(wxCommandEvent &event)
507 {
508 //if( !SysHasValidState() && !CorePlugins.AreAnyInitialized() ) return;
509
510 UI_DisableSysShutdown();
511 CoreThread.Reset();
512 }
513
514 void MainEmuFrame::Menu_ConfigPlugin_Click(wxCommandEvent &event)
515 {
516 const int eventId = event.GetId() - MenuId_PluginBase_Settings;
517
518 PluginsEnum_t pid = (PluginsEnum_t)(eventId / PluginMenuId_Interval);
519
520 // Don't try to call the Patches config dialog until we write one.
521 if (event.GetId() == MenuId_Config_Patches) return;
522
523 if( !pxAssertDev( (eventId >= 0) || (pid < PluginId_Count), "Invalid plugin identifier passed to ConfigPlugin event handler." ) ) return;
524
525 wxWindowDisabler disabler;
526 ScopedCoreThreadPause paused_core( new SysExecEvent_SaveSinglePlugin(pid) );
527 GetCorePlugins().Configure( pid );
528 }
529
530 void MainEmuFrame::Menu_Debug_Open_Click(wxCommandEvent &event)
531 {
532 }
533
534 void MainEmuFrame::Menu_Debug_MemoryDump_Click(wxCommandEvent &event)
535 {
536 }
537
538 void MainEmuFrame::Menu_Debug_Logging_Click(wxCommandEvent &event)
539 {
540 AppOpenDialog<LogOptionsDialog>( this );
541 }
542
543 void MainEmuFrame::Menu_ShowConsole(wxCommandEvent &event)
544 {
545 // Use messages to relay open/close commands (thread-safe)
546
547 g_Conf->ProgLogBox.Visible = event.IsChecked();
548 wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, g_Conf->ProgLogBox.Visible ? wxID_OPEN : wxID_CLOSE );
549 wxGetApp().ProgramLog_PostEvent( evt );
550 }
551
552 void MainEmuFrame::Menu_ShowConsole_Stdio(wxCommandEvent &event)
553 {
554 g_Conf->EmuOptions.ConsoleToStdio = GetMenuBar()->IsChecked( MenuId_Console_Stdio );
555 SaveEmuOptions();
556 }
557
558 void MainEmuFrame::Menu_PrintCDVD_Info(wxCommandEvent &event)
559 {
560 g_Conf->EmuOptions.CdvdVerboseReads = GetMenuBar()->IsChecked( MenuId_CDVD_Info );
561 const_cast<Pcsx2Config&>(EmuConfig).CdvdVerboseReads = g_Conf->EmuOptions.CdvdVerboseReads; // read-only in core thread, so it's safe to modify.
562 SaveEmuOptions();
563 }
564
565 void MainEmuFrame::Menu_ShowAboutBox(wxCommandEvent &event)
566 {
567 AppOpenDialog<AboutBoxDialog>( this );
568 }

  ViewVC Help
Powered by ViewVC 1.1.22