main.h 7.9 KB

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