main.h 6.2 KB

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