From dd2ec8f71e6be706c27f4e780f4feb3c5b3df550 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Mon, 26 Oct 2015 00:42:13 -0400 Subject: [PATCH] mempak editor gui (wip) --- tool/Makefile | 9 +- tool/gcn64cfg.glade | 233 +++++++++++++++++++++++++++++++++++- tool/gcn64ctl_gui.c | 25 +--- tool/gcn64ctl_gui.h | 27 +++++ tool/gcn64ctl_gui_mpkedit.c | 107 +++++++++++++++++ tool/gcn64ctl_gui_mpkedit.h | 10 ++ 6 files changed, 387 insertions(+), 24 deletions(-) create mode 100644 tool/gcn64ctl_gui.h create mode 100644 tool/gcn64ctl_gui_mpkedit.c create mode 100644 tool/gcn64ctl_gui_mpkedit.h diff --git a/tool/Makefile b/tool/Makefile index c54c6d1..7aef01c 100644 --- a/tool/Makefile +++ b/tool/Makefile @@ -24,15 +24,18 @@ MEMPAKLIB_OBJS=mempak.o mempak_fs.o .PHONY : clean install -all: gcn64ctl gcn64ctl_gui mempak_ls mempak_format mempak_extract_note mempak_insert_note mempak_rm mempak_convert +all: gcn64ctl mempak_ls mempak_format mempak_extract_note mempak_insert_note mempak_rm mempak_convert gcn64ctl_gui -gcn64ctl_gui: gcn64ctl_gui.o gcn64.o gcn64lib.o mempak_old.o hexdump.o ihex.o $(COMPAT_OBJS) +gcn64ctl_gui: gcn64ctl_gui.o gcn64ctl_gui_mpkedit.o gcn64.o gcn64lib.o hexdump.o ihex.o $(COMPAT_OBJS) $(MEMPAKLIB_OBJS) $(LD) $^ $(LDFLAGS) $(GTK_LDFLAGS) -o $@ gcn64ctl: main.o gcn64.o mempak_old.o gcn64lib.o hexdump.o gc2n64_adapter.o ihex.o delay.o $(COMPAT_OBJS) $(LD) $^ $(LDFLAGS) -o $@ -gcn64ctl_gui.o: gcn64ctl_gui.c +gcn64ctl_gui.o: gcn64ctl_gui.c gcn64ctl_gui.h + $(CC) $(CFLAGS) $(GTK_CFLAGS) -c $< + +gcn64ctl_gui_mpkedit.o: gcn64ctl_gui_mpkedit.c gcn64ctl_gui_mpkedit.h $(CC) $(CFLAGS) $(GTK_CFLAGS) -c $< mempak_convert: mempak_convert.o $(MEMPAKLIB_OBJS) diff --git a/tool/gcn64cfg.glade b/tool/gcn64cfg.glade index e1de1dc..6beea42 100644 --- a/tool/gcn64cfg.glade +++ b/tool/gcn64cfg.glade @@ -82,6 +82,21 @@ Author: Raphaël Assénat False gtk-missing-image + + True + False + gtk-missing-image + + + + + + + + + + + 1 255 @@ -139,7 +154,30 @@ Author: Raphaël Assénat False True True - + + + + + + + + + + True + False + _Tools + True + + + True + False + + + True + False + Open mempak editor + True + @@ -768,4 +806,197 @@ Author: Raphaël Assénat update_cancel_button + + False + True + mainWindow + + + + + True + False + True + vertical + + + True + False + + + True + False + _File + True + + + True + False + + + gtk-new + True + False + True + True + + + + + + gtk-open + True + False + True + True + + + + + + gtk-save + True + False + True + True + + + + + + gtk-save-as + True + False + True + True + + + + + + True + False + + + + + gtk-close + True + False + True + True + + + + + + + + + + True + False + _Edit + True + + + True + False + + + True + False + Insert note + True + + + + + + True + False + Export note + True + + + + + + Delete note + True + False + image2 + False + + + + + + + + + + False + True + 0 + + + + + True + True + n64_notes + False + both + True + + + + + + True + Note ID + + + + 0 + + + + + + + True + Game Data + + + + 1 + + + + + + + True + Pages + descending + + + + 2 + + + + + + + True + True + 1 + + + + + diff --git a/tool/gcn64ctl_gui.c b/tool/gcn64ctl_gui.c index f8c8dc3..5742e75 100644 --- a/tool/gcn64ctl_gui.c +++ b/tool/gcn64ctl_gui.c @@ -2,29 +2,10 @@ #include #include #include -#include -#include -#include "gcn64.h" -#include "gcn64lib.h" #include "../requests.h" #include "ihex.h" -#define GET_ELEMENT(TYPE, ELEMENT) (TYPE *)gtk_builder_get_object(app->builder, #ELEMENT) -#define GET_UI_ELEMENT(TYPE, ELEMENT) TYPE *ELEMENT = GET_ELEMENT(TYPE, ELEMENT) - -struct application { - GtkBuilder *builder; - GtkWindow *mainwindow; - - gcn64_hdl_t current_adapter_handle; - struct gcn64_info current_adapter_info; - GThread *updater_thread; - - const char *update_status; - const char *updateHexFile; - int update_percent; - int update_dialog_response; -}; +#include "gcn64ctl_gui.h" static void updateGuiFromAdapter(struct application *app); gboolean rebuild_device_list_store(gpointer data); @@ -600,6 +581,8 @@ main( int argc, return( 1 ); } + app.mpke = mpkedit_new(&app); + /* Get main window pointer from UI */ window = GTK_WINDOW( gtk_builder_get_object( app.builder, "mainWindow" ) ); app.mainwindow = window; @@ -616,6 +599,8 @@ main( int argc, /* Start main loop */ gtk_main(); + mpkedit_free(app.mpke); + return( 0 ); } diff --git a/tool/gcn64ctl_gui.h b/tool/gcn64ctl_gui.h new file mode 100644 index 0000000..ba0bdc0 --- /dev/null +++ b/tool/gcn64ctl_gui.h @@ -0,0 +1,27 @@ +#include +#include + +#include "gcn64.h" +#include "gcn64lib.h" +#include "gcn64ctl_gui_mpkedit.h" + +#define GET_ELEMENT(TYPE, ELEMENT) (TYPE *)gtk_builder_get_object(app->builder, #ELEMENT) +#define GET_UI_ELEMENT(TYPE, ELEMENT) TYPE *ELEMENT = GET_ELEMENT(TYPE, ELEMENT) + +struct application { + GtkBuilder *builder; + GtkWindow *mainwindow; + + gcn64_hdl_t current_adapter_handle; + struct gcn64_info current_adapter_info; + GThread *updater_thread; + + const char *update_status; + const char *updateHexFile; + int update_percent; + int update_dialog_response; + + struct mpkedit_data *mpke; +}; + + diff --git a/tool/gcn64ctl_gui_mpkedit.c b/tool/gcn64ctl_gui_mpkedit.c new file mode 100644 index 0000000..b734206 --- /dev/null +++ b/tool/gcn64ctl_gui_mpkedit.c @@ -0,0 +1,107 @@ +#include +#include +#include "gcn64ctl_gui.h" +#include "mempak.h" + +void mpke_syncModel(struct application *app); + +struct mpkedit_data { + struct mempak_structure *mpk; +}; + +struct mpkedit_data *mpkedit_new(struct application *app) +{ + struct mpkedit_data *mpke; + + mpke = calloc(sizeof(struct mpkedit_data), 1); + if (!mpke) { + perror("calloc"); + return NULL; + } + +// mpke->mpk = mempak_new(); + mpke->mpk = mempak_loadFromFile("/home/raph/0Dream/programming/multiuse_pcbX/gc_n64_usb-v3/tmp/perfect_dark_b.N64"); + + + return mpke; +} + +void mpkedit_free(struct mpkedit_data *mpke) +{ + if (mpke) { + free(mpke); + } +} + +void mpke_syncModel(struct application *app) +{ + GET_UI_ELEMENT(GtkListStore, n64_notes); + GET_UI_ELEMENT(GtkTreeView, n64_notes_treeview); + int i, res; + + gtk_list_store_clear(n64_notes); + if (!app->mpke->mpk) { + return; + } + + for (i=0; i<16; i++) { + GtkTreeIter iter; + entry_structure_t note_data; + + gtk_list_store_append(n64_notes, &iter); + + res = get_mempak_entry(app->mpke->mpk, i, ¬e_data); + if (res) { + gtk_list_store_set(n64_notes, &iter, 0, i, 1, "!!ERROR!!", 2, 0, -1); + } else { + if (note_data.valid) { + gtk_list_store_set(n64_notes, &iter, 0, i, 1, note_data.name, 2, note_data.blocks, -1); + } else { + gtk_list_store_set(n64_notes, &iter, 0, i, -1); + } + } + } + + gtk_tree_view_set_model(n64_notes_treeview, GTK_TREE_MODEL(n64_notes)); + +} + +G_MODULE_EXPORT void mpke_export_note(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void mpke_insert_note(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void mpke_new(GtkWidget *win, gpointer data) +{ + struct application *app = data; + + mempak_free(app->mpke->mpk); + app->mpke->mpk = mempak_new(); + + mpke_syncModel(app); +} + +G_MODULE_EXPORT void mpke_open(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void mpke_saveas(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void mpke_save(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void mpke_delete(GtkWidget *win, gpointer data) +{ +} + +G_MODULE_EXPORT void onMempakWindowShow(GtkWidget *win, gpointer data) +{ + struct application *app = data; + mpke_syncModel(app); +} diff --git a/tool/gcn64ctl_gui_mpkedit.h b/tool/gcn64ctl_gui_mpkedit.h new file mode 100644 index 0000000..e94795d --- /dev/null +++ b/tool/gcn64ctl_gui_mpkedit.h @@ -0,0 +1,10 @@ +#ifndef gcn64ctl_gui_mpkedit_h__ +#define gcn64ctl_gui_mpkedit_h__ + +struct mpkedit_data; +struct application; + +struct mpkedit_data *mpkedit_new(struct application *app); +void mpkedit_free(struct mpkedit_data *mpke); + +#endif