From 8c0ea991c8cefe4ce1d292e29fd12b65333ac906 Mon Sep 17 00:00:00 2001 From: bgk Date: Sun, 20 Feb 2011 14:53:04 +0000 Subject: [PATCH] GTK: Added GBA cheats support. Thanks to unmacaque for the patch. --- CMakeLists.txt | 3 + src/gtk/cheatedit.cpp | 116 ++++++++++++++ src/gtk/cheatedit.h | 62 ++++++++ src/gtk/cheatlist.cpp | 293 ++++++++++++++++++++++++++++++++++++ src/gtk/cheatlist.h | 69 +++++++++ src/gtk/stringtokenizer.cpp | 42 ++++++ src/gtk/stringtokenizer.h | 40 +++++ src/gtk/ui/cheatedit.ui | 179 ++++++++++++++++++++++ src/gtk/ui/cheatlist.ui | 180 ++++++++++++++++++++++ src/gtk/ui/vbam.ui | 25 +++ src/gtk/window.cpp | 18 +++ src/gtk/window.h | 2 + src/gtk/windowcallbacks.cpp | 31 ++++ 13 files changed, 1060 insertions(+) create mode 100644 src/gtk/cheatedit.cpp create mode 100644 src/gtk/cheatedit.h create mode 100644 src/gtk/cheatlist.cpp create mode 100644 src/gtk/cheatlist.h create mode 100644 src/gtk/stringtokenizer.cpp create mode 100644 src/gtk/stringtokenizer.h create mode 100644 src/gtk/ui/cheatedit.ui create mode 100644 src/gtk/ui/cheatlist.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e4c1c29..1cb806b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,6 +250,8 @@ SET(SRC_GTK src/gtk/filters.cpp src/gtk/gameboyconfig.cpp src/gtk/gameboyadvanceconfig.cpp + src/gtk/cheatlist.cpp + src/gtk/cheatedit.cpp src/gtk/joypadconfig.cpp src/gtk/directoriesconfig.cpp src/gtk/displayconfig.cpp @@ -257,6 +259,7 @@ SET(SRC_GTK src/gtk/screenarea.cpp src/gtk/screenarea-cairo.cpp src/gtk/screenarea-opengl.cpp + src/gtk/stringtokenizer.cpp src/gtk/tools.cpp src/gtk/window.cpp src/sdl/inputSDL.cpp diff --git a/src/gtk/cheatedit.cpp b/src/gtk/cheatedit.cpp new file mode 100644 index 00000000..e722cb93 --- /dev/null +++ b/src/gtk/cheatedit.cpp @@ -0,0 +1,116 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "cheatedit.h" + +#include "intl.h" + +namespace VBA +{ + +class CheatCodeColumns : public Gtk::TreeModel::ColumnRecord +{ + public: + CheatCodeColumns() + { + add(uText); + add(iType); + } + + ~CheatCodeColumns() {} + + Gtk::TreeModelColumn uText; + Gtk::TreeModelColumn iType; +}; + +CheatCodeColumns cTypeModel; + +/** + * GameBoyAdvanceCheatEditDialog + * + * A unified cheat editing dialog for multiple code types. + */ +CheatEditDialog::CheatEditDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : + Gtk::Dialog(_pstDialog) +{ + refBuilder->get_widget("CheatDescEntry", m_poCheatDescEntry); + refBuilder->get_widget("CheatTypeComboBox", m_poCheatTypeComboBox); + refBuilder->get_widget("CheatInputTextView", m_poCheatInputTextView); + refBuilder->get_widget("CheatApplyButton", m_poCheatApplyButton); + refBuilder->get_widget("CheatCancelButton", m_poCheatCancelButton); + + // Tree View model + m_poCheatTypeStore = Gtk::ListStore::create(cTypeModel); + + m_poCheatTypeComboBox->set_model(m_poCheatTypeStore); + + Gtk::TreeModel::Row row = *(m_poCheatTypeStore->append()); + + row[cTypeModel.iType] = CheatGeneric; + row[cTypeModel.uText] = "Generic Code"; + + row = *(m_poCheatTypeStore->append()); + + row[cTypeModel.iType] = CheatGSA; + row[cTypeModel.uText] = "Gameshark Advance"; + + row = *(m_poCheatTypeStore->append()); + + row[cTypeModel.iType] = CheatCBA; + row[cTypeModel.uText] = "CodeBreaker Advance"; + + m_poCheatTypeComboBox->set_active(CheatGeneric); + + m_poCheatApplyButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatEditDialog::vOnApply)); + m_poCheatCancelButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatEditDialog::vOnCancel)); +} + +Glib::RefPtr CheatEditDialog::vGetCode() +{ + return m_poCheatInputTextView->get_buffer(); +} + +Glib::ustring CheatEditDialog::vGetDesc() +{ + return m_poCheatDescEntry->get_text(); +} + +ECheatType CheatEditDialog::vGetType() +{ + Gtk::TreeModel::iterator iter = m_poCheatTypeComboBox->get_active(); + + if (iter) + { + Gtk::TreeModel::Row row = *iter; + + return row[cTypeModel.iType]; + } + + return CheatGeneric; +} + +void CheatEditDialog::vOnApply() +{ + response(Gtk::RESPONSE_APPLY); +} + +void CheatEditDialog::vOnCancel() { + response(Gtk::RESPONSE_CANCEL); +} + +} // namespace VBA diff --git a/src/gtk/cheatedit.h b/src/gtk/cheatedit.h new file mode 100644 index 00000000..6027caf5 --- /dev/null +++ b/src/gtk/cheatedit.h @@ -0,0 +1,62 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __VBA_CHEATEDIT_H__ +#define __VBA_CHEATEDIT_H__ + +#include + +#include "window.h" + +namespace VBA +{ + +enum ECheatType +{ + CheatGeneric, + CheatGSA, + CheatCBA +}; + +class CheatEditDialog : public Gtk::Dialog +{ +public: + CheatEditDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder); + Glib::RefPtr vGetCode(); + Glib::ustring vGetDesc(); + ECheatType vGetType(); + +private: + void vOnApply(); + void vOnCancel(); + + VBA::Window * m_poWindow; + + Gtk::Entry * m_poCheatDescEntry; + Gtk::ComboBox * m_poCheatTypeComboBox; + Gtk::TextView * m_poCheatInputTextView; + Gtk::Button * m_poCheatApplyButton; + Gtk::Button * m_poCheatCancelButton; + Glib::RefPtr m_poCheatInputBuffer; + Glib::RefPtr m_poCheatTypeStore; +}; + +} // namespace VBA + + +#endif diff --git a/src/gtk/cheatlist.cpp b/src/gtk/cheatlist.cpp new file mode 100644 index 00000000..3d8c456f --- /dev/null +++ b/src/gtk/cheatlist.cpp @@ -0,0 +1,293 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "cheatlist.h" + +#include "intl.h" +#include "stringtokenizer.h" +#include + +namespace VBA +{ + +class CheatCodeColumns : public Gtk::TreeModel::ColumnRecord +{ + public: + CheatCodeColumns() + { + add(iIndex); + add(bEnabled); + add(uDesc); + } + + ~CheatCodeColumns() {} + + Gtk::TreeModelColumn iIndex; + Gtk::TreeModelColumn bEnabled; + Gtk::TreeModelColumn uDesc; +}; + +CheatCodeColumns cRecordModel; + +CheatListDialog::CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : + Gtk::Dialog(_pstDialog) +{ + refBuilder->get_widget("CheatOpenButton", m_poCheatOpenButton); + refBuilder->get_widget("CheatSaveButton", m_poCheatSaveButton); + refBuilder->get_widget("CheatAddButton", m_poCheatAddButton); + refBuilder->get_widget("CheatRemoveButton", m_poCheatRemoveButton); + refBuilder->get_widget("CheatRemoveAllButton", m_poCheatRemoveAllButton); + refBuilder->get_widget("CheatMarkAllButton", m_poCheatMarkAllButton); + refBuilder->get_widget("CheatTreeView", m_poCheatTreeView); + + // Tree View model + m_poCheatListStore = Gtk::ListStore::create(cRecordModel); + + m_poCheatTreeView->set_model(m_poCheatListStore); + + Gtk::CellRendererToggle* pRenderer = Gtk::manage(new Gtk::CellRendererToggle()); + + int cols_count = m_poCheatTreeView->append_column("", *pRenderer); + + pRenderer->signal_toggled().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatToggled)); + + Gtk::TreeViewColumn* pColumn = m_poCheatTreeView->get_column(cols_count - 1); + + if (pColumn) + pColumn->add_attribute(pRenderer->property_active(), cRecordModel.bEnabled); + + m_poCheatTreeView->append_column("Description", cRecordModel.uDesc); + + m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatOpen)); + m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatSave)); + m_poCheatAddButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatAdd)); + m_poCheatRemoveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemove)); + m_poCheatRemoveAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemoveAll)); + m_poCheatMarkAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatMarkAll)); + + bMark = false; + + vUpdateList(); +} + +void CheatListDialog::vOnCheatOpen() +{ + Gtk::FileChooserDialog oDialog(*this, _("Open cheat list")); + oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + oDialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + + oDialog.set_current_folder(Glib::get_home_dir()); // TODO: remember dir? + + while (oDialog.run() == Gtk::RESPONSE_OK) + { + // delete existing cheats before loading the list + cheatsDeleteAll(false); + + m_poCheatListStore->clear(); + + if (cheatsLoadCheatList(oDialog.get_filename().c_str())) + { + vUpdateList(); + break; + } + } +} + +void CheatListDialog::vOnCheatSave() +{ + Gtk::FileChooserDialog sDialog(*this, _("Save cheat list")); + sDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + sDialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + + sDialog.set_current_folder(Glib::get_home_dir()); + + if (sDialog.run() == Gtk::RESPONSE_OK) + cheatsSaveCheatList(sDialog.get_filename().c_str()); +} + +void CheatListDialog::vOnCheatAdd() +{ + std::string sUiFile = VBA::Window::sGetUiFilePath("cheatedit.ui"); + Glib::RefPtr poBuilder = Gtk::Builder::create_from_file(sUiFile); + + CheatEditDialog * poDialog = 0; + poBuilder->get_widget_derived("CheatEditDialog", poDialog); + poDialog->set_transient_for(*this); + int response = poDialog->run(); + poDialog->hide(); + + if (response == Gtk::RESPONSE_APPLY) + { + Glib::ustring sDesc = poDialog->vGetDesc(); + + int previous = cheatsNumber; + + switch (poDialog->vGetType()) + { + // Generic Code + case CheatGeneric: + { + std::vector tokens; + Glib::RefPtr code_buffer = poDialog->vGetCode(); + + StringTokenizer::tokenize(code_buffer->get_text(), tokens); + + for (std::vector::iterator it = tokens.begin(); + it != tokens.end(); + it++) + { + Glib::ustring sToken = it->uppercase(); + + cheatsAddCheatCode(sToken.c_str(), sDesc.c_str()); + } + + break; + } + // Gameshark Advance & CodeBreaker Advance + case CheatGSA: + case CheatCBA: + { + std::vector tokens; + Glib::RefPtr code_buffer = poDialog->vGetCode(); + + Glib::ustring sToken; + Glib::ustring sCode; + Glib::ustring sPart = ""; + + StringTokenizer::tokenize(code_buffer->get_text(), tokens); + + for (std::vector::iterator it = tokens.begin(); + it != tokens.end(); + it++) + { + + sToken = it->uppercase(); + const char *cToken = sToken.c_str(); + + if (sToken.size() == 16) + { + cheatsAddGSACode(cToken, sDesc.c_str(), false); + } + else if (sToken.size() == 12) + { + sCode = sToken.substr(0,8); + sCode += " "; + sCode += sToken.substr(9,4); // TODO: is this safe? + cheatsAddCBACode(sCode.c_str(), sDesc.c_str()); + } + else + if (sPart.empty()) + { + sPart = sToken; + } + else + { + if (sToken.size() == 4) + { + sCode = sPart; + sCode += " "; + sCode += cToken; + cheatsAddCBACode(sCode.c_str(), sDesc.c_str()); + } + else + { + sCode = sPart + sToken; + cheatsAddGSACode(sCode.c_str(), sDesc.c_str(), true); + } + + sPart = ""; + } + } // end of loop + + } // end of case + } // end of switch + + vUpdateList(previous); + + } // end of condition +} + +void CheatListDialog::vOnCheatRemove() +{ + Gtk::TreeModel::iterator iter = m_poCheatTreeView->get_selection()->get_selected(); + + if (iter) + { + Gtk::TreeModel::Row row = *iter; + + cheatsDelete(row[cRecordModel.iIndex], false); + + m_poCheatListStore->erase(iter); + } +} + +void CheatListDialog::vOnCheatRemoveAll() +{ + cheatsDeleteAll(false); + + m_poCheatListStore->clear(); +} + +void CheatListDialog::vOnCheatMarkAll() +{ + Gtk::TreeModel::Children cListEntries = m_poCheatListStore->children(); + + for (Gtk::TreeModel::iterator iter = cListEntries.begin(); iter; iter++) + { + Gtk::TreeModel::Row row = *iter; + + row[cRecordModel.bEnabled] = bMark; + + vToggleCheat(row[cRecordModel.iIndex], row[cRecordModel.bEnabled]); + } + + bMark = !bMark; +} + +void CheatListDialog::vOnCheatToggled(Glib::ustring const& string_path) +{ + Gtk::TreeIter iter = m_poCheatListStore->get_iter(string_path); + + Gtk::TreeModel::Row row = *iter; + + row[cRecordModel.bEnabled] = !row[cRecordModel.bEnabled]; + + vToggleCheat(row[cRecordModel.iIndex], row[cRecordModel.bEnabled]); +} + +void CheatListDialog::vToggleCheat(int index, bool enable) { + if (enable) + cheatsEnable(index); + else + cheatsDisable(index); +} + +void CheatListDialog::vUpdateList(int previous) +{ + for (int i = previous; i < cheatsNumber; i++) + { + // Add row for each newly added cheat + Gtk::TreeModel::Row row = *(m_poCheatListStore->append()); + + row[cRecordModel.iIndex] = i; + row[cRecordModel.bEnabled] = cheatsList[i].enabled; + row[cRecordModel.uDesc] = cheatsList[i].desc; + } +} + +} // namespace VBA diff --git a/src/gtk/cheatlist.h b/src/gtk/cheatlist.h new file mode 100644 index 00000000..4a522aa4 --- /dev/null +++ b/src/gtk/cheatlist.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 2008 VBA-M development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __VBA_CHEATLIST_H__ +#define __VBA_CHEATLIST_H__ + +#include + +#include "../System.h" +#include "../gba/Cheats.h" +#include "../gba/GBA.h" +#include "../gba/Globals.h" +#include "cheatedit.h" + +#include "window.h" + +namespace VBA +{ + +class CheatListDialog : public Gtk::Dialog +{ +public: + CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder); + +private: + void vAddCheat(int index, Glib::ustring desc, bool enabled = true); + void vOnCheatOpen(); + void vOnCheatSave(); + void vOnCheatAdd(); + void vOnCheatRemove(); + void vOnCheatRemoveAll(); + void vOnCheatMarkAll(); + void vOnCheatToggled(Glib::ustring const& string_path); + void vToggleCheat(int index, bool enable); + void vUpdateList(int previous = 0); + + VBA::Window * m_poWindow; + + Gtk::ToolButton * m_poCheatOpenButton; + Gtk::ToolButton * m_poCheatSaveButton; + Gtk::ToolButton * m_poCheatAddButton; + Gtk::ToolButton * m_poCheatRemoveButton; + Gtk::ToolButton * m_poCheatRemoveAllButton; + Gtk::ToolButton * m_poCheatMarkAllButton; + Gtk::TreeView * m_poCheatTreeView; + Glib::RefPtr m_poCheatListStore; + + bool bMark; +}; + +} // namespace VBA + + +#endif diff --git a/src/gtk/stringtokenizer.cpp b/src/gtk/stringtokenizer.cpp new file mode 100644 index 00000000..056e9f9f --- /dev/null +++ b/src/gtk/stringtokenizer.cpp @@ -0,0 +1,42 @@ +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 1999-2003 Forgotten +// Copyright (C) 2004 Forgotten and the VBA development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "stringtokenizer.h" + +namespace VBA +{ + +void StringTokenizer::tokenize(Glib::ustring source, std::vector& tokens) +{ + // Skip delimiters at beginning. + Glib::ustring::size_type lastPos = source.find_first_not_of(delimiters, 0); + // Find first "non-delimiter". + Glib::ustring::size_type pos = source.find_first_of(delimiters, lastPos); + + while (Glib::ustring::npos != pos || std:: string::npos != lastPos) + { + // Found a token, add it to the vector. + tokens.push_back(source.substr(lastPos, pos - lastPos)); + // Skip delimiters. Note the "not_of" + lastPos = source.find_first_not_of(delimiters, pos); + // Find next "non-delimiter" + pos = source.find_first_of(delimiters, lastPos); + } +} + +} // VBA namespace diff --git a/src/gtk/stringtokenizer.h b/src/gtk/stringtokenizer.h new file mode 100644 index 00000000..41912aed --- /dev/null +++ b/src/gtk/stringtokenizer.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. +// Copyright (C) 1999-2003 Forgotten +// Copyright (C) 2004 Forgotten and the VBA development team + +// 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; either version 2, or(at your option) +// any later version. +// +// 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __VBA_STRINGTOKENIZER_H__ +#define __VBA_STRINGTOKENIZER_H__ + +#include +#include +#include + +namespace VBA +{ + +class StringTokenizer +{ +public: + static void tokenize(Glib::ustring source, std::vector& tokens); +}; + +static const Glib::ustring delimiters = " \t\n\r"; + +} // VBA namespace + +#endif diff --git a/src/gtk/ui/cheatedit.ui b/src/gtk/ui/cheatedit.ui new file mode 100644 index 00000000..1c3e144e --- /dev/null +++ b/src/gtk/ui/cheatedit.ui @@ -0,0 +1,179 @@ + + + + + + + + + + + + 5 + Edit cheat + center-on-parent + dialog + + + True + + + True + + + True + 0 + none + + + True + 12 + + + True + True + 31 + + + + + + + + True + <b>Description</b> + True + + + + + False + 0 + + + + + True + 0 + none + + + True + 12 + + + True + model1 + + + + 0 + + + + + + + + + True + <b>Type</b> + True + + + + + False + 1 + + + + + True + 0 + none + + + True + 12 + + + True + True + never + automatic + + + True + True + + + + + + + + + True + <b>Codes</b> + True + + + + + end + 2 + + + + + 1 + + + + + True + end + + + gtk-apply + True + True + True + True + + + False + False + 0 + + + + + gtk-close + True + True + True + True + + + False + False + 1 + + + + + False + end + 0 + + + + + + CheatApplyButton + CheatCancelButton + + + diff --git a/src/gtk/ui/cheatlist.ui b/src/gtk/ui/cheatlist.ui new file mode 100644 index 00000000..922e450d --- /dev/null +++ b/src/gtk/ui/cheatlist.ui @@ -0,0 +1,180 @@ + + + + + + 320 + 260 + 5 + Cheat list + center-on-parent + dialog + + + True + + + True + + + True + Open cheat list + gtk-open + True + document-open + + + False + True + + + + + True + Save cheat list + gtk-save + True + document-save + + + False + True + + + + + True + + + False + True + + + + + True + Add new cheat + gtk-add + True + list-add + + + False + True + + + + + True + Delete selected cheat + gtk-delete + True + list-remove + + + False + True + + + + + True + Delete all cheats + True + gtk-clear + + + False + True + + + + + True + + + False + True + + + + + True + Toggle all Cheats + gtk-markall + True + edit-select-all + + + False + True + + + + + False + 0 + + + + + True + True + + + True + True + never + automatic + + + True + True + + + + + end + 0 + + + + + 1 + + + + + True + end + + + + + + gtk-close + True + True + True + True + + + False + False + 1 + + + + + False + end + 2 + + + + + + button1 + + + diff --git a/src/gtk/ui/vbam.ui b/src/gtk/ui/vbam.ui index 44d5abd4..0d1573c8 100644 --- a/src/gtk/ui/vbam.ui +++ b/src/gtk/ui/vbam.ui @@ -435,6 +435,31 @@ + + + True + False + + + + + True + False + False + _List cheats ... + True + + + + + + True + False + False + _Disable cheats + True + + diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 38e8fe3e..74f3547a 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -31,6 +31,7 @@ #include "../gba/Sound.h" #include "../gb/gb.h" #include "../gb/gbGlobals.h" +#include "../gb/gbCheats.h" #include "../gb/gbSound.h" #include "../gb/gbPrinter.h" #include "../Util.h" @@ -342,6 +343,19 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml _poXml->get_widget("GameBoyAdvanceConfigure", poMI); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnGameBoyAdvanceConfigure)); + // Cheat list menu + _poXml->get_widget("CheatList", poMI); + poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnCheatList)); + m_listSensitiveWhenPlaying.push_back(poMI); + + // Cheat disable item + _poXml->get_widget("CheatDisable", poCMI); + poCMI->set_active(!cheatsEnabled); + poCMI->signal_toggled().connect(sigc::bind( + sigc::mem_fun(*this, &Window::vOnCheatDisableToggled), + poCMI)); + m_listSensitiveWhenPlaying.push_back(poCMI); + // Display menu _poXml->get_widget("DisplayConfigure", poMI); poMI->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnDisplayConfigure)); @@ -993,6 +1007,10 @@ bool Window::bLoadROM(const std::string & _rsFile) { vOnFileClose(); + // clear cheat list + cheatsDeleteAll(false); + gbCheatRemoveAll(); + m_sRomFile = _rsFile; const char * csFile = _rsFile.c_str(); diff --git a/src/gtk/window.h b/src/gtk/window.h index cfe33bdc..0befaf90 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -161,6 +161,8 @@ protected: virtual void vOnSoundConfigure(); virtual void vOnGameBoyConfigure(); virtual void vOnGameBoyAdvanceConfigure(); + virtual void vOnCheatList(); + virtual void vOnCheatDisableToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnHelpAbout(); virtual bool bOnEmuIdle(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 89abbd9d..3ee2dada 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -40,6 +40,7 @@ #include "soundconfig.h" #include "gameboyconfig.h" #include "gameboyadvanceconfig.h" +#include "cheatlist.h" namespace VBA { @@ -471,6 +472,36 @@ void Window::vOnGameBoyAdvanceConfigure() poDialog->hide(); } +void Window::vOnCheatList() +{ + if (m_eCartridge == CartridgeGBA) + { + std::string sUiFile = sGetUiFilePath("cheatlist.ui"); + Glib::RefPtr poBuilder = Gtk::Builder::create_from_file(sUiFile); + + CheatListDialog * poDialog = 0; + poBuilder->get_widget_derived("CheatListDialog", poDialog); + poDialog->set_transient_for(*this); + poDialog->run(); + poDialog->hide(); + } + else + { + vPopupError(_("Only Gameboy Advance cheats are supported")); + } +} + +void Window::vOnCheatDisableToggled(Gtk::CheckMenuItem * _poCMI) +{ + if (m_eCartridge == CartridgeGB) { + // TODO: implement + } + else if (m_eCartridge == CartridgeGBA) { + cheatsEnabled = !cheatsEnabled; + } + + _poCMI->set_active(!cheatsEnabled); +} void Window::vOnHelpAbout() {