main.h 10 KB

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