main.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 WebBrowserOpenWebPage(std::string_view main_url, std::string_view additional_args,
  117. bool is_local);
  118. void OnAppFocusStateChanged(Qt::ApplicationState state);
  119. private:
  120. void InitializeWidgets();
  121. void InitializeDebugWidgets();
  122. void InitializeRecentFileMenuActions();
  123. void SetDefaultUIGeometry();
  124. void RestoreUIState();
  125. void ConnectWidgetEvents();
  126. void ConnectMenuEvents();
  127. void PreventOSSleep();
  128. void AllowOSSleep();
  129. bool LoadROM(const QString& filename, std::size_t program_index);
  130. void BootGame(const QString& filename, std::size_t program_index = 0);
  131. void ShutdownGame();
  132. void ShowTelemetryCallout();
  133. void SetDiscordEnabled(bool state);
  134. void LoadAmiibo(const QString& filename);
  135. void SelectAndSetCurrentUser();
  136. /**
  137. * Stores the filename in the recently loaded files list.
  138. * The new filename is stored at the beginning of the recently loaded files list.
  139. * After inserting the new entry, duplicates are removed meaning that if
  140. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  141. * and remove from its previous position.
  142. *
  143. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  144. *
  145. * @param filename the filename to store
  146. */
  147. void StoreRecentFile(const QString& filename);
  148. /**
  149. * Updates the recent files menu.
  150. * Menu entries are rebuilt from the configuration file.
  151. * If there is no entry in the menu, the menu is greyed out.
  152. */
  153. void UpdateRecentFiles();
  154. /**
  155. * If the emulation is running,
  156. * asks the user if he really want to close the emulator
  157. *
  158. * @return true if the user confirmed
  159. */
  160. bool ConfirmClose();
  161. bool ConfirmChangeGame();
  162. bool ConfirmForceLockedExit();
  163. void RequestGameExit();
  164. void closeEvent(QCloseEvent* event) override;
  165. private slots:
  166. void OnStartGame();
  167. void OnPauseGame();
  168. void OnStopGame();
  169. void OnMenuReportCompatibility();
  170. void OnOpenModsPage();
  171. void OnOpenQuickstartGuide();
  172. void OnOpenFAQ();
  173. /// Called whenever a user selects a game in the game list widget.
  174. void OnGameListLoadFile(QString game_path);
  175. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
  176. const std::string& game_path);
  177. void OnTransferableShaderCacheOpenFile(u64 program_id);
  178. void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type);
  179. void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target);
  180. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  181. void OnGameListCopyTID(u64 program_id);
  182. void OnGameListNavigateToGamedbEntry(u64 program_id,
  183. const CompatibilityList& compatibility_list);
  184. void OnGameListOpenDirectory(const QString& directory);
  185. void OnGameListAddDirectory();
  186. void OnGameListShowList(bool show);
  187. void OnGameListOpenPerGameProperties(const std::string& file);
  188. void OnMenuLoadFile();
  189. void OnMenuLoadFolder();
  190. void IncrementInstallProgress();
  191. void OnMenuInstallToNAND();
  192. void OnMenuRecentFile();
  193. void OnConfigure();
  194. void OnConfigurePerGame();
  195. void OnLoadAmiibo();
  196. void OnOpenYuzuFolder();
  197. void OnAbout();
  198. void OnToggleFilterBar();
  199. void OnDisplayTitleBars(bool);
  200. void InitializeHotkeys();
  201. void ToggleFullscreen();
  202. void ShowFullscreen();
  203. void HideFullscreen();
  204. void ToggleWindowMode();
  205. void ResetWindowSize720();
  206. void ResetWindowSize1080();
  207. void OnCaptureScreenshot();
  208. void OnCoreError(Core::System::ResultStatus, std::string);
  209. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  210. void OnLanguageChanged(const QString& locale);
  211. void OnMouseActivity();
  212. private:
  213. void RemoveBaseContent(u64 program_id, const QString& entry_type);
  214. void RemoveUpdateContent(u64 program_id, const QString& entry_type);
  215. void RemoveAddOnContent(u64 program_id, const QString& entry_type);
  216. void RemoveTransferableShaderCache(u64 program_id);
  217. void RemoveCustomConfiguration(u64 program_id);
  218. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  219. InstallResult InstallNSPXCI(const QString& filename);
  220. InstallResult InstallNCA(const QString& filename);
  221. void MigrateConfigFiles();
  222. void UpdateWindowTitle(const std::string& title_name = {},
  223. const std::string& title_version = {});
  224. void UpdateStatusBar();
  225. void UpdateStatusButtons();
  226. void UpdateUISettings();
  227. void HideMouseCursor();
  228. void ShowMouseCursor();
  229. void OpenURL(const QUrl& url);
  230. void LoadTranslation();
  231. void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
  232. Ui::MainWindow ui;
  233. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  234. std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
  235. GRenderWindow* render_window;
  236. GameList* game_list;
  237. LoadingScreen* loading_screen;
  238. GameListPlaceholder* game_list_placeholder;
  239. // Status bar elements
  240. QLabel* message_label = nullptr;
  241. QLabel* shader_building_label = nullptr;
  242. QLabel* emu_speed_label = nullptr;
  243. QLabel* game_fps_label = nullptr;
  244. QLabel* emu_frametime_label = nullptr;
  245. QPushButton* async_status_button = nullptr;
  246. QPushButton* multicore_status_button = nullptr;
  247. QPushButton* renderer_status_button = nullptr;
  248. QPushButton* dock_status_button = nullptr;
  249. QTimer status_bar_update_timer;
  250. std::unique_ptr<Config> config;
  251. // Whether emulation is currently running in yuzu.
  252. bool emulation_running = false;
  253. std::unique_ptr<EmuThread> emu_thread;
  254. // The path to the game currently running
  255. QString game_path;
  256. bool auto_paused = false;
  257. QTimer mouse_hide_timer;
  258. // FS
  259. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  260. std::unique_ptr<FileSys::ManualContentProvider> provider;
  261. // Debugger panes
  262. ProfilerWidget* profilerWidget;
  263. MicroProfileDialog* microProfileDialog;
  264. WaitTreeWidget* waitTreeWidget;
  265. QAction* actions_recent_files[max_recent_files_item];
  266. // stores default icon theme search paths for the platform
  267. QStringList default_theme_paths;
  268. HotkeyRegistry hotkey_registry;
  269. QTranslator translator;
  270. // Install progress dialog
  271. QProgressDialog* install_progress;
  272. // Last game booted, used for multi-process apps
  273. QString last_filename_booted;
  274. // Disables the web applet for the rest of the emulated session
  275. bool disable_web_applet{};
  276. protected:
  277. void dropEvent(QDropEvent* event) override;
  278. void dragEnterEvent(QDragEnterEvent* event) override;
  279. void dragMoveEvent(QDragMoveEvent* event) override;
  280. };