[gcompris] mining: add button to start tutorial



commit 7c5f347899efbf09368a6483669a78cdfb4990e6
Author: Peter Albrecht <pa-dev gmx de>
Date:   Mon Sep 24 20:50:33 2012 +0200

    mining: add button to start tutorial
    
    Now the tutorial does not start automatically, but has to be started
    explicitly by pressing the "tux-teacher" icon. (The "tux-teacher.png"
    was copied from the memory activity.)
    
    The tutorial is still only startable at level 1.
    
    And since we start the tutorial now by a mouse-click event, we can
    provide an initial mouse position for the "move to" tutorial. :)

 src/mining-activity/mining.py                      |   64 ++++++++++++++++----
 src/mining-activity/mining_tutorial.py             |    7 +--
 src/mining-activity/resources/mining/Makefile.am   |    1 +
 .../resources/mining/tux-teacher.png               |  Bin 0 -> 12235 bytes
 4 files changed, 55 insertions(+), 17 deletions(-)
---
diff --git a/src/mining-activity/mining.py b/src/mining-activity/mining.py
index 0e9f77b..11596b3 100644
--- a/src/mining-activity/mining.py
+++ b/src/mining-activity/mining.py
@@ -62,6 +62,11 @@ class Gcompris_mining:
 
   # handle to the tutorial object
   tutorial = None
+
+  # can the tutorial be started in this level?
+  is_tutorial_startable = False
+
+  # has the tutorial been started for this nugget?
   is_tutorial_enabled = False
 
   # the distance, the mouse cursor has to approach the nugget, triggering the next tutorial step
@@ -137,6 +142,18 @@ class Gcompris_mining:
     # prepare the tutorial
     self.tutorial = mining_tutorial.MiningTutorial(self.rootitem)
 
+    # prepare the teacher icon to start the tutorial with
+    self.teacher_img = goocanvas.Image(
+      parent = self.rootitem,
+      pixbuf = gcompris.utils.load_pixmap("mining/tux-teacher.png"),
+      x = 850,
+      y = 850,
+      visibility = goocanvas.ITEM_INVISIBLE
+      )
+    self.teacher_img.scale(0.5, 0.5)
+    self.teacher_img.connect("button_press_event", self.start_tutorial)
+    gcompris.utils.item_focus_init(self.teacher_img, None)
+
     # initialize the level, to start with
     self.set_level(1)
 
@@ -147,6 +164,7 @@ class Gcompris_mining:
     print("mining set level: %i" % level)
 
     self.end_level()
+    self.is_tutorial_enabled = False
 
     # store new level
     self.gcomprisBoard.level = level
@@ -155,9 +173,7 @@ class Gcompris_mining:
     # load level specific values
     if level == 1:
       self.nuggets_to_collect = 3
-
-      # Enable the tutorial for level 1
-      self.is_tutorial_enabled = True
+      self.is_tutorial_startable = True
 
       # add the tutorials blocking area, to avoid the nugget being placed behind
       # the tutorial mouse or touchpad
@@ -165,11 +181,11 @@ class Gcompris_mining:
 
     elif level == 2:
       self.nuggets_to_collect = 6
-      self.is_tutorial_enabled = False
+      self.is_tutorial_startable = False
 
     elif level == 3:
       self.nuggets_to_collect = 9
-      self.is_tutorial_enabled = False
+      self.is_tutorial_startable = False
 
     else:
       print("Warning: No level specific values defined for level %i! Keeping current settings." % level)
@@ -204,15 +220,41 @@ class Gcompris_mining:
     self.sparkling.animation_start()
     self.need_new_nugget = False
 
-    if self.is_tutorial_enabled:
-      self.tutorial.start()
-      nuggetArea = Area(self.nugget.get_bounds())
-      self.tutorial.set_tutorial_state('move to', nuggetArea.center_x, nuggetArea.center_y)
-
-
     # The following sound was copied form "Tuxpaint" (GPL)
     gcompris.sound.play_ogg("mining/realrainbow.ogg")
 
+    # tutorial stuff
+    self.is_tutorial_enabled = False
+    if self.is_tutorial_startable:
+      self.show_teacher_icon()
+    else:
+      self.hide_teacher_icon()
+
+
+  def start_tutorial(self, item, target_item, event):
+    """
+    Start the tutorial (teacher icon has been clicked)
+      item - The element connected with this callback function
+      target_item - The element under the cursor
+      event  - gtk.gdk.Event
+    """
+
+    self.hide_teacher_icon()
+    self.is_tutorial_enabled = True
+    self.tutorial.start()
+    nuggetArea = Area(self.nugget.get_bounds())
+    self.tutorial.set_tutorial_state('move to', event.x_root, event.y_root, nuggetArea.center_x, nuggetArea.center_y)
+
+
+  def show_teacher_icon(self):
+    """ Show the teacher icon (the icon to start the tutorial with """
+    self.teacher_img.props.visibility = goocanvas.ITEM_VISIBLE
+
+
+  def hide_teacher_icon(self):
+    """ Hide the teacher icon (the icon to start the tutorial with """
+    self.teacher_img.props.visibility = goocanvas.ITEM_INVISIBLE
+
 
   def on_mouse_move(self, item, target_item, event):
     """
diff --git a/src/mining-activity/mining_tutorial.py b/src/mining-activity/mining_tutorial.py
index 8ef6bf7..98e887d 100644
--- a/src/mining-activity/mining_tutorial.py
+++ b/src/mining-activity/mining_tutorial.py
@@ -86,12 +86,7 @@ class MiningTutorial:
     # advance to next state, if current state matches
     if state == 'move to':
       if self.current_state == 'start':
-        # we should send the real mouse position, but best, I could get is
-        # the mouse position in screen pixels:
-        #   x, y = self.rootitem.get_canvas().get_pointer()
-        # And the documented function goocanvas.Canvas.convert_from_pixel() does not exist. :(
-        # So we take the middle of the screen as starting point for the animation.
-        self.cursor.start(gcompris.BOARD_WIDTH / 2, gcompris.BOARD_HEIGHT / 2, *special_state_arguments)
+        self.cursor.start(*special_state_arguments)
 
         self.current_state = state
 
diff --git a/src/mining-activity/resources/mining/Makefile.am b/src/mining-activity/resources/mining/Makefile.am
index 0e26e0d..d75e26b 100644
--- a/src/mining-activity/resources/mining/Makefile.am
+++ b/src/mining-activity/resources/mining/Makefile.am
@@ -2,6 +2,7 @@ imgdir = $(pkgdatadir)/@PACKAGE_DATA_DIR@/mining
 img_DATA = \
 	rockwall.svgz \
 	tutorial.svgz \
+	tux-teacher.png \
 	pickaxe.ogg \
 	realrainbow.ogg
 
diff --git a/src/mining-activity/resources/mining/tux-teacher.png b/src/mining-activity/resources/mining/tux-teacher.png
new file mode 100644
index 0000000..bd09a23
Binary files /dev/null and b/src/mining-activity/resources/mining/tux-teacher.png differ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]