gcompris r3504 - in branches/gcomprixogoo/src: gcompris superbrain-activity
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3504 - in branches/gcomprixogoo/src: gcompris superbrain-activity
- Date: Sat, 23 Aug 2008 11:22:05 +0000 (UTC)
Author: bcoudoin
Date: Sat Aug 23 11:22:05 2008
New Revision: 3504
URL: http://svn.gnome.org/viewvc/gcompris?rev=3504&view=rev
Log:
Added support for removing a previously set item focus.
Numerous fixes in superbrain, graphical but also in the game
itself. It was possible to mismatch the visible item and its
internal representation so that a good response was refused.
Need to check if this requires a backport to trunk.
Modified:
branches/gcomprixogoo/src/gcompris/gameutil.c
branches/gcomprixogoo/src/gcompris/gameutil.h
branches/gcomprixogoo/src/superbrain-activity/superbrain.c
Modified: branches/gcomprixogoo/src/gcompris/gameutil.c
==============================================================================
--- branches/gcomprixogoo/src/gcompris/gameutil.c (original)
+++ branches/gcomprixogoo/src/gcompris/gameutil.c Sat Aug 23 11:22:05 2008
@@ -304,6 +304,35 @@
target_item);
}
+/**
+ * gc_item_focus_remove
+ *
+ * Remove a previously set of item focus
+ *
+ * @param[in] source_item is the same as the one passed to
+ * gc_item_focus_init()
+ * @param[in] target_itemis the same as the one passed to
+ * gc_item_focus_init()
+ */
+ void gc_item_focus_remove(GooCanvasItem *source_item,
+ GooCanvasItem *target_item)
+{
+ GooCanvasItem *highlight_item;
+
+ if(!target_item)
+ target_item = source_item;
+
+ g_signal_handlers_disconnect_by_func(source_item,
+ (GtkSignalFunc) gc_item_focus_event,
+ target_item);
+
+ highlight_item = g_object_get_data (G_OBJECT(target_item),
+ "highlight_item");
+
+ if(highlight_item)
+ goo_canvas_item_remove(highlight_item);
+}
+
/*
* Return a new copy of the given string in which it has
* changes '\''n' to '\n'.
Modified: branches/gcomprixogoo/src/gcompris/gameutil.h
==============================================================================
--- branches/gcomprixogoo/src/gcompris/gameutil.h (original)
+++ branches/gcomprixogoo/src/gcompris/gameutil.h Sat Aug 23 11:22:05 2008
@@ -46,6 +46,8 @@
RsvgHandle *gc_rsvg_load(const gchar *format, ...);
void gc_item_focus_init(GooCanvasItem *source_item,
GooCanvasItem *target_item);
+void gc_item_focus_remove(GooCanvasItem *source_item,
+ GooCanvasItem *target_item);
gchar *convertUTF8Toisolat1(gchar * text);
void gc_item_absolute_move(GooCanvasItem *item, int x, int y);
Modified: branches/gcomprixogoo/src/superbrain-activity/superbrain.c
==============================================================================
--- branches/gcomprixogoo/src/superbrain-activity/superbrain.c (original)
+++ branches/gcomprixogoo/src/superbrain-activity/superbrain.c Sat Aug 23 11:22:05 2008
@@ -32,7 +32,6 @@
guint selecteditem;
GooCanvasItem *good;
GooCanvasItem *misplaced;
- gboolean completed;
} Piece;
static GList * listPieces = NULL;
@@ -88,6 +87,7 @@
GdkEventButton *event,
Piece *piece);
static void mark_pieces(void);
+static void listPiecesClear();
static guint number_of_color = 0;
static guint number_of_piece = 0;
@@ -96,6 +96,7 @@
#define MAX_PIECES 10
static guint solution[MAX_PIECES];
+/* After this level, we provide less feedback to the user */
#define LEVEL_MAX_FOR_HELP 4
#define Y_STEP (PIECE_HEIGHT*2+PIECE_GAP)
@@ -161,7 +162,7 @@
gcomprisBoard->level=1;
gcomprisBoard->maxlevel=6;
gcomprisBoard->sublevel=1;
- gcomprisBoard->number_of_sublevel=1; /* Go to next level after this number of 'play' */
+ gcomprisBoard->number_of_sublevel=6; /* Go to next level after this number of 'play' */
gc_bar_set(GC_BAR_LEVEL);
gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
@@ -260,16 +261,14 @@
{
guint j;
- j = (guint)g_random_int_range(1, number_of_color);
+ j = (guint)g_random_int_range(0, number_of_color);
while(selected_color[j])
- j = (guint)g_random_int_range(1, number_of_color);
+ j = (guint)g_random_int_range(0, number_of_color);
solution[i] = j;
selected_color[j] = TRUE;
}
-
-
boardRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
NULL);
@@ -278,7 +277,7 @@
NULL);
/* The OK Button */
- gc_util_button_text(boardRootItem,
+ gc_util_button_text(boardLogoItem,
270, 360,
"button_large.png",
_("OK"),
@@ -305,6 +304,8 @@
/* Destroy all the items */
static void superbrain_destroy_all_items()
{
+ listPiecesClear();
+
if(boardRootItem!=NULL)
goo_canvas_item_remove(boardRootItem);
@@ -324,6 +325,8 @@
GooCanvasItem *item = NULL;
Piece *piece = NULL;
+ listPiecesClear();
+
if(current_y_position < SCROLL_LIMIT)
{
goo_canvas_item_translate(boardRootItem, 0.0, Y_STEP);
@@ -371,14 +374,12 @@
NULL);
/* Draw the pieces */
- listPieces = g_list_alloc();
for(i=0; i<number_of_piece; i++)
{
piece = g_new(Piece, 1);
- piece->listitem = g_list_alloc();
- piece->completed = FALSE;
+ piece->listitem = NULL;
listPieces = g_list_append(listPieces, piece);
piece->rootitem = goo_canvas_group_new (parent,
@@ -425,10 +426,11 @@
g_object_set (item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
piece->listitem = g_list_append(piece->listitem, item);
- g_signal_connect(item, "button-press-event", (GtkSignalFunc) item_event, piece);
+ g_signal_connect(item, "button-press-event",
+ (GtkSignalFunc) item_event, piece);
}
- piece->selecteditem = 1;
+ piece->selecteditem = 0;
item = g_list_nth_data(piece->listitem,
piece->selecteditem);
g_object_set (item, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
@@ -462,36 +464,39 @@
Piece *piece)
{
GooCanvasItem *newitem;
+ guint j;
if(board_paused)
return FALSE;
- if(!piece->completed)
+ switch(event->button)
{
- g_object_set (item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
-
- switch(event->button)
- {
- case 1:
- case 4:
- piece->selecteditem++;
- if(piece->selecteditem>=g_list_length(piece->listitem))
- piece->selecteditem = 1;
- break;
- case 2:
- case 3:
- case 5:
- piece->selecteditem--;
- if(piece->selecteditem<=0)
- piece->selecteditem = g_list_length(piece->listitem)-1;
- break;
- }
+ case 1:
+ case 4:
+ piece->selecteditem++;
+ if(piece->selecteditem >= g_list_length(piece->listitem))
+ piece->selecteditem = 0;
+ break;
+ case 2:
+ case 3:
+ case 5:
+ if(piece->selecteditem == 0)
+ piece->selecteditem = g_list_length(piece->listitem)-1;
+ else
+ piece->selecteditem--;
+ break;
+ }
- newitem = g_list_nth_data(piece->listitem,
- piece->selecteditem);
- g_object_set (newitem, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
+ for(j=0; j<g_list_length(piece->listitem); j++)
+ {
+ g_object_set (g_list_nth_data(piece->listitem, j),
+ "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL);
}
+ newitem = g_list_nth_data(piece->listitem,
+ piece->selecteditem);
+ g_object_set (newitem, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
+
return FALSE;
}
@@ -512,40 +517,39 @@
gamewon = TRUE;
/* Mark good placed */
- for(i=1; i<g_list_length(listPieces); i++)
+ for(i=0; i<g_list_length(listPieces); i++)
{
piece = g_list_nth_data(listPieces, i);
- if(piece->selecteditem == solution_tmp[i-1])
+ if(piece->selecteditem == solution_tmp[i])
{
if(gcomprisBoard->level<LEVEL_MAX_FOR_HELP)
g_object_set (piece->good, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
nbgood++;
- solution_tmp[i-1] = G_MAXINT;
+ solution_tmp[i] = G_MAXINT;
}
else
{
gamewon = FALSE;
}
- piece->completed = TRUE;
}
/* Mark misplaced */
- for(i=1; i<=number_of_piece; i++)
+ for(i=0; i<g_list_length(listPieces); i++)
{
gboolean done;
piece = g_list_nth_data(listPieces, i);
/* Search if this color is elsewhere */
- j = 1;
+ j = 0;
done = FALSE;
do {
- if(piece->selecteditem != solution[i-1] &&
- piece->selecteditem == solution_tmp[j-1])
+ if(piece->selecteditem != solution[i] &&
+ piece->selecteditem == solution_tmp[j])
{
nbmisplaced++;
- solution_tmp[j-1] = G_MAXINT;
+ solution_tmp[j] = G_MAXINT;
if(gcomprisBoard->level<LEVEL_MAX_FOR_HELP)
g_object_set (piece->misplaced, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL);
done = TRUE;
@@ -583,8 +587,27 @@
current_y_position -= Y_STEP;
- g_list_free(listPieces);
-
superbrain_create_item(boardRootItem);
}
+
+void listPiecesClear()
+{
+ guint i, j;
+ for(i=0; i<g_list_length(listPieces); i++)
+ {
+ Piece *piece = g_list_nth_data(listPieces, i);
+
+ for(j=0; j<g_list_length(piece->listitem); j++)
+ {
+ GooCanvasItem *item = g_list_nth_data(piece->listitem, j);
+ g_signal_handlers_disconnect_by_func(item,
+ (GtkSignalFunc) item_event, piece);
+ gc_item_focus_remove(item, NULL);
+ }
+ g_free(piece);
+ }
+ g_list_free(listPieces);
+ listPieces = NULL;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]