main.h 9.4 KB

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