Skip to content

Commit

Permalink
win32: changes to GUI cheat handling
Browse files Browse the repository at this point in the history
  • Loading branch information
OV2 committed Apr 30, 2018
1 parent e69fd7c commit 25fa85b
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions win32/wsnes9x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2306,10 +2306,8 @@ LRESULT CALLBACK WinProc(
break;
case ID_CHEAT_ENTER:
RestoreGUIDisplay ();
S9xCheatsDisable ();
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_CHEATER), hWnd, DlgCheater);
S9xSaveCheatFile (S9xGetFilename (".cht", CHEAT_DIR));
S9xCheatsEnable ();
RestoreSNESDisplay ();
break;
case ID_CHEAT_SEARCH:
Expand Down Expand Up @@ -8544,19 +8542,18 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
for(counter=0; counter < Cheat.g.size(); counter++)
{
char *code_string;
Utf8ToWide *wstring;
int curr_idx=-1;
code_string = S9xCheatGroupToText(counter);
wstring = new Utf8ToWide(code_string);
Utf8ToWide wstring(code_string);
delete[] code_string;

LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.mask=LVIF_TEXT;
lvi.cchTextMax = CHEAT_SIZE;
lvi.pszText = *wstring;
lvi.pszText = wstring;
lvi.iItem=counter;
curr_idx=ListView_InsertItem(GetDlgItem(hDlg,IDC_CHEAT_LIST), &lvi);
delete[] code_string;
delete wstring;

unsigned int k;
for(k=0;k<counter;k++)
Expand All @@ -8567,15 +8564,14 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
ct.index[counter]=curr_idx;
ct.state[counter]=Untouched;

wstring = new Utf8ToWide(Cheat.g[counter].name);
Utf8ToWide wstring2(Cheat.g[counter].name);
memset(&lvi, 0, sizeof(LVITEM));
lvi.iItem=curr_idx;
lvi.iSubItem=1;
lvi.mask=LVIF_TEXT;
lvi.cchTextMax = CHEAT_SIZE;
lvi.pszText = *wstring;
lvi.pszText = wstring2;
SendDlgItemMessage(hDlg,IDC_CHEAT_LIST, LVM_SETITEM, 0, (LPARAM)&lvi);
delete wstring;

ListView_SetCheckState(GetDlgItem(hDlg,IDC_CHEAT_LIST), curr_idx, Cheat.g[counter].enabled);

Expand Down Expand Up @@ -8663,22 +8659,19 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)

if(valid_cheat)
{
Utf8ToWide *wstring;

wstring = new Utf8ToWide(valid_cheat);

Utf8ToWide wstring(valid_cheat);
delete[] valid_cheat;

int curr_idx=-1;

LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.mask=LVIF_TEXT;
lvi.pszText=*wstring;
lvi.pszText=wstring;
lvi.iItem=ListView_GetItemCount(GetDlgItem(hDlg,IDC_CHEAT_LIST));
curr_idx=ListView_InsertItem(GetDlgItem(hDlg,IDC_CHEAT_LIST), &lvi);

SetDlgItemText(hDlg, IDC_CHEAT_CODE, *wstring);
SetDlgItemText(hDlg, IDC_CHEAT_CODE, wstring);

unsigned int k;
for(k=0;k<Cheat.g.size();k++)
Expand All @@ -8694,8 +8687,6 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
lvi.pszText=tempDesc;
lvi.cchTextMax=CHEAT_SIZE;
SendDlgItemMessage(hDlg,IDC_CHEAT_LIST, LVM_SETITEM, 0, (LPARAM)&lvi);

delete wstring;
}
}
break;
Expand All @@ -8710,27 +8701,24 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)

if(valid_cheat)
{
Utf8ToWide *wstring;
delete[] valid_cheat;

for(j=0;j<(int)Cheat.g.size();j++)
{
if(ct.index[j]==sel_idx)
ct.state[j]=Modified;
}

wstring = new Utf8ToWide(code);
Utf8ToWide wstring(code);

LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.mask=LVIF_TEXT;
lvi.pszText=*wstring;
lvi.pszText=wstring;
lvi.iItem=sel_idx;
lvi.cchTextMax = CHEAT_SIZE;
ListView_SetItem(GetDlgItem(hDlg,IDC_CHEAT_LIST), &lvi);
SetDlgItemText(hDlg, IDC_CHEAT_CODE, *wstring);

delete wstring;
delete[] valid_cheat;
SetDlgItemText(hDlg, IDC_CHEAT_CODE, wstring);

GetDlgItemText(hDlg, IDC_CHEAT_DESCRIPTION, temp, CHEAT_SIZE);

Expand Down Expand Up @@ -8817,14 +8805,9 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
if(ct.index[l]==k)
{
hit=true;
Cheat.g[l].enabled=ListView_GetCheckState(GetDlgItem(hDlg, IDC_CHEAT_LIST),l);
if(ct.state[l]==Untouched)
l=Cheat.g.size();

else if(ct.state[l]==(unsigned long)Modified)
if(ct.state[l]==(unsigned long)Modified) // modified in GUI, change in core
{
S9xDisableCheatGroup(l);

TCHAR wcode[CHEAT_SIZE];
TCHAR wdescription[CHEAT_SIZE];

Expand All @@ -8848,11 +8831,16 @@ INT_PTR CALLBACK DlgCheater(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
WideToUtf8 description(wdescription);

S9xModifyCheatGroup(l, description, code);

if (ListView_GetCheckState(GetDlgItem(hDlg, IDC_CHEAT_LIST), k))
S9xEnableCheatGroup(l);
}

// set core state according to checkbox
if (ListView_GetCheckState(GetDlgItem(hDlg, IDC_CHEAT_LIST), k))
S9xEnableCheatGroup(l);
else
S9xDisableCheatGroup(l);

// we've found the internal cheat index, stop checking for this list entry
break;
}
}
if(!hit)
Expand Down

0 comments on commit 25fa85b

Please sign in to comment.