main.h 13 KB

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