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
};
enum
{
COLUMN_SIZE_TEXT,
NUM_SIZE_COLUMNS
};
GtkTreeModel * size_model;
enum {
TYPE_TOGGLE,
TYPE_COMBO,
TYPE_STRING
};
@ -50,7 +59,7 @@ static struct {
gint column;
} columnTable[]={
{ "Enabled", TYPE_TOGGLE, COLUMN_ENABLED},
{ "Size", TYPE_STRING, COLUMN_SIZE},
{ "Size", TYPE_COMBO, COLUMN_SIZE},
{ "Offset", TYPE_STRING, COLUMN_HI},
{ "Value", TYPE_STRING, COLUMN_LO},
{ "Description", TYPE_STRING, COLUMN_DESC}
@ -177,7 +186,39 @@ static void cheat_list_add_cheat(GtkWidget * widget, gpointer data)
#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));
@ -186,20 +227,40 @@ static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore *store)
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
const gchar *attrib;
if (columnTable[ii].type == TYPE_TOGGLE) {
switch (columnTable[ii].type) {
case TYPE_TOGGLE:
renderer = gtk_cell_renderer_toggle_new();
g_signal_connect(renderer, "toggled",
G_CALLBACK(enabled_toggled), model);
attrib = "active";
} else {
break;
case TYPE_STRING:
renderer = gtk_cell_renderer_text_new();
g_object_set (renderer, "editable", TRUE, NULL);
g_signal_connect (renderer, "edited", G_CALLBACK (cheat_list_modify_cheat), store);
g_object_set(renderer, "editable", TRUE, NULL);
g_signal_connect(renderer, "edited",
G_CALLBACK(cheat_list_modify_cheat), store);
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,
renderer, attrib, columnTable[ii].column, NULL);
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (columnTable[ii].column));
column =
gtk_tree_view_column_new_with_attributes(columnTable[ii].
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);
}
@ -254,6 +315,7 @@ static GtkWidget *cheat_list_create_ui()
g_signal_connect (button, "clicked", G_CALLBACK (cheat_list_remove_cheat), tree);
gtk_container_add(GTK_CONTAINER(hbbox),button);
size_model = create_numbers_model();
cheat_list_add_columns(GTK_TREE_VIEW(tree), store);
/* Setup the selection handler */

View File

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

View File

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