main.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. private:
  148. void RegisterMetaTypes();
  149. void InitializeWidgets();
  150. void InitializeDebugWidgets();
  151. void InitializeRecentFileMenuActions();
  152. void SetDefaultUIGeometry();
  153. void RestoreUIState();
  154. void ConnectWidgetEvents();
  155. void ConnectMenuEvents();
  156. void PreventOSSleep();
  157. void AllowOSSleep();
  158. bool LoadROM(const QString& filename, u64 program_id, std::size_t program_index);
  159. void BootGame(const QString& filename, u64 program_id = 0, std::size_t program_index = 0,
  160. StartGameType with_config = StartGameType::Normal);
  161. void ShutdownGame();
  162. void ShowTelemetryCallout();
  163. void SetDiscordEnabled(bool state);
  164. void LoadAmiibo(const QString& filename);
  165. void SelectAndSetCurrentUser();
  166. /**
  167. * Stores the filename in the recently loaded files list.
  168. * The new filename is stored at the beginning of the recently loaded files list.
  169. * After inserting the new entry, duplicates are removed meaning that if
  170. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  171. * and remove from its previous position.
  172. *
  173. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  174. *
  175. * @param filename the filename to store
  176. */
  177. void StoreRecentFile(const QString& filename);
  178. /**
  179. * Updates the recent files menu.
  180. * Menu entries are rebuilt from the configuration file.
  181. * If there is no entry in the menu, the menu is greyed out.
  182. */
  183. void UpdateRecentFiles();
  184. /**
  185. * If the emulation is running,
  186. * asks the user if he really want to close the emulator
  187. *
  188. * @return true if the user confirmed
  189. */
  190. bool ConfirmClose();
  191. bool ConfirmChangeGame();
  192. bool ConfirmForceLockedExit();
  193. void RequestGameExit();
  194. void closeEvent(QCloseEvent* event) override;
  195. private slots:
  196. void OnStartGame();
  197. void OnPauseGame();
  198. void OnStopGame();
  199. void OnMenuReportCompatibility();
  200. void OnOpenModsPage();
  201. void OnOpenQuickstartGuide();
  202. void OnOpenFAQ();
  203. /// Called whenever a user selects a game in the game list widget.
  204. void OnGameListLoadFile(QString game_path, u64 program_id);
  205. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
  206. const std::string& game_path);
  207. void OnTransferableShaderCacheOpenFile(u64 program_id);
  208. void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type);
  209. void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target,
  210. const std::string& game_path);
  211. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path, DumpRomFSTarget target);
  212. void OnGameListCopyTID(u64 program_id);
  213. void OnGameListNavigateToGamedbEntry(u64 program_id,
  214. const CompatibilityList& compatibility_list);
  215. void OnGameListOpenDirectory(const QString& directory);
  216. void OnGameListAddDirectory();
  217. void OnGameListShowList(bool show);
  218. void OnGameListOpenPerGameProperties(const std::string& file);
  219. void OnMenuLoadFile();
  220. void OnMenuLoadFolder();
  221. void IncrementInstallProgress();
  222. void OnMenuInstallToNAND();
  223. void OnMenuRecentFile();
  224. void OnConfigure();
  225. void OnConfigureTas();
  226. void OnConfigurePerGame();
  227. void OnLoadAmiibo();
  228. void OnOpenYuzuFolder();
  229. void OnAbout();
  230. void OnToggleFilterBar();
  231. void OnDisplayTitleBars(bool);
  232. void InitializeHotkeys();
  233. void ToggleFullscreen();
  234. void ShowFullscreen();
  235. void HideFullscreen();
  236. void ToggleWindowMode();
  237. void ResetWindowSize(u32 width, u32 height);
  238. void ResetWindowSize720();
  239. void ResetWindowSize900();
  240. void ResetWindowSize1080();
  241. void OnCaptureScreenshot();
  242. void OnCoreError(Core::SystemResultStatus, std::string);
  243. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  244. void OnLanguageChanged(const QString& locale);
  245. void OnMouseActivity();
  246. private:
  247. void RemoveBaseContent(u64 program_id, const QString& entry_type);
  248. void RemoveUpdateContent(u64 program_id, const QString& entry_type);
  249. void RemoveAddOnContent(u64 program_id, const QString& entry_type);
  250. void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target);
  251. void RemoveAllTransferableShaderCaches(u64 program_id);
  252. void RemoveCustomConfiguration(u64 program_id, const std::string& game_path);
  253. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  254. InstallResult InstallNSPXCI(const QString& filename);
  255. InstallResult InstallNCA(const QString& filename);
  256. void MigrateConfigFiles();
  257. void UpdateWindowTitle(std::string_view title_name = {}, std::string_view title_version = {},
  258. std::string_view gpu_vendor = {});
  259. void UpdateFilterText();
  260. void UpdateAAText();
  261. void UpdateStatusBar();
  262. void UpdateGPUAccuracyButton();
  263. void UpdateStatusButtons();
  264. void UpdateUISettings();
  265. void HideMouseCursor();
  266. void ShowMouseCursor();
  267. void OpenURL(const QUrl& url);
  268. void LoadTranslation();
  269. void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
  270. QString GetTasStateDescription() const;
  271. std::unique_ptr<Ui::MainWindow> ui;
  272. std::unique_ptr<Core::System> system;
  273. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  274. std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
  275. GRenderWindow* render_window;
  276. GameList* game_list;
  277. LoadingScreen* loading_screen;
  278. GameListPlaceholder* game_list_placeholder;
  279. // Status bar elements
  280. QLabel* message_label = nullptr;
  281. QLabel* shader_building_label = nullptr;
  282. QLabel* res_scale_label = nullptr;
  283. QLabel* emu_speed_label = nullptr;
  284. QLabel* game_fps_label = nullptr;
  285. QLabel* emu_frametime_label = nullptr;
  286. QLabel* tas_label = nullptr;
  287. QPushButton* gpu_accuracy_button = nullptr;
  288. QPushButton* renderer_status_button = nullptr;
  289. QPushButton* dock_status_button = nullptr;
  290. QPushButton* filter_status_button = nullptr;
  291. QPushButton* aa_status_button = nullptr;
  292. QTimer status_bar_update_timer;
  293. std::unique_ptr<Config> config;
  294. // Whether emulation is currently running in yuzu.
  295. bool emulation_running = false;
  296. std::unique_ptr<EmuThread> emu_thread;
  297. // The path to the game currently running
  298. QString game_path;
  299. bool auto_paused = false;
  300. QTimer mouse_hide_timer;
  301. // FS
  302. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  303. std::unique_ptr<FileSys::ManualContentProvider> provider;
  304. // Debugger panes
  305. ProfilerWidget* profilerWidget;
  306. MicroProfileDialog* microProfileDialog;
  307. WaitTreeWidget* waitTreeWidget;
  308. ControllerDialog* controller_dialog;
  309. QAction* actions_recent_files[max_recent_files_item];
  310. // stores default icon theme search paths for the platform
  311. QStringList default_theme_paths;
  312. HotkeyRegistry hotkey_registry;
  313. QTranslator translator;
  314. // Install progress dialog
  315. QProgressDialog* install_progress;
  316. // Last game booted, used for multi-process apps
  317. QString last_filename_booted;
  318. // Disables the web applet for the rest of the emulated session
  319. bool disable_web_applet{};
  320. // Applets
  321. QtSoftwareKeyboardDialog* software_keyboard = nullptr;
  322. protected:
  323. void dropEvent(QDropEvent* event) override;
  324. void dragEnterEvent(QDragEnterEvent* event) override;
  325. void dragMoveEvent(QDragMoveEvent* event) override;
  326. };