main.h 13 KB

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