Clarified Patch Add/Edit, added AR Add/Edit by slink3

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2313 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2009-02-20 00:07:35 +00:00
parent a1cd6c982e
commit 4883727384
6 changed files with 77 additions and 6 deletions

View File

@ -24,6 +24,8 @@ namespace ActionReplay
{
struct AREntry {
AREntry() {}
AREntry(u32 _addr, u32 _value) : cmd_addr(_addr), value(_value) {}
u32 cmd_addr;
u32 value;
};

View File

@ -21,6 +21,7 @@ extern std::vector<ActionReplay::ARCode> 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("<Insert name here>");
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<ActionReplay::AREntry> 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();

View File

@ -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__

View File

@ -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:

View File

@ -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));

View File

@ -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<PatchEngine::PatchEntry>::iterator iterEntry);
int selection;
int selection, currentItem;
std::vector<PatchEngine::PatchEntry> tempEntries;
std::vector<PatchEngine::PatchEntry>::iterator itCurEntry;