gtk-port: unhide cheat menu items

limit cheat size option to 1-4
This commit is contained in:
matusz 2009-06-17 18:04:10 +00:00
parent 7ca7824ebf
commit 8d4a505f72
3 changed files with 78 additions and 19 deletions

View File

@ -39,8 +39,17 @@ enum {
NUM_COL NUM_COL
}; };
enum
{
COLUMN_SIZE_TEXT,
NUM_SIZE_COLUMNS
};
GtkTreeModel * size_model;
enum { enum {
TYPE_TOGGLE, TYPE_TOGGLE,
TYPE_COMBO,
TYPE_STRING TYPE_STRING
}; };
@ -50,7 +59,7 @@ static struct {
gint column; gint column;
} columnTable[]={ } columnTable[]={
{ "Enabled", TYPE_TOGGLE, COLUMN_ENABLED}, { "Enabled", TYPE_TOGGLE, COLUMN_ENABLED},
{ "Size", TYPE_STRING, COLUMN_SIZE}, { "Size", TYPE_COMBO, COLUMN_SIZE},
{ "Offset", TYPE_STRING, COLUMN_HI}, { "Offset", TYPE_STRING, COLUMN_HI},
{ "Value", TYPE_STRING, COLUMN_LO}, { "Value", TYPE_STRING, COLUMN_LO},
{ "Description", TYPE_STRING, COLUMN_DESC} { "Description", TYPE_STRING, COLUMN_DESC}
@ -177,7 +186,39 @@ static void cheat_list_add_cheat(GtkWidget * widget, gpointer data)
#undef NEW_DESC #undef NEW_DESC
} }
static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore *store) static GtkTreeModel *
create_numbers_model (void)
{
#define N_NUMBERS 4
gint i = 0;
GtkListStore *model;
GtkTreeIter iter;
/* create list store */
model = gtk_list_store_new (NUM_SIZE_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
/* add numbers */
for (i = 1; i < N_NUMBERS+1; i++)
{
char str[2];
str[0] = '0' + i;
str[1] = '\0';
gtk_list_store_append (model, &iter);
gtk_list_store_set (model, &iter,
COLUMN_SIZE_TEXT, str,
-1);
}
return GTK_TREE_MODEL (model);
#undef N_NUMBERS
}
static void cheat_list_add_columns(GtkTreeView * tree,
GtkListStore * store)
{ {
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree));
@ -186,20 +227,40 @@ static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore *store)
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
const gchar *attrib; const gchar *attrib;
if (columnTable[ii].type == TYPE_TOGGLE) { switch (columnTable[ii].type) {
case TYPE_TOGGLE:
renderer = gtk_cell_renderer_toggle_new(); renderer = gtk_cell_renderer_toggle_new();
g_signal_connect(renderer, "toggled", g_signal_connect(renderer, "toggled",
G_CALLBACK(enabled_toggled), model); G_CALLBACK(enabled_toggled), model);
attrib = "active"; attrib = "active";
} else { break;
case TYPE_STRING:
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
g_object_set (renderer, "editable", TRUE, NULL); g_object_set(renderer, "editable", TRUE, NULL);
g_signal_connect (renderer, "edited", G_CALLBACK (cheat_list_modify_cheat), store); g_signal_connect(renderer, "edited",
G_CALLBACK(cheat_list_modify_cheat), store);
attrib = "text"; attrib = "text";
break;
case TYPE_COMBO:
renderer = gtk_cell_renderer_combo_new();
g_object_set(renderer,
"model", size_model,
"text-column", COLUMN_SIZE_TEXT,
"editable", TRUE,
"has-entry", FALSE,
NULL);
g_signal_connect(renderer, "edited",
G_CALLBACK(cheat_list_modify_cheat), store);
attrib = "text";
break;
} }
column = gtk_tree_view_column_new_with_attributes(columnTable[ii].caption, column =
renderer, attrib, columnTable[ii].column, NULL); gtk_tree_view_column_new_with_attributes(columnTable[ii].
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (columnTable[ii].column)); caption, renderer,
attrib, columnTable[ii].column,
NULL);
g_object_set_data(G_OBJECT(renderer), "column",
GINT_TO_POINTER(columnTable[ii].column));
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
} }
@ -254,6 +315,7 @@ static GtkWidget *cheat_list_create_ui()
g_signal_connect (button, "clicked", G_CALLBACK (cheat_list_remove_cheat), tree); g_signal_connect (button, "clicked", G_CALLBACK (cheat_list_remove_cheat), tree);
gtk_container_add(GTK_CONTAINER(hbbox),button); gtk_container_add(GTK_CONTAINER(hbbox),button);
size_model = create_numbers_model();
cheat_list_add_columns(GTK_TREE_VIEW(tree), store); cheat_list_add_columns(GTK_TREE_VIEW(tree), store);
/* Setup the selection handler */ /* Setup the selection handler */

