main.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 GraphicsBreakPointsWidget;
  21. class GRenderWindow;
  22. class LoadingScreen;
  23. class MicroProfileDialog;
  24. class ProfilerWidget;
  25. class QLabel;
  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. namespace Tegra {
  38. class DebugContext;
  39. }
  40. enum class EmulatedDirectoryTarget {
  41. NAND,
  42. SDMC,
  43. };
  44. enum class ReinitializeKeyBehavior {
  45. NoWarning,
  46. Warning,
  47. };
  48. namespace DiscordRPC {
  49. class DiscordInterface;
  50. }
  51. class GMainWindow : public QMainWindow {
  52. Q_OBJECT
  53. /// Max number of recently loaded items to keep track of
  54. static const int max_recent_files_item = 10;
  55. // TODO: Make use of this!
  56. enum {
  57. UI_IDLE,
  58. UI_EMU_BOOTING,
  59. UI_EMU_RUNNING,
  60. UI_EMU_STOPPING,
  61. };
  62. public:
  63. void filterBarSetChecked(bool state);
  64. void UpdateUITheme();
  65. GMainWindow();
  66. ~GMainWindow() override;
  67. std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
  68. signals:
  69. /**
  70. * Signal that is emitted when a new EmuThread has been created and an emulation session is
  71. * about to start. At this time, the core system emulation has been initialized, and all
  72. * emulation handles and memory should be valid.
  73. *
  74. * @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
  75. * access/change emulation state).
  76. */
  77. void EmulationStarting(EmuThread* emu_thread);
  78. /**
  79. * Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
  80. * system emulation handles and memory are still valid, but are about become invalid.
  81. */
  82. void EmulationStopping();
  83. // Signal that tells widgets to update icons to use the current theme
  84. void UpdateThemedIcons();
  85. void ErrorDisplayFinished();
  86. void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
  87. void SoftwareKeyboardFinishedText(std::optional<std::u16string> text);
  88. void SoftwareKeyboardFinishedCheckDialog();
  89. void WebBrowserUnpackRomFS();
  90. void WebBrowserFinishedBrowsing();
  91. public slots:
  92. void OnLoadComplete();
  93. void ErrorDisplayDisplayError(QString body);
  94. void ProfileSelectorSelectProfile();
  95. void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters);
  96. void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message);
  97. void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);
  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. QStringList GetUnsupportedGLExtensions();
  109. bool LoadROM(const QString& filename);
  110. void BootGame(const QString& filename);
  111. void ShutdownGame();
  112. void ShowTelemetryCallout();
  113. void SetDiscordEnabled(bool state);
  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. void closeEvent(QCloseEvent* event) override;
  142. private slots:
  143. void OnStartGame();
  144. void OnPauseGame();
  145. void OnStopGame();
  146. void OnMenuReportCompatibility();
  147. /// Called whenever a user selects a game in the game list widget.
  148. void OnGameListLoadFile(QString game_path);
  149. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target);
  150. void OnTransferableShaderCacheOpenFile(u64 program_id);
  151. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  152. void OnGameListCopyTID(u64 program_id);
  153. void OnGameListNavigateToGamedbEntry(u64 program_id,
  154. const CompatibilityList& compatibility_list);
  155. void OnGameListOpenDirectory(const QString& directory);
  156. void OnGameListAddDirectory();
  157. void OnGameListShowList(bool show);
  158. void OnGameListOpenPerGameProperties(const std::string& file);
  159. void OnMenuLoadFile();
  160. void OnMenuLoadFolder();
  161. void OnMenuInstallToNAND();
  162. /// Called whenever a user select the "File->Select -- Directory" where -- is NAND or SD Card
  163. void OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target);
  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 OnCaptureScreenshot();
  177. void OnCoreError(Core::System::ResultStatus, std::string);
  178. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  179. private:
  180. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  181. void UpdateWindowTitle(const QString& title_name = {});
  182. void UpdateStatusBar();
  183. Ui::MainWindow ui;
  184. std::shared_ptr<Tegra::DebugContext> debug_context;
  185. GRenderWindow* render_window;
  186. GameList* game_list;
  187. LoadingScreen* loading_screen;
  188. GameListPlaceholder* game_list_placeholder;
  189. // Status bar elements
  190. QLabel* message_label = nullptr;
  191. QLabel* emu_speed_label = nullptr;
  192. QLabel* game_fps_label = nullptr;
  193. QLabel* emu_frametime_label = nullptr;
  194. QTimer status_bar_update_timer;
  195. std::unique_ptr<Config> config;
  196. // Whether emulation is currently running in yuzu.
  197. bool emulation_running = false;
  198. std::unique_ptr<EmuThread> emu_thread;
  199. // The path to the game currently running
  200. QString game_path;
  201. // FS
  202. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  203. std::unique_ptr<FileSys::ManualContentProvider> provider;
  204. // Debugger panes
  205. ProfilerWidget* profilerWidget;
  206. MicroProfileDialog* microProfileDialog;
  207. GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
  208. WaitTreeWidget* waitTreeWidget;
  209. QAction* actions_recent_files[max_recent_files_item];
  210. // stores default icon theme search paths for the platform
  211. QStringList default_theme_paths;
  212. HotkeyRegistry hotkey_registry;
  213. protected:
  214. void dropEvent(QDropEvent* event) override;
  215. void dragEnterEvent(QDragEnterEvent* event) override;
  216. void dragMoveEvent(QDragMoveEvent* event) override;
  217. // Overrides used to forward signals to the render window when the focus moves out.
  218. void keyPressEvent(QKeyEvent* event) override;
  219. void keyReleaseEvent(QKeyEvent* event) override;
  220. };