main.h 6.9 KB

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