main.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <unordered_map>
  7. #include <QMainWindow>
  8. #include <QTimer>
  9. #include "common/common_types.h"
  10. #include "core/core.h"
  11. #include "ui_main.h"
  12. #include "yuzu/compatibility_list.h"
  13. #include "yuzu/hotkeys.h"
  14. class Config;
  15. class EmuThread;
  16. class GameList;
  17. class GImageInfo;
  18. class GraphicsBreakPointsWidget;
  19. class GraphicsSurfaceWidget;
  20. class GRenderWindow;
  21. class MicroProfileDialog;
  22. class ProfilerWidget;
  23. class WaitTreeWidget;
  24. enum class GameListOpenTarget;
  25. namespace FileSys {
  26. class VfsFilesystem;
  27. }
  28. namespace Tegra {
  29. class DebugContext;
  30. }
  31. enum class EmulatedDirectoryTarget {
  32. NAND,
  33. SDMC,
  34. };
  35. class GMainWindow : public QMainWindow {
  36. Q_OBJECT
  37. /// Max number of recently loaded items to keep track of
  38. static const int max_recent_files_item = 10;
  39. // TODO: Make use of this!
  40. enum {
  41. UI_IDLE,
  42. UI_EMU_BOOTING,
  43. UI_EMU_RUNNING,
  44. UI_EMU_STOPPING,
  45. };
  46. public:
  47. void filterBarSetChecked(bool state);
  48. void UpdateUITheme();
  49. GMainWindow();
  50. ~GMainWindow() override;
  51. signals:
  52. /**
  53. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  54. * about to start. At this time, the core system emulation has been initialized, and all
  55. * emulation handles and memory should be valid.
  56. *
  57. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  58. * access/change emulation state).
  59. */
  60. void EmulationStarting(EmuThread* emu_thread);
  61. /**
  62. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  63. * system emulation handles and memory are still valid, but are about become invalid.
  64. */
  65. void EmulationStopping();
  66. // Signal that tells widgets to update icons to use the current theme
  67. void UpdateThemedIcons();
  68. private:
  69. void InitializeWidgets();
  70. void InitializeDebugWidgets();
  71. void InitializeRecentFileMenuActions();
  72. void InitializeHotkeys();
  73. void SetDefaultUIGeometry();
  74. void RestoreUIState();
  75. void ConnectWidgetEvents();
  76. void ConnectMenuEvents();
  77. QStringList GetUnsupportedGLExtensions();
  78. bool LoadROM(const QString& filename);
  79. void BootGame(const QString& filename);
  80. void ShutdownGame();
  81. void ShowCallouts();
  82. /**
  83. * Stores the filename in the recently loaded files list.
  84. * The new filename is stored at the beginning of the recently loaded files list.
  85. * After inserting the new entry, duplicates are removed meaning that if
  86. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  87. * and remove from its previous position.
  88. *
  89. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  90. *
  91. * @param filename the filename to store
  92. */
  93. void StoreRecentFile(const QString& filename);
  94. /**
  95. * Updates the recent files menu.
  96. * Menu entries are rebuilt from the configuration file.
  97. * If there is no entry in the menu, the menu is greyed out.
  98. */
  99. void UpdateRecentFiles();
  100. /**
  101. * If the emulation is running,
  102. * asks the user if he really want to close the emulator
  103. *
  104. * @return true if the user confirmed
  105. */
  106. bool ConfirmClose();
  107. bool ConfirmChangeGame();
  108. void closeEvent(QCloseEvent* event) override;
  109. private slots:
  110. void OnStartGame();
  111. void OnPauseGame();
  112. void OnStopGame();
  113. /// Called whenever a user selects a game in the game list widget.
  114. void OnGameListLoadFile(QString game_path);
  115. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target);
  116. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  117. void OnGameListCopyTID(u64 program_id);
  118. void OnGameListNavigateToGamedbEntry(u64 program_id,
  119. const CompatibilityList& compatibility_list);
  120. void OnMenuLoadFile();
  121. void OnMenuLoadFolder();
  122. void OnMenuInstallToNAND();
  123. /// Called whenever a user selects the "File->Select Game List Root" menu item
  124. void OnMenuSelectGameListRoot();
  125. /// Called whenever a user select the "File->Select -- Directory" where -- is NAND or SD Card
  126. void OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target);
  127. void OnMenuRecentFile();
  128. void OnConfigure();
  129. void OnAbout();
  130. void OnToggleFilterBar();
  131. void OnDisplayTitleBars(bool);
  132. void ToggleFullscreen();
  133. void ShowFullscreen();
  134. void HideFullscreen();
  135. void ToggleWindowMode();
  136. void OnCoreError(Core::System::ResultStatus, std::string);
  137. private:
  138. void UpdateStatusBar();
  139. Ui::MainWindow ui;
  140. std::shared_ptr<Tegra::DebugContext> debug_context;
  141. GRenderWindow* render_window;
  142. GameList* game_list;
  143. // Status bar elements
  144. QLabel* message_label = nullptr;
  145. QLabel* emu_speed_label = nullptr;
  146. QLabel* game_fps_label = nullptr;
  147. QLabel* emu_frametime_label = nullptr;
  148. QTimer status_bar_update_timer;
  149. std::unique_ptr<Config> config;
  150. // Whether emulation is currently running in yuzu.
  151. bool emulation_running = false;
  152. std::unique_ptr<EmuThread> emu_thread;
  153. // The path to the game currently running
  154. QString game_path;
  155. // FS
  156. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  157. // Debugger panes
  158. ProfilerWidget* profilerWidget;
  159. MicroProfileDialog* microProfileDialog;
  160. GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
  161. GraphicsSurfaceWidget* graphicsSurfaceWidget;
  162. WaitTreeWidget* waitTreeWidget;
  163. QAction* actions_recent_files[max_recent_files_item];
  164. // stores default icon theme search paths for the platform
  165. QStringList default_theme_paths;
  166. HotkeyRegistry hotkey_registry;
  167. protected:
  168. void dropEvent(QDropEvent* event) override;
  169. void dragEnterEvent(QDragEnterEvent* event) override;
  170. void dragMoveEvent(QDragMoveEvent* event) override;
  171. };