main.h 10 KB

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