Changed the way the iterator is used in PatchAddEdit, I thought I'd submit it since it makes for shorter code.

Also a couple of bugfixes

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1755 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
facugaich 2009-01-03 23:02:13 +00:00
parent 22753f9e3c
commit 09b3d2d227
4 changed files with 45 additions and 47 deletions

View File

@ -45,8 +45,8 @@ void CARCodeAddEdit::CreateGUIControls(int _selection)
EditCheatName = new wxTextCtrl(this, ID_EDITCHEAT_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); EditCheatName = new wxTextCtrl(this, ID_EDITCHEAT_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
EditCheatName->SetValue(wxString::FromAscii(currentCode.name.c_str())); EditCheatName->SetValue(wxString::FromAscii(currentCode.name.c_str()));
EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT, wxDefaultPosition, wxDefaultSize, wxVERTICAL); EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT, wxDefaultPosition, wxDefaultSize, wxVERTICAL);
EntrySelection->SetRange((int)arCodes.size()-1, 0); EntrySelection->SetRange(0, (int)arCodes.size()-1);
EntrySelection->SetValue(_selection); EntrySelection->SetValue((int)arCodes.size()-1 - _selection);
EditCheatCode = new wxTextCtrl(this, ID_EDITCHEAT_CODE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); EditCheatCode = new wxTextCtrl(this, ID_EDITCHEAT_CODE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
UpdateTextCtrl(currentCode); UpdateTextCtrl(currentCode);
wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0); wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0);
@ -76,7 +76,7 @@ void CARCodeAddEdit::OnClose(wxCloseEvent& WXUNUSED (event))
void CARCodeAddEdit::ChangeEntry(wxSpinEvent& event) void CARCodeAddEdit::ChangeEntry(wxSpinEvent& event)
{ {
ActionReplay::ARCode currentCode = arCodes.at(event.GetPosition()); ActionReplay::ARCode currentCode = arCodes.at((int)arCodes.size()-1 - event.GetPosition());
EditCheatName->SetValue(wxString::FromAscii(currentCode.name.c_str())); EditCheatName->SetValue(wxString::FromAscii(currentCode.name.c_str()));
UpdateTextCtrl(currentCode); UpdateTextCtrl(currentCode);
} }

View File

