2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "PatchAddEdit.h"
|
2013-02-28 04:37:38 +00:00
|
|
|
#include "WxUtils.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
extern std::vector<PatchEngine::Patch> onFrame;
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CPatchAddEdit, wxDialog)
|
2009-01-03 21:55:49 +00:00
|
|
|
EVT_BUTTON(wxID_OK, CPatchAddEdit::SavePatchData)
|
|
|
|
EVT_BUTTON(ID_ENTRY_ADD, CPatchAddEdit::AddRemoveEntry)
|
|
|
|
EVT_BUTTON(ID_ENTRY_REMOVE, CPatchAddEdit::AddRemoveEntry)
|
2008-12-08 05:30:24 +00:00
|
|
|
EVT_SPIN(ID_ENTRY_SELECT, CPatchAddEdit::ChangeEntry)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
CPatchAddEdit::CPatchAddEdit(int _selection, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
|
|
|
|
: wxDialog(parent, id, title, position, size, style)
|
|
|
|
{
|
2009-01-03 21:55:49 +00:00
|
|
|
selection = _selection;
|
2008-12-08 05:30:24 +00:00
|
|
|
CreateGUIControls(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
CPatchAddEdit::~CPatchAddEdit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPatchAddEdit::CreateGUIControls(int _selection)
|
|
|
|
{
|
2011-01-05 17:56:08 +00:00
|
|
|
wxString currentName = _("<Insert name here>");
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
if (_selection == -1)
|
|
|
|
{
|
2009-01-03 23:02:13 +00:00
|
|
|
tempEntries.clear();
|
2009-01-03 21:55:49 +00:00
|
|
|
tempEntries.push_back(PatchEngine::PatchEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-28 08:39:06 +00:00
|
|
|
currentName = StrToWxStr(onFrame.at(_selection).name);
|
2009-01-03 22:21:34 +00:00
|
|
|
tempEntries = onFrame.at(_selection).entries;
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-01-03 23:02:13 +00:00
|
|
|
itCurEntry = tempEntries.begin();
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
wxBoxSizer* sEditPatch = new wxBoxSizer(wxVERTICAL);
|
2011-03-17 04:26:01 +00:00
|
|
|
wxStaticText* EditPatchNameText = new wxStaticText(this, ID_EDITPATCH_NAME_TEXT, _("Name:"));
|
|
|
|
EditPatchName = new wxTextCtrl(this, ID_EDITPATCH_NAME);
|
2009-01-03 22:21:34 +00:00
|
|
|
EditPatchName->SetValue(currentName);
|
2011-03-17 04:26:01 +00:00
|
|
|
wxStaticText* EditPatchOffsetText = new wxStaticText(this, ID_EDITPATCH_OFFSET_TEXT, _("Offset:"));
|
|
|
|
EditPatchOffset = new wxTextCtrl(this, ID_EDITPATCH_OFFSET);
|
2009-01-03 21:55:49 +00:00
|
|
|
EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), tempEntries.at(0).address));
|
2008-12-08 05:30:24 +00:00
|
|
|
EntrySelection = new wxSpinButton(this, ID_ENTRY_SELECT, wxDefaultPosition, wxDefaultSize, wxVERTICAL);
|
2009-01-03 21:55:49 +00:00
|
|
|
EntrySelection->SetRange(0, (int)tempEntries.size()-1);
|
|
|
|
EntrySelection->SetValue((int)tempEntries.size()-1);
|
2008-12-08 05:30:24 +00:00
|
|
|
wxArrayString wxArrayStringFor_EditPatchType;
|
|
|
|
for (int i = 0; i < 3; ++i)
|
2013-02-28 04:37:38 +00:00
|
|
|
wxArrayStringFor_EditPatchType.Add(StrToWxStr(PatchEngine::PatchTypeStrings[i]));
|
2011-03-17 04:26:01 +00:00
|
|
|
EditPatchType = new wxRadioBox(this, ID_EDITPATCH_TYPE, _("Type"), wxDefaultPosition, wxDefaultSize, wxArrayStringFor_EditPatchType, 3, wxRA_SPECIFY_COLS);
|
2009-01-03 21:55:49 +00:00
|
|
|
EditPatchType->SetSelection((int)tempEntries.at(0).type);
|
2011-03-17 04:26:01 +00:00
|
|
|
wxStaticText* EditPatchValueText = new wxStaticText(this, ID_EDITPATCH_VALUE_TEXT, _("Value:"));
|
|
|
|
EditPatchValue = new wxTextCtrl(this, ID_EDITPATCH_VALUE);
|
2011-07-09 21:00:30 +00:00
|
|
|
EditPatchValue->SetValue(wxString::Format(wxT("%0*X"), PatchEngine::GetPatchTypeCharLength(tempEntries.at(0).type), tempEntries.at(0).value));
|
2011-03-17 04:26:01 +00:00
|
|
|
wxButton *EntryAdd = new wxButton(this, ID_ENTRY_ADD, _("Add"));
|
|
|
|
EntryRemove = new wxButton(this, ID_ENTRY_REMOVE, _("Remove"));
|
2009-01-03 21:55:49 +00:00
|
|
|
if ((int)tempEntries.size() <= 1)
|
|
|
|
EntryRemove->Disable();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
wxBoxSizer* sEditPatchName = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sEditPatchName->Add(EditPatchNameText, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
|
|
|
sEditPatchName->Add(EditPatchName, 1, wxEXPAND|wxALL, 5);
|
|
|
|
sEditPatch->Add(sEditPatchName, 0, wxEXPAND);
|
2011-01-05 17:56:08 +00:00
|
|
|
sbEntry = new wxStaticBoxSizer(wxVERTICAL, this, wxString::Format(_("Entry 1/%d"), (int)tempEntries.size()));
|
2009-02-20 00:07:35 +00:00
|
|
|
currentItem = 1;
|
2008-12-08 05:30:24 +00:00
|
|
|
wxGridBagSizer* sgEntry = new wxGridBagSizer(0, 0);
|
|
|
|
sgEntry->Add(EditPatchType, wxGBPosition(0, 0), wxGBSpan(1, 2), wxEXPAND|wxALL, 5);
|
|
|
|
sgEntry->Add(EditPatchOffsetText, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
|
|
|
sgEntry->Add(EditPatchOffset, wxGBPosition(1, 1), wxGBSpan(1, 1), wxEXPAND|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(EntrySelection, wxGBPosition(0, 2), wxGBSpan(3, 1), wxEXPAND|wxALL, 5);
|
2010-06-11 08:39:03 +00:00
|
|
|
sgEntry->AddGrowableCol(1);
|
2009-01-03 21:55:49 +00:00
|
|
|
wxBoxSizer* sEntryAddRemove = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sEntryAddRemove->Add(EntryAdd, 0, wxALL, 5);
|
|
|
|
sEntryAddRemove->Add(EntryRemove, 0, wxALL, 5);
|
2008-12-08 05:30:24 +00:00
|
|
|
sbEntry->Add(sgEntry, 0, wxEXPAND);
|
2009-01-03 21:55:49 +00:00
|
|
|
sbEntry->Add(sEntryAddRemove, 0, wxEXPAND);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
sEditPatch->Add(sbEntry, 0, wxEXPAND|wxALL, 5);
|
|
|
|
sEditPatch->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5);
|
|
|
|
SetSizerAndFit(sEditPatch);
|
|
|
|
SetFocus();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPatchAddEdit::ChangeEntry(wxSpinEvent& event)
|
|
|
|
{
|
2011-07-09 21:00:30 +00:00
|
|
|
if (!UpdateTempEntryData(itCurEntry))
|
|
|
|
return;
|
2009-01-03 23:02:13 +00:00
|
|
|
|
|
|
|
itCurEntry = tempEntries.end() - event.GetPosition() - 1;
|
2009-02-20 00:07:35 +00:00
|
|
|
currentItem = (int)tempEntries.size() - event.GetPosition();
|
2009-01-03 23:02:13 +00:00
|
|
|
UpdateEntryCtrls(*itCurEntry);
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|
|
|
|
|
2011-03-17 04:26:01 +00:00
|
|
|
void CPatchAddEdit::SavePatchData(wxCommandEvent& event)
|
2009-01-03 21:55:49 +00:00
|
|
|
{
|
2011-07-09 21:00:30 +00:00
|
|
|
if (!UpdateTempEntryData(itCurEntry))
|
|
|
|
return;
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
if (selection == -1)
|
|
|
|
{
|
|
|
|
PatchEngine::Patch newPatch;
|
2013-02-28 04:37:38 +00:00
|
|
|
newPatch.name = WxStrToStr(EditPatchName->GetValue());
|
2009-01-03 21:55:49 +00:00
|
|
|
newPatch.entries = tempEntries;
|
|
|
|
newPatch.active = true;
|
|
|
|
|
|
|
|
onFrame.push_back(newPatch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-28 04:37:38 +00:00
|
|
|
onFrame.at(selection).name = WxStrToStr(EditPatchName->GetValue());
|
2009-01-03 21:55:49 +00:00
|
|
|
onFrame.at(selection).entries = tempEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
AcceptAndClose();
|
2011-03-17 04:26:01 +00:00
|
|
|
event.Skip();
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPatchAddEdit::AddRemoveEntry(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case ID_ENTRY_ADD:
|
|
|
|
{
|
2011-07-09 21:00:30 +00:00
|
|
|
if (!UpdateTempEntryData(itCurEntry))
|
|
|
|
break;
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
PatchEngine::PatchEntry peEmptyEntry(PatchEngine::PATCH_8BIT, 0x00000000, 0x00000000);
|
2010-05-28 23:14:16 +00:00
|
|
|
++itCurEntry;
|
2009-02-20 00:07:35 +00:00
|
|
|
currentItem++;
|
2009-01-03 23:02:13 +00:00
|
|
|
itCurEntry = tempEntries.insert(itCurEntry, peEmptyEntry);
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() + 1);
|
2009-01-03 23:02:13 +00:00
|
|
|
UpdateEntryCtrls(*itCurEntry);
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
EntryRemove->Enable();
|
|
|
|
EntrySelection->Enable();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ID_ENTRY_REMOVE:
|
2009-01-03 23:02:13 +00:00
|
|
|
{
|
|
|
|
itCurEntry = tempEntries.erase(itCurEntry);
|
|
|
|
|
|
|
|
if (itCurEntry != tempEntries.begin())
|
2009-01-03 21:55:49 +00:00
|
|
|
{
|
2010-05-28 23:14:16 +00:00
|
|
|
--itCurEntry;
|
2009-02-20 00:07:35 +00:00
|
|
|
currentItem--;
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|
2009-01-03 23:02:13 +00:00
|
|
|
else
|
2009-01-03 21:55:49 +00:00
|
|
|
{
|
2009-01-03 23:02:13 +00:00
|
|
|
EntrySelection->SetValue(EntrySelection->GetValue() - 1);
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|
2009-01-03 23:02:13 +00:00
|
|
|
|
|
|
|
EntrySelection->SetRange(EntrySelection->GetMin(), EntrySelection->GetMax() - 1);
|
|
|
|
UpdateEntryCtrls(*itCurEntry);
|
2009-01-03 21:55:49 +00:00
|
|
|
|
|
|
|
if ((int)tempEntries.size() <= 1)
|
|
|
|
{
|
|
|
|
EntryRemove->Disable();
|
|
|
|
EntrySelection->Disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPatchAddEdit::UpdateEntryCtrls(PatchEngine::PatchEntry pE)
|
|
|
|
{
|
2011-01-05 17:56:08 +00:00
|
|
|
sbEntry->GetStaticBox()->SetLabel(wxString::Format(_("Entry %d/%d"), currentItem,
|
2009-02-20 00:07:35 +00:00
|
|
|
(int)tempEntries.size()));
|
2008-12-08 05:30:24 +00:00
|
|
|
EditPatchOffset->SetValue(wxString::Format(wxT("%08X"), pE.address));
|
|
|
|
EditPatchType->SetSelection(pE.type);
|
2011-07-09 21:00:30 +00:00
|
|
|
EditPatchValue->SetValue(wxString::Format(wxT("%0*X"),
|
|
|
|
PatchEngine::GetPatchTypeCharLength(pE.type), pE.value));
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2009-01-03 21:55:49 +00:00
|
|
|
|
2011-07-09 21:00:30 +00:00
|
|
|
bool CPatchAddEdit::UpdateTempEntryData(std::vector<PatchEngine::PatchEntry>::iterator iterEntry)
|
2009-01-03 21:55:49 +00:00
|
|
|
{
|
|
|
|
unsigned long value;
|
2011-07-09 21:00:30 +00:00
|
|
|
bool parsed_ok = true;
|
2009-01-03 23:02:13 +00:00
|
|
|
|
2009-01-03 21:55:49 +00:00
|
|
|
if (EditPatchOffset->GetValue().ToULong(&value, 16))
|
2009-01-03 23:02:13 +00:00
|
|
|
(*iterEntry).address = value;
|
2011-07-09 21:00:30 +00:00
|
|
|
else
|
|
|
|
parsed_ok = false;
|
|
|
|
|
|
|
|
PatchEngine::PatchType tempType =
|
|
|
|
(*iterEntry).type = (PatchEngine::PatchType)EditPatchType->GetSelection();
|
|
|
|
|
2009-01-03 21:55:49 +00:00
|
|
|
if (EditPatchValue->GetValue().ToULong(&value, 16))
|
2011-07-09 21:00:30 +00:00
|
|
|
{
|
2009-01-03 23:02:13 +00:00
|
|
|
(*iterEntry).value = value;
|
2011-07-09 21:00:30 +00:00
|
|
|
if (tempType == PatchEngine::PATCH_8BIT && value > 0xff)
|
|
|
|
parsed_ok = false;
|
|
|
|
else if (tempType == PatchEngine::PATCH_16BIT && value > 0xffff)
|
|
|
|
parsed_ok = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parsed_ok = false;
|
|
|
|
|
|
|
|
if (!parsed_ok)
|
|
|
|
{
|
|
|
|
PanicAlertT("Unable to create patch from given values.\nEntry not modified.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsed_ok;
|
2009-01-03 21:55:49 +00:00
|
|
|
}
|