main.h 8.0 KB

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