GTK: Merged the GB and GBA cheat list dialogs. Patch by unmacaque.
This commit is contained in:
parent
e49be92119
commit
a8c1e753b1
|
@ -246,6 +246,7 @@ SET(SRC_GTK
|
||||||
src/gtk/gameboyadvanceconfig.cpp
|
src/gtk/gameboyadvanceconfig.cpp
|
||||||
src/gtk/cheatlist.cpp
|
src/gtk/cheatlist.cpp
|
||||||
src/gtk/cheatedit.cpp
|
src/gtk/cheatedit.cpp
|
||||||
|
src/gtk/gameboyadvancecheatlist.cpp
|
||||||
src/gtk/gameboycheatlist.cpp
|
src/gtk/gameboycheatlist.cpp
|
||||||
src/gtk/joypadconfig.cpp
|
src/gtk/joypadconfig.cpp
|
||||||
src/gtk/directoriesconfig.cpp
|
src/gtk/directoriesconfig.cpp
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "cheatlist.h"
|
#include "cheatlist.h"
|
||||||
#include "tools.h"
|
|
||||||
|
|
||||||
#include <gtkmm/stock.h>
|
#include <gtkmm/stock.h>
|
||||||
|
|
||||||
|
@ -56,19 +55,17 @@ CheatListDialog::CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::
|
||||||
|
|
||||||
m_poCheatTreeView->append_column("Description", m_oRecordModel.uDesc);
|
m_poCheatTreeView->append_column("Description", m_oRecordModel.uDesc);
|
||||||
|
|
||||||
m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatOpen));
|
m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatListOpen));
|
||||||
m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatSave));
|
m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatListSave));
|
||||||
m_poCheatAddButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatAdd));
|
m_poCheatAddButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatAdd));
|
||||||
m_poCheatRemoveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemove));
|
m_poCheatRemoveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemove));
|
||||||
m_poCheatRemoveAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemoveAll));
|
m_poCheatRemoveAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatRemoveAll));
|
||||||
m_poCheatMarkAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatMarkAll));
|
m_poCheatMarkAllButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatMarkAll));
|
||||||
|
|
||||||
bMark = false;
|
bMark = false;
|
||||||
|
|
||||||
vUpdateList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatListDialog::vOnCheatOpen()
|
void CheatListDialog::vOnCheatListOpen()
|
||||||
{
|
{
|
||||||
Gtk::FileChooserDialog oDialog(*this, _("Open cheat list"));
|
Gtk::FileChooserDialog oDialog(*this, _("Open cheat list"));
|
||||||
oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||||
|
@ -79,11 +76,11 @@ void CheatListDialog::vOnCheatOpen()
|
||||||
while (oDialog.run() == Gtk::RESPONSE_OK)
|
while (oDialog.run() == Gtk::RESPONSE_OK)
|
||||||
{
|
{
|
||||||
// delete existing cheats before loading the list
|
// delete existing cheats before loading the list
|
||||||
cheatsDeleteAll(false);
|
vRemoveAllCheats();
|
||||||
|
|
||||||
m_poCheatListStore->clear();
|
m_poCheatListStore->clear();
|
||||||
|
|
||||||
if (cheatsLoadCheatList(oDialog.get_filename().c_str()))
|
if (vCheatListOpen(oDialog.get_filename().c_str()))
|
||||||
{
|
{
|
||||||
vUpdateList();
|
vUpdateList();
|
||||||
break;
|
break;
|
||||||
|
@ -91,7 +88,7 @@ void CheatListDialog::vOnCheatOpen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatListDialog::vOnCheatSave()
|
void CheatListDialog::vOnCheatListSave()
|
||||||
{
|
{
|
||||||
Gtk::FileChooserDialog sDialog(*this, _("Save cheat list"));
|
Gtk::FileChooserDialog sDialog(*this, _("Save cheat list"));
|
||||||
sDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
sDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||||
|
@ -100,7 +97,7 @@ void CheatListDialog::vOnCheatSave()
|
||||||
sDialog.set_current_folder(Glib::get_home_dir());
|
sDialog.set_current_folder(Glib::get_home_dir());
|
||||||
|
|
||||||
if (sDialog.run() == Gtk::RESPONSE_OK)
|
if (sDialog.run() == Gtk::RESPONSE_OK)
|
||||||
cheatsSaveCheatList(sDialog.get_filename().c_str());
|
vCheatListSave(sDialog.get_filename().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatListDialog::vOnCheatAdd()
|
void CheatListDialog::vOnCheatAdd()
|
||||||
|
@ -116,95 +113,7 @@ void CheatListDialog::vOnCheatAdd()
|
||||||
poDialog->hide();
|
poDialog->hide();
|
||||||
|
|
||||||
if (response == Gtk::RESPONSE_APPLY)
|
if (response == Gtk::RESPONSE_APPLY)
|
||||||
{
|
vAddCheat(poDialog->vGetDesc(), poDialog->vGetType(), poDialog->vGetCode());
|
||||||
Glib::ustring sDesc = poDialog->vGetDesc();
|
|
||||||
|
|
||||||
int previous = cheatsNumber;
|
|
||||||
|
|
||||||
switch (poDialog->vGetType())
|
|
||||||
{
|
|
||||||
// Generic Code
|
|
||||||
case CheatGeneric:
|
|
||||||
{
|
|
||||||
std::vector<Glib::ustring> tokens;
|
|
||||||
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
|
|
||||||
|
|
||||||
vTokenize(code_buffer->get_text(), tokens);
|
|
||||||
|
|
||||||
for (std::vector<Glib::ustring>::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<Glib::ustring> tokens;
|
|
||||||
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
|
|
||||||
|
|
||||||
Glib::ustring sToken;
|
|
||||||
Glib::ustring sCode;
|
|
||||||
Glib::ustring sPart = "";
|
|
||||||
|
|
||||||
vTokenize(code_buffer->get_text(), tokens);
|
|
||||||
|
|
||||||
for (std::vector<Glib::ustring>::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
|
|
||||||
default:; // silence warnings
|
|
||||||
} // end of switch
|
|
||||||
|
|
||||||
vUpdateList(previous);
|
|
||||||
|
|
||||||
} // end of condition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheatListDialog::vOnCheatRemove()
|
void CheatListDialog::vOnCheatRemove()
|
||||||
|
@ -215,7 +124,7 @@ void CheatListDialog::vOnCheatRemove()
|
||||||
{
|
{
|
||||||
Gtk::TreeModel::Row row = *iter;
|
Gtk::TreeModel::Row row = *iter;
|
||||||
|
|
||||||
cheatsDelete(row[m_oRecordModel.iIndex], false);
|
vRemoveCheat(row[m_oRecordModel.iIndex]);
|
||||||
|
|
||||||
m_poCheatListStore->erase(iter);
|
m_poCheatListStore->erase(iter);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +132,7 @@ void CheatListDialog::vOnCheatRemove()
|
||||||
|
|
||||||
void CheatListDialog::vOnCheatRemoveAll()
|
void CheatListDialog::vOnCheatRemoveAll()
|
||||||
{
|
{
|
||||||
cheatsDeleteAll(false);
|
vRemoveAllCheats();
|
||||||
|
|
||||||
m_poCheatListStore->clear();
|
m_poCheatListStore->clear();
|
||||||
}
|
}
|
||||||
|
@ -260,24 +169,4 @@ void CheatListDialog::vSetWindow(VBA::Window * _poWindow)
|
||||||
m_poWindow = _poWindow;
|
m_poWindow = _poWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
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[m_oRecordModel.iIndex] = i;
|
|
||||||
row[m_oRecordModel.bEnabled] = cheatsList[i].enabled;
|
|
||||||
row[m_oRecordModel.uDesc] = cheatsList[i].desc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace VBA
|
} // namespace VBA
|
||||||
|
|
|
@ -21,10 +21,6 @@
|
||||||
|
|
||||||
#include <gtkmm/toolbutton.h>
|
#include <gtkmm/toolbutton.h>
|
||||||
|
|
||||||
#include "../System.h"
|
|
||||||
#include "../gba/Cheats.h"
|
|
||||||
#include "../gba/GBA.h"
|
|
||||||
#include "../gba/Globals.h"
|
|
||||||
#include "cheatedit.h"
|
#include "cheatedit.h"
|
||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
@ -55,17 +51,26 @@ public:
|
||||||
CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
||||||
void vSetWindow(VBA::Window * _poWindow);
|
void vSetWindow(VBA::Window * _poWindow);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer) = 0;
|
||||||
|
virtual bool vCheatListOpen(const char *file) = 0;
|
||||||
|
virtual void vCheatListSave(const char *file) = 0;
|
||||||
|
virtual void vRemoveCheat(int index) = 0;
|
||||||
|
virtual void vRemoveAllCheats() = 0;
|
||||||
|
virtual void vToggleCheat(int index, bool enable) = 0;
|
||||||
|
virtual void vUpdateList(int previous = 0) = 0;
|
||||||
|
|
||||||
|
Glib::RefPtr<Gtk::ListStore> m_poCheatListStore;
|
||||||
|
ListCheatCodeColumns m_oRecordModel;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void vAddCheat(int index, Glib::ustring desc, bool enabled = true);
|
void vOnCheatListOpen();
|
||||||
void vOnCheatOpen();
|
void vOnCheatListSave();
|
||||||
void vOnCheatSave();
|
|
||||||
void vOnCheatAdd();
|
void vOnCheatAdd();
|
||||||
void vOnCheatRemove();
|
void vOnCheatRemove();
|
||||||
void vOnCheatRemoveAll();
|
void vOnCheatRemoveAll();
|
||||||
void vOnCheatMarkAll();
|
void vOnCheatMarkAll();
|
||||||
void vOnCheatToggled(Glib::ustring const& string_path);
|
void vOnCheatToggled(Glib::ustring const& string_path);
|
||||||
void vToggleCheat(int index, bool enable);
|
|
||||||
void vUpdateList(int previous = 0);
|
|
||||||
|
|
||||||
VBA::Window * m_poWindow;
|
VBA::Window * m_poWindow;
|
||||||
|
|
||||||
|
@ -76,8 +81,6 @@ private:
|
||||||
Gtk::ToolButton * m_poCheatRemoveAllButton;
|
Gtk::ToolButton * m_poCheatRemoveAllButton;
|
||||||
Gtk::ToolButton * m_poCheatMarkAllButton;
|
Gtk::ToolButton * m_poCheatMarkAllButton;
|
||||||
Gtk::TreeView * m_poCheatTreeView;
|
Gtk::TreeView * m_poCheatTreeView;
|
||||||
Glib::RefPtr<Gtk::ListStore> m_poCheatListStore;
|
|
||||||
ListCheatCodeColumns m_oRecordModel;
|
|
||||||
|
|
||||||
bool bMark;
|
bool bMark;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
// -*- 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 "gameboyadvancecheatlist.h"
|
||||||
|
#include "tools.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace VBA
|
||||||
|
{
|
||||||
|
|
||||||
|
GameBoyAdvanceCheatListDialog::GameBoyAdvanceCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder) :
|
||||||
|
CheatListDialog(_pstDialog, refBuilder)
|
||||||
|
{
|
||||||
|
vUpdateList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer)
|
||||||
|
{
|
||||||
|
int previous = cheatsNumber;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
// Generic Code
|
||||||
|
case CheatGeneric:
|
||||||
|
{
|
||||||
|
std::vector<Glib::ustring> tokens;
|
||||||
|
|
||||||
|
vTokenize(buffer->get_text(), tokens);
|
||||||
|
|
||||||
|
for (std::vector<Glib::ustring>::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<Glib::ustring> tokens;
|
||||||
|
|
||||||
|
Glib::ustring sToken;
|
||||||
|
Glib::ustring sCode;
|
||||||
|
Glib::ustring sPart = "";
|
||||||
|
|
||||||
|
vTokenize(buffer->get_text(), tokens);
|
||||||
|
|
||||||
|
for (std::vector<Glib::ustring>::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);
|
||||||
|
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
|
||||||
|
default:; // silence warnings
|
||||||
|
} // end of switch
|
||||||
|
|
||||||
|
vUpdateList(previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GameBoyAdvanceCheatListDialog::vCheatListOpen(const char *file)
|
||||||
|
{
|
||||||
|
return cheatsLoadCheatList(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::vCheatListSave(const char *file)
|
||||||
|
{
|
||||||
|
cheatsSaveCheatList(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::vRemoveCheat(int index) {
|
||||||
|
cheatsDelete(index, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::vRemoveAllCheats() {
|
||||||
|
cheatsDeleteAll(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::vToggleCheat(int index, bool enable) {
|
||||||
|
if (enable)
|
||||||
|
cheatsEnable(index);
|
||||||
|
else
|
||||||
|
cheatsDisable(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyAdvanceCheatListDialog::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[m_oRecordModel.iIndex] = i;
|
||||||
|
row[m_oRecordModel.bEnabled] = cheatsList[i].enabled;
|
||||||
|
row[m_oRecordModel.uDesc] = cheatsList[i].desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace VBA
|
|
@ -0,0 +1,49 @@
|
||||||
|
// -*- 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_GAMEBOYADVANCECHEATLIST_H__
|
||||||
|
#define __VBA_GAMEBOYADVANCECHEATLIST_H__
|
||||||
|
|
||||||
|
#include "../System.h"
|
||||||
|
#include "../gba/Cheats.h"
|
||||||
|
#include "../gba/GBA.h"
|
||||||
|
#include "../gba/Globals.h"
|
||||||
|
#include "cheatlist.h"
|
||||||
|
|
||||||
|
namespace VBA
|
||||||
|
{
|
||||||
|
|
||||||
|
class GameBoyAdvanceCheatListDialog : public CheatListDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GameBoyAdvanceCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer);
|
||||||
|
bool vCheatListOpen(const char *file);
|
||||||
|
void vCheatListSave(const char *file);
|
||||||
|
void vRemoveCheat(int index);
|
||||||
|
void vRemoveAllCheats();
|
||||||
|
void vToggleCheat(int index, bool enable);
|
||||||
|
void vUpdateList(int previous = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace VBA
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -19,209 +19,84 @@
|
||||||
#include "gameboycheatlist.h"
|
#include "gameboycheatlist.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
#include <gtkmm/stock.h>
|
|
||||||
|
|
||||||
#include "intl.h"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
||||||
GameBoyCheatListDialog::GameBoyCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder) :
|
GameBoyCheatListDialog::GameBoyCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder) :
|
||||||
Gtk::Dialog(_pstDialog)
|
CheatListDialog(_pstDialog, refBuilder)
|
||||||
{
|
{
|
||||||
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(m_oRecordModel);
|
|
||||||
|
|
||||||
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, &GameBoyCheatListDialog::vOnCheatToggled));
|
|
||||||
|
|
||||||
Gtk::TreeViewColumn* pColumn = m_poCheatTreeView->get_column(cols_count - 1);
|
|
||||||
|
|
||||||
if (pColumn)
|
|
||||||
pColumn->add_attribute(pRenderer->property_active(), m_oRecordModel.bEnabled);
|
|
||||||
|
|
||||||
m_poCheatTreeView->append_column("Description", m_oRecordModel.uDesc);
|
|
||||||
|
|
||||||
m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatOpen));
|
|
||||||
m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatSave));
|
|
||||||
m_poCheatAddButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatAdd));
|
|
||||||
m_poCheatRemoveButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatRemove));
|
|
||||||
m_poCheatRemoveAllButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatRemoveAll));
|
|
||||||
m_poCheatMarkAllButton->signal_clicked().connect(sigc::mem_fun(*this, &GameBoyCheatListDialog::vOnCheatMarkAll));
|
|
||||||
|
|
||||||
bMark = false;
|
|
||||||
|
|
||||||
vUpdateList();
|
vUpdateList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatOpen()
|
void GameBoyCheatListDialog::vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer)
|
||||||
{
|
{
|
||||||
Gtk::FileChooserDialog oDialog(*this, _("Open cheat list"));
|
int previous = gbCheatNumber;
|
||||||
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());
|
switch (type)
|
||||||
|
|
||||||
while (oDialog.run() == Gtk::RESPONSE_OK)
|
|
||||||
{
|
{
|
||||||
// delete existing cheats before loading the list
|
// GameShark
|
||||||
gbCheatRemoveAll();
|
case CheatGS:
|
||||||
|
{
|
||||||
|
std::vector<Glib::ustring> tokens;
|
||||||
|
|
||||||
m_poCheatListStore->clear();
|
vTokenize(buffer->get_text(), tokens);
|
||||||
|
|
||||||
if (gbCheatsLoadCheatList(oDialog.get_filename().c_str()))
|
for (std::vector<Glib::ustring>::iterator it = tokens.begin();
|
||||||
|
it != tokens.end();
|
||||||
|
it++)
|
||||||
{
|
{
|
||||||
vUpdateList();
|
Glib::ustring sToken = it->uppercase();
|
||||||
break;
|
|
||||||
|
gbAddGsCheat(sToken.c_str(), sDesc.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
// GameGenie
|
||||||
|
case CheatGG:
|
||||||
void GameBoyCheatListDialog::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)
|
|
||||||
gbCheatsSaveCheatList(sDialog.get_filename().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatAdd()
|
|
||||||
{
|
|
||||||
std::string sUiFile = VBA::Window::sGetUiFilePath("cheatedit.ui");
|
|
||||||
Glib::RefPtr<Gtk::Builder> poBuilder = Gtk::Builder::create_from_file(sUiFile);
|
|
||||||
|
|
||||||
CheatEditDialog * poDialog = 0;
|
|
||||||
poBuilder->get_widget_derived("CheatEditDialog", poDialog);
|
|
||||||
poDialog->set_transient_for(*this);
|
|
||||||
poDialog->vSetWindow(m_poWindow);
|
|
||||||
int response = poDialog->run();
|
|
||||||
poDialog->hide();
|
|
||||||
|
|
||||||
if (response == Gtk::RESPONSE_APPLY)
|
|
||||||
{
|
{
|
||||||
Glib::ustring sDesc = poDialog->vGetDesc();
|
std::vector<Glib::ustring> tokens;
|
||||||
|
|
||||||
int previous = gbCheatNumber;
|
vTokenize(buffer->get_text(), tokens);
|
||||||
|
|
||||||
switch (poDialog->vGetType())
|
for (std::vector<Glib::ustring>::iterator it = tokens.begin();
|
||||||
|
it != tokens.end();
|
||||||
|
it++)
|
||||||
{
|
{
|
||||||
// GameShark
|
Glib::ustring sToken = it->uppercase();
|
||||||
case CheatGS:
|
|
||||||
{
|
|
||||||
std::vector<Glib::ustring> tokens;
|
|
||||||
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
|
|
||||||
|
|
||||||
vTokenize(code_buffer->get_text(), tokens);
|
gbAddGgCheat(sToken.c_str(), sDesc.c_str());
|
||||||
|
|
||||||
for (std::vector<Glib::ustring>::iterator it = tokens.begin();
|
|
||||||
it != tokens.end();
|
|
||||||
it++)
|
|
||||||
{
|
|
||||||
Glib::ustring sToken = it->uppercase();
|
|
||||||
|
|
||||||
gbAddGsCheat(sToken.c_str(), sDesc.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// GameGenie
|
|
||||||
case CheatGG:
|
|
||||||
{
|
|
||||||
std::vector<Glib::ustring> tokens;
|
|
||||||
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
|
|
||||||
|
|
||||||
vTokenize(code_buffer->get_text(), tokens);
|
break;
|
||||||
|
|
||||||
for (std::vector<Glib::ustring>::iterator it = tokens.begin();
|
|
||||||
it != tokens.end();
|
|
||||||
it++)
|
|
||||||
{
|
|
||||||
|
|
||||||
Glib::ustring sToken = it->uppercase();
|
|
||||||
|
|
||||||
gbAddGgCheat(sToken.c_str(), sDesc.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:; // silence warnings
|
|
||||||
}
|
|
||||||
// end of switch
|
|
||||||
|
|
||||||
vUpdateList(previous);
|
|
||||||
|
|
||||||
} // end of condition
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatRemove()
|
|
||||||
{
|
|
||||||
Gtk::TreeModel::iterator iter = m_poCheatTreeView->get_selection()->get_selected();
|
|
||||||
|
|
||||||
if (iter)
|
|
||||||
{
|
|
||||||
Gtk::TreeModel::Row row = *iter;
|
|
||||||
|
|
||||||
gbCheatRemove(row[m_oRecordModel.iIndex]);
|
|
||||||
|
|
||||||
m_poCheatListStore->erase(iter);
|
|
||||||
}
|
}
|
||||||
|
default:; // silence warnings
|
||||||
|
}
|
||||||
|
// end of switch
|
||||||
|
|
||||||
|
vUpdateList(previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatRemoveAll()
|
bool GameBoyCheatListDialog::vCheatListOpen(const char *file)
|
||||||
|
{
|
||||||
|
return gbCheatsLoadCheatList(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyCheatListDialog::vCheatListSave(const char *file)
|
||||||
|
{
|
||||||
|
gbCheatsSaveCheatList(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyCheatListDialog::vRemoveCheat(int index)
|
||||||
|
{
|
||||||
|
gbCheatRemove(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameBoyCheatListDialog::vRemoveAllCheats()
|
||||||
{
|
{
|
||||||
gbCheatRemoveAll();
|
gbCheatRemoveAll();
|
||||||
|
|
||||||
m_poCheatListStore->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatMarkAll()
|
|
||||||
{
|
|
||||||
Gtk::TreeModel::Children cListEntries = m_poCheatListStore->children();
|
|
||||||
|
|
||||||
for (Gtk::TreeModel::iterator iter = cListEntries.begin(); iter; iter++)
|
|
||||||
{
|
|
||||||
Gtk::TreeModel::Row row = *iter;
|
|
||||||
|
|
||||||
row[m_oRecordModel.bEnabled] = bMark;
|
|
||||||
|
|
||||||
vToggleCheat(row[m_oRecordModel.iIndex], row[m_oRecordModel.bEnabled]);
|
|
||||||
}
|
|
||||||
|
|
||||||
bMark = !bMark;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vOnCheatToggled(Glib::ustring const& string_path)
|
|
||||||
{
|
|
||||||
Gtk::TreeIter iter = m_poCheatListStore->get_iter(string_path);
|
|
||||||
|
|
||||||
Gtk::TreeModel::Row row = *iter;
|
|
||||||
|
|
||||||
row[m_oRecordModel.bEnabled] = !row[m_oRecordModel.bEnabled];
|
|
||||||
|
|
||||||
vToggleCheat(row[m_oRecordModel.iIndex], row[m_oRecordModel.bEnabled]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vSetWindow(VBA::Window * _poWindow)
|
|
||||||
{
|
|
||||||
m_poWindow = _poWindow;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameBoyCheatListDialog::vToggleCheat(int index, bool enable) {
|
void GameBoyCheatListDialog::vToggleCheat(int index, bool enable) {
|
||||||
|
|
|
@ -19,64 +19,25 @@
|
||||||
#ifndef __VBA_GAMEBOYCHEATLIST_H__
|
#ifndef __VBA_GAMEBOYCHEATLIST_H__
|
||||||
#define __VBA_GAMEBOYCHEATLIST_H__
|
#define __VBA_GAMEBOYCHEATLIST_H__
|
||||||
|
|
||||||
#include <gtkmm/toolbutton.h>
|
|
||||||
|
|
||||||
#include "../System.h"
|
|
||||||
#include "../gb/gbCheats.h"
|
#include "../gb/gbCheats.h"
|
||||||
#include "cheatedit.h"
|
#include "cheatlist.h"
|
||||||
|
|
||||||
#include "window.h"
|
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
{
|
{
|
||||||
|
|
||||||
class ListGameboyCheatCodeColumns : public Gtk::TreeModel::ColumnRecord
|
class GameBoyCheatListDialog : public CheatListDialog
|
||||||
{
|
|
||||||
public:
|
|
||||||
ListGameboyCheatCodeColumns()
|
|
||||||
{
|
|
||||||
add(iIndex);
|
|
||||||
add(bEnabled);
|
|
||||||
add(uDesc);
|
|
||||||
}
|
|
||||||
|
|
||||||
~ListGameboyCheatCodeColumns() {}
|
|
||||||
|
|
||||||
Gtk::TreeModelColumn<int> iIndex;
|
|
||||||
Gtk::TreeModelColumn<bool> bEnabled;
|
|
||||||
Gtk::TreeModelColumn<Glib::ustring> uDesc;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GameBoyCheatListDialog : public Gtk::Dialog
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GameBoyCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
GameBoyCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
||||||
void vSetWindow(VBA::Window * _poWindow);
|
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void vOnCheatOpen();
|
void vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer);
|
||||||
void vOnCheatSave();
|
bool vCheatListOpen(const char *file);
|
||||||
void vOnCheatAdd();
|
void vCheatListSave(const char *file);
|
||||||
void vOnCheatRemove();
|
void vRemoveCheat(int index);
|
||||||
void vOnCheatRemoveAll();
|
void vRemoveAllCheats();
|
||||||
void vOnCheatMarkAll();
|
|
||||||
void vOnCheatToggled(Glib::ustring const& string_path);
|
|
||||||
void vToggleCheat(int index, bool enable);
|
void vToggleCheat(int index, bool enable);
|
||||||
void vUpdateList(int previous = 0);
|
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<Gtk::ListStore> m_poCheatListStore;
|
|
||||||
ListGameboyCheatCodeColumns m_oRecordModel;
|
|
||||||
|
|
||||||
bool bMark;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace VBA
|
} // namespace VBA
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "gameboyconfig.h"
|
#include "gameboyconfig.h"
|
||||||
#include "gameboyadvanceconfig.h"
|
#include "gameboyadvanceconfig.h"
|
||||||
#include "generalconfig.h"
|
#include "generalconfig.h"
|
||||||
#include "cheatlist.h"
|
#include "gameboyadvancecheatlist.h"
|
||||||
#include "gameboycheatlist.h"
|
#include "gameboycheatlist.h"
|
||||||
|
|
||||||
namespace VBA
|
namespace VBA
|
||||||
|
@ -451,7 +451,7 @@ void Window::vOnCheatList()
|
||||||
std::string sUiFile = sGetUiFilePath("cheatlist.ui");
|
std::string sUiFile = sGetUiFilePath("cheatlist.ui");
|
||||||
Glib::RefPtr<Gtk::Builder> poBuilder = Gtk::Builder::create_from_file(sUiFile);
|
Glib::RefPtr<Gtk::Builder> poBuilder = Gtk::Builder::create_from_file(sUiFile);
|
||||||
|
|
||||||
CheatListDialog * poDialog = 0;
|
GameBoyAdvanceCheatListDialog * poDialog = 0;
|
||||||
poBuilder->get_widget_derived("CheatListDialog", poDialog);
|
poBuilder->get_widget_derived("CheatListDialog", poDialog);
|
||||||
poDialog->set_transient_for(*this);
|
poDialog->set_transient_for(*this);
|
||||||
poDialog->vSetWindow(this);
|
poDialog->vSetWindow(this);
|
||||||
|
|
Loading…
Reference in New Issue