main.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 ErrorDisplayFinished();
  85. void ProfileSelectorFinishedSelection(std::optional<Service::Account::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. private:
  98. void InitializeWidgets();
  99. void InitializeDebugWidgets();
  100. void InitializeRecentFileMenuActions();
  101. void SetDefaultUIGeometry();
  102. void RestoreUIState();
  103. void ConnectWidgetEvents();
  104. void ConnectMenuEvents();
  105. QStringList GetUnsupportedGLExtensions();
  106. bool LoadROM(const QString& filename);
  107. void BootGame(const QString& filename);
  108. void ShutdownGame();
  109. void ShowTelemetryCallout();
  110. void SetDiscordEnabled(bool state);
  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. void closeEvent(QCloseEvent* event) override;
  139. private slots:
  140. void OnStartGame();
  141. void OnPauseGame();
  142. void OnStopGame();
  143. void OnMenuReportCompatibility();
  144. /// Called whenever a user selects a game in the game list widget.
  145. void OnGameListLoadFile(QString game_path);
  146. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target);
  147. void OnTransferableShaderCacheOpenFile(u64 program_id);
  148. void OnGameListDumpRomFS(u64 program_id, const std::string& game_path);
  149. void OnGameListCopyTID(u64 program_id);
  150. void OnGameListNavigateToGamedbEntry(u64 program_id,
  151. const CompatibilityList& compatibility_list);
  152. void OnGameListOpenPerGameProperties(const std::string& file);
  153. void OnMenuLoadFile();
  154. void OnMenuLoadFolder();
  155. void OnMenuInstallToNAND();
  156. /// Called whenever a user selects the "File->Select Game List Root" menu item
  157. void OnMenuSelectGameListRoot();
  158. /// Called whenever a user select the "File->Select -- Directory" where -- is NAND or SD Card
  159. void OnMenuSelectEmulatedDirectory(EmulatedDirectoryTarget target);
  160. void OnMenuRecentFile();
  161. void OnConfigure();
  162. void OnLoadAmiibo();
  163. void OnOpenYuzuFolder();
  164. void OnAbout();
  165. void OnToggleFilterBar();
  166. void OnDisplayTitleBars(bool);
  167. void InitializeHotkeys();
  168. void ToggleFullscreen();
  169. void ShowFullscreen();
  170. void HideFullscreen();
  171. void ToggleWindowMode();
  172. void OnCaptureScreenshot();
  173. void OnCoreError(Core::System::ResultStatus, std::string);
  174. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  175. private:
  176. std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
  177. void UpdateWindowTitle(const QString& title_name = {});
  178. void UpdateStatusBar();
  179. Ui::MainWindow ui;
  180. std::shared_ptr<Tegra::DebugContext> debug_context;
  181. GRenderWindow* render_window;
  182. GameList* game_list;
  183. LoadingScreen* loading_screen;
  184. // Status bar elements
  185. QLabel* message_label = nullptr;
  186. QLabel* emu_speed_label = nullptr;
  187. QLabel* game_fps_label = nullptr;
  188. QLabel* emu_frametime_label = nullptr;
  189. QTimer status_bar_update_timer;
  190. std::unique_ptr<Config> config;
  191. // Whether emulation is currently running in yuzu.
  192. bool emulation_running = false;
  193. std::unique_ptr<EmuThread> emu_thread;
  194. // The path to the game currently running
  195. QString game_path;
  196. // FS
  197. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  198. std::unique_ptr<FileSys::ManualContentProvider> provider;
  199. // Debugger panes
  200. ProfilerWidget* profilerWidget;
  201. MicroProfileDialog* microProfileDialog;
  202. GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
  203. WaitTreeWidget* waitTreeWidget;
  204. QAction* actions_recent_files[max_recent_files_item];
  205. // stores default icon theme search paths for the platform
  206. QStringList default_theme_paths;
  207. HotkeyRegistry hotkey_registry;
  208. protected:
  209. void dropEvent(QDropEvent* event) override;
  210. void dragEnterEvent(QDragEnterEvent* event) override;
  211. void dragMoveEvent(QDragMoveEvent* event) override;
  212. // Overrides used to forward signals to the render window when the focus moves out.
  213. void keyPressEvent(QKeyEvent* event) override;
  214. void keyReleaseEvent(QKeyEvent* event) override;
  215. };