From a0fe0e38c161b09566d38ffb85b36419f600fef6 Mon Sep 17 00:00:00 2001 From: shenweip <1037567878@qq.com> Date: Thu, 22 Oct 2020 17:14:35 +0800 Subject: [PATCH] SwicthUMD:Only update Switch UMD item of Windows menu instead of entire UI. --- Core/HLE/sceUmd.cpp | 12 ++++++++---- Core/Host.h | 2 ++ Qt/QtHost.h | 2 ++ UI/HostTypes.h | 2 ++ UWP/UWPHost.h | 2 ++ Windows/MainWindow.cpp | 4 ++++ Windows/MainWindow.h | 2 ++ Windows/MainWindowMenu.cpp | 7 +++++++ Windows/WindowsHost.cpp | 4 ++++ Windows/WindowsHost.h | 2 ++ headless/StubHost.h | 2 ++ 11 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Core/HLE/sceUmd.cpp b/Core/HLE/sceUmd.cpp index 5cb209c6c4..51c44b72ae 100644 --- a/Core/HLE/sceUmd.cpp +++ b/Core/HLE/sceUmd.cpp @@ -515,17 +515,21 @@ bool getUMDReplacePermit() { static u32 sceUmdReplaceProhibit() { - UMDReplacePermit = false; DEBUG_LOG(SCEIO,"sceUmdReplaceProhibit()"); - host->UpdateUI(); + if (UMDReplacePermit) { + UMDReplacePermit = false; + host->NotifySwitchUMDUpdated(); + } return 0; } static u32 sceUmdReplacePermit() { - UMDReplacePermit = true; DEBUG_LOG(SCEIO,"sceUmdReplacePermit()"); - host->UpdateUI(); + if (!UMDReplacePermit) { + UMDReplacePermit = true; + host->NotifySwitchUMDUpdated(); + } return 0; } diff --git a/Core/Host.h b/Core/Host.h index 35838c8083..4a4c739c3d 100644 --- a/Core/Host.h +++ b/Core/Host.h @@ -57,6 +57,8 @@ public: virtual void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) {} virtual void SendUIMessage(const std::string &message, const std::string &value) {} + virtual void NotifySwitchUMDUpdated() {} + // Used for headless. virtual bool ShouldSkipUI() { return false; } virtual void SendDebugOutput(const std::string &output) {} diff --git a/Qt/QtHost.h b/Qt/QtHost.h index e0c7ef4b7e..2aa9bc1870 100644 --- a/Qt/QtHost.h +++ b/Qt/QtHost.h @@ -92,6 +92,8 @@ public: NativeMessageReceived(message.c_str(), value.c_str()); } + void NotifySwitchUMDUpdated() override {} + private: std::string SymbolMapFilename(std::string currentFilename); MainWindow* mainWindow; diff --git a/UI/HostTypes.h b/UI/HostTypes.h index 134c808862..c801859b07 100644 --- a/UI/HostTypes.h +++ b/UI/HostTypes.h @@ -53,4 +53,6 @@ public: void SendUIMessage(const std::string &message, const std::string &value) override { NativeMessageReceived(message.c_str(), value.c_str()); } + + void NotifySwitchUMDUpdated() override {} }; diff --git a/UWP/UWPHost.h b/UWP/UWPHost.h index 3c70db9991..ee49d0cba5 100644 --- a/UWP/UWPHost.h +++ b/UWP/UWPHost.h @@ -40,6 +40,8 @@ public: void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override; + void NotifySwitchUMDUpdated() override {} + GraphicsContext *GetGraphicsContext() { return nullptr; } private: diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index f925f05fe8..7ef4340741 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -970,6 +970,10 @@ namespace MainWindow InputDevice::BeginPolling(); break; + case WM_USER_SWITCHUMD_UPDATED: + UpdateSwitchUMD(); + break; + case WM_MENUSELECT: // Called when a menu is opened. Also when an item is selected, but meh. UpdateMenus(true); diff --git a/Windows/MainWindow.h b/Windows/MainWindow.h index 0341e897e7..c0bb7a8f84 100644 --- a/Windows/MainWindow.h +++ b/Windows/MainWindow.h @@ -21,6 +21,7 @@ namespace MainWindow WM_USER_BROWSE_BOOT_DONE = WM_USER + 104, WM_USER_TOGGLE_FULLSCREEN = WM_USER + 105, WM_USER_RESTART_EMUTHREAD = WM_USER + 106, + WM_USER_SWITCHUMD_UPDATED = WM_USER + 107 }; enum { @@ -66,6 +67,7 @@ namespace MainWindow void Close(); void UpdateMenus(bool isMenuSelect = false); void UpdateCommands(); + void UpdateSwitchUMD(); void SetWindowTitle(const wchar_t *title); void Redraw(); HWND GetHWND(); diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index ee9500291d..979a60ecb7 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1379,6 +1379,13 @@ namespace MainWindow { TranslateMenuItem(menu, ID_TOGGLE_BREAK, L"\tF8", isPaused ? "Run" : "Break"); } + void UpdateSwitchUMD() { + HMENU menu = GetMenu(GetHWND()); + GlobalUIState state = GetUIState(); + UINT umdSwitchEnable = state == UISTATE_INGAME && getUMDReplacePermit() ? MF_ENABLED : MF_GRAYED; + EnableMenuItem(menu, ID_EMULATION_SWITCH_UMD, umdSwitchEnable); + } + // Message handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { diff --git a/Windows/WindowsHost.cpp b/Windows/WindowsHost.cpp index 210344033f..d7b3d93396 100644 --- a/Windows/WindowsHost.cpp +++ b/Windows/WindowsHost.cpp @@ -407,3 +407,7 @@ void WindowsHost::NotifyUserMessage(const std::string &message, float duration, void WindowsHost::SendUIMessage(const std::string &message, const std::string &value) { NativeMessageReceived(message.c_str(), value.c_str()); } + +void WindowsHost::NotifySwitchUMDUpdated() { + PostMessage(mainWindow_, MainWindow::WM_USER_SWITCHUMD_UPDATED, 0, 0); +} diff --git a/Windows/WindowsHost.h b/Windows/WindowsHost.h index 581a8064d3..492d47a9db 100644 --- a/Windows/WindowsHost.h +++ b/Windows/WindowsHost.h @@ -63,6 +63,8 @@ public: void NotifyUserMessage(const std::string &message, float duration = 1.0f, u32 color = 0x00FFFFFF, const char *id = nullptr) override; void SendUIMessage(const std::string &message, const std::string &value) override; + void NotifySwitchUMDUpdated() override; + GraphicsContext *GetGraphicsContext() { return gfx_; } private: diff --git a/headless/StubHost.h b/headless/StubHost.h index 8ac54ddff8..571444ce0b 100644 --- a/headless/StubHost.h +++ b/headless/StubHost.h @@ -72,6 +72,8 @@ public: void SendDebugScreenshot(const u8 *pixbuf, u32 w, u32 h) override; + void NotifySwitchUMDUpdated() override {} + // Unique for HeadlessHost virtual void SwapBuffers() {}