project64/Source/Project64/UserInterface/CheatClassUI.cpp

1120 lines
34 KiB
C++
Raw Normal View History

/****************************************************************************
* *
2015-11-10 05:21:49 +00:00
* Project64 - A Nintendo 64 emulator. *
* http://www.pj64-emu.com/ *
* Copyright (C) 2012 Project64. All rights reserved. *
* *
* License: *
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
* *
****************************************************************************/
#include "stdafx.h"
#include <Project64-core\N64System\Enhancement\Enhancements.h>
CCheatsUI::CCheatsUI(void) :
m_EditCheat(m_Cheats, m_SelectCheat),
m_SelectCheat(m_Cheats, m_EditCheat),
m_bModal(false)
{
}
CCheatsUI::~CCheatsUI()
{
}
void CCheatsUI::Display(HWND hParent, bool BlockExecution)
{
m_Cheats = g_Enhancements->Cheats();
2020-05-19 02:25:57 +00:00
if (g_BaseSystem)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_Cheats);
2015-12-23 19:26:17 +00:00
}
if (BlockExecution)
{
m_bModal = true;
DoModal(hParent);
}
else if (m_hWnd != NULL)
{
SetFocus();
}
else
{
m_bModal = false;
Create(hParent);
}
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
2020-05-19 02:25:57 +00:00
bool inBasicMode = g_Settings->LoadBool(UserInterface_BasicMode);
m_StateBtn.Attach(GetDlgItem(IDC_STATE));
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
WINDOWPLACEMENT WndPlac = {0};
WndPlac.length = sizeof(WndPlac);
GetWindowPlacement(&WndPlac);
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
SetWindowText(wGS(CHEAT_TITLE).c_str());
m_SelectCheat.Create(m_hWnd, (LPARAM)this);
m_SelectCheat.SetWindowPos(HWND_TOP, 5, 8, 0, 0, SWP_NOSIZE);
m_SelectCheat.ShowWindow(SW_SHOW);
2020-05-19 02:25:57 +00:00
if (inBasicMode)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
CRect rcList;
m_SelectCheat.GetWindowRect(&rcList);
m_MinSizeDlg = rcList.right - rcList.left + 16;
m_MaxSizeDlg = m_MinSizeDlg;
m_DialogState = CONTRACTED;
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + m_MinSizeDlg;
SetWindowPlacement(&WndPlac);
m_StateBtn.ShowWindow(SW_HIDE);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
else
{
m_EditCheat.Create(m_hWnd);
m_EditCheat.SetWindowPos(HWND_TOP, (WndPlac.rcNormalPosition.right - WndPlac.rcNormalPosition.left) / 2, 8, 0, 0, SWP_NOSIZE);
m_EditCheat.ShowWindow(SW_HIDE);
CRect rcList, rcEditCheat;
m_SelectCheat.GetWindowRect(&rcList);
m_EditCheat.GetWindowRect(&rcEditCheat);
m_MinSizeDlg = rcList.Width() + 32;
m_MaxSizeDlg = rcEditCheat.right - rcList.left + 32;
m_DialogState = CONTRACTED;
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + m_MinSizeDlg;
SetWindowPlacement(&WndPlac);
CRect rc;
GetClientRect(&rc);
m_StateBtn.SetWindowPos(HWND_TOP, rc.Width() - 16, 0, 16, rc.Height(), 0);
m_StateBtn.SetIcon(AtlLoadIconImage(MAKEINTRESOURCE(IDI_RIGHT), LR_DEFAULTCOLOR));
}
CRect rcDlg, rcParent;
GetWindowRect(&rcDlg);
GetParent().GetWindowRect(&rcParent);
int32_t DlgWidth = rcDlg.Width();
int32_t DlgHeight = rcDlg.Height();
int32_t X = (((rcParent.Width()) - DlgWidth) / 2) + rcParent.left;
int32_t Y = (((rcParent.Height()) - DlgHeight) / 2) + rcParent.top;
SetWindowPos(NULL, X, Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
m_SelectCheat.RefreshItems();
return 0;
}
LRESULT CCheatsUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_StateBtn.Detach();
return 0;
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2015-12-23 19:26:17 +00:00
if (g_BaseSystem)
{
2020-05-19 02:25:57 +00:00
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_Cheats);
2015-12-23 19:26:17 +00:00
}
if (m_bModal)
{
EndDialog(0);
}
else
{
DestroyWindow();
}
2020-05-19 02:25:57 +00:00
return 0;
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatsUI::OnStateChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2020-05-19 02:25:57 +00:00
WINDOWPLACEMENT WndPlac;
WndPlac.length = sizeof(WndPlac);
GetWindowPlacement(&WndPlac);
if (m_DialogState == CONTRACTED)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
m_DialogState = EXPANDED;
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + m_MaxSizeDlg;
SetWindowPlacement(&WndPlac);
RECT clientrect;
GetClientRect(&clientrect);
m_StateBtn.SetIcon(AtlLoadIconImage(MAKEINTRESOURCE(IDI_LEFT), LR_DEFAULTCOLOR));
m_StateBtn.SetWindowPos(HWND_TOP, (clientrect.right - clientrect.left) - 16, 0, 16, clientrect.bottom - clientrect.top, 0);
m_EditCheat.ShowWindow(SW_SHOW);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
else
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
m_DialogState = CONTRACTED;
WndPlac.rcNormalPosition.right = WndPlac.rcNormalPosition.left + m_MinSizeDlg;
SetWindowPlacement(&WndPlac);
RECT clientrect;
GetClientRect(&clientrect);
m_StateBtn.SetIcon(AtlLoadIconImage(MAKEINTRESOURCE(IDI_RIGHT), LR_DEFAULTCOLOR));
m_StateBtn.SetWindowPos(HWND_TOP, (clientrect.right - clientrect.left) - 16, 0, 16, clientrect.bottom - clientrect.top, 0);
m_EditCheat.ShowWindow(SW_HIDE);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
return 0;
}
CCheatList::CCheatList(CEnhancementList & Cheats, CEditCheat & EditCheat) :
m_Cheats(Cheats),
2020-05-19 02:25:57 +00:00
m_EditCheat(EditCheat),
m_hSelectedItem(NULL),
m_DeleteingEntries(false)
{
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
CCheatList::~CCheatList()
{
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
GetDlgItem(IDC_NOTESFRAME).SetWindowText(wGS(CHEAT_NOTES_FRAME).c_str());
GetDlgItem(IDC_UNMARK).SetWindowText(wGS(CHEAT_MARK_NONE).c_str());
RECT rcButton, rcList;
GetDlgItem(IDC_UNMARK).GetWindowRect(&rcButton);
GetWindowRect(&rcList);
CRect hCheatTreeRect(6, 4, rcList.right - rcList.left - 13, rcButton.top - rcList.top - 8);
m_hCheatTree.Create(m_hWnd, &hCheatTreeRect, L"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | WS_TABSTOP | TVS_FULLROWSELECT,
WS_EX_CLIENTEDGE, (HMENU)IDC_MYTREE);
m_hCheatTree.SetWindowLong(GWL_STYLE, TVS_CHECKBOXES | TVS_SHOWSELALWAYS | m_hCheatTree.GetWindowLong(GWL_STYLE));
CImageList hImageList;
hImageList.Create(16, 16, ILC_COLOR | ILC_MASK, 40, 40);
CBitmap bmp;
bmp.LoadBitmap(MAKEINTRESOURCE(IDB_TRI_STATE));
hImageList.Add(bmp, RGB(255, 0, 255));
m_hCheatTree.SetImageList(hImageList, TVSIL_STATE);
return true;
}
2015-12-23 19:26:17 +00:00
LRESULT CCheatList::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_hCheatTree.Detach();
return 0;
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnChangeCodeExtension(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
m_hSelectedItem = (HTREEITEM)lParam;
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
TVITEM item = { 0 };
item.mask = TVIF_PARAM;
item.hItem = m_hSelectedItem;
if (!m_hCheatTree.GetItem(&item) || item.lParam == NULL)
2020-05-19 02:25:57 +00:00
{
return 0;
}
2015-12-23 19:26:17 +00:00
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
if (Enhancement->CodeOptionSize() == 0 || Enhancement->GetOptions().empty())
2020-05-19 02:25:57 +00:00
{
return 0;
}
2015-12-23 19:26:17 +00:00
CEnhancementCodeEx(Enhancement).DoModal();
stdstr Name = Enhancement->GetNameAndExtension();
const char * ChildName = strrchr(Name.c_str(), '\\');
if (ChildName != nullptr)
2020-05-19 02:25:57 +00:00
{
Name = &ChildName[1];
2015-12-23 19:26:17 +00:00
}
std::wstring wName = Name.ToUTF16();
2020-05-19 02:25:57 +00:00
item.mask = TVIF_TEXT;
item.pszText = (LPWSTR)wName.c_str();
item.cchTextMax = wName.length();
2020-05-19 02:25:57 +00:00
m_hCheatTree.SetItem(&item);
return 0;
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnPopupDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2020-05-19 02:25:57 +00:00
int Response = MessageBox(wGS(MSG_DEL_SURE).c_str(), wGS(MSG_DEL_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION);
if (Response != IDYES)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
return 0;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
TVITEM item = { 0 };
item.hItem = m_hSelectedItem;
item.mask = TVIF_PARAM;
m_hCheatTree.GetItem(&item);
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
ChangeChildrenStatus(TVI_ROOT, false);
DeleteCheat(item.lParam);
RefreshItems();
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnUnmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
ChangeChildrenStatus(TVI_ROOT, false);
if (g_Enhancements != nullptr)
2015-12-23 19:26:17 +00:00
{
g_Enhancements->UpdateCheats();
2020-05-19 02:25:57 +00:00
}
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnTreeClicked(NMHDR* lpnmh)
{
uint32_t dwpos = GetMessagePos();
TVHITTESTINFO ht = { 0 };
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
TreeView_HitTest(lpnmh->hwndFrom, &ht);
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
if (TVHT_ONITEMSTATEICON & ht.flags)
{
switch (TV_GetCheckState(ht.hItem))
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
case TV_STATE_CLEAR:
case TV_STATE_INDETERMINATE:
if (m_hCheatTree.GetChildItem(ht.hItem) == NULL)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
TVITEM item = { 0 };
2015-12-23 19:26:17 +00:00
item.mask = TVIF_PARAM;
2020-05-19 02:25:57 +00:00
item.hItem = ht.hItem;
m_hCheatTree.GetItem(&item);
if (item.lParam != NULL)
2015-12-23 19:26:17 +00:00
{
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
if (Enhancement->CodeOptionSize() != 0 && Enhancement->GetOptions().size() > 0 && !Enhancement->OptionSelected())
2020-05-19 02:25:57 +00:00
{
SendMessage(UM_CHANGECODEEXTENSION, 0, (LPARAM)ht.hItem);
TV_SetCheckState(ht.hItem, TV_STATE_CLEAR);
break;
}
}
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
TV_SetCheckState(ht.hItem, TV_STATE_CHECKED);
ChangeChildrenStatus(ht.hItem, true);
CheckParentStatus(m_hCheatTree.GetParentItem(ht.hItem));
break;
case TV_STATE_CHECKED:
TV_SetCheckState(ht.hItem, TV_STATE_CLEAR);
ChangeChildrenStatus(ht.hItem, false);
CheckParentStatus(m_hCheatTree.GetParentItem(ht.hItem));
break;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
switch (TV_GetCheckState(ht.hItem))
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
case TV_STATE_CHECKED: TV_SetCheckState(ht.hItem, TV_STATE_INDETERMINATE); break;
case TV_STATE_CLEAR: TV_SetCheckState(ht.hItem, TV_STATE_CHECKED); break;
case TV_STATE_INDETERMINATE: TV_SetCheckState(ht.hItem, TV_STATE_CLEAR); break;
2015-12-23 19:26:17 +00:00
}
if (g_Enhancements != nullptr)
2015-12-23 19:26:17 +00:00
{
g_Enhancements->UpdateCheats();
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
return 0;
}
LRESULT CCheatList::OnTreeRClicked(NMHDR* lpnmh)
{
if (g_Settings->LoadBool(UserInterface_BasicMode)) { return true; }
//Work out what item is selected
TVHITTESTINFO ht = { 0 };
uint32_t dwpos = GetMessagePos();
// include <windowsx.h> and <windows.h> header files
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(lpnmh->hwndFrom, &ht);
m_hSelectedItem = ht.hItem;
//Show Menu
HMENU hMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_CHEAT_MENU));
HMENU hPopupMenu = GetSubMenu(hMenu, 0);
POINT Mouse;
GetCursorPos(&Mouse);
MenuSetText(hPopupMenu, 0, wGS(CHEAT_ADDNEW).c_str(), NULL);
MenuSetText(hPopupMenu, 1, wGS(CHEAT_EDIT).c_str(), NULL);
MenuSetText(hPopupMenu, 3, wGS(CHEAT_DELETE).c_str(), NULL);
if (m_hSelectedItem != NULL && m_hCheatTree.GetChildItem(m_hSelectedItem) == NULL)
{
TrackPopupMenu(hPopupMenu, 0, Mouse.x, Mouse.y, 0, m_hWnd, NULL);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
DestroyMenu(hMenu);
2015-12-23 19:26:17 +00:00
return true;
}
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnTreeDClicked(NMHDR* lpnmh)
{
2020-05-19 02:25:57 +00:00
uint32_t dwpos = GetMessagePos();
TVHITTESTINFO ht = { 0 };
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(lpnmh->hwndFrom, &ht);
if (TVHT_ONITEMLABEL & ht.flags)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
PostMessage(UM_CHANGECODEEXTENSION, 0, (LPARAM)ht.hItem);
}
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CCheatList::OnTreeSelChanged(NMHDR * /*lpnmh*/)
{
HTREEITEM hItem = m_hCheatTree.GetSelectedItem();
GetDlgItem(IDC_NOTES).SetWindowText(L"");
2020-05-19 02:25:57 +00:00
if (m_hCheatTree.GetChildItem(hItem) == NULL)
{
TVITEM item = { 0 };
2015-12-23 19:26:17 +00:00
item.mask = TVIF_PARAM;
2020-05-19 02:25:57 +00:00
item.hItem = hItem;
m_hCheatTree.GetItem(&item);
if (item.lParam != NULL)
2015-12-23 19:26:17 +00:00
{
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
GetDlgItem(IDC_NOTES).SetWindowText(stdstr(Enhancement->GetNote()).ToUTF16().c_str());
if (m_EditCheat.m_hWnd != NULL)
{
m_EditCheat.SendMessage(CEditCheat::WM_EDITCHEAT, item.lParam, 0);
}
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
return 0;
}
void CCheatList::RefreshItems()
{
if (m_hWnd == NULL) { return; }
m_DeleteingEntries = true;
2021-01-17 03:17:58 +00:00
m_hCheatTree.DeleteAllItems();
2020-05-19 02:25:57 +00:00
m_DeleteingEntries = false;
for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
{
std::string Name = itr->second.GetNameAndExtension();
if (Name.length() == 0)
{
continue;
}
AddCodeLayers((LPARAM)&itr->second, stdstr(Name).ToUTF16(), TVI_ROOT, itr->second.Active());
2020-05-19 02:25:57 +00:00
}
}
void CCheatList::AddCodeLayers(LPARAM Enhancement, const std::wstring &Name, HTREEITEM hParent, bool CheatActive)
2020-05-19 02:25:57 +00:00
{
TV_INSERTSTRUCT tv;
wchar_t Text[500], Item[500];
2021-01-17 03:17:58 +00:00
if (Name.length() > ((sizeof(Text) / sizeof(Text[0])) - 5)) { g_Notify->BreakPoint(__FILE__, __LINE__); }
wcscpy(Text, Name.c_str());
2020-05-19 02:25:57 +00:00
if (wcschr(Text, L'\\') > 0) { *wcschr(Text, L'\\') = 0; }
tv.item.mask = TVIF_TEXT;
tv.item.pszText = Item;
tv.item.cchTextMax = sizeof(Item);
tv.item.hItem = TreeView_GetChild(m_hCheatTree, hParent);
while (tv.item.hItem)
{
TreeView_GetItem(m_hCheatTree, &tv.item);
if (wcscmp(Text, Item) == 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
TV_CHECK_STATE State = TV_GetCheckState(tv.item.hItem);
if ((CheatActive && State == TV_STATE_CLEAR) || (!CheatActive && State == TV_STATE_CHECKED))
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
TV_SetCheckState(tv.item.hItem, TV_STATE_INDETERMINATE);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
size_t StartPos = wcslen(Text) + 1;
std::wstring TempCheatName;
if (StartPos < Name.length())
2020-05-19 02:25:57 +00:00
{
TempCheatName = Name.substr(StartPos);
2020-05-19 02:25:57 +00:00
}
AddCodeLayers(Enhancement, TempCheatName, tv.item.hItem, CheatActive);
2020-05-19 02:25:57 +00:00
return;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
tv.item.hItem = TreeView_GetNextSibling(m_hCheatTree, tv.item.hItem);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
tv.hInsertAfter = TVI_SORT;
tv.item.mask = TVIF_TEXT | TVIF_PARAM;
tv.item.pszText = Text;
tv.item.lParam = Enhancement;
2020-05-19 02:25:57 +00:00
tv.hParent = hParent;
hParent = TreeView_InsertItem(m_hCheatTree, &tv);
TV_SetCheckState(hParent, CheatActive ? TV_STATE_CHECKED : TV_STATE_CLEAR);
if (wcscmp(Text, Name.c_str()) == 0) { return; }
AddCodeLayers(Enhancement, Name.substr(wcslen(Text) + 1), hParent, CheatActive);
}
2020-05-19 02:25:57 +00:00
void CCheatList::ChangeChildrenStatus(HTREEITEM hParent, bool Checked)
{
2020-05-19 02:25:57 +00:00
HTREEITEM hItem = m_hCheatTree.GetChildItem(hParent);;
if (hItem == NULL)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (hParent == TVI_ROOT) { return; }
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
TVITEM item = { 0 };
2015-12-23 19:26:17 +00:00
item.mask = TVIF_PARAM;
2020-05-19 02:25:57 +00:00
item.hItem = hParent;
m_hCheatTree.GetItem(&item);
if (item.lParam == NULL)
2015-12-23 19:26:17 +00:00
{
return;
}
CEnhancement * Enhancement = (CEnhancement *)item.lParam;
if (Checked && Enhancement->CodeOptionSize() != 0 && Enhancement->GetOptions().size() > 0 && !Enhancement->OptionSelected())
{
return;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
TV_SetCheckState(hParent, Checked ? TV_STATE_CHECKED : TV_STATE_CLEAR);
Enhancement->SetActive(Checked);
2020-05-19 02:25:57 +00:00
return;
}
TV_CHECK_STATE state = TV_STATE_UNKNOWN;
while (hItem != NULL)
{
TV_CHECK_STATE ChildState = TV_GetCheckState(hItem);
if ((ChildState != TV_STATE_CHECKED || !Checked) &&
(ChildState != TV_STATE_CLEAR || Checked))
{
ChangeChildrenStatus(hItem, Checked);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
ChildState = TV_GetCheckState(hItem);
if (state == TV_STATE_UNKNOWN) { state = ChildState; }
if (state != ChildState) { state = TV_STATE_INDETERMINATE; }
hItem = m_hCheatTree.GetNextSiblingItem(hItem);
}
if (state != TV_STATE_UNKNOWN)
{
TV_SetCheckState(hParent, state);
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
void CCheatList::CheckParentStatus(HTREEITEM hParent)
{
2020-05-19 02:25:57 +00:00
if (hParent == NULL)
{
return;
}
HTREEITEM hItem = m_hCheatTree.GetChildItem(hParent);
TV_CHECK_STATE InitialState = TV_GetCheckState(hParent);
TV_CHECK_STATE CurrentState = TV_GetCheckState(hItem);
while (hItem != NULL)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (TV_GetCheckState(hItem) != CurrentState)
{
CurrentState = TV_STATE_INDETERMINATE;
break;
}
hItem = m_hCheatTree.GetNextSiblingItem(hItem);
}
TV_SetCheckState(hParent, CurrentState);
if (InitialState != CurrentState)
{
CheckParentStatus(m_hCheatTree.GetParentItem(hParent));
2015-12-23 19:26:17 +00:00
}
}
void CCheatList::DeleteCheat(LPARAM Enhancement)
{
for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
2015-12-23 19:26:17 +00:00
{
if (Enhancement != (LPARAM)&itr->second)
2015-12-23 19:26:17 +00:00
{
continue;
2015-12-23 19:26:17 +00:00
}
m_Cheats.erase(itr);
g_Enhancements->UpdateCheats(m_Cheats);
RefreshItems();
break;
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
CCheatList::TV_CHECK_STATE CCheatList::TV_GetCheckState(HTREEITEM hItem)
{
2020-05-19 02:25:57 +00:00
TVITEM tvItem = { 0 };
2015-12-23 19:26:17 +00:00
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
2020-05-19 02:25:57 +00:00
tvItem.hItem = hItem;
2015-12-23 19:26:17 +00:00
tvItem.stateMask = TVIS_STATEIMAGEMASK;
2020-05-19 02:25:57 +00:00
m_hCheatTree.GetItem(&tvItem);
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
switch (tvItem.state >> 12)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
case 1: return TV_STATE_CHECKED;
case 2: return TV_STATE_CLEAR;
case 3: return TV_STATE_INDETERMINATE;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
return TV_STATE_UNKNOWN;
}
2020-05-19 02:25:57 +00:00
bool CCheatList::TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state)
{
2020-05-19 02:25:57 +00:00
TVITEM tvItem = { 0 };
2015-12-23 19:26:17 +00:00
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = (HTREEITEM)hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
2020-05-19 02:25:57 +00:00
switch (state)
{
case TV_STATE_CHECKED: tvItem.state = INDEXTOSTATEIMAGEMASK(1); break;
case TV_STATE_CLEAR: tvItem.state = INDEXTOSTATEIMAGEMASK(2); break;
case TV_STATE_INDETERMINATE: tvItem.state = INDEXTOSTATEIMAGEMASK(3); break;
default: tvItem.state = INDEXTOSTATEIMAGEMASK(0); break;
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
return m_hCheatTree.SetItem(&tvItem) != 0;
}
2020-05-19 02:25:57 +00:00
void CCheatList::MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, const wchar_t * ShortCut)
{
2020-05-19 02:25:57 +00:00
if (Title == NULL || wcslen(Title) == 0)
{
return;
}
2015-12-23 19:26:17 +00:00
MENUITEMINFO MenuInfo = { 0 };
2020-05-19 02:25:57 +00:00
wchar_t String[256];
2015-12-23 19:26:17 +00:00
MenuInfo.cbSize = sizeof(MENUITEMINFO);
MenuInfo.fMask = MIIM_TYPE;
MenuInfo.fType = MFT_STRING;
MenuInfo.fState = MFS_ENABLED;
MenuInfo.dwTypeData = String;
MenuInfo.cch = 256;
GetMenuItemInfo(hMenu, MenuPos, true, &MenuInfo);
2015-12-23 19:26:17 +00:00
wcscpy(String, Title);
if (wcschr(String, '\t') != NULL) { *(wcschr(String, '\t')) = '\0'; }
if (ShortCut) { _swprintf(String, L"%s\t%s", String, ShortCut); }
SetMenuItemInfo(hMenu, MenuPos, true, &MenuInfo);
}
CEditCheat::CEditCheat(CEnhancementList & Cheats, CCheatList & CheatList) :
m_Cheats(Cheats),
2020-05-19 02:25:57 +00:00
m_CheatList(CheatList),
m_EditEnhancement(nullptr)
{
}
2020-05-19 02:25:57 +00:00
CEditCheat::~CEditCheat()
{
2020-05-19 02:25:57 +00:00
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CEditCheat::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
GetDlgItem(IDC_NAME).SetWindowText(wGS(CHEAT_ADDCHEAT_NAME).c_str());
GetDlgItem(IDC_CODE).SetWindowText(wGS(CHEAT_ADDCHEAT_CODE).c_str());
GetDlgItem(IDC_LABEL_OPTIONS).SetWindowText(wGS(CHEAT_ADDCHEAT_OPT).c_str());
GetDlgItem(IDC_CODE_DES).SetWindowText(wGS(CHEAT_ADDCHEAT_CODEDES).c_str());
GetDlgItem(IDC_LABEL_OPTIONS_FORMAT).SetWindowText(wGS(CHEAT_ADDCHEAT_OPTDES).c_str());
GetDlgItem(IDC_CHEATNOTES).SetWindowText(wGS(CHEAT_ADDCHEAT_NOTES).c_str());
GetDlgItem(IDC_NEWCHEAT).SetWindowText(wGS(CHEAT_ADDCHEAT_NEW).c_str());
GetDlgItem(IDC_ADD).SetWindowText(wGS(CHEAT_ADDCHEAT_ADD).c_str());
RecordCurrentValues();
2020-05-19 02:25:57 +00:00
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CEditCheat::OnEditCheat(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if (ValuesChanged())
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
return 0;
2015-12-23 19:26:17 +00:00
}
m_EditEnhancement = (CEnhancement *)wParam;
if (m_EditEnhancement == NULL)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
return 0;
}
GetDlgItem(IDC_CODE_NAME).SetWindowText(stdstr(m_EditEnhancement->GetName()).ToUTF16().c_str());
2020-05-19 02:25:57 +00:00
stdstr Buffer;
const CEnhancement::CodeEntries & Entries = m_EditEnhancement->GetEntries();
for (size_t i = 0, n = Entries.size(); i < n; i++)
2020-05-19 02:25:57 +00:00
{
const CEnhancement::CodeEntry Entry = Entries[i];
if (!Buffer.empty())
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
Buffer.append("\r\n");
2015-12-23 19:26:17 +00:00
}
Buffer += stdstr_f("%08X %s", Entry.Command, Entry.Value.c_str());
}
2020-05-19 02:25:57 +00:00
GetDlgItem(IDC_CHEAT_CODES).SetWindowText(Buffer.ToUTF16().c_str());
const CEnhancement::CodeOptions & Options = m_EditEnhancement->GetOptions();
Buffer.clear();
for (size_t i = 0, n = Options.size(); i < n; i++)
2020-05-19 02:25:57 +00:00
{
const CEnhancement::CodeOption Option = Options[i];
if (!Buffer.empty())
2015-12-23 19:26:17 +00:00
{
Buffer.append("\r\n");
}
Buffer += stdstr_f(m_EditEnhancement->CodeOptionSize() == 2 ? "%02X %s" : "%04X %s", Option.Value, Option.Name.c_str());
2020-05-19 02:25:57 +00:00
}
GetDlgItem(IDC_CHEAT_OPTIONS).SetWindowText(Buffer.ToUTF16().c_str());
GetDlgItem(IDC_NOTES).SetWindowText(stdstr(m_EditEnhancement->GetNote()).ToUTF16().c_str());
GetDlgItem(IDC_ADD).SetWindowText(wGS(CHEAT_EDITCHEAT_UPDATE).c_str());
2020-05-19 02:25:57 +00:00
SendMessage(WM_COMMAND, MAKELPARAM(IDC_CHEAT_CODES, EN_CHANGE), (LPARAM)(HWND)GetDlgItem(IDC_CHEAT_CODES));
RecordCurrentValues();
2020-05-19 02:25:57 +00:00
return 0;
}
2020-05-22 01:57:16 +00:00
LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
2020-05-19 02:25:57 +00:00
{
std::string NewCheatName = GetItemText(IDC_CODE_NAME);
for (CEnhancementList::const_iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
2020-05-19 02:25:57 +00:00
{
const CEnhancement & Enhancement = itr->second;
if (_stricmp(Enhancement.GetName().c_str(), NewCheatName.c_str()) != 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
continue;
2015-12-23 19:26:17 +00:00
}
if (m_EditEnhancement == &Enhancement)
2015-12-23 19:26:17 +00:00
{
continue;
2015-12-23 19:26:17 +00:00
}
g_Notify->DisplayWarning(GS(MSG_CHEAT_NAME_IN_USE));
GetDlgItem(IDC_CODE_NAME).SetFocus();
return 0;
2015-12-23 19:26:17 +00:00
}
bool validcodes = false, validoptions = false, nooptions = false;
CodeFormat Format;
CEnhancement::CodeEntries Entries = ReadCodeEntries(validcodes, validoptions, nooptions, Format);
CEnhancement::CodeOptions Options;
if (validcodes && !nooptions)
2020-05-19 02:25:57 +00:00
{
Options = ReadOptions(validoptions, Format);
}
if (!validcodes || !validoptions)
{
g_Notify->BreakPoint(__FILE__, __LINE__);
return 0;
2020-05-19 02:25:57 +00:00
}
if (m_EditEnhancement != nullptr)
{
m_EditEnhancement->SetName(NewCheatName.c_str());
m_EditEnhancement->SetEntries(Entries);
m_EditEnhancement->SetOptions(Options);
m_EditEnhancement->SetNote(GetItemText(IDC_NOTES).c_str());
}
else
{
CEnhancement Enhancement("Cheat");
Enhancement.SetName(NewCheatName.c_str());
Enhancement.SetEntries(Entries);
Enhancement.SetOptions(Options);
Enhancement.SetNote(GetItemText(IDC_NOTES).c_str());
m_Cheats.AddItem(Enhancement);
}
g_Enhancements->UpdateCheats(m_Cheats);
RecordCurrentValues();
2020-05-19 02:25:57 +00:00
m_CheatList.RefreshItems();
return 0;
}
2020-05-22 01:57:16 +00:00
LRESULT CEditCheat::OnNewCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if (ValuesChanged())
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
return 0;
}
m_EditEnhancement = nullptr;
2020-05-19 02:25:57 +00:00
SetDlgItemText(IDC_CODE_NAME, L"");
SetDlgItemText(IDC_CHEAT_CODES, L"");
SetDlgItemText(IDC_CHEAT_OPTIONS, L"");
SetDlgItemText(IDC_NOTES, L"");
GetDlgItem(IDC_ADD).EnableWindow(false);
GetDlgItem(IDC_CHEAT_OPTIONS).EnableWindow(false);
RecordCurrentValues();
2020-05-19 02:25:57 +00:00
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CEditCheat::OnCodeNameChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
bool validcodes, validoptions, nooptions;
CodeFormat Format;
ReadCodeEntries(validcodes, validoptions, nooptions, Format);
2020-05-19 02:25:57 +00:00
if (!nooptions)
{
ReadOptions(validoptions, Format);
2020-05-19 02:25:57 +00:00
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
bool CanAdd = validcodes && (validoptions || nooptions) && GetDlgItem(IDC_CODE_NAME).GetWindowTextLength() > 0;
GetDlgItem(IDC_ADD).EnableWindow(CanAdd);
return 0;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
LRESULT CEditCheat::OnCheatCodeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
bool validcodes, validoptions, nooptions;
CodeFormat Format;
ReadCodeEntries(validcodes, validoptions, nooptions, Format);
2020-05-19 02:25:57 +00:00
if (Format > 0 && !GetDlgItem(IDC_LABEL_OPTIONS).IsWindowEnabled())
{
GetDlgItem(IDC_LABEL_OPTIONS).EnableWindow(true);
GetDlgItem(IDC_LABEL_OPTIONS_FORMAT).EnableWindow(true);
GetDlgItem(IDC_CHEAT_OPTIONS).EnableWindow(true);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
if (Format <= 0 && GetDlgItem(IDC_LABEL_OPTIONS).IsWindowEnabled())
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
GetDlgItem(IDC_LABEL_OPTIONS).EnableWindow(false);
GetDlgItem(IDC_LABEL_OPTIONS_FORMAT).EnableWindow(false);
GetDlgItem(IDC_CHEAT_OPTIONS).EnableWindow(false);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
if (!nooptions)
2015-12-23 19:26:17 +00:00
{
ReadOptions(validoptions, Format);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
bool CanAdd = validcodes && (validoptions || nooptions) && GetDlgItem(IDC_CODE_NAME).GetWindowTextLength() > 0;
GetDlgItem(IDC_ADD).EnableWindow(CanAdd);
return 0;
}
2020-05-19 02:25:57 +00:00
LRESULT CEditCheat::OnCheatOptionsChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
2020-05-19 02:25:57 +00:00
bool ValidCodes, ValidOptions, NoOptions;
CodeFormat Format;
ReadCodeEntries(ValidCodes, ValidOptions, NoOptions, Format);
2020-05-19 02:25:57 +00:00
if (!NoOptions)
2015-12-23 19:26:17 +00:00
{
ReadOptions(ValidOptions, Format);
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
bool CanAdd = ValidCodes && (ValidOptions || NoOptions) && GetDlgItem(IDC_CODE_NAME).GetWindowTextLength() > 0;
GetDlgItem(IDC_ADD).EnableWindow(CanAdd);
return 0;
}
CEnhancement::CodeEntries CEditCheat::ReadCodeEntries(bool &ValidCodes, bool &ValidOptions, bool &NoOptions, CodeFormat & Format)
{
2020-05-19 02:25:57 +00:00
const char * FormatNormal = "XXXXXXXX XXXX";
const char * FormatOptionLB = "XXXXXXXX XX??";
const char * FormatOptionW = "XXXXXXXX ????";
CEnhancement::CodeEntries Entries;
2020-05-19 02:25:57 +00:00
ValidCodes = true;
ValidOptions = true;
NoOptions = true;
Format = CodeFormat_Invalid;
CEdit CheatCodes(GetDlgItem(IDC_CHEAT_CODES));
int NumLines = CheatCodes.GetLineCount();
if (NumLines == 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
ValidCodes = false;
}
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
for (int i = 0; i < NumLines; i++)
{
wchar_t wc_str[128];
int len = CheatCodes.GetLine(i, wc_str, sizeof(wc_str) / sizeof(wc_str[0]));
if (len <= 0)
{
continue;
}
wc_str[len] = 0;
std::string str = stdstr().FromUTF16(wc_str);
2020-05-19 02:25:57 +00:00
char TempFormat[128] = { 0 };
for (size_t c = 0; c < str.length(); c++)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (isxdigit(str[c]))
{
TempFormat[c] = 'X';
}
else if ((str[c] == ' ') || (str[c] == '?'))
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
TempFormat[c] = str[c];
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
else
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
TempFormat[c] = '#';
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
CEnhancement::CodeEntry Entry;
Entry.Command = strtoul(str.c_str(), 0, 16);
const char * ReadPos = strchr(str.c_str(), ' ');
if (ReadPos != nullptr)
{
Entry.Value = ReadPos + 1;
Entries.push_back(Entry);
}
else
{
Entries.clear();
break;
}
2020-05-19 02:25:57 +00:00
if (strcmp(TempFormat, FormatNormal) == 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (Format == CodeFormat_Invalid)
{
Format = CodeFormat_Normal;
}
2015-12-23 19:26:17 +00:00
}
2020-05-19 02:25:57 +00:00
else if (strcmp(TempFormat, FormatOptionLB) == 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (Format != CodeFormat_Word)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
Format = CodeFormat_LowerByte;
NoOptions = false;
ValidOptions = false;
2015-12-23 19:26:17 +00:00
}
else
{
2020-05-19 02:25:57 +00:00
ValidCodes = false;
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
else if (strcmp(TempFormat, FormatOptionW) == 0)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
if (Format != CodeFormat_LowerByte)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
Format = CodeFormat_Word;
NoOptions = false;
ValidOptions = false;
2015-12-23 19:26:17 +00:00
}
else
{
2020-05-19 02:25:57 +00:00
ValidCodes = false;
2015-12-23 19:26:17 +00:00
}
}
else
{
2020-05-19 02:25:57 +00:00
ValidCodes = false;
2015-12-23 19:26:17 +00:00
}
}
2020-05-19 02:25:57 +00:00
if (Entries.empty())
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
ValidCodes = false;
2015-12-23 19:26:17 +00:00
}
return Entries;
}
CEnhancement::CodeOptions CEditCheat::ReadOptions(bool &validoptions, CodeFormat Format)
{
CEnhancement::CodeOptions Options;
2015-12-23 19:26:17 +00:00
validoptions = true;
2020-05-19 02:25:57 +00:00
CEdit CheatOptions(GetDlgItem(IDC_CHEAT_OPTIONS));
int NumLines = CheatOptions.GetLineCount();
std::string OptionsStr;
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
for (int i = 0; i < NumLines; i++)
2015-12-23 19:26:17 +00:00
{
2020-05-19 02:25:57 +00:00
wchar_t wc_str[128];
int len = CheatOptions.GetLine(i, wc_str, sizeof(wc_str) / sizeof(wc_str[0]));
if (len <= 0)
{
continue;
}
wc_str[len] = 0;
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
std::string str = stdstr().FromUTF16(wc_str);
CEnhancement::CodeOption Option;
2015-12-23 19:26:17 +00:00
2020-05-19 02:25:57 +00:00
switch (Format)
{
case CodeFormat_LowerByte:
if (len >= 2) {
for (int c = 0; c < 2; c++)
{
if (!isxdigit(str[c]))
2015-12-23 19:26:17 +00:00
{
validoptions = false;
break;
}
}
2020-05-19 02:25:57 +00:00
if ((str[2] != ' ') && (len > 2))
2015-12-23 19:26:17 +00:00
{
validoptions = false;
break;
}
Option.Name = &str[3];
Option.Value = (uint16_t)strtoul(str.c_str(), 0, 16);
Options.push_back(Option);
2020-05-19 02:25:57 +00:00
}
else
{
validoptions = false;
break;
}
break;
case CodeFormat_Word:
if (len >= 4)
{
for (int c = 0; c < 4; c++)
{
if (!isxdigit(str[c]))
2015-12-23 19:26:17 +00:00
{
validoptions = false;
break;
}
}
2020-05-19 02:25:57 +00:00
if (str[4] != ' ' && (len > 4))
2015-12-23 19:26:17 +00:00
{
validoptions = false;
break;
}
Option.Name = &str[5];
Option.Value = (uint16_t)strtoul(str.c_str(), 0, 16);
Options.push_back(Option);
2020-05-19 02:25:57 +00:00
}
else
{
validoptions = false;
2015-12-23 19:26:17 +00:00
break;
}
2020-05-19 02:25:57 +00:00
break;
default:
validoptions = false;
break;
2015-12-23 19:26:17 +00:00
}
}
if (Options.size() == 0)
2015-12-23 19:26:17 +00:00
{
validoptions = false;
}
return Options;
2020-05-19 02:25:57 +00:00
}
void CEditCheat::RecordCurrentValues(void)
2020-05-19 02:25:57 +00:00
{
m_EditName = GetItemText(IDC_CODE_NAME);
m_EditCode = GetItemText(IDC_CHEAT_CODES);
m_EditOptions = GetItemText(IDC_CHEAT_OPTIONS);
m_EditNotes = GetItemText(IDC_NOTES);
}
bool CEditCheat::ValuesChanged(void)
2020-05-19 02:25:57 +00:00
{
bool Changed = false;
if (m_EditName != GetItemText(IDC_CODE_NAME) ||
m_EditCode != GetItemText(IDC_CHEAT_CODES) ||
m_EditOptions != GetItemText(IDC_CHEAT_OPTIONS) ||
m_EditNotes != GetItemText(IDC_NOTES))
{
Changed = true;
}
if (!Changed)
{
return false;
}
int Result = MessageBox(wGS(CHEAT_CHANGED_MSG).c_str(), wGS(CHEAT_CHANGED_TITLE).c_str(), MB_YESNOCANCEL);
if (Result == IDCANCEL)
{
return true;
}
if (Result == IDYES)
{
SendMessage(WM_COMMAND, MAKELPARAM(IDC_ADD, 0));
}
return false;
}
std::string CEditCheat::GetItemText(int nIDDlgItem)
{
CWindow Window = GetDlgItem(nIDDlgItem);
int length = Window.GetWindowTextLength();
if (length == 0)
{
return "";
}
std::wstring Result;
Result.resize(length + 1);
Window.GetWindowText((wchar_t *)Result.c_str(), Result.length());
return stdstr().FromUTF16(Result.c_str());
}
CEnhancementCodeEx::CEnhancementCodeEx(CEnhancement * Enhancement) :
m_Enhancement(Enhancement)
2020-05-19 02:25:57 +00:00
{
}
LRESULT CEnhancementCodeEx::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
2020-05-19 02:25:57 +00:00
{
SetWindowText(wGS(CHEAT_CODE_EXT_TITLE).c_str());
GetDlgItem(IDC_NOTE).SetWindowText(wGS(CHEAT_CODE_EXT_TXT).c_str());
GetDlgItem(IDOK).SetWindowText(wGS(CHEAT_OK).c_str());
GetDlgItem(IDCANCEL).SetWindowText(wGS(CHEAT_CANCEL).c_str());
GetDlgItem(IDC_CHEAT_NAME).SetWindowText(stdstr(m_Enhancement->GetName()).ToUTF16().c_str());
2020-05-19 02:25:57 +00:00
CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST);
CEnhancement::CodeOptions Options = m_Enhancement->GetOptions();
bool OptionSelected = m_Enhancement->OptionSelected();
uint16_t SelectedOption = m_Enhancement->SelectedOption();
for (size_t i = 0, n = Options.size(); i < n; i++)
2020-05-19 02:25:57 +00:00
{
stdstr_f Option(m_Enhancement->CodeOptionSize() == 2 ? "$%02X %s" : "$%04X %s", Options[i].Value, Options[i].Name.c_str());
int index = CheatList.AddString(Option.ToUTF16().c_str());
if (index >= 0)
2020-05-19 02:25:57 +00:00
{
CheatList.SetItemData(index, Options[i].Value);
if (OptionSelected && SelectedOption == Options[i].Value)
{
CheatList.SetCurSel(index);
}
2020-05-19 02:25:57 +00:00
}
}
return 0;
}
LRESULT CEnhancementCodeEx::OnListDblClick(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
2020-05-19 02:25:57 +00:00
{
PostMessage(WM_COMMAND, IDOK, 0);
return 0;
}
LRESULT CEnhancementCodeEx::OnOkCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
2020-05-19 02:25:57 +00:00
{
CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST);
int index = CheatList.GetCurSel();
if (index < 0)
{
index = 0;
}
m_Enhancement->SetSelectedOption((uint16_t)(CheatList.GetItemData(index)));
if (g_Enhancements != nullptr)
2020-05-19 02:25:57 +00:00
{
g_Enhancements->UpdateCheats();
2020-05-19 02:25:57 +00:00
}
EndDialog(0);
return 0;
}
LRESULT CEnhancementCodeEx::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
2020-05-19 02:25:57 +00:00
{
EndDialog(0);
return 0;
}