~ml-launchpad/ubuntu/natty/gcompris/fix-for-777349

« back to all changes in this revision

Viewing changes to src/drawnumber-activity/clickanddraw.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  gcompris - clickanddraw
 
2
#
 
3
#
 
4
# Copyright (C) 2007, 2008 Olivier Ponchaut
 
5
#
 
6
#   This program is free software; you can redistribute it and/or modify
 
7
#   it under the terms of the GNU General Public License as published by
 
8
#   the Free Software Foundation; either version 3 of the License, or
 
9
#   (at your option) any later version.
 
10
#
 
11
#   This program is distributed in the hope that it will be useful,
 
12
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#   GNU General Public License for more details.
 
15
#
 
16
#   You should have received a copy of the GNU General Public License
 
17
#   along with this program; if not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
 
 
20
import goocanvas
 
21
import gcompris
 
22
import gcompris.utils
 
23
import gcompris.bonus
 
24
import gcompris.score
 
25
import gtk
 
26
import gtk.gdk
 
27
import gobject
 
28
import cairo
 
29
from drawnumber import Gcompris_drawnumber
 
30
 
 
31
class Gcompris_clickanddraw(Gcompris_drawnumber):
 
32
 
 
33
  def set_sublevel(self, sublevel=1):
 
34
    """Start of the game at sublevel number sublevel of level n"""
 
35
 
 
36
    if self.MAX!=0 :
 
37
      self.end()
 
38
 
 
39
    #Creation of canvas group use by the activity
 
40
    self.ROOT = \
 
41
    goocanvas.Group(
 
42
      parent = self.gcomprisBoard.canvas.get_root_item(),
 
43
      )
 
44
 
 
45
    #Setting of the first background image of the level
 
46
    gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
 
47
                            self.data[sublevel][0][1])
 
48
 
 
49
    #Initialisation of sub-elements in list
 
50
    self.POINT=[0]
 
51
    self.actu=0
 
52
 
 
53
    #Display actual sublevel and number of sublevel of this level
 
54
    self.gcomprisBoard.sublevel=sublevel
 
55
    self.gcomprisBoard.number_of_sublevel=len(self.data)
 
56
    #Display of score
 
57
    gcompris.score.start(gcompris.score.STYLE_NOTE, 10, 485,self.gcomprisBoard.number_of_sublevel)
 
58
    gcompris.score.set(self.gcomprisBoard.sublevel)
 
59
 
 
60
    #Set point number 0 from which the draw start. This point is equal to first one.
 
61
    self.MAX=self.data[sublevel][0][0]
 
62
    self.POINT[0]=self.point(0,self.data[sublevel][self.MAX][0],self.data[sublevel][self.MAX][1],30)
 
63
    self.POINT[0].props.visibility = goocanvas.ITEM_INVISIBLE
 
64
 
 
65
    #Data loading from global data and display of points and numbers
 
66
    i=self.MAX
 
67
    prev_point = None
 
68
    while(i>0):
 
69
      if self.gcomprisBoard.level==1 :
 
70
        self.POINT.append(self.point(idpt=(self.MAX-i+1),
 
71
                                     x=self.data[sublevel][i][0],
 
72
                                     y=self.data[sublevel][i][1],d=45))
 
73
      elif self.gcomprisBoard.level==2 :
 
74
        self.POINT.append(self.point(idpt=(self.MAX-i+1),
 
75
                                     x=self.data[sublevel][i][0],
 
76
                                     y=self.data[sublevel][i][1],d=30))
 
77
      else :
 
78
        self.POINT.append(self.point(idpt=(self.MAX-i+1),
 
79
                                     x=self.data[sublevel][i][0],
 
80
                                     y=self.data[sublevel][i][1],d=20))
 
81
 
 
82
      self.POINT[(self.MAX-i+1)].connect('button_press_event',
 
83
                                         self.action,(self.MAX-i+1))
 
84
 
 
85
      #Setting of display level to prevent covering a point with another
 
86
      #point which cause an impossibility to select it.
 
87
      if prev_point:
 
88
        self.POINT[(self.MAX-i+1)].lower(prev_point)
 
89
      prev_point = self.POINT[(self.MAX-i+1)]
 
90
      i = i-1
 
91
 
 
92
    #Setting color of the first point to blue instead of green
 
93
    self.POINT[1].set_properties(fill_color_rgba = 0x003DF5D0)
 
94
 
 
95
  def action(self, objet, target, truc, idpt):
 
96
    """Action to do at each step during normal execution of the game"""
 
97
    if truc.type == gtk.gdk.BUTTON_PRESS :
 
98
      if idpt == (self.actu+1): #Action to execute if the selected point is the following of previous one
 
99
        xd,yd,xa,ya = self.POINT[(idpt-1)].x, self.POINT[(idpt-1)].y, self.POINT[idpt].x, self.POINT[idpt].y
 
100
        goocanvas.Polyline(
 
101
          parent = self.ROOT,
 
102
          points = goocanvas.Points([(xd,yd), (xa,ya)]),
 
103
          fill_color = 'black',
 
104
          line_cap = cairo.LINE_CAP_ROUND,
 
105
          line_width = 2)
 
106
 
 
107
        if idpt == 2: # Always raise the first point
 
108
          self.POINT[self.MAX].raise_(None)
 
109
 
 
110
        objet.props.visibility = goocanvas.ITEM_INVISIBLE
 
111
        if idpt==self.MAX : #Action to exectute if all points have been selected in good way
 
112
          gcompris.set_background(self.ROOT,
 
113
                                  self.data[self.gcomprisBoard.sublevel][0][2])
 
114
          self.gamewon = 1
 
115
          gcompris.bar_hide(True)
 
116
          self.timeout = gobject.timeout_add(1500, self.lauch_bonus) # The level is complete -> Bonus display
 
117
 
 
118
        else : # Action to execute if the selected point isn''t the last one of this level
 
119
          # Set color in blue to next point. Too easy ???
 
120
          self.POINT[(idpt+1)].set_properties(fill_color_rgba=0x003DF5D0)
 
121
          self.actu = self.actu+1 #self.actu update to set it at actual value of selected point