pineapple-src/src/yuzu/main.h

425 lines
13 KiB
C
Raw Normal View History

2020-12-28 15:15:37 +00:00
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <optional>
#include <QMainWindow>
#include <QTimer>
#include <QTranslator>
#include "common/common_types.h"
#include "yuzu/compatibility_list.h"
#include "yuzu/hotkeys.h"
2021-12-22 09:32:56 +00:00
#ifdef __linux__
#include <QVariant>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QtDBus>
#endif
2020-12-28 15:15:37 +00:00
class Config;
class EmuThread;
class GameList;
class GImageInfo;
class GRenderWindow;
class LoadingScreen;
class MicroProfileDialog;
class ProfilerWidget;
2021-01-26 05:32:32 +00:00
class ControllerDialog;
2020-12-28 15:15:37 +00:00
class QLabel;
class QPushButton;
class QProgressDialog;
class WaitTreeWidget;
enum class GameListOpenTarget;
enum class GameListRemoveTarget;
2021-06-28 09:33:07 +00:00
enum class DumpRomFSTarget;
2020-12-28 15:15:37 +00:00
enum class InstalledEntryType;
class GameListPlaceholder;
2021-04-13 00:50:20 +00:00
class QtSoftwareKeyboardDialog;
2021-06-08 05:46:24 +00:00
enum class StartGameType {
Normal, // Can use custom configuration
Global, // Only uses global configuration
};
2021-10-16 00:35:29 +00:00
namespace Core {
enum class SystemResultStatus : u32;
class System;
} // namespace Core
2020-12-28 15:15:37 +00:00
namespace Core::Frontend {
struct ControllerParameters;
2021-04-13 00:50:20 +00:00
struct InlineAppearParameters;
struct InlineTextParameters;
struct KeyboardInitializeParameters;
2020-12-28 15:15:37 +00:00
} // namespace Core::Frontend
namespace DiscordRPC {
class DiscordInterface;
}
namespace FileSys {
class ContentProvider;
class ManualContentProvider;
class VfsFilesystem;
} // namespace FileSys
namespace InputCommon {
class InputSubsystem;
}
namespace Service::AM::Applets {
2021-04-13 00:50:20 +00:00
enum class SwkbdResult : u32;
enum class SwkbdTextCheckResult : u32;
enum class SwkbdReplyType : u32;
2020-12-28 15:15:37 +00:00
enum class WebExitReason : u32;
2021-04-13 00:50:20 +00:00
} // namespace Service::AM::Applets
2020-12-28 15:15:37 +00:00
2021-10-16 00:35:29 +00:00
namespace Ui {
class MainWindow;
}
2020-12-28 15:15:37 +00:00
enum class EmulatedDirectoryTarget {
NAND,
SDMC,
};
enum class InstallResult {
Success,
Overwrite,
Failure,
2021-05-16 19:32:58 +00:00
BaseInstallAttempted,
2020-12-28 15:15:37 +00:00
};
enum class ReinitializeKeyBehavior {
NoWarning,
Warning,
};
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();
2021-10-16 00:35:29 +00:00
explicit GMainWindow();
2020-12-28 15:15:37 +00:00
~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();
void ControllerSelectorReconfigureFinished();
void ErrorDisplayFinished();
void ProfileSelectorFinishedSelection(std::optional<Common::UUID> uuid);
2021-04-13 00:50:20 +00:00
void SoftwareKeyboardSubmitNormalText(Service::AM::Applets::SwkbdResult result,
2021-11-08 19:53:36 +00:00
std::u16string submitted_text, bool confirmed);
2021-04-13 00:50:20 +00:00
void SoftwareKeyboardSubmitInlineText(Service::AM::Applets::SwkbdReplyType reply_type,
std::u16string submitted_text, s32 cursor_position);
2020-12-28 15:15:37 +00:00
void WebBrowserExtractOfflineRomFS();
void WebBrowserClosed(Service::AM::Applets::WebExitReason exit_reason, std::string last_url);
public slots:
void OnLoadComplete();
void OnExecuteProgram(std::size_t program_index);
2021-09-26 21:58:49 +00:00
void OnExit();
2020-12-28 15:15:37 +00:00
void ControllerSelectorReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters);
2021-04-13 00:50:20 +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);
2020-12-28 15:15:37 +00:00
void ProfileSelectorSelectProfile();
2021-04-29 01:46:54 +00:00
void WebBrowserOpenWebPage(const std::string& main_url, const std::string& additional_args,
2020-12-28 15:15:37 +00:00
bool is_local);
void OnAppFocusStateChanged(Qt::ApplicationState state);
2021-11-22 06:17:44 +00:00
void OnTasStateChanged();
2020-12-28 15:15:37 +00:00
private:
2021-12-29 20:59:21 +00:00
/// Updates an action's shortcut and text to reflect an updated hotkey from the hotkey registry.
void LinkActionShortcut(QAction* action, const QString& action_name);
2021-04-13 00:50:20 +00:00
void RegisterMetaTypes();
2020-12-28 15:15:37 +00:00
void InitializeWidgets();
void InitializeDebugWidgets();
void InitializeRecentFileMenuActions();
void SetDefaultUIGeometry();
void RestoreUIState();
void ConnectWidgetEvents();
void ConnectMenuEvents();
2021-11-25 03:15:25 +00:00
void UpdateMenuState();
2020-12-28 15:15:37 +00:00
void PreventOSSleep();
void AllowOSSleep();
2021-07-11 20:43:19 +00:00
bool LoadROM(const QString& filename, u64 program_id, std::size_t program_index);
void BootGame(const QString& filename, u64 program_id = 0, std::size_t program_index = 0,
2021-06-08 05:46:24 +00:00
StartGameType with_config = StartGameType::Normal);
2020-12-28 15:15:37 +00:00
void ShutdownGame();
void ShowTelemetryCallout();
void SetDiscordEnabled(bool state);
void LoadAmiibo(const QString& filename);
void SelectAndSetCurrentUser();
/**
* 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 closeEvent(QCloseEvent* event) override;
private slots:
void OnStartGame();
2021-11-25 03:15:25 +00:00
void OnRestartGame();
2020-12-28 15:15:37 +00:00
void OnPauseGame();
2021-11-25 03:15:25 +00:00
void OnPauseContinueGame();
2020-12-28 15:15:37 +00:00
void OnStopGame();
void OnMenuReportCompatibility();
void OnOpenModsPage();
void OnOpenQuickstartGuide();
void OnOpenFAQ();
/// Called whenever a user selects a game in the game list widget.
2021-07-11 20:43:19 +00:00
void OnGameListLoadFile(QString game_path, u64 program_id);
2020-12-28 15:15:37 +00:00
void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target,
const std::string& game_path);
void OnTransferableShaderCacheOpenFile(u64 program_id);
void OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryType type);
2021-06-02 01:16:38 +00:00
void OnGameListRemoveFile(u64 program_id, GameListRemoveTarget target,
2021-06-03 06:01:41 +00:00
const std::string& game_path);
2021-06-28 09:33:07 +00:00
void OnGameListDumpRomFS(u64 program_id, const std::string& game_path, DumpRomFSTarget target);
2020-12-28 15:15:37 +00:00
void OnGameListCopyTID(u64 program_id);
void OnGameListNavigateToGamedbEntry(u64 program_id,
const CompatibilityList& compatibility_list);
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();
2021-07-26 01:00:19 +00:00
void OnConfigureTas();
2021-11-22 06:17:44 +00:00
void OnTasStartStop();
void OnTasRecord();
void OnTasReset();
2022-02-10 18:04:38 +00:00
void OnToggleDockedMode();
void OnToggleGpuAccuracy();
void OnToggleAdaptingFilter();
2020-12-28 15:15:37 +00:00
void OnConfigurePerGame();
void OnLoadAmiibo();
void OnOpenYuzuFolder();
void OnAbout();
void OnToggleFilterBar();
2021-12-29 20:59:21 +00:00
void OnToggleStatusBar();
2020-12-28 15:15:37 +00:00
void OnDisplayTitleBars(bool);
void InitializeHotkeys();
void ToggleFullscreen();
void ShowFullscreen();
void HideFullscreen();
void ToggleWindowMode();
2021-10-12 01:16:41 +00:00
void ResetWindowSize(u32 width, u32 height);
2020-12-28 15:15:37 +00:00
void ResetWindowSize720();
2021-10-12 01:16:41 +00:00
void ResetWindowSize900();
2020-12-28 15:15:37 +00:00
void ResetWindowSize1080();
void OnCaptureScreenshot();
2021-10-16 00:35:29 +00:00
void OnCoreError(Core::SystemResultStatus, std::string);
2020-12-28 15:15:37 +00:00
void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
void OnLanguageChanged(const QString& locale);
2021-01-05 02:12:39 +00:00
void OnMouseActivity();
2020-12-28 15:15:37 +00:00
private:
void RemoveBaseContent(u64 program_id, const QString& entry_type);
void RemoveUpdateContent(u64 program_id, const QString& entry_type);
void RemoveAddOnContent(u64 program_id, const QString& entry_type);
2021-07-11 20:43:19 +00:00
void RemoveTransferableShaderCache(u64 program_id, GameListRemoveTarget target);
void RemoveAllTransferableShaderCaches(u64 program_id);
2021-06-03 06:01:41 +00:00
void RemoveCustomConfiguration(u64 program_id, const std::string& game_path);
2020-12-28 15:15:37 +00:00
std::optional<u64> SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id);
InstallResult InstallNSPXCI(const QString& filename);
InstallResult InstallNCA(const QString& filename);
void MigrateConfigFiles();
2021-06-23 12:35:57 +00:00
void UpdateWindowTitle(std::string_view title_name = {}, std::string_view title_version = {},
std::string_view gpu_vendor = {});
2021-10-24 04:39:01 +00:00
void UpdateFilterText();
void UpdateAAText();
2020-12-28 15:15:37 +00:00
void UpdateStatusBar();
2021-07-09 01:27:40 +00:00
void UpdateGPUAccuracyButton();
2020-12-28 15:15:37 +00:00
void UpdateStatusButtons();
void UpdateUISettings();
void HideMouseCursor();
void ShowMouseCursor();
2022-04-18 12:36:15 +00:00
void CenterMouseCursor();
2020-12-28 15:15:37 +00:00
void OpenURL(const QUrl& url);
void LoadTranslation();
void OpenPerGameConfiguration(u64 title_id, const std::string& file_name);
2021-11-22 06:17:44 +00:00
2021-07-26 01:00:19 +00:00
QString GetTasStateDescription() const;
2020-12-28 15:15:37 +00:00
2021-10-16 00:35:29 +00:00
std::unique_ptr<Ui::MainWindow> ui;
2020-12-28 15:15:37 +00:00
2021-10-16 00:35:29 +00:00
std::unique_ptr<Core::System> system;
2020-12-28 15:15:37 +00:00
std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
GRenderWindow* render_window;
GameList* game_list;
LoadingScreen* loading_screen;
GameListPlaceholder* game_list_placeholder;
// Status bar elements
QLabel* message_label = nullptr;
QLabel* shader_building_label = nullptr;
2021-10-24 04:39:01 +00:00
QLabel* res_scale_label = nullptr;
2020-12-28 15:15:37 +00:00
QLabel* emu_speed_label = nullptr;
QLabel* game_fps_label = nullptr;
QLabel* emu_frametime_label = nullptr;
2021-07-26 01:00:19 +00:00
QLabel* tas_label = nullptr;
2021-07-09 01:27:40 +00:00
QPushButton* gpu_accuracy_button = nullptr;
2020-12-28 15:15:37 +00:00
QPushButton* renderer_status_button = nullptr;
QPushButton* dock_status_button = nullptr;
2021-10-24 04:39:01 +00:00
QPushButton* filter_status_button = nullptr;
QPushButton* aa_status_button = nullptr;
2020-12-28 15:15:37 +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 game_path;
bool auto_paused = false;
2022-02-10 18:04:38 +00:00
bool auto_muted = false;
2020-12-28 15:15:37 +00:00
QTimer mouse_hide_timer;
2022-04-18 12:36:15 +00:00
QTimer mouse_center_timer;
2020-12-28 15:15:37 +00:00
// FS
std::shared_ptr<FileSys::VfsFilesystem> vfs;
std::unique_ptr<FileSys::ManualContentProvider> provider;
// Debugger panes
ProfilerWidget* profilerWidget;
MicroProfileDialog* microProfileDialog;
WaitTreeWidget* waitTreeWidget;
2021-02-04 20:32:13 +00:00
ControllerDialog* controller_dialog;
2020-12-28 15:15:37 +00:00
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;
2021-04-13 00:50:20 +00:00
// Applets
QtSoftwareKeyboardDialog* software_keyboard = nullptr;
2021-12-29 20:59:21 +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{};
2021-12-22 09:32:56 +00:00
#ifdef __linux__
QDBusObjectPath wake_lock{};
#endif
2021-04-13 00:50:20 +00:00
2020-12-28 15:15:37 +00:00
protected:
void dropEvent(QDropEvent* event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
2022-04-18 12:36:15 +00:00
void leaveEvent(QEvent* event) override;
2020-12-28 15:15:37 +00:00
};