main.h 7.7 KB

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