main.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. class GameListPlaceholder;
  31. namespace Core::Frontend {
  32. struct SoftwareKeyboardParameters;
  33. } // namespace Core::Frontend
  34. namespace FileSys {
  35. class ContentProvider;
  36. class ManualContentProvider;
  37. class VfsFilesystem;
  38. } // namespace FileSys
  39. enum class EmulatedDirectoryTarget {
  40. NAND,
  41. SDMC,
  42. };
  43. enum class InstallResult {
  44. Success,
  45. Overwrite,
  46. Failure,
  47. };
  48. enum class ReinitializeKeyBehavior {
  49. NoWarning,
  50. Warning,
  51. };
  52. namespace DiscordRPC {
  53. class DiscordInterface;
  54. }
  55. class GMainWindow : public QMainWindow {
  56. Q_OBJECT
  57. /// Max number of recently loaded items to keep track of
  58. static const int max_recent_files_item = 10;
  59. // TODO: Make use of this!
  60. enum {
  61. UI_IDLE,
  62. UI_EMU_BOOTING,
  63. UI_EMU_RUNNING,
  64. UI_EMU_STOPPING,
  65. };
  66. public:
  67. void filterBarSetChecked(bool state);
  68. void UpdateUITheme();
  69. GMainWindow();
  70. ~GMainWindow() override;
  71. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  72. bool DropAction(QDropEvent* event);
  73. void AcceptDropEvent(QDropEvent* event);
  74. signals:
  75. /**
  76. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  77. * about to start. At this time, the core system emulation has been initialized, and all
  78. * emulation handles and memory should be valid.
  79. *
  80. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  81. * access/change emulation state).
  82. */
  83. void EmulationStarting(EmuThread* emu_thread);
  84. /**
  85. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  86. * system emulation handles and memory are still valid, but are about become invalid.
  87. */
  88. void EmulationStopping();
  89. // Signal that tells widgets to update icons to use the current theme
  90. void UpdateThemedIcons();
  91. void UpdateInstallProgress();
  92. void ErrorDisplayFinished();
  93. void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
  94. void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
  95. void SoftwareKeyboardFinishedCheckDialog();
  96. void WebBrowserUnpackRomFS();
  97. void WebBrowserFinishedBrowsing();
  98. public slots:
  99. void OnLoadComplete();
  100. void ErrorDisplayDisplayError(QString body);
  101. void ProfileSelectorSelectProfile();
  102. void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
  103. void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
  104. void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);
  105. void OnAppFocusStateChanged(Qt::ApplicationState state);
  106. private:
  107. void InitializeWidgets();
  108. void InitializeDebugWidgets();
  109. void InitializeRecentFileMenuActions();
  110. void SetDefaultUIGeometry();
  111. void RestoreUIState();
  112. void ConnectWidgetEvents();
  113. void ConnectMenuEvents();
  114. void PreventOSSleep();
  115. void AllowOSSleep();
  116. bool LoadROM(const QString& filename);
  117. void BootGame(const QString& filename);
  118. void ShutdownGame();
  119. void ShowTelemetryCallout();
  120. void SetDiscordEnabled(bool state);
  121. void LoadAmiibo(const QString& filename);
  122. void SelectAndSetCurrentUser();
  123. /**
  124. * Stores the filename in the recently loaded files list.
  125. * The new filename is stored at the beginning of the recently loaded files list.
  126. * After inserting the new entry, duplicates are removed meaning that if
  127. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  128. * and remove from its previous position.
  129. *
  130. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  131. *
  132. * @param filename the filename to store
  133. */
  134. void StoreRecentFile(const QString& filename);
  135. /**
  136. * Updates the recent files menu.
  137. * Menu entries are rebuilt from the configuration file.
  138. * If there is no entry in the menu, the menu is greyed out.
  139. */
  140. void UpdateRecentFiles();
  141. /**
  142. * If the emulation is running,
  143. * asks the user if he really want to close the emulator
  144. *
  145. * @return true if the user confirmed
  146. */
  147. bool ConfirmClose();
  148. bool ConfirmChangeGame();
  149. bool ConfirmForceLockedExit();
  150. void RequestGameExit();
  151. void closeEvent(QCloseEvent* event) override;
  152. private slots:
  153. void OnStartGame();
  154. void OnPauseGame();
  155. void OnStopGame();
  156. void OnMenuReportCompatibility();
  157. void OnOpenModsPage();
  158. void OnOpenQuickstartGuide();
  159. void OnOpenFAQ();
  160. /// Called whenever a user selects a game in the game list widget.
  161. void OnGameListLoadFile(QString game_path);
  162. void OnGameListOpenFolder(GameListOpenTarget target, const std::string& game_path);
  163. void OnTransferableShaderCacheOpenFile(u64 program_id);
  164. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  165. void OnGameListCopyTID(u64 program_id);
  166. void OnGameListNavigateToGamedbEntry(u64 program_id,
  167. const CompatibilityList& compatibility_list);
  168. void OnGameListOpenDirectory(const QString& directory);
  169. void OnGameListAddDirectory();
  170. void OnGameListShowList(bool show);
  171. void OnGameListOpenPerGameProperties(const std::string& file);
  172. void OnMenuLoadFile();
  173. void OnMenuLoadFolder();
  174. void IncrementInstallProgress();
  175. void OnMenuInstallToNAND();
  176. void OnMenuRecentFile();
  177. void OnConfigure();
  178. void OnLoadAmiibo();
  179. void OnOpenYuzuFolder();
  180. void OnAbout();
  181. void OnToggleFilterBar();
  182. void OnDisplayTitleBars(bool);
  183. void InitializeHotkeys();
  184. void ToggleFullscreen();
  185. void ShowFullscreen();
  186. void HideFullscreen();
  187. void ToggleWindowMode();
  188. void ResetWindowSize();
  189. void OnCaptureScreenshot();
  190. void OnCoreError(Core::System::ResultStatus, std::string);
  191. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  192. void OnLanguageChanged(const QString& locale);
  193. private:
  194. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  195. InstallResult InstallNSPXCI(const QString& filename);
  196. InstallResult InstallNCA(const QString& filename);
  197. void UpdateWindowTitle(const std::string& title_name = {},
  198. const std::string& title_version = {});
  199. void UpdateStatusBar();
  200. void UpdateStatusButtons();
  201. void HideMouseCursor();
  202. void ShowMouseCursor();
  203. void OpenURL(const QUrl& url);
  204. void LoadTranslation();
  205. Ui::MainWindow ui;
  206. GRenderWindow* render_window;
  207. GameList* game_list;
  208. LoadingScreen* loading_screen;
  209. GameListPlaceholder* game_list_placeholder;
  210. // Status bar elements
  211. QLabel* message_label = nullptr;
  212. QLabel* shader_building_label = nullptr;
  213. QLabel* emu_speed_label = nullptr;
  214. QLabel* game_fps_label = nullptr;
  215. QLabel* emu_frametime_label = nullptr;
  216. QPushButton* async_status_button = nullptr;
  217. QPushButton* multicore_status_button = nullptr;
  218. QPushButton* renderer_status_button = nullptr;
  219. QPushButton* dock_status_button = nullptr;
  220. QTimer status_bar_update_timer;
  221. std::unique_ptr<Config> config;
  222. // Whether emulation is currently running in yuzu.
  223. bool emulation_running = false;
  224. std::unique_ptr<EmuThread> emu_thread;
  225. // The path to the game currently running
  226. QString game_path;
  227. bool auto_paused = false;
  228. QTimer mouse_hide_timer;
  229. // FS
  230. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  231. std::unique_ptr<FileSys::ManualContentProvider> provider;
  232. // Debugger panes
  233. ProfilerWidget* profilerWidget;
  234. MicroProfileDialog* microProfileDialog;
  235. WaitTreeWidget* waitTreeWidget;
  236. QAction* actions_recent_files[max_recent_files_item];
  237. // stores default icon theme search paths for the platform
  238. QStringList default_theme_paths;
  239. HotkeyRegistry hotkey_registry;
  240. QTranslator translator;
  241. // Install progress dialog
  242. QProgressDialog* install_progress;
  243. protected:
  244. void dropEvent(QDropEvent* event) override;
  245. void dragEnterEvent(QDragEnterEvent* event) override;
  246. void dragMoveEvent(QDragMoveEvent* event) override;
  247. void mouseMoveEvent(QMouseEvent* event) override;
  248. void mousePressEvent(QMouseEvent* event) override;
  249. };