main.h 12 KB

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