main.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 "core/hle/service/acc/profile_manager.h"
  13. #include "ui_main.h"
  14. #include "yuzu/compatibility_list.h"
  15. #include "yuzu/hotkeys.h"
  16. class Config;
  17. class EmuThread;
  18. class GameList;
  19. class GImageInfo;
  20. class GRenderWindow;
  21. class LoadingScreen;
  22. class MicroProfileDialog;
  23. class ProfilerWidget;
  24. class QLabel;
  25. class QPushButton;
  26. class QProgressDialog;
  27. class WaitTreeWidget;
  28. enum class GameListOpenTarget;
  29. class GameListPlaceholder;
  30. namespace Core::Frontend {
  31. struct SoftwareKeyboardParameters;
  32. } // namespace Core::Frontend
  33. namespace FileSys {
  34. class ContentProvider;
  35. class ManualContentProvider;
  36. class VfsFilesystem;
  37. } // namespace FileSys
  38. enum class EmulatedDirectoryTarget {
  39. NAND,
  40. SDMC,
  41. };
  42. enum class InstallResult {
  43. Success,
  44. Overwrite,
  45. Failure,
  46. };
  47. enum class ReinitializeKeyBehavior {
  48. NoWarning,
  49. Warning,
  50. };
  51. namespace DiscordRPC {
  52. class DiscordInterface;
  53. }
  54. class GMainWindow : public QMainWindow {
  55. Q_OBJECT
  56. /// Max number of recently loaded items to keep track of
  57. static const int max_recent_files_item = 10;
  58. // TODO: Make use of this!
  59. enum {
  60. UI_IDLE,
  61. UI_EMU_BOOTING,
  62. UI_EMU_RUNNING,
  63. UI_EMU_STOPPING,
  64. };
  65. public:
  66. void filterBarSetChecked(bool state);
  67. void UpdateUITheme();
  68. GMainWindow();
  69. ~GMainWindow() override;
  70. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  71. bool DropAction(QDropEvent* event);
  72. void AcceptDropEvent(QDropEvent* event);
  73. signals:
  74. /**
  75. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  76. * about to start. At this time, the core system emulation has been initialized, and all
  77. * emulation handles and memory should be valid.
  78. *
  79. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  80. * access/change emulation state).
  81. */
  82. void EmulationStarting(EmuThread* emu_thread);
  83. /**
  84. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  85. * system emulation handles and memory are still valid, but are about become invalid.
  86. */
  87. void EmulationStopping();
  88. // Signal that tells widgets to update icons to use the current theme
  89. void UpdateThemedIcons();
  90. void UpdateInstallProgress();
  91. void ErrorDisplayFinished();
  92. void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
  93. void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
  94. void SoftwareKeyboardFinishedCheckDialog();
  95. void WebBrowserUnpackRomFS();
  96. void WebBrowserFinishedBrowsing();
  97. public slots:
  98. void OnLoadComplete();
  99. void ErrorDisplayDisplayError(QString body);
  100. void ProfileSelectorSelectProfile();
  101. void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
  102. void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
  103. void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);
  104. void OnAppFocusStateChanged(Qt::ApplicationState state);
  105. private:
  106. void InitializeWidgets();
  107. void InitializeDebugWidgets();
  108. void InitializeRecentFileMenuActions();
  109. void SetDefaultUIGeometry();
  110. void RestoreUIState();
  111. void ConnectWidgetEvents();
  112. void ConnectMenuEvents();
  113. void PreventOSSleep();
  114. void AllowOSSleep();
  115. bool LoadROM(const QString& filename);
  116. void BootGame(const QString& filename);
  117. void ShutdownGame();
  118. void ShowTelemetryCallout();
  119. void SetDiscordEnabled(bool state);
  120. void LoadAmiibo(const QString& filename);
  121. void SelectAndSetCurrentUser();
  122. /**
  123. * Stores the filename in the recently loaded files list.
  124. * The new filename is stored at the beginning of the recently loaded files list.
  125. * After inserting the new entry, duplicates are removed meaning that if
  126. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  127. * and remove from its previous position.
  128. *
  129. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  130. *
  131. * @param filename the filename to store
  132. */
  133. void StoreRecentFile(const QString& filename);
  134. /**
  135. * Updates the recent files menu.
  136. * Menu entries are rebuilt from the configuration file.
  137. * If there is no entry in the menu, the menu is greyed out.
  138. */
  139. void UpdateRecentFiles();
  140. /**
  141. * If the emulation is running,
  142. * asks the user if he really want to close the emulator
  143. *
  144. * @return true if the user confirmed
  145. */
  146. bool ConfirmClose();
  147. bool ConfirmChangeGame();
  148. bool ConfirmForceLockedExit();
  149. void RequestGameExit();
  150. void closeEvent(QCloseEvent* event) override;
  151. private slots:
  152. void OnStartGame();
  153. void OnPauseGame();
  154. void OnStopGame();
  155. void OnMenuReportCompatibility();
  156. void OnOpenModsPage();
  157. void OnOpenQuickstartGuide();
  158. void OnOpenFAQ();
  159. /// Called whenever a user selects a game in the game list widget.
  160. void OnGameListLoadFile(QString game_path);
  161. void OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path);
  162. void OnTransferableShaderCacheOpenFile(u64 program_id);
  163. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  164. void OnGameListCopyTID(u64 program_id);
  165. void OnGameListNavigateToGamedbEntry(u64 program_id,
  166. const CompatibilityList& compatibility_list);
  167. void OnGameListOpenDirectory(const QString& directory);
  168. void OnGameListAddDirectory();
  169. void OnGameListShowList(bool show);
  170. void OnGameListOpenPerGameProperties(const std::string& file);
  171. void OnMenuLoadFile();
  172. void OnMenuLoadFolder();
  173. void IncrementInstallProgress();
  174. void OnMenuInstallToNAND();
  175. void OnMenuRecentFile();
  176. void OnConfigure();
  177. void OnLoadAmiibo();
  178. void OnOpenYuzuFolder();
  179. void OnAbout();
  180. void OnToggleFilterBar();
  181. void OnDisplayTitleBars(bool);
  182. void InitializeHotkeys();
  183. void ToggleFullscreen();
  184. void ShowFullscreen();
  185. void HideFullscreen();
  186. void ToggleWindowMode();
  187. void ResetWindowSize();
  188. void OnCaptureScreenshot();
  189. void OnCoreError(Core::System::ResultStatus, std::string);
  190. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  191. private:
  192. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  193. InstallResult InstallNSPXCI(const QString& filename);
  194. InstallResult InstallNCA(const QString& filename);
  195. void UpdateWindowTitle(const std::string& title_name = {},
  196. const std::string& title_version = {});
  197. void UpdateStatusBar();
  198. void UpdateStatusButtons();
  199. void HideMouseCursor();
  200. void ShowMouseCursor();
  201. void OpenURL(const QUrl& url);
  202. Ui::MainWindow ui;
  203. GRenderWindow* render_window;
  204. GameList* game_list;
  205. LoadingScreen* loading_screen;
  206. GameListPlaceholder* game_list_placeholder;
  207. // Status bar elements
  208. QLabel* message_label = nullptr;
  209. QLabel* emu_speed_label = nullptr;
  210. QLabel* game_fps_label = nullptr;
  211. QLabel* emu_frametime_label = nullptr;
  212. QPushButton* async_status_button = nullptr;
  213. QPushButton* multicore_status_button = nullptr;
  214. QPushButton* renderer_status_button = nullptr;
  215. QPushButton* dock_status_button = nullptr;
  216. QTimer status_bar_update_timer;
  217. std::unique_ptr<Config> config;
  218. // Whether emulation is currently running in yuzu.
  219. bool emulation_running = false;
  220. std::unique_ptr<EmuThread> emu_thread;
  221. // The path to the game currently running
  222. QString game_path;
  223. bool auto_paused = false;
  224. QTimer mouse_hide_timer;
  225. // FS
  226. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  227. std::unique_ptr<FileSys::ManualContentProvider> provider;
  228. // Debugger panes
  229. ProfilerWidget* profilerWidget;
  230. MicroProfileDialog* microProfileDialog;
  231. WaitTreeWidget* waitTreeWidget;
  232. QAction* actions_recent_files[max_recent_files_item];
  233. // stores default icon theme search paths for the platform
  234. QStringList default_theme_paths;
  235. HotkeyRegistry hotkey_registry;
  236. // Install progress dialog
  237. QProgressDialog* install_progress;
  238. protected:
  239. void dropEvent(QDropEvent* event) override;
  240. void dragEnterEvent(QDragEnterEvent* event) override;
  241. void dragMoveEvent(QDragMoveEvent* event) override;
  242. void mouseMoveEvent(QMouseEvent* event) override;
  243. void mousePressEvent(QMouseEvent* event) override;
  244. };