complete patchaddedit. thanks facugaich
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1753 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
677c94414b
commit
161d7f369a
|
@ -643,16 +643,14 @@ void CISOProperties::PatchList_Load()
|
|||
void CISOProperties::PatchList_Save()
|
||||
{
|
||||
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)
|
||||
{
|
||||
lines.push_back(Patches->IsChecked(index) ? "+$" + onFrame_it->name : "$" + onFrame_it->name);
|
||||
lines.push_back(onFrame_it->active ? "+$" + onFrame_it->name : "$" + onFrame_it->name);
|
||||
|
||||
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()));
|
||||
}
|
||||
++index;
|
||||
}
|
||||
GameIni.SetLines("OnFrame", lines);
|
||||
lines.clear();
|
||||
|
@ -672,7 +670,8 @@ void CISOProperties::PatchButtonClicked(wxCommandEvent& event)
|
|||
break;
|
||||
case ID_ADDPATCH:
|
||||
{
|
||||
// dialog;
|
||||
CPatchAddEdit dlg(-1, this, 1, _("Add Patch"));
|
||||
dlg.ShowModal();
|
||||
}
|
||||
break;
|
||||
case ID_REMOVEPATCH:
|
||||
|
|
|
@ -21,6 +21,9 @@ extern std::vector<PatchEngine::Patch> onFrame;
|
|||
|
||||
BEGIN_EVENT_TABLE(CPatchAddEdit, wxDialog)
|
||||
EVT_CLOSE(CPatchAddEdit::OnClose)
|
||||
EVT_BUTTON(wxID_OK, CPatchAddEdit::SavePatchData)
|
||||
EVT_BUTTON(ID_ENTRY_ADD, CPatchAddEdit::AddRemoveEntry)
|
||||
EVT_BUTTON(ID_ENTRY_REMOVE, CPatchAddEdit::AddRemoveEntry)
|
||||
EVT_SPIN(ID_ENTRY_SELECT, CPatchAddEdit::ChangeEntry)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
@ -28,6 +31,7 @@ CPatchAddEdit::CPatchAddEdit(int _selection, wxWindow* parent, wxWindowID id, co
|
|||
: wxDialog(parent, id, title, position, size, style)
|
||||
{
|
||||
selection = _selection;
|
||||
curEntry = 0;
|
||||
CreateGUIControls(selection);
|
||||
}
|
||||
|
||||
|
@ -37,8 +41,17 @@ CPatchAddEdit::~CPatchAddEdit()
|
|||
|
||||
void CPatchAddEdit::CreateGUIControls(int _selection)
|
||||
{
|
||||
std::string currentName = onFrame.at(_selection).name;
|
||||
std::vector<PatchEngine::PatchEntry> currentEntries = onFrame.at(_selection).entries;
|
||||
std::string currentName = _("<Insert name here>");
|
||||
|
||||
if (_selection == -1)
|
||||
{
|
||||
tempEntries.push_back(PatchEngine::PatchEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000));
|
||||
}
|
||||
else
|
||||
{
|
||||
currentName = onFrame.at(_selection).name;
|
||||
tempEntries = onFrame.at(_selection).entries;
|
||||
}
|
||||
|
||||
wxBoxSizer* sEditPatch = new wxBoxSizer(wxVERTICAL);
|
||||
wxStaticText* EditPatchNameText = new wxStaticText(this, ID_EDITPATCH_NAME_TEXT, _("Name:"), wxDefaultPosition, wxDefaultSize);
|
||||
|
@ -46,17 +59,22 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
|
|||
EditPatchName->SetValue(wxString::FromAscii(currentName.c_str()));
|
||||
wxStaticText* EditPatchOffsetText = new wxStaticText(this, ID_EDITPATCH_OFFSET_TEXT, _("Offset:"), wxDefaultPosition, wxDefaultSize);
|
||||
EditPatchOffset = new wxTextCtrl(this, ID_EDITPATCH_OFFSET, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
|
||||
EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), currentEntries.at(0).address));
|
||||
EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), tempEntries.at(0).address));
|
||||
EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT, wxDefaultPosition, wxDefaultSize, wxVERTICAL);
|
||||
EntrySelection->SetRange((int)currentEntries.size()-1, 0);
|
||||
EntrySelection->SetRange(0, (int)tempEntries.size()-1);
|
||||
EntrySelection->SetValue((int)tempEntries.size()-1);
|
||||
wxArrayString wxArrayStringFor_EditPatchType;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
wxArrayStringFor_EditPatchType.Add(wxString::FromAscii(PatchEngine::PatchTypeStrings[i]));
|
||||
EditPatchType = new wxRadioBox(this, ID_EDITPATCH_TYPE, _("Type"), wxDefaultPosition, wxDefaultSize, wxArrayStringFor_EditPatchType, 3, wxRA_SPECIFY_COLS, wxDefaultValidator);
|
||||
EditPatchType->SetSelection((int)currentEntries.at(0).type);
|
||||
EditPatchType->SetSelection((int)tempEntries.at(0).type);
|
||||
wxStaticText* EditPatchValueText = new wxStaticText(this, ID_EDITPATCH_VALUE_TEXT, _("Value:"), wxDefaultPosition, wxDefaultSize);
|
||||
EditPatchValue = new wxTextCtrl(this, ID_EDITPATCH_VALUE, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
|
||||
EditPatchValue->SetValue(wxString::Format(wxT("%08X"), currentEntries.at(0).value));
|
||||
EditPatchValue->SetValue(wxString::Format(wxT("%08X"), tempEntries.at(0).value));
|
||||
wxButton *EntryAdd = new wxButton(this, ID_ENTRY_ADD, _("Add"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
EntryRemove = new wxButton(this, ID_ENTRY_REMOVE, _("Remove"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
if ((int)tempEntries.size() <= 1)
|
||||
EntryRemove->Disable();
|
||||
|
||||
wxBoxSizer* sEditPatchName = new wxBoxSizer(wxHORIZONTAL);
|
||||
sEditPatchName->Add(EditPatchNameText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
|
@ -71,7 +89,14 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
|
|||
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(EntrySelection, wxGBPosition(0, 2), wxGBSpan(3, 1), wxEXPAND|wxALL, 5);
|
||||
|
||||
wxBoxSizer* sEntryAddRemove = new wxBoxSizer(wxHORIZONTAL);
|
||||
sEntryAddRemove->Add(EntryAdd, 0, wxALL, 5);
|
||||
sEntryAddRemove->Add(EntryRemove, 0, wxALL, 5);
|
||||
|
||||
sbEntry->Add(sgEntry, 0, wxEXPAND);
|
||||
sbEntry->Add(sEntryAddRemove, 0, wxEXPAND);
|
||||
|
||||
sEditPatch->Add(sbEntry, 0, wxEXPAND|wxALL, 5);
|
||||
wxBoxSizer* sEditPatchButtons = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxButton* bOK = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
|
@ -82,17 +107,7 @@ void CPatchAddEdit::CreateGUIControls(int _selection)
|
|||
sEditPatch->Add(sEditPatchButtons, 0, wxEXPAND, 5);
|
||||
this->SetSizer(sEditPatch);
|
||||
sEditPatch->Layout();
|
||||
|
||||
/*if (this->ShowModal() == wxID_OK)
|
||||
{
|
||||
onFrame.at(selection).name = std::string(EditPatchName->GetValue().mb_str());
|
||||
unsigned long value;
|
||||
if (EditPatchOffset->GetValue().ToULong(&value, 16))
|
||||
onFrame.at(selection).entries.at(0).address = value;
|
||||
onFrame.at(selection).entries.at(0).type = (PatchEngine::PatchType)EditPatchType->GetSelection();
|
||||
if (EditPatchValue->GetValue().ToULong(&value, 16))
|
||||
onFrame.at(selection).entries.at(0).value = value;
|
||||
}*/
|
||||
Fit();
|
||||
}
|
||||
|
||||
void CPatchAddEdit::OnClose(wxCloseEvent& WXUNUSED (event))
|
||||
|
@ -102,8 +117,103 @@ void CPatchAddEdit::OnClose(wxCloseEvent& WXUNUSED (event))
|
|||
|
||||
void CPatchAddEdit::ChangeEntry(wxSpinEvent& event)
|
||||
{
|
||||
PatchEngine::PatchEntry pE = onFrame.at(selection).entries.at(event.GetPosition());
|
||||
SaveEntryData();
|
||||
|
||||
curEntry = ((int)tempEntries.size()-1 - event.GetPosition());
|
||||
PatchEngine::PatchEntry pE = tempEntries.at(curEntry);
|
||||
UpdateEntryCtrls(pE);
|
||||
}
|
||||
|
||||
void CPatchAddEdit::SavePatchData(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
SaveEntryData();
|
||||
|
||||
if (selection == -1)
|
||||
{
|
||||
PatchEngine::Patch newPatch;
|
||||
newPatch.name = std::string(EditPatchName->GetValue().mb_str());
|
||||
newPatch.entries = tempEntries;
|
||||
newPatch.active = true;
|
||||
|
||||
onFrame.push_back(newPatch);
|
||||
}
|
||||
else
|
||||
{
|
||||
onFrame.at(selection).name = std::string(EditPatchName->GetValue().mb_str());
|
||||
onFrame.at(selection).entries = tempEntries;
|
||||
}
|
||||
|
||||
AcceptAndClose();
|
||||
}
|
||||
|
||||
void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event)
|
||||
{
|
||||
int currentPos = (int)tempEntries.size() - EntrySelection->GetValue();
|
||||
switch (event.GetId())
|
||||
{
|
||||
case ID_ENTRY_ADD:
|
||||
{
|
||||
SaveEntryData();
|
||||
|
||||
PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000);
|
||||
std::vector<PatchEngine::PatchEntry>::iterator iterWhere(tempEntries.begin() + currentPos);
|
||||
|
||||
tempEntries.insert(iterWhere, peEmptyEntry);
|
||||
|
||||
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1);
|
||||
EntrySelection->SetValue(EntrySelection->GetMax() - currentPos);
|
||||
|
||||
iterWhere = tempEntries.begin() + currentPos;
|
||||
UpdateEntryCtrls(*iterWhere);
|
||||
|
||||
EntryRemove->Enable();
|
||||
EntrySelection->Enable();
|
||||
}
|
||||
break;
|
||||
case ID_ENTRY_REMOVE:
|
||||
{
|
||||
currentPos--;
|
||||
std::vector<PatchEngine::PatchEntry>::iterator iterWhere(tempEntries.begin() + currentPos);
|
||||
tempEntries.erase(iterWhere);
|
||||
|
||||
if (currentPos != 0)
|
||||
{
|
||||
iterWhere = tempEntries.begin() + currentPos;
|
||||
}
|
||||
else if (tempEntries.size() > 0)
|
||||
{
|
||||
iterWhere = tempEntries.begin();
|
||||
}
|
||||
|
||||
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1);
|
||||
EntrySelection->SetValue(EntrySelection->GetMax() - currentPos);
|
||||
|
||||
UpdateEntryCtrls(*iterWhere);
|
||||
|
||||
if ((int)tempEntries.size() <= 1)
|
||||
{
|
||||
EntryRemove->Disable();
|
||||
EntrySelection->Disable();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
curEntry = currentPos;
|
||||
}
|
||||
|
||||
void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE)
|
||||
{
|
||||
EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), pE.address));
|
||||
EditPatchType->SetSelection(pE.type);
|
||||
EditPatchValue->SetValue(wxString::Format(wxT("%08X"), pE.value));
|
||||
}
|
||||
|
||||
void CPatchAddEdit::SaveEntryData()
|
||||
{
|
||||
unsigned long value;
|
||||
if (EditPatchOffset->GetValue().ToULong(&value, 16))
|
||||
tempEntries.at(curEntry).address = value;
|
||||
tempEntries.at(curEntry).type = (PatchEngine::PatchType) EditPatchType->GetSelection();
|
||||
if (EditPatchValue->GetValue().ToULong(&value, 16))
|
||||
tempEntries.at(curEntry).value = value;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class CPatchAddEdit : public wxDialog
|
|||
wxWindowID id = 1,
|
||||
const wxString& title = wxT("Edit Patch"),
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxSize(300, -1),
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxDEFAULT_DIALOG_STYLE);
|
||||
virtual ~CPatchAddEdit();
|
||||
|
||||
|
@ -41,6 +41,7 @@ class CPatchAddEdit : public wxDialog
|
|||
wxRadioBox *EditPatchType;
|
||||
wxTextCtrl *EditPatchValue;
|
||||
wxSpinButton *EntrySelection;
|
||||
wxButton *EntryRemove;
|
||||
|
||||
enum {
|
||||
ID_EDITPATCH_NAME_TEXT = 4500,
|
||||
|
@ -50,14 +51,22 @@ class CPatchAddEdit : public wxDialog
|
|||
ID_ENTRY_SELECT,
|
||||
ID_EDITPATCH_TYPE,
|
||||
ID_EDITPATCH_VALUE_TEXT,
|
||||
ID_EDITPATCH_VALUE
|
||||
ID_EDITPATCH_VALUE,
|
||||
ID_ENTRY_ADD,
|
||||
ID_ENTRY_REMOVE
|
||||
};
|
||||
|
||||
void CreateGUIControls(int selection);
|
||||
void OnClose(wxCloseEvent& event);
|
||||
void ChangeEntry(wxSpinEvent& event);
|
||||
void SavePatchData(wxCommandEvent& event);
|
||||
void AddRemoveEntry(wxCommandEvent& event);
|
||||
void UpdateEntryCtrls(PatchEngine::PatchEntry pE);
|
||||
void SaveEntryData();
|
||||
|
||||
int selection;
|
||||
int curEntry;
|
||||
std::vector<PatchEngine::PatchEntry> tempEntries;
|
||||
|
||||
};
|
||||
#endif // __PATCH_ADDEDIT_h__
|
||||
|
|
Loading…
Reference in New Issue