From 3f4fc0e25acf9ba180d7cc71a4cedb038a0440b0 Mon Sep 17 00:00:00 2001 From: OV2 Date: Tue, 1 May 2018 22:59:09 +0200 Subject: [PATCH] win32: updates to cheat dialog handling --- win32/wsnes9x.cpp | 198 +++++++++++++++++++++++++--------------------- 1 file changed, 107 insertions(+), 91 deletions(-) diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp index 2af28d23..7919a321 100644 --- a/win32/wsnes9x.cpp +++ b/win32/wsnes9x.cpp @@ -8603,6 +8603,8 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) TCHAR buf[CHEAT_SIZE]; LV_ITEM lvi; + internal_change = true; // do not enable update button + /* Code */ ITEM_QUERY (lvi, IDC_CHEAT_LIST, 0, buf, CHEAT_SIZE); SetDlgItemText(hDlg, IDC_CHEAT_CODE, lvi.pszText); @@ -8611,7 +8613,7 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) ITEM_QUERY(lvi, IDC_CHEAT_LIST, 1, buf, CHEAT_SIZE); SetDlgItemText(hDlg, IDC_CHEAT_DESCRIPTION, lvi.pszText); - internal_change = true; + internal_change = false; } sel_idx=ListView_GetSelectionMark(GetDlgItem(hDlg, IDC_CHEAT_LIST)); has_sel=true; @@ -8633,13 +8635,13 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) if(internal_change) { - internal_change=!internal_change; return false; } if(!has_sel) return true; - EnableWindow(GetDlgItem(hDlg, IDC_UPDATE_CHEAT), true); - return true; + + EnableWindow(GetDlgItem(hDlg, IDC_UPDATE_CHEAT), true); + return true; } break; @@ -8701,8 +8703,11 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) for(j=0;j<(int)Cheat.g.size();j++) { - if(ct.index[j]==sel_idx) - ct.state[j]=Modified; + if (ct.index[j] == sel_idx) + { + ct.state[j] = Modified; + break; + } } Utf8ToWide wstring(code); @@ -8725,6 +8730,9 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) lvi.pszText=temp; lvi.cchTextMax = CHEAT_SIZE; SendDlgItemMessage(hDlg,IDC_CHEAT_LIST, LVM_SETITEM, 0, (LPARAM)&lvi); + + // update done, disable update button + EnableWindow(GetDlgItem(hDlg, IDC_UPDATE_CHEAT), false); } } @@ -8734,8 +8742,11 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) unsigned int j; for(j=0;j= 0) - if (ListView_GetCheckState(GetDlgItem(hDlg, IDC_CHEAT_LIST), k)) - S9xEnableCheatGroup(index); + // we've found the internal cheat index, stop checking for this list entry + break; } } - - for(l=(int)Cheat.g.size()-1; l>=0; l--) + if(!hit) { - if(ct.state[l]==Deleted) - { - S9xDeleteCheatGroup(l); - } + TCHAR wcode[CHEAT_SIZE]; + TCHAR wdescription[CHEAT_SIZE]; + + LV_ITEM lvi; + memset(&lvi, 0, sizeof(LV_ITEM)); + lvi.iItem = k; + lvi.mask = LVIF_TEXT; + lvi.pszText = wcode; + lvi.cchTextMax = CHEAT_SIZE; + ListView_GetItem(GetDlgItem(hDlg, IDC_CHEAT_LIST), &lvi); + + memset(&lvi, 0, sizeof(LV_ITEM)); + lvi.iItem = k; + lvi.iSubItem = 1; + lvi.mask = LVIF_TEXT; + lvi.pszText = wdescription; + lvi.cchTextMax = CHEAT_SIZE; + ListView_GetItem(GetDlgItem(hDlg, IDC_CHEAT_LIST), &lvi); + + WideToUtf8 code(wcode); + WideToUtf8 description(wdescription); + + int index = S9xAddCheatGroup(description, code); + + if (index >= 0) + if (ListView_GetCheckState(GetDlgItem(hDlg, IDC_CHEAT_LIST), k)) + S9xEnableCheatGroup(index); } } - case IDCANCEL: - delete [] ct.index; - delete [] ct.state; - EndDialog(hDlg, 0); - return true; - default:return false; + + for(l=(int)Cheat.g.size()-1; l>=0; l--) + { + if(ct.state[l]==Deleted) + { + S9xDeleteCheatGroup(l); + } } + } + case IDCANCEL: + delete [] ct.index; + delete [] ct.state; + EndDialog(hDlg, 0); + return true; + default: + return false; + } } default: return false; }