From ddcd6ef8551156a0109416f4d7a181e97d983c82 Mon Sep 17 00:00:00 2001 From: zilmar Date: Sun, 17 Jan 2021 16:15:26 +1030 Subject: [PATCH] Confirm cheat changes on closing window --- Lang/English.pj.Lang | 3 ++- Source/Project64-core/Multilanguage.h | 2 ++ .../Multilanguage/LanguageClass.cpp | 2 ++ .../Project64/UserInterface/CheatClassUI.cpp | 24 ++++++++++++++++++- Source/Project64/UserInterface/CheatClassUI.h | 3 +++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Lang/English.pj.Lang b/Lang/English.pj.Lang index 92f6e6b0a..e53e97b37 100644 --- a/Lang/English.pj.Lang +++ b/Lang/English.pj.Lang @@ -536,7 +536,8 @@ #2059# "Nintendo 64DD Japanese Retail IPL ROM not found.\nIt is required to play japanese region 64DD disk images.\n\nPlease select the required ROM in the Settings." #2061# "Nintendo 64DD American Retail IPL ROM not found.\nIt is required to play american region 64DD disk images.\n\nPlease select the required ROM in the Settings." #2062# "Nintendo 64DD Development IPL ROM not found.\nIt is required to play development 64DD disk images.\n\nPlease select the required ROM in the Settings." - +#2063# "Failed to update cheat, it is invalid" +#2064# "Invalid Cheat" /********************************************************************************* * Android * diff --git a/Source/Project64-core/Multilanguage.h b/Source/Project64-core/Multilanguage.h index da4f4af7a..2c3b47ca5 100644 --- a/Source/Project64-core/Multilanguage.h +++ b/Source/Project64-core/Multilanguage.h @@ -577,6 +577,8 @@ enum LanguageStringID MSG_MSGBOX_WARNING_TITLE = 2060, MSG_USA_IPL_REQUIRED = 2061, MSG_TOOL_IPL_REQUIRED = 2062, + MSG_CHEAT_INVALID_MSG = 2063, + MSG_CHEAT_INVALID_TITLE = 2064, /********************************************************************************* * Android * diff --git a/Source/Project64-core/Multilanguage/LanguageClass.cpp b/Source/Project64-core/Multilanguage/LanguageClass.cpp index 9e6ce04a7..88ea67385 100644 --- a/Source/Project64-core/Multilanguage/LanguageClass.cpp +++ b/Source/Project64-core/Multilanguage/LanguageClass.cpp @@ -542,6 +542,8 @@ void CLanguage::LoadDefaultStrings(void) DEF_STR(MSG_IPL_REQUIRED, "Nintendo 64DD Japanese Retail IPL ROM not found.\nIt is required to play japanese region 64DD disk images.\n\nPlease select the required ROM in the Settings."); DEF_STR(MSG_USA_IPL_REQUIRED, "Nintendo 64DD American Retail IPL ROM not found.\nIt is required to play american region 64DD disk images.\n\nPlease select the required ROM in the Settings."); DEF_STR(MSG_TOOL_IPL_REQUIRED, "Nintendo 64DD Development IPL ROM not found.\nIt is required to play development 64DD disk images.\n\nPlease select the required ROM in the Settings."); + DEF_STR(MSG_CHEAT_INVALID_MSG, "Failed to update cheat, it is invalid"); + DEF_STR(MSG_CHEAT_INVALID_TITLE, "Invalid Cheat"); /********************************************************************************* * Android * diff --git a/Source/Project64/UserInterface/CheatClassUI.cpp b/Source/Project64/UserInterface/CheatClassUI.cpp index 5d08cd859..1d8ab1857 100644 --- a/Source/Project64/UserInterface/CheatClassUI.cpp +++ b/Source/Project64/UserInterface/CheatClassUI.cpp @@ -112,6 +112,11 @@ LRESULT CCheatsUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/ LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { + if (m_EditCheat.ValuesChanged()) + { + return 0; + } + if (g_BaseSystem) { g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_Cheats); @@ -1034,7 +1039,24 @@ bool CEditCheat::ValuesChanged(void) } if (Result == IDYES) { - SendMessage(WM_COMMAND, MAKELPARAM(IDC_ADD, 0)); + bool validcodes, validoptions, nooptions; + CodeFormat Format; + ReadCodeEntries(validcodes, validoptions, nooptions, Format); + if (!nooptions) + { + ReadOptions(validoptions, Format); + } + + bool CanAdd = validcodes && (validoptions || nooptions) && GetDlgItem(IDC_CODE_NAME).GetWindowTextLength() > 0; + if (CanAdd) + { + SendMessage(WM_COMMAND, MAKELPARAM(IDC_ADD, 0)); + } + else + { + MessageBox(wGS(MSG_CHEAT_INVALID_MSG).c_str(), wGS(MSG_CHEAT_INVALID_TITLE).c_str(), MB_ICONERROR); + return true; + } } return false; } diff --git a/Source/Project64/UserInterface/CheatClassUI.h b/Source/Project64/UserInterface/CheatClassUI.h index e64655183..44d2893fb 100644 --- a/Source/Project64/UserInterface/CheatClassUI.h +++ b/Source/Project64/UserInterface/CheatClassUI.h @@ -14,6 +14,7 @@ #include class CEditCheat; +class CCheatsUI; class CCheatList : public CDialogImpl @@ -79,6 +80,8 @@ private: class CEditCheat : public CDialogImpl { + friend CCheatsUI; + public: enum {