GTK: Merged the GB and GBA cheat list dialogs. Patch by unmacaque.
git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@1007 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
222dd4c1b3
commit
e23e553abe
|
@ -246,6 +246,7 @@ SET(SRC_GTK
|
|||
src/gtk/gameboyadvanceconfig.cpp
|
||||
src/gtk/cheatlist.cpp
|
||||
src/gtk/cheatedit.cpp
|
||||
src/gtk/gameboyadvancecheatlist.cpp
|
||||
src/gtk/gameboycheatlist.cpp
|
||||
src/gtk/joypadconfig.cpp
|
||||
src/gtk/directoriesconfig.cpp
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "cheatlist.h"
|
||||
#include "tools.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_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatOpen));
|
||||
m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatSave));
|
||||
m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatListOpen));
|
||||
m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatListSave));
|
||||
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()
|
||||
void CheatListDialog::vOnCheatListOpen()
|
||||
{
|
||||
Gtk::FileChooserDialog oDialog(*this, _("Open cheat list"));
|
||||
oDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||
|
@ -79,11 +76,11 @@ void CheatListDialog::vOnCheatOpen()
|
|||
while (oDialog.run() == Gtk::RESPONSE_OK)
|
||||
{
|
||||
// delete existing cheats before loading the list
|
||||
cheatsDeleteAll(false);
|
||||
vRemoveAllCheats();
|
||||
|
||||
m_poCheatListStore->clear();
|
||||
|
||||
if (cheatsLoadCheatList(oDialog.get_filename().c_str()))
|
||||
if (vCheatListOpen(oDialog.get_filename().c_str()))
|
||||
{
|
||||
vUpdateList();
|
||||
break;
|
||||
|
@ -91,7 +88,7 @@ void CheatListDialog::vOnCheatOpen()
|
|||
}
|
||||
}
|
||||
|
||||
void CheatListDialog::vOnCheatSave()
|
||||
void CheatListDialog::vOnCheatListSave()
|
||||
{
|
||||
Gtk::FileChooserDialog sDialog(*this, _("Save cheat list"));
|
||||
sDialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||
|
@ -100,7 +97,7 @@ void CheatListDialog::vOnCheatSave()
|
|||
sDialog.set_current_folder(Glib::get_home_dir());
|
||||
|
||||
if (sDialog.run() == Gtk::RESPONSE_OK)
|
||||
cheatsSaveCheatList(sDialog.get_filename().c_str());
|
||||
vCheatListSave(sDialog.get_filename().c_str());
|
||||
}
|
||||
|
||||
void CheatListDialog::vOnCheatAdd()
|
||||
|
@ -116,95 +113,7 @@ void CheatListDialog::vOnCheatAdd()
|
|||
poDialog->hide();
|
||||
|
||||
if (response == Gtk::RESPONSE_APPLY)
|
||||
{
|
||||
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
|
||||
vAddCheat(poDialog->vGetDesc(), poDialog->vGetType(), poDialog->vGetCode());
|
||||
}
|
||||
|
||||
void CheatListDialog::vOnCheatRemove()
|
||||
|
@ -215,7 +124,7 @@ void CheatListDialog::vOnCheatRemove()
|
|||
{
|
||||
Gtk::TreeModel::Row row = *iter;
|
||||
|
||||
cheatsDelete(row[m_oRecordModel.iIndex], false);
|
||||
vRemoveCheat(row[m_oRecordModel.iIndex]);
|
||||
|
||||
m_poCheatListStore->erase(iter);
|
||||
}
|
||||
|
@ -223,7 +132,7 @@ void CheatListDialog::vOnCheatRemove()
|
|||
|
||||
void CheatListDialog::vOnCheatRemoveAll()
|
||||
{
|
||||
cheatsDeleteAll(false);
|
||||
vRemoveAllCheats();
|
||||
|
||||
m_poCheatListStore->clear();
|
||||
}
|
||||
|
@ -260,24 +169,4 @@ void CheatListDialog::vSetWindow(VBA::Window * _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
|
||||
|
|
|
@ -21,10 +21,6 @@
|
|||
|
||||
#include <gtkmm/toolbutton.h>
|
||||
|
||||
#include "../System.h"
|
||||
#include "../gba/Cheats.h"
|
||||
#include "../gba/GBA.h"
|
||||
#include "../gba/Globals.h"
|
||||
#include "cheatedit.h"
|
||||
|
||||
#include "window.h"
|
||||
|
@ -55,17 +51,26 @@ public:
|
|||
CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
||||
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:
|
||||
void vAddCheat(int index, Glib::ustring desc, bool enabled = true);
|
||||
void vOnCheatOpen();
|
||||
void vOnCheatSave();
|
||||
void vOnCheatListOpen();
|
||||
void vOnCheatListSave();
|
||||
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;
|
||||
|
||||
|
@ -76,8 +81,6 @@ private:
|
|||
Gtk::ToolButton * m_poCheatRemoveAllButton;
|
||||
Gtk::ToolButton * m_poCheatMarkAllButton;
|
||||
Gtk::TreeView * m_poCheatTreeView;
|
||||
Glib::RefPtr<Gtk::ListStore> m_poCheatListStore;
|
||||
ListCheatCodeColumns m_oRecordModel;
|
||||
|
||||
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 "tools.h"
|
||||
|
||||
#include <gtkmm/stock.h>
|
||||
|
||||
#include "intl.h"
|
||||
#include <vector>
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void GameBoyCheatListDialog::vOnCheatOpen()
|
||||
void GameBoyCheatListDialog::vAddCheat(Glib::ustring sDesc, ECheatType type, Glib::RefPtr<Gtk::TextBuffer> buffer)
|
||||
{
|
||||
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);
|
||||
int previous = gbCheatNumber;
|
||||
|
||||
oDialog.set_current_folder(Glib::get_home_dir());
|
||||
|
||||
while (oDialog.run() == Gtk::RESPONSE_OK)
|
||||
switch (type)
|
||||
{
|
||||
// delete existing cheats before loading the list
|
||||
gbCheatRemoveAll();
|
||||
// GameShark
|
||||
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();
|
||||
break;
|
||||
Glib::ustring sToken = it->uppercase();
|
||||
|
||||
gbAddGsCheat(sToken.c_str(), sDesc.c_str());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
// GameGenie
|
||||
case CheatGG:
|
||||
{
|
||||
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
|
||||
case CheatGS:
|
||||
{
|
||||
std::vector<Glib::ustring> tokens;
|
||||
Glib::RefPtr<Gtk::TextBuffer> code_buffer = poDialog->vGetCode();
|
||||
Glib::ustring sToken = it->uppercase();
|
||||
|
||||
vTokenize(code_buffer->get_text(), tokens);
|
||||
|
||||
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;
|
||||
gbAddGgCheat(sToken.c_str(), sDesc.c_str());
|
||||
}
|
||||
// GameGenie
|
||||
case CheatGG:
|
||||
{
|
||||
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();
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
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();
|
||||
|
||||
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) {
|
||||
|
|
|
@ -19,64 +19,25 @@
|
|||
#ifndef __VBA_GAMEBOYCHEATLIST_H__
|
||||
#define __VBA_GAMEBOYCHEATLIST_H__
|
||||
|
||||
#include <gtkmm/toolbutton.h>
|
||||
|
||||
#include "../System.h"
|
||||
#include "../gb/gbCheats.h"
|
||||
#include "cheatedit.h"
|
||||
|
||||
#include "window.h"
|
||||
#include "cheatlist.h"
|
||||
|
||||
namespace VBA
|
||||
{
|
||||
|
||||
class ListGameboyCheatCodeColumns : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
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
|
||||
class GameBoyCheatListDialog : public CheatListDialog
|
||||
{
|
||||
public:
|
||||
GameBoyCheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr<Gtk::Builder>& refBuilder);
|
||||
void vSetWindow(VBA::Window * _poWindow);
|
||||
|
||||
private:
|
||||
void vOnCheatOpen();
|
||||
void vOnCheatSave();
|
||||
void vOnCheatAdd();
|
||||
void vOnCheatRemove();
|
||||
void vOnCheatRemoveAll();
|
||||
void vOnCheatMarkAll();
|
||||
void vOnCheatToggled(Glib::ustring const& string_path);
|
||||
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);
|
||||
|
||||
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
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include "gameboyconfig.h"
|
||||
#include "gameboyadvanceconfig.h"
|
||||
#include "generalconfig.h"
|
||||
#include "cheatlist.h"
|
||||
#include "gameboyadvancecheatlist.h"
|
||||
#include "gameboycheatlist.h"
|
||||
|
||||
namespace VBA
|
||||
|
@ -451,7 +451,7 @@ void Window::vOnCheatList()
|
|||
std::string sUiFile = sGetUiFilePath("cheatlist.ui");
|
||||
Glib::RefPtr<Gtk::Builder> poBuilder = Gtk::Builder::create_from_file(sUiFile);
|
||||
|
||||
CheatListDialog * poDialog = 0;
|
||||
GameBoyAdvanceCheatListDialog * poDialog = 0;
|
||||
poBuilder->get_widget_derived("CheatListDialog", poDialog);
|
||||
poDialog->set_transient_for(*this);
|
||||
poDialog->vSetWindow(this);
|
||||
|
|
Loading…
Reference in New Issue