View File

@ -192,12 +192,10 @@ static const char *ui_description =
" <menuitem action='layersubbg3'/>" " <menuitem action='layersubbg3'/>"
" <menuitem action='layersubobj'/>" " <menuitem action='layersubobj'/>"
" </menu>" " </menu>"
#ifdef DESMUME_GTK_CHEAT_BROKEN
" <menu action='CheatMenu'>" " <menu action='CheatMenu'>"
" <menuitem action='cheatsearch'/>" " <menuitem action='cheatsearch'/>"
" <menuitem action='cheatlist'/>" " <menuitem action='cheatlist'/>"
" </menu>" " </menu>"
#endif
" </menu>" " </menu>"
" <menu action='ConfigMenu'>" " <menu action='ConfigMenu'>"
" <menu action='ConfigSaveMenu'>" " <menu action='ConfigSaveMenu'>"
@ -264,11 +262,9 @@ static const GtkActionEntry action_entries[] = {
{ "reset", "gtk-refresh", "Re_set", NULL, NULL, Reset }, { "reset", "gtk-refresh", "Re_set", NULL, NULL, Reset },
{ "FrameskipMenu", NULL, "_Frameskip" }, { "FrameskipMenu", NULL, "_Frameskip" },
{ "LayersMenu", NULL, "_Layers" }, { "LayersMenu", NULL, "_Layers" },
#ifdef DESMUME_GTK_CHEAT_BROKEN
{ "CheatMenu", NULL, "_Cheat" }, { "CheatMenu", NULL, "_Cheat" },
{ "cheatsearch", NULL, "_Search", NULL, NULL, CheatSearch }, { "cheatsearch", NULL, "_Search", NULL, NULL, CheatSearch },
{ "cheatlist", NULL, "_List", NULL, NULL, CheatList }, { "cheatlist", NULL, "_List", NULL, NULL, CheatList },
#endif
{ "ConfigMenu", NULL, "_Config" }, { "ConfigMenu", NULL, "_Config" },
{ "ConfigSaveMenu", NULL, "_Saves" }, { "ConfigSaveMenu", NULL, "_Saves" },
@ -582,10 +578,8 @@ static int Open(const char *filename, const char *cflash_disk_image)
{ {
int res; int res;
res = NDS_LoadROM( filename, cflash_disk_image ); res = NDS_LoadROM( filename, cflash_disk_image );
#ifdef DESMUME_GTK_CHEAT_BROKEN
if(res > 0) if(res > 0)
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), TRUE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), TRUE);
#endif
return res; return res;
} }
@ -1840,10 +1834,8 @@ common_gtk_main( struct configured_features *my_config)
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE);
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE);
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE);
#ifdef DESMUME_GTK_CHEAT_BROKEN
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), FALSE);
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatsearch"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatsearch"), FALSE);
#endif
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);

View File

@ -1,2 +1,7 @@
extern void Pause(); #ifndef __DESMUME_GTK_MAIN_H__
extern void Launch(); #define __DESMUME_GTK_MAIN_H__
void Pause();
void Launch();
#endif