mirror of
https://github.com/0ldsk00l/nestopia.git
synced 2024-06-22 06:02:26 -04:00
Enable cheat list saving and fix up menu items when games are loaded and paused
This commit is contained in:
parent
8631f9dc6f
commit
27d1ded22a
|
@ -26,6 +26,9 @@
|
|||
|
||||
#include "cheats.h"
|
||||
|
||||
static Xml savexml;
|
||||
static Xml::Node saveroot;
|
||||
|
||||
std::vector<NstCheat> chtlist;
|
||||
|
||||
extern Emulator emulator;
|
||||
|
@ -93,6 +96,55 @@ void nst_cheats_init(const char *cheatpath) {
|
|||
}
|
||||
}
|
||||
|
||||
void nst_cheats_save(const char *cheatpath) {
|
||||
// Save the cheat list
|
||||
std::ofstream cheatfile(cheatpath, std::ifstream::out|std::ifstream::binary);
|
||||
|
||||
if (cheatfile.is_open()) {
|
||||
saveroot = (savexml.GetRoot());
|
||||
|
||||
saveroot = savexml.Create( L"cheats" );
|
||||
saveroot.AddAttribute( L"version", L"1.0" );
|
||||
|
||||
char buf[9];
|
||||
wchar_t wbuf[9];
|
||||
|
||||
for (int i = 0; i < chtlist.size(); i++) {
|
||||
Xml::Node node(saveroot.AddChild(L"cheat"));
|
||||
node.AddAttribute(L"enabled", chtlist[i].enabled ? L"1" : L"0");
|
||||
|
||||
if (chtlist[i].gg.size() > 0) {
|
||||
node.AddChild(L"genie", chtlist[i].gg.c_str());
|
||||
}
|
||||
|
||||
if (chtlist[i].par.size() > 0) {
|
||||
node.AddChild(L"rocky", chtlist[i].par.c_str());
|
||||
}
|
||||
|
||||
if (chtlist[i].address != 0) {
|
||||
snprintf(buf, sizeof(buf), "0x%04X", chtlist[i].address);
|
||||
mbstowcs(wbuf, buf, 9);
|
||||
node.AddChild(L"address", wbuf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "0x%02x", chtlist[i].value);
|
||||
mbstowcs(wbuf, buf, 9);
|
||||
node.AddChild(L"value", wbuf);
|
||||
|
||||
snprintf(buf, sizeof(buf), "0x%02x", chtlist[i].compare);
|
||||
mbstowcs(wbuf, buf, 9);
|
||||
node.AddChild(L"compare", wbuf);
|
||||
}
|
||||
|
||||
if (chtlist[i].description.size() > 0) {
|
||||
node.AddChild(L"description", chtlist[i].description.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
savexml.Write(saveroot, cheatfile);
|
||||
cheatfile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void nst_cheats_code_gg_add(const std::wstring data) {
|
||||
// Add a Game Genie code
|
||||
Cheats cheats(emulator);
|
||||
|
@ -120,7 +172,7 @@ void nst_cheats_code_par_add(const std::wstring data) {
|
|||
void nst_cheats_refresh() {
|
||||
Cheats cheats(emulator);
|
||||
cheats.ClearCodes();
|
||||
|
||||
|
||||
for (int i = 0; i < chtlist.size(); i++) {
|
||||
if (chtlist[i].enabled) {
|
||||
if (chtlist[i].gg.size()) {
|
||||
|
|
|
@ -25,6 +25,7 @@ typedef struct NstCheat {
|
|||
} NstCheat;
|
||||
|
||||
void nst_cheats_init(const char *cheatpath);
|
||||
void nst_cheats_save(const char *cheatpath);
|
||||
void nst_cheats_refresh();
|
||||
void nst_cheats_code_gg_add(const std::wstring data);
|
||||
void nst_cheats_code_par_add(const std::wstring data);
|
||||
|
|
|
@ -55,6 +55,8 @@ static NstGlArea *glarea;
|
|||
static NstChtWindow *chtwin;
|
||||
static NstConfWindow *confwin;
|
||||
|
||||
extern int loaded;
|
||||
|
||||
Fl_Color NstGreen = 0x255f6500;
|
||||
Fl_Color NstPurple = 0x5f578700;
|
||||
Fl_Color NstRed = 0xb51e2c00;
|
||||
|
@ -67,6 +69,7 @@ extern nstpaths_t nstpaths;
|
|||
extern bool (*nst_archive_select)(const char*, char*, size_t);
|
||||
|
||||
static void fltkui_cheats(Fl_Widget* w, void* userdata) {
|
||||
if (!loaded) { return; }
|
||||
chtwin->refresh();
|
||||
chtwin->show();
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ static void fltkui_rom_open(Fl_Widget* w, void* userdata) {
|
|||
case 1: break; // Cancel
|
||||
default:
|
||||
if (fc.filename()) {
|
||||
int loaded = nst_load(fc.filename());
|
||||
loaded = nst_load(fc.filename());
|
||||
nstwin->label(nstpaths.gamename);
|
||||
if (loaded) { nst_play(); }
|
||||
}
|
||||
|
@ -98,7 +101,7 @@ static void fltkui_rom_open(Fl_Widget* w, void* userdata) {
|
|||
|
||||
static void fltkui_movie_load(Fl_Widget* w, void* userdata) {
|
||||
// Create native chooser
|
||||
if (!nst_playing()) { return; }
|
||||
if (!loaded) { return; }
|
||||
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Select a Movie");
|
||||
|
@ -120,7 +123,7 @@ static void fltkui_movie_load(Fl_Widget* w, void* userdata) {
|
|||
|
||||
static void fltkui_movie_save(Fl_Widget* w, void* userdata) {
|
||||
// Create native chooser
|
||||
if (!nst_playing()) { return; }
|
||||
if (!loaded) { return; }
|
||||
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Save Movie");
|
||||
|
@ -141,7 +144,7 @@ static void fltkui_movie_stop(Fl_Widget* w, void* userdata) {
|
|||
|
||||
static void fltkui_state_load(Fl_Widget* w, void* userdata) {
|
||||
// Create native chooser
|
||||
if (!nst_playing()) { return; }
|
||||
if (!loaded) { return; }
|
||||
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Load State");
|
||||
|
@ -163,7 +166,7 @@ static void fltkui_state_load(Fl_Widget* w, void* userdata) {
|
|||
|
||||
static void fltkui_state_save(Fl_Widget* w, void* userdata) {
|
||||
// Create native chooser
|
||||
if (!nst_playing()) { return; }
|
||||
if (!loaded) { return; }
|
||||
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Save State");
|
||||
|
@ -180,7 +183,7 @@ static void fltkui_state_save(Fl_Widget* w, void* userdata) {
|
|||
|
||||
static void fltkui_screenshot(Fl_Widget* w, void* userdata) {
|
||||
// Create native chooser
|
||||
if (!nst_playing()) { return; }
|
||||
if (!loaded) { return; }
|
||||
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Save Screenshot");
|
||||
|
|
|
@ -152,6 +152,22 @@ void cb_load(Fl_Widget* w, long) {
|
|||
}
|
||||
}
|
||||
|
||||
void cb_save(Fl_Widget* w, long) {
|
||||
Fl_Native_File_Chooser fc;
|
||||
fc.title("Save Cheat List");
|
||||
fc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
||||
fc.directory((const char*)nstpaths.cheatpath);
|
||||
std::string preset = std::string(nstpaths.cheatpath) + "/" + std::string(nstpaths.gamename) + ".xml";
|
||||
fc.preset_file(preset.c_str());
|
||||
fc.filter("Nestopia Cheats\t*.xml");
|
||||
fc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
|
||||
|
||||
// Show file chooser
|
||||
if (fc.show()) { return; }
|
||||
|
||||
nst_cheats_save(fc.filename());
|
||||
}
|
||||
|
||||
// Handle drawing all cells in table
|
||||
void ChtTable::draw_cell(TableContext context, int r, int c, int X, int Y, int W, int H) {
|
||||
static char s[128];
|
||||
|
@ -246,9 +262,12 @@ void NstChtWindow::populate() {
|
|||
Fl_Button *btnclr = new Fl_Button(200, 300, 80, 25, "Clear");
|
||||
btnclr->callback(cb_clr, 0);
|
||||
|
||||
Fl_Button *btnload = new Fl_Button(20, 360, 80, 25, "Load...");
|
||||
Fl_Button *btnload = new Fl_Button(20, 350, 80, 25, "Load...");
|
||||
btnload->callback(cb_load, 0);
|
||||
|
||||
Fl_Button *btnsave = new Fl_Button(20, 380, 80, 25, "Save...");
|
||||
btnsave->callback(cb_save, 0);
|
||||
|
||||
Fl_Button *btnok = new Fl_Button(560, 460, 80, 25, "&OK");
|
||||
btnok->callback(cb_ok, 0);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ static std::fstream *movierecfile;
|
|||
void *custompalette = NULL;
|
||||
static size_t custpalsize;
|
||||
|
||||
static int loaded = 0;
|
||||
int loaded = 0;
|
||||
|
||||
bool (*nst_archive_select)(const char*, char*, size_t);
|
||||
|
||||
|
|
Loading…
Reference in a new issue