main.h 9.8 KB

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