@ -643,14 +643,19 @@ void CISOProperties::PatchList_Load()
void CISOProperties::PatchList_Save() void CISOProperties::PatchList_Save()
{ {
std::vector<std::string> lines; std::vector<std::string> lines;
u32 index = 0;
for (std::vector<PatchEngine::Patch>::const_iterator onFrame_it = onFrame.begin(); onFrame_it != onFrame.end(); ++onFrame_it) for (std::vector<PatchEngine::Patch>::const_iterator onFrame_it = onFrame.begin(); onFrame_it != onFrame.end(); ++onFrame_it)
{ {
lines.push_back(onFrame_it->active ? "+$" + onFrame_it->name : "$" + onFrame_it->name); lines.push_back(Patches->IsChecked(index) ? "+$" + onFrame_it->name : "$" + onFrame_it->name);
for (std::vector<PatchEngine::PatchEntry>::const_iterator iter2 = onFrame_it->entries.begin(); iter2 != onFrame_it->entries.end(); ++iter2) for (std::vector<PatchEngine::PatchEntry>::const_iterator iter2 = onFrame_it->entries.begin(); iter2 != onFrame_it->entries.end(); ++iter2)
{ {
lines.push_back(std::string(wxString::Format(wxT("0x%08X:%s:0x%08X"), iter2->address, PatchEngine::PatchTypeStrings[iter2->type], iter2->value).mb_str())); std::string temp;
ToStringFromFormat(&temp, "0x%08X:%s:0x%08X", iter2->address, PatchEngine::PatchTypeStrings[iter2->type], iter2->value);
lines.push_back(temp);
} }
++index;
} }
GameIni.SetLines("OnFrame", lines); GameIni.SetLines("OnFrame", lines);
lines.clear(); lines.clear();
@ -671,7 +676,11 @@ void CISOProperties::PatchButtonClicked(wxCommandEvent& event)
case ID_ADDPATCH: case ID_ADDPATCH:
{ {
CPatchAddEdit dlg(-1, this, 1, _("Add Patch")); CPatchAddEdit dlg(-1, this, 1, _("Add Patch"));
dlg.ShowModal(); if (dlg.ShowModal() == wxID_OK)
{
Patches->Append(wxString::FromAscii(onFrame.back().name.c_str()));
Patches->Check(onFrame.size() - 1, onFrame.back().active);
}
} }
break; break;
case ID_REMOVEPATCH: case ID_REMOVEPATCH:

View File

@ -31,7 +31,6 @@ CPatchAddEdit::CPatchAddEdit(int _selection, wxWindow* parent, wxWindowID id, co
: wxDialog(parent, id, title, position, size, style) : wxDialog(parent, id, title, position, size, style)
{ {
selection = _selection; selection = _selection;
curEntry = 0;
CreateGUIControls(selection); CreateGUIControls(selection);
} }
@ -45,6 +44,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
if (_selection == -1) if (_selection == -1)
{ {
tempEntries.clear();
tempEntries.push_back(PatchEngine::PatchEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000)); tempEntries.push_back(PatchEngine::PatchEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000));
} }
else else
@ -53,6 +53,8 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
tempEntries = onFrame.at(_selection).entries; tempEntries = onFrame.at(_selection).entries;
} }
itCurEntry = tempEntries.begin();
wxBoxSizer* sEditPatch = new wxBoxSizer(wxVERTICAL); wxBoxSizer* sEditPatch = new wxBoxSizer(wxVERTICAL);
wxStaticText* EditPatchNameText = new wxStaticText(this, ID_EDITPATCH_NAME_TEXT, _("Name:"), wxDefaultPosition, wxDefaultSize); wxStaticText* EditPatchNameText = new wxStaticText(this, ID_EDITPATCH_NAME_TEXT, _("Name:"), wxDefaultPosition, wxDefaultSize);
EditPatchName = new wxTextCtrl(this, ID_EDITPATCH_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); EditPatchName = new wxTextCtrl(this, ID_EDITPATCH_NAME, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
@ -89,14 +91,11 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
sgEntry->Add(EditPatchValueText, wxGBPosition(2, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5); sgEntry->Add(EditPatchValueText, wxGBPosition(2, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
sgEntry->Add(EditPatchValue, wxGBPosition(2, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5); sgEntry->Add(EditPatchValue, wxGBPosition(2, 1), wxGBSpan(1, 1), wxEXPAND|wxALL, 5);
sgEntry->Add(EntrySelection, wxGBPosition(0, 2), wxGBSpan(3, 1), wxEXPAND|wxALL, 5); sgEntry->Add(EntrySelection, wxGBPosition(0, 2), wxGBSpan(3, 1), wxEXPAND|wxALL, 5);
wxBoxSizer* sEntryAddRemove = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* sEntryAddRemove = new wxBoxSizer(wxHORIZONTAL);
sEntryAddRemove->Add(EntryAdd, 0, wxALL, 5); sEntryAddRemove->Add(EntryAdd, 0, wxALL, 5);
sEntryAddRemove->Add(EntryRemove, 0, wxALL, 5); sEntryAddRemove->Add(EntryRemove, 0, wxALL, 5);
sbEntry->Add(sgEntry, 0, wxEXPAND); sbEntry->Add(sgEntry, 0, wxEXPAND);
sbEntry->Add(sEntryAddRemove, 0, wxEXPAND); sbEntry->Add(sEntryAddRemove, 0, wxEXPAND);
sEditPatch->Add(sbEntry, 0, wxEXPAND|wxALL, 5); sEditPatch->Add(sbEntry, 0, wxEXPAND|wxALL, 5);
wxBoxSizer* sEditPatchButtons = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer* sEditPatchButtons = new wxBoxSizer(wxHORIZONTAL);
wxButton* bOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); wxButton* bOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
@ -117,16 +116,15 @@ void CPatchAddEdit::OnClose(wxCloseEvent& WXUNUSED (event))
void CPatchAddEdit::ChangeEntry(wxSpinEvent& event) void CPatchAddEdit::ChangeEntry(wxSpinEvent& event)
{ {
SaveEntryData(); SaveEntryData(itCurEntry);
curEntry = ((int)tempEntries.size()-1 - event.GetPosition()); itCurEntry = tempEntries.end() - event.GetPosition() - 1;
PatchEngine::PatchEntry pE = tempEntries.at(curEntry); UpdateEntryCtrls(*itCurEntry);
UpdateEntryCtrls(pE);
} }
void CPatchAddEdit::SavePatchData(wxCommandEvent& WXUNUSED (event)) void CPatchAddEdit::SavePatchData(wxCommandEvent& WXUNUSED (event))
{ {
SaveEntryData(); SaveEntryData(itCurEntry);
if (selection == -1) if (selection == -1)
{ {
@ -148,47 +146,38 @@ void CPatchAddEdit::SavePatchData(wxCommandEvent& WXUNUSED (event))
void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event) void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event)
{ {
int currentPos = (int)tempEntries.size() - EntrySelection->GetValue();
switch (event.GetId()) switch (event.GetId())
{ {
case ID_ENTRY_ADD: case ID_ENTRY_ADD:
{ {
SaveEntryData(); SaveEntryData(itCurEntry);
PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000); PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000);
std::vector<PatchEngine::PatchEntry>::iterator iterWhere(tempEntries.begin() + currentPos); itCurEntry++;
itCurEntry = tempEntries.insert(itCurEntry, peEmptyEntry);
tempEntries.insert(iterWhere, peEmptyEntry);
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1); EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1);
EntrySelection->SetValue(EntrySelection->GetMax() - currentPos); UpdateEntryCtrls(*itCurEntry);
iterWhere = tempEntries.begin() + currentPos;
UpdateEntryCtrls(*iterWhere);
EntryRemove->Enable(); EntryRemove->Enable();
EntrySelection->Enable(); EntrySelection->Enable();
} }
break; break;
case ID_ENTRY_REMOVE: case ID_ENTRY_REMOVE:
{ {
currentPos--; itCurEntry = tempEntries.erase(itCurEntry);
std::vector<PatchEngine::PatchEntry>::iterator iterWhere(tempEntries.begin() + currentPos);
tempEntries.erase(iterWhere); if (itCurEntry != tempEntries.begin())
if (currentPos != 0)
{ {
iterWhere = tempEntries.begin() + currentPos; itCurEntry--;
} }
else if (tempEntries.size() > 0) else
{ {
iterWhere = tempEntries.begin(); EntrySelection->SetValue(EntrySelection->GetValue() - 1);
} }
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1); EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1);
EntrySelection->SetValue(EntrySelection->GetMax() - currentPos); UpdateEntryCtrls(*itCurEntry);
UpdateEntryCtrls(*iterWhere);
if ((int)tempEntries.size() <= 1) if ((int)tempEntries.size() <= 1)
{ {
@ -198,7 +187,6 @@ void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event)
} }
break; break;
} }
curEntry = currentPos;
} }
void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE) void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE)
@ -208,12 +196,13 @@ void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE)
EditPatchValue->SetValue(wxString::Format(wxT("%08X"), pE.value)); EditPatchValue->SetValue(wxString::Format(wxT("%08X"), pE.value));
} }
void CPatchAddEdit::SaveEntryData() void CPatchAddEdit::SaveEntryData(std::vector<PatchEngine::PatchEntry>::iterator iterEntry)
{ {
unsigned long value; unsigned long value;
if (EditPatchOffset->GetValue().ToULong(&value, 16)) if (EditPatchOffset->GetValue().ToULong(&value, 16))
tempEntries.at(curEntry).address = value; (*iterEntry).address = value;
tempEntries.at(curEntry).type = (PatchEngine::PatchType) EditPatchType->GetSelection(); (*iterEntry).type = (PatchEngine::PatchType) EditPatchType->GetSelection();
if (EditPatchValue->GetValue().ToULong(&value, 16)) if (EditPatchValue->GetValue().ToULong(&value, 16))
tempEntries.at(curEntry).value = value; (*iterEntry).value = value;
} }

View File

@ -62,11 +62,11 @@ class CPatchAddEdit : public wxDialog
void SavePatchData(wxCommandEvent& event); void SavePatchData(wxCommandEvent& event);
void AddRemoveEntry(wxCommandEvent& event); void AddRemoveEntry(wxCommandEvent& event);
void UpdateEntryCtrls(PatchEngine::PatchEntry pE); void UpdateEntryCtrls(PatchEngine::PatchEntry pE);
void SaveEntryData(); void SaveEntryData(std::vector<PatchEngine::PatchEntry>::iterator iterEntry);
int selection; int selection;
int curEntry;
std::vector<PatchEngine::PatchEntry> tempEntries; std::vector<PatchEngine::PatchEntry> tempEntries;
std::vector<PatchEngine::PatchEntry>::iterator itCurEntry;
}; };
#endif // __PATCH_ADDEDIT_h__ #endif // __PATCH_ADDEDIT_h__