pineapple-src/src/yuzu/main.h

535 lines
18 KiB
C
Raw Normal View History

2022-11-05 12:58:44 +00:00
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include <optional>
#include <QMainWindow>
#include <QTimer>
#include <QTranslator>
#include "common/announce_multiplayer_room.h"
#include "common/common_types.h"
2023-01-07 23:07:19 +00:00
#include "input_common/drivers/tas_input.h"
2022-11-05 12:58:44 +00:00
#include "yuzu/compatibility_list.h"
#include "yuzu/hotkeys.h"
2022-11-05 14:35:56 +00:00
#ifdef __unix__
2022-11-05 12:58:44 +00:00
#include <QVariant>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QtDBus>
#endif
class Config;
class ClickableLabel;
class EmuThread;
class GameList;
class GImageInfo;
class GRenderWindow;
class LoadingScreen;
class MicroProfileDialog;
2022-12-20 16:05:00 +00:00
class OverlayDialog;
2022-11-05 12:58:44 +00:00
class ProfilerWidget;
class ControllerDialog;
class QLabel;
class MultiplayerState;
class QPushButton;
class QProgressDialog;
2023-02-04 23:53:19 +00:00
class QSlider;
class QHBoxLayout;
2022-11-05 12:58:44 +00:00
class WaitTreeWidget;
enum class GameListOpenTarget;
enum class GameListRemoveTarget;
2022-12-17 10:00:04 +00:00
enum class GameListShortcutTarget;
2022-11-05 12:58:44 +00:00
enum class DumpRomFSTarget;
enum class InstalledEntryType;
class GameListPlaceholder;
2023-03-27 04:50:51 +00:00
class QtAmiiboSettingsDialog;
class QtControllerSelectorDialog;
class QtProfileSelectionDialog;
2022-11-05 12:58:44 +00:00
class QtSoftwareKeyboardDialog;
2023-03-27 04:50:51 +00:00
class QtNXWebEngineView;
2022-11-05 12:58:44 +00:00
enum class StartGameType {
Normal, // Can use custom configuration
Global, // Only uses global configuration
};
2023-09-10 19:22:54 +00:00
enum class AmLaunchType {
UserInitiated,
ApplicationInitiated,
};
2022-11-05 12:58:44 +00:00
namespace Core {
enum class SystemResultStatus : u32;
class System;
} // namespace Core
namespace Core::Frontend {
2022-11-15 06:19:04 +00:00
struct CabinetParameters;
2022-11-05 12:58:44 +00:00
struct ControllerParameters;
struct InlineAppearParameters;
struct InlineTextParameters;
struct KeyboardInitializeParameters;
2023-03-30 04:35:16 +00:00
struct ProfileSelectParameters;
2022-11-05 12:58:44 +00:00
} // namespace Core::Frontend
namespace DiscordRPC {
class DiscordInterface;
}
2023-08-27 22:07:09 +00:00
namespace PlayTime {
class PlayTimeManager;
}
2022-11-05 12:58:44 +00:00
namespace FileSys {
class ContentProvider;
class ManualContentProvider;
class VfsFilesystem;
} // namespace FileSys
namespace InputCommon {
class InputSubsystem;
}
namespace Service::AM::Applets {
enum class SwkbdResult : u32;
enum class SwkbdTextCheckResult : u32;
enum class SwkbdReplyType : u32;
enum class WebExitReason : u32;
} // namespace Service::AM::Applets
2023-05-07 21:22:35 +00:00
namespace Service::NFC {
class NfcDevice;
} // namespace Service::NFC
2022-11-15 06:19:04 +00:00
2022-11-05 12:58:44 +00:00
namespace Ui {
class MainWindow;
}
enum class EmulatedDirectoryTarget {
NAND,
SDMC,
};
enum class InstallResult {
Success,
Overwrite,
Failure,
BaseInstallAttempted,
};
enum class ReinitializeKeyBehavior {
NoWarning,
Warning,
};
2023-06-09 15:18:31 +00:00
namespace VkDeviceInfo {
class Record;
}
2022-11-05 12:58:44 +00:00
class GMainWindow : public QMainWindow {
Q_OBJECT
/// Max number of recently loaded items to keep track of
static const int max_recent_files_item = 10;
// TODO: Make use of this!
enum {
UI_IDLE,
UI_EMU_BOOTING,
UI_EMU_RUNNING,
UI_EMU_STOPPING,
};
public:
void filterBarSetChecked(bool state);
void UpdateUITheme();
explicit GMainWindow(std::unique_ptr<Config> config_, bool has_broken_vulkan);
~GMainWindow() override;
bool DropAction(QDropEvent* event);
void AcceptDropEvent(QDropEvent* event);
signals:
/**
* Signal that is emitted when a new EmuThread has been created and an emulation session is
* about to start. At this time, the core system emulation has been initialized, and all
* emulation handles and memory should be valid.
*
* @param emu_thread Pointer to the newly created EmuThread (to be used by widgets that need to
* access/change emulation state).
*/
void EmulationStarting(EmuThread* emu_thread);
/**
* Signal that is emitted when emulation is about to stop. At this time, the EmuThread and core
* system emulation handles and memory are still valid, but are about become invalid.
*/
void EmulationStopping();
// Signal that tells widgets to update icons to use the current theme
void UpdateThemedIcons();
void UpdateInstallProgress();
2022-11-15 06:19:04 +00:00
void AmiiboSettingsFinished(bool is_success, const std::string& name);
2023-03-30 02:13:07 +00:00
void ControllerSelectorReconfigureFinished(bool is_success);
2022-11-05 12:58:44 +00:00
void ErrorDisplayFinished();
void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
void SoftwareKeyboardSubmitNormalText(Service::AM::Applets::SwkbdResult result,
std::u16string submitted_text, bool confirmed);
void SoftwareKeyboardSubmitInlineText(Service::AM::Applets::SwkbdReplyType reply_type,
std::u16string submitted_text, s32 cursor_position);
void WebBrowserExtractOfflineRomFS();
void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url);
void SigInterrupt();
public slots:
void OnLoadComplete();
void OnExecuteProgram(std::size_t program_index);
void OnExit();
void OnSaveConfig();
2022-11-15 06:19:04 +00:00
void AmiiboSettingsShowDialog(const Core::Frontend::CabinetParameters& parameters,
2023-05-07 21:22:35 +00:00
std::shared_ptr<Service::NFC::NfcDevice> nfp_device);
2023-03-27 04:50:51 +00:00
void AmiiboSettingsRequestExit();
2022-11-05 12:58:44 +00:00
void ControllerSelectorReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters);
2023-03-27 04:50:51 +00:00
void ControllerSelectorRequestExit();
2022-11-05 12:58:44 +00:00
void SoftwareKeyboardInitialize(
bool is_inline, Core::Frontend::KeyboardInitializeParameters initialize_parameters);
void SoftwareKeyboardShowNormal();
void SoftwareKeyboardShowTextCheck(Service::AM::Applets::SwkbdTextCheckResult text_check_result,
std::u16string text_check_message);
void SoftwareKeyboardShowInline(Core::Frontend::InlineAppearParameters appear_parameters);
void SoftwareKeyboardHideInline();
void SoftwareKeyboardInlineTextChanged(Core::Frontend::InlineTextParameters text_parameters);
void SoftwareKeyboardExit();
void ErrorDisplayDisplayError(QString error_code, QString error_text);
2023-03-27 04:50:51 +00:00
void ErrorDisplayRequestExit();
2023-03-30 04:35:16 +00:00
void ProfileSelectorSelectProfile(const Core::Frontend::ProfileSelectParameters& parameters);
2023-03-27 04:50:51 +00:00
void ProfileSelectorRequestExit();
2022-11-05 12:58:44 +00:00
void WebBrowserOpenWebPage(const std::string& main_url, const std::string& additional_args,
bool is_local);
2023-03-27 04:50:51 +00:00
void WebBrowserRequestExit();
2022-11-05 12:58:44 +00:00
void OnAppFocusStateChanged(Qt::ApplicationState state);
void OnTasStateChanged();
private:
/// Updates an action's shortcut and text to reflect an updated hotkey from the hotkey registry.
2023-05-11 20:19:53 +00:00
void LinkActionShortcut(QAction* action, const QString& action_name,
const bool tas_allowed = false);
2022-11-05 12:58:44 +00:00
void RegisterMetaTypes();
void InitializeWidgets();
void InitializeDebugWidgets();
void InitializeRecentFileMenuActions();
void SetDefaultUIGeometry();
void RestoreUIState();
void ConnectWidgetEvents();
void ConnectMenuEvents();
void UpdateMenuState();
void SetupPrepareForSleep();
void PreventOSSleep();
void AllowOSSleep();
2023-09-10 19:22:54 +00:00
bool LoadROM(const QString& filename, u64 program_id, std::size_t program_index,
AmLaunchType launch_type);
2022-11-05 12:58:44 +00:00
void BootGame(const QString& filename, u64 program_id = 0, std::size_t program_index = 0,
2023-09-10 19:22:54 +00:00
StartGameType with_config = StartGameType::Normal,
AmLaunchType launch_type = AmLaunchType::UserInitiated);
2022-11-05 12:58:44 +00:00
void ShutdownGame();
void ShowTelemetryCallout();
void SetDiscordEnabled(bool state);
void LoadAmiibo(const QString& filename);
2023-03-30 04:35:16 +00:00
bool SelectAndSetCurrentUser(const Core::Frontend::ProfileSelectParameters& parameters);
2022-11-05 12:58:44 +00:00
/**
* Stores the filename in the recently loaded files list.
* The new filename is stored at the beginning of the recently loaded files list.
* After inserting the new entry, duplicates are removed meaning that if
* this was inserted from \a OnMenuRecentFile(), the entry will be put on top
* and remove from its previous position.
*
* Finally, this function calls \a UpdateRecentFiles() to update the UI.
*
* @param filename the filename to store
*/
void StoreRecentFile(const QString& filename);
/**
* Updates the recent files menu.
* Menu entries are rebuilt from the configuration file.
* If there is no entry in the menu, the menu is greyed out.
*/
void UpdateRecentFiles();
/**
* If the emulation is running,
* asks the user if he really want to close the emulator
*
* @return true if the user confirmed
*/
bool ConfirmClose();
bool ConfirmChangeGame();
bool ConfirmForceLockedExit();
void RequestGameExit();
void RequestGameResume();
void changeEvent(QEvent* event) override;
void closeEvent(QCloseEvent* event) override;
2023-01-07 23:07:19 +00:00
std::string CreateTASFramesString(
std::array<size_t, InputCommon::TasInput::PLAYER_NUMBER> frames) const;
2022-11-05 14:35:56 +00:00
#ifdef __unix__
2022-11-05 12:58:44 +00:00
void SetupSigInterrupts();
static void HandleSigInterrupt(int);
void OnSigInterruptNotifierActivated();
#endif
private slots:
void OnStartGame();
void OnRestartGame();
void OnPauseGame();
void OnPauseContinueGame();
void OnStopGame();
void OnPrepareForSleep(bool prepare_sleep);
void OnMenuReportCompatibility();
void OnOpenModsPage();
void OnOpenQuickstartGuide();
void OnOpenFAQ();
/// Called whenever a user selects a game in the game list widget.
void OnGameListLoadFile(QString game_path, u64 program_id);
void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
const std::string& game_path);
void OnTransferableShaderCacheOpenFile(u64 program_id);
void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type);
void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target,
const std::string& game_path);
2023-08-27 22:07:09 +00:00
void OnGameListRemovePlayTimeData(u64 program_id);
2022-11-05 12:58:44 +00:00
void OnGameListDumpRomFS(u64 program_id, const std::string& game_path, DumpRomFSTarget target);
2023-09-08 15:22:41 +00:00
void OnGameListVerifyIntegrity(const std::string& game_path);
2022-11-05 12:58:44 +00:00
void OnGameListCopyTID(u64 program_id);
void OnGameListNavigateToGamedbEntry(u64 program_id,
const CompatibilityList& compatibility_list);
2022-12-17 10:00:04 +00:00
void OnGameListCreateShortcut(u64 program_id, const std::string& game_path,
GameListShortcutTarget target);
2022-11-05 12:58:44 +00:00
void OnGameListOpenDirectory(const QString& directory);
void OnGameListAddDirectory();
void OnGameListShowList(bool show);
void OnGameListOpenPerGameProperties(const std::string& file);
void OnMenuLoadFile();
void OnMenuLoadFolder();
void IncrementInstallProgress();
void OnMenuInstallToNAND();
void OnMenuRecentFile();
void OnConfigure();
void OnConfigureTas();
2023-02-04 23:53:19 +00:00
void OnDecreaseVolume();
void OnIncreaseVolume();
void OnMute();
2022-11-05 12:58:44 +00:00
void OnTasStartStop();
void OnTasRecord();
void OnTasReset();
2022-12-03 17:20:46 +00:00
void OnToggleGraphicsAPI();
2022-11-05 12:58:44 +00:00
void OnToggleDockedMode();
void OnToggleGpuAccuracy();
void OnToggleAdaptingFilter();
void OnConfigurePerGame();
void OnLoadAmiibo();
void OnOpenYuzuFolder();
2023-09-13 15:42:25 +00:00
void OnVerifyInstalledContents();
2022-11-05 12:58:44 +00:00
void OnAbout();
void OnToggleFilterBar();
void OnToggleStatusBar();
void OnDisplayTitleBars(bool);
void InitializeHotkeys();
void ToggleFullscreen();
2022-12-14 19:21:58 +00:00
bool UsingExclusiveFullscreen();
2022-11-05 12:58:44 +00:00
void ShowFullscreen();
void HideFullscreen();
void ToggleWindowMode();
void ResetWindowSize(u32 width, u32 height);
void ResetWindowSize720();
void ResetWindowSize900();
void ResetWindowSize1080();
2023-09-23 01:56:47 +00:00
void OnMiiEdit();
2022-11-05 12:58:44 +00:00
void OnCaptureScreenshot();
void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
void OnLanguageChanged(const QString& locale);
void OnMouseActivity();
2022-12-25 04:37:45 +00:00
bool OnShutdownBegin();
2022-12-20 16:05:00 +00:00
void OnShutdownBeginDialog();
void OnEmulationStopped();
void OnEmulationStopTimeExpired();
2022-11-05 12:58:44 +00:00
private:
2022-11-11 04:38:22 +00:00
QString GetGameListErrorRemoving(InstalledEntryType type) const;
void RemoveBaseContent(u64 program_id, InstalledEntryType type);
void RemoveUpdateContent(u64 program_id, InstalledEntryType type);
void RemoveAddOnContent(u64 program_id, InstalledEntryType type);
2022-11-05 12:58:44 +00:00
void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target);
2023-01-05 22:14:41 +00:00
void RemoveVulkanDriverPipelineCache(u64 program_id);
2022-11-05 12:58:44 +00:00
void RemoveAllTransferableShaderCaches(u64 program_id);
void RemoveCustomConfiguration(u64 program_id, const std::string& game_path);
2023-08-27 22:07:09 +00:00
void RemovePlayTimeData(u64 program_id);
2023-05-28 22:16:57 +00:00
void RemoveCacheStorage(u64 program_id);
2023-08-27 00:56:33 +00:00
bool SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id,
u64* selected_title_id, u8* selected_content_record_type);
2022-11-05 12:58:44 +00:00
InstallResult InstallNSPXCI(const QString& filename);
InstallResult InstallNCA(const QString& filename);
void MigrateConfigFiles();
void UpdateWindowTitle(std::string_view title_name = {}, std::string_view title_version = {},
std::string_view gpu_vendor = {});
void UpdateDockedButton();
2022-12-03 17:20:46 +00:00
void UpdateAPIText();
2022-11-05 12:58:44 +00:00
void UpdateFilterText();
void UpdateAAText();
2023-02-04 23:53:19 +00:00
void UpdateVolumeUI();
2022-11-05 12:58:44 +00:00
void UpdateStatusBar();
void UpdateGPUAccuracyButton();
void UpdateStatusButtons();
void UpdateUISettings();
2022-11-27 19:29:54 +00:00
void UpdateInputDrivers();
2022-11-05 12:58:44 +00:00
void HideMouseCursor();
void ShowMouseCursor();
void CenterMouseCursor();
void OpenURL(const QUrl& url);
void LoadTranslation();
void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
bool CheckDarkMode();
2023-05-01 17:17:11 +00:00
bool CheckSystemArchiveDecryption();
2023-09-23 01:56:47 +00:00
bool CheckFirmwarePresence();
2023-08-24 20:11:26 +00:00
void ConfigureFilesystemProvider(const std::string& filepath);
2022-11-05 12:58:44 +00:00
QString GetTasStateDescription() const;
2022-12-17 10:00:04 +00:00
bool CreateShortcut(const std::string& shortcut_path, const std::string& title,
const std::string& comment, const std::string& icon_path,
const std::string& command, const std::string& arguments,
const std::string& categories, const std::string& keywords);
2022-11-05 12:58:44 +00:00
std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<Core::System> system;
std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
2023-08-27 22:07:09 +00:00
std::unique_ptr<PlayTime::PlayTimeManager> play_time_manager;
2022-11-05 12:58:44 +00:00
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
MultiplayerState* multiplayer_state = nullptr;
GRenderWindow* render_window;
GameList* game_list;
LoadingScreen* loading_screen;
2022-12-20 16:05:00 +00:00
QTimer shutdown_timer;
2022-12-24 03:43:08 +00:00
OverlayDialog* shutdown_dialog{};
2022-11-05 12:58:44 +00:00
GameListPlaceholder* game_list_placeholder;
2023-06-09 15:18:31 +00:00
std::vector<VkDeviceInfo::Record> vk_device_records;
2022-11-05 12:58:44 +00:00
// Status bar elements
QLabel* message_label = nullptr;
QLabel* shader_building_label = nullptr;
QLabel* res_scale_label = nullptr;
QLabel* emu_speed_label = nullptr;
QLabel* game_fps_label = nullptr;
QLabel* emu_frametime_label = nullptr;
QLabel* tas_label = nullptr;
QPushButton* gpu_accuracy_button = nullptr;
QPushButton* renderer_status_button = nullptr;
QPushButton* dock_status_button = nullptr;
QPushButton* filter_status_button = nullptr;
QPushButton* aa_status_button = nullptr;
2023-02-04 23:53:19 +00:00
QPushButton* volume_button = nullptr;
QWidget* volume_popup = nullptr;
QSlider* volume_slider = nullptr;
2022-11-05 12:58:44 +00:00
QTimer status_bar_update_timer;
std::unique_ptr<Config> config;
// Whether emulation is currently running in yuzu.
bool emulation_running = false;
std::unique_ptr<EmuThread> emu_thread;
// The path to the game currently running
QString current_game_path;
bool auto_paused = false;
bool auto_muted = false;
QTimer mouse_hide_timer;
QTimer mouse_center_timer;
2022-11-27 19:29:54 +00:00
QTimer update_input_timer;
2022-11-05 12:58:44 +00:00
QString startup_icon_theme;
bool os_dark_mode = false;
// FS
std::shared_ptr<FileSys::VfsFilesystem> vfs;
std::unique_ptr<FileSys::ManualContentProvider> provider;
// Debugger panes
ProfilerWidget* profilerWidget;
MicroProfileDialog* microProfileDialog;
WaitTreeWidget* waitTreeWidget;
ControllerDialog* controller_dialog;
QAction* actions_recent_files[max_recent_files_item];
// stores default icon theme search paths for the platform
QStringList default_theme_paths;
HotkeyRegistry hotkey_registry;
QTranslator translator;
// Install progress dialog
QProgressDialog* install_progress;
// Last game booted, used for multi-process apps
QString last_filename_booted;
// Applets
2023-03-27 04:50:51 +00:00
QtAmiiboSettingsDialog* cabinet_applet = nullptr;
QtControllerSelectorDialog* controller_applet = nullptr;
QtProfileSelectionDialog* profile_select_applet = nullptr;
QDialog* error_applet = nullptr;
2022-11-05 12:58:44 +00:00
QtSoftwareKeyboardDialog* software_keyboard = nullptr;
2023-03-27 04:50:51 +00:00
QtNXWebEngineView* web_applet = nullptr;
2022-11-05 12:58:44 +00:00
// True if amiibo file select is visible
bool is_amiibo_file_select_active{};
// True if load file select is visible
bool is_load_file_select_active{};
// True if TAS recording dialog is visible
bool is_tas_recording_dialog_active{};
2022-11-05 14:35:56 +00:00
#ifdef __unix__
2022-11-05 12:58:44 +00:00
QSocketNotifier* sig_interrupt_notifier;
static std::array<int, 3> sig_interrupt_fds;
#endif
protected:
void dropEvent(QDropEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void leaveEvent(QEvent* event) override;
};