diff --git a/Source/Core/Core/Src/ActionReplay.h b/Source/Core/Core/Src/ActionReplay.h index 2fde6de1f3..a459b635ef 100644 --- a/Source/Core/Core/Src/ActionReplay.h +++ b/Source/Core/Core/Src/ActionReplay.h @@ -24,6 +24,8 @@ namespace ActionReplay { struct AREntry { + AREntry() {} + AREntry(u32 _addr, u32 _value) : cmd_addr(_addr), value(_value) {} u32 cmd_addr; u32 value; }; diff --git a/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp b/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp index c3194c48d2..5077c856bb 100644 --- a/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp +++ b/Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp @@ -21,6 +21,7 @@ extern std::vector arCodes; BEGIN_EVENT_TABLE(CARCodeAddEdit, wxDialog) EVT_CLOSE(CARCodeAddEdit::OnClose) + EVT_BUTTON(wxID_OK, CARCodeAddEdit::SaveCheatData) EVT_SPIN(ID_ENTRY_SELECT, CARCodeAddEdit::ChangeEntry) END_EVENT_TABLE() @@ -37,18 +38,28 @@ CARCodeAddEdit::~CARCodeAddEdit() void CARCodeAddEdit::CreateGUIControls(int _selection) { - ActionReplay::ARCode currentCode = arCodes.at(_selection); + wxString currentName = wxT(""); + + if (_selection == -1) + { + tempEntries.name = ""; + } + else + { + currentName = wxString::FromAscii(arCodes.at(_selection).name.c_str()); + tempEntries = arCodes.at(_selection); + } wxBoxSizer* sEditCheat = new wxBoxSizer(wxVERTICAL); wxStaticBoxSizer* sbEntry = new wxStaticBoxSizer(wxVERTICAL, this, _("Code")); wxStaticText* EditCheatNameText = new wxStaticText(this, ID_EDITCHEAT_NAME_TEXT, _("Name:"), wxDefaultPosition, wxDefaultSize); EditCheatName = new wxTextCtrl(this, ID_EDITCHEAT_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); - EditCheatName->SetValue(wxString::FromAscii(currentCode.name.c_str())); + EditCheatName->SetValue(currentName); EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT, wxDefaultPosition, wxDefaultSize, wxVERTICAL); EntrySelection->SetRange(0, (int)arCodes.size()-1); EntrySelection->SetValue((int)arCodes.size()-1 - _selection); EditCheatCode = new wxTextCtrl(this, ID_EDITCHEAT_CODE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); - UpdateTextCtrl(currentCode); + UpdateTextCtrl(tempEntries); wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0); sgEntry->AddGrowableCol(1); sgEntry->AddGrowableRow(1); @@ -81,6 +92,50 @@ void CARCodeAddEdit::ChangeEntry(wxSpinEvent& event) UpdateTextCtrl(currentCode); } +void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event)) +{ + + std::vector tempEntries; + std::string cheatValues = std::string(EditCheatCode->GetValue().mb_str()); + bool bWhile = true; size_t line = 0; + + while (bWhile) + { + bWhile = false; + u32 addr, value; + + addr = strtol(std::string(cheatValues.substr(line, line+8)).c_str(), NULL, 16); // cmd_addr of ArCode + value = strtol(std::string(cheatValues.substr(line+9, line+17)).c_str(), NULL, 16); // value of ArCode + + tempEntries.push_back(ActionReplay::AREntry(addr, value)); + + line = cheatValues.find("\n", line); + + if (line != std::string::npos && cheatValues.length() > (line+17)) + bWhile = true; // newline found, if not empty, go on + + line += 2; + } + + if (selection == -1) + { + ActionReplay::ARCode newCheat; + newCheat.name = std::string(EditCheatName->GetValue().mb_str()); + newCheat.ops = tempEntries; + + newCheat.active = true; + + arCodes.push_back(newCheat); + } + else + { + arCodes.at(selection).name = std::string(EditCheatName->GetValue().mb_str()); + arCodes.at(selection).ops = tempEntries; + } + + AcceptAndClose(); +} + void CARCodeAddEdit::UpdateTextCtrl(ActionReplay::ARCode arCode) { EditCheatCode->Clear(); diff --git a/Source/Core/DolphinWX/Src/ARCodeAddEdit.h b/Source/Core/DolphinWX/Src/ARCodeAddEdit.h index 0157488d59..7376c571b4 100644 --- a/Source/Core/DolphinWX/Src/ARCodeAddEdit.h +++ b/Source/Core/DolphinWX/Src/ARCodeAddEdit.h @@ -49,10 +49,12 @@ class CARCodeAddEdit : public wxDialog void CreateGUIControls(int selection); void OnClose(wxCloseEvent& event); + void SaveCheatData(wxCommandEvent& event); void ChangeEntry(wxSpinEvent& event); void UpdateTextCtrl(ActionReplay::ARCode arCode); int selection; + ActionReplay::ARCode tempEntries; }; #endif // __PATCH_ADDEDIT_h__ diff --git a/Source/Core/DolphinWX/Src/ISOProperties.cpp b/Source/Core/DolphinWX/Src/ISOProperties.cpp index 5642309d8e..d4c603353b 100644 --- a/Source/Core/DolphinWX/Src/ISOProperties.cpp +++ b/Source/Core/DolphinWX/Src/ISOProperties.cpp @@ -730,7 +730,12 @@ void CISOProperties::ActionReplayButtonClicked(wxCommandEvent& event) break; case ID_ADDCHEAT: { - // dialog + CARCodeAddEdit dlg(-1, this, 1, _("Add AR Code")); + if (dlg.ShowModal() == wxID_OK) + { + Cheats->Append(wxString::FromAscii(arCodes.back().name.c_str())); + Cheats->Check((unsigned int)(arCodes.size() - 1), arCodes.back().active); + } } break; case ID_REMOVECHEAT: diff --git a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp index ed44dfdfb8..c666161296 100644 --- a/Source/Core/DolphinWX/Src/PatchAddEdit.cpp +++ b/Source/Core/DolphinWX/Src/PatchAddEdit.cpp @@ -82,7 +82,8 @@ void CPatchAddEdit::CreateGUIControls(int _selection) sEditPatchName->Add(EditPatchNameText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); sEditPatchName->Add(EditPatchName, 1, wxEXPAND|wxALL, 5); sEditPatch->Add(sEditPatchName, 0, wxEXPAND); - wxStaticBoxSizer* sbEntry = new wxStaticBoxSizer(wxVERTICAL, this, _("Entry")); + sbEntry = new wxStaticBoxSizer(wxVERTICAL, this, wxString::Format(wxT("Entry 1/%d"), (int)tempEntries.size())); + currentItem = 1; wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0); sgEntry->AddGrowableCol(1); sgEntry->Add(EditPatchType, wxGBPosition(0, 0), wxGBSpan(1, 2), wxEXPAND|wxALL, 5); @@ -119,6 +120,7 @@ void CPatchAddEdit::ChangeEntry(wxSpinEvent& event) SaveEntryData(itCurEntry); itCurEntry = tempEntries.end() - event.GetPosition() - 1; + currentItem = (int)tempEntries.size() - event.GetPosition(); UpdateEntryCtrls(*itCurEntry); } @@ -154,6 +156,7 @@ void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event) PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000); itCurEntry++; + currentItem++; itCurEntry = tempEntries.insert(itCurEntry, peEmptyEntry); EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1); @@ -170,6 +173,7 @@ void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event) if (itCurEntry != tempEntries.begin()) { itCurEntry--; + currentItem--; } else { @@ -191,6 +195,8 @@ void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event) void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE) { + sbEntry->GetStaticBox()->SetLabel(wxString::Format(wxT("Entry %d/%d"), currentItem, + (int)tempEntries.size())); EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), pE.address)); EditPatchType->SetSelection(pE.type); EditPatchValue->SetValue(wxString::Format(wxT("%08X"), pE.value)); diff --git a/Source/Core/DolphinWX/Src/PatchAddEdit.h b/Source/Core/DolphinWX/Src/PatchAddEdit.h index 75afaa3732..ebf2e16502 100644 --- a/Source/Core/DolphinWX/Src/PatchAddEdit.h +++ b/Source/Core/DolphinWX/Src/PatchAddEdit.h @@ -42,6 +42,7 @@ class CPatchAddEdit : public wxDialog wxTextCtrl *EditPatchValue; wxSpinButton *EntrySelection; wxButton *EntryRemove; + wxStaticBoxSizer* sbEntry; enum { ID_EDITPATCH_NAME_TEXT = 4500, @@ -64,7 +65,7 @@ class CPatchAddEdit : public wxDialog void UpdateEntryCtrls(PatchEngine::PatchEntry pE); void SaveEntryData(std::vector::iterator iterEntry); - int selection; + int selection, currentItem; std::vector tempEntries; std::vector::iterator itCurEntry;