main.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 GraphicsSurfaceWidget;
  22. class GRenderWindow;
  23. class LoadingScreen;
  24. class MicroProfileDialog;
  25. class ProfilerWidget;
  26. class QLabel;
  27. class WaitTreeWidget;
  28. enum class GameListOpenTarget;
  29. namespace Core::Frontend {
  30. struct SoftwareKeyboardParameters;
  31. } // namespace Core::Frontend
  32. namespace FileSys {
  33. class RegisteredCacheUnion;
  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 InitializeHotkeys();
  100. void SetDefaultUIGeometry();
  101. void RestoreUIState();
  102. void ConnectWidgetEvents();
  103. void ConnectMenuEvents();
  104. QStringList GetUnsupportedGLExtensions();
  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 SelectAndSetCurrentUser();
  111. /**
  112. * Stores the filename in the recently loaded files list.
  113. * The new filename is stored at the beginning of the recently loaded files list.
  114. * After inserting the new entry, duplicates are removed meaning that if
  115. * this was inserted from \a OnMenuRecentFile(), the entry will be put on top
  116. * and remove from its previous position.
  117. *
  118. * Finally, this function calls \a UpdateRecentFiles() to update the UI.
  119. *
  120. * @param filename the filename to store
  121. */
  122. void StoreRecentFile(const QString& filename);
  123. /**
  124. * Updates the recent files menu.
  125. * Menu entries are rebuilt from the configuration file.
  126. * If there is no entry in the menu, the menu is greyed out.
  127. */
  128. void UpdateRecentFiles();
  129. /**
  130. * If the emulation is running,
  131. * asks the user if he really want to close the emulator
  132. *
  133. * @return true if the user confirmed
  134. */
  135. bool ConfirmClose();
  136. bool ConfirmChangeGame();
  137. void closeEvent(QCloseEvent* event) override;
  138. private slots:
  139. void OnStartGame();
  140. void OnPauseGame();
  141. void OnStopGame();
  142. void OnMenuReportCompatibility();
  143. /// Called whenever a user selects a game in the game list widget.
  144. void OnGameListLoadFile(QString game_path);
  145. void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target);
  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 ToggleFullscreen();
  166. void ShowFullscreen();
  167. void HideFullscreen();
  168. void ToggleWindowMode();
  169. void OnCaptureScreenshot();
  170. void OnCoreError(Core::System::ResultStatus, std::string);
  171. void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
  172. private:
  173. std::optional<u64> SelectRomFSDumpTarget(const FileSys::RegisteredCacheUnion&, u64 program_id);
  174. void UpdateStatusBar();
  175. Ui::MainWindow ui;
  176. std::shared_ptr<Tegra::DebugContext> debug_context;
  177. GRenderWindow* render_window;
  178. GameList* game_list;
  179. LoadingScreen* loading_screen;
  180. // Status bar elements
  181. QLabel* message_label = nullptr;
  182. QLabel* emu_speed_label = nullptr;
  183. QLabel* game_fps_label = nullptr;
  184. QLabel* emu_frametime_label = nullptr;
  185. QTimer status_bar_update_timer;
  186. std::unique_ptr<Config> config;
  187. // Whether emulation is currently running in yuzu.
  188. bool emulation_running = false;
  189. std::unique_ptr<EmuThread> emu_thread;
  190. // The path to the game currently running
  191. QString game_path;
  192. // FS
  193. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  194. // Debugger panes
  195. ProfilerWidget* profilerWidget;
  196. MicroProfileDialog* microProfileDialog;
  197. GraphicsBreakPointsWidget* graphicsBreakpointsWidget;
  198. GraphicsSurfaceWidget* graphicsSurfaceWidget;
  199. WaitTreeWidget* waitTreeWidget;
  200. QAction* actions_recent_files[max_recent_files_item];
  201. // stores default icon theme search paths for the platform
  202. QStringList default_theme_paths;
  203. HotkeyRegistry hotkey_registry;
  204. protected:
  205. void dropEvent(QDropEvent* event) override;
  206. void dragEnterEvent(QDragEnterEvent* event) override;
  207. void dragMoveEvent(QDragMoveEvent* event) override;
  208. };