Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Kaufmann <humitos@gmail.com>2012-03-29 14:43:51 (GMT)
committer Rafael Ortiz <rafael@activitycentral.com>2012-03-29 16:54:21 (GMT)
commitd1f63be988a0fe2b6c376ad7dedae451ed7031e8 (patch)
tree2f7963dcb4b10cdb9ed2e88499655b49a1e7c17f
parent11596627ecd4705f19ef6f9dd0e56d0473ece96b (diff)
Buttons to generate a harder or an easier level
Added two buttons in the toolbar to generate a new level (harder or easier). These butons do the same work than '+' and '-' keys respectively. Icons by Manuel QuiƱones (manuq). This commit solves ticket: #3376 Signed-off-by: Manuel Kaufmann <humitos@gmail.com> Signed-off-by: Rafael Ortiz <rafael@activitycentral.com>
-rwxr-xr-xactivity.py36
-rw-r--r--game.py7
-rw-r--r--icons/create-easier.svg17
-rw-r--r--icons/create-harder.svg17
4 files changed, 75 insertions, 2 deletions
diff --git a/activity.py b/activity.py
index f21efdd..fec3947 100755
--- a/activity.py
+++ b/activity.py
@@ -1,9 +1,43 @@
+import gtk
import olpcgames
-from gettext import gettext as _
+import pygame
+from sugar.graphics.toolbutton import ToolButton
+from gettext import gettext as _
class MazeActivity(olpcgames.PyGameActivity):
game_name = 'game'
game_title = _('Maze')
game_size = None # let olpcgames pick a nice size for us
+
+ def build_toolbar(self):
+ """Build our Activity toolbar for the Sugar system."""
+ toolbar = super(MazeActivity, self).build_toolbar()
+
+ separator = gtk.SeparatorToolItem()
+ separator.set_expand(True)
+ separator.set_draw(False)
+ toolbar.insert(separator, 0)
+
+ harder_button = ToolButton('create-harder')
+ harder_button.set_tooltip(_('Harder level'))
+ harder_button.connect('clicked', self._harder_button_cb)
+ toolbar.insert(harder_button, 2)
+ harder_button.show()
+
+ easier_button = ToolButton('create-easier')
+ easier_button.set_tooltip(_('Easier level'))
+ easier_button.connect('clicked', self._easier_button_cb)
+ toolbar.insert(easier_button, 2)
+ easier_button.show()
+
+ return toolbar
+
+ def _easier_button_cb(self, button):
+ pygame.event.post(olpcgames.eventwrap.Event(
+ pygame.USEREVENT, action='easier_button'))
+
+ def _harder_button_cb(self, button):
+ pygame.event.post(olpcgames.eventwrap.Event(
+ pygame.USEREVENT, action='harder_button'))
diff --git a/game.py b/game.py
index 8482123..e9ec3b4 100644
--- a/game.py
+++ b/game.py
@@ -298,8 +298,13 @@ class MazeGame:
print "Message from unknown buddy?"
elif event.type == pygame.USEREVENT:
+ # process our buttons
+ if hasattr(event, 'action') and event.action == 'harder_button':
+ self.harder()
+ elif hasattr(event, 'action') and event.action == 'easier_button':
+ self.easier()
# process file save / restore events
- if event.code == olpcgames.FILE_READ_REQUEST:
+ elif event.code == olpcgames.FILE_READ_REQUEST:
log.debug('Loading the state of the game...')
state = json.loads(event.metadata['state'])
log.debug('Loaded data: %s', state)
diff --git a/icons/create-easier.svg b/icons/create-easier.svg
new file mode 100644
index 0000000..9d46c48
--- /dev/null
+++ b/icons/create-easier.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY fill_color "#FFFFFF">
+ <!ENTITY stroke_color "#010101">
+]>
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="50"
+ height="50"
+ viewBox="0 0 50 50"
+ id="svg2">
+ <path
+ d="m 5,5 0,5 5,0 0,10 0,10 -5,0 0,5 0,5 5,0 0,5 5,0 5,0 0,-5 10,0 0,5 5,0 5,0 0,-5 5,0 0,-5 0,-5 -5,0 -10,0 -10,0 0,-10 10,0 10,0 5,0 0,-5 0,-5 0,-5 -5,0 -5,0 0,5 -5,0 -10,0 0,-5 -5,0 -5,0 -5,0 z"
+ id="rect3770"
+ style="color:#000000;fill:&fill_color;;fill-opacity:1;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
+</svg>
diff --git a/icons/create-harder.svg b/icons/create-harder.svg
new file mode 100644
index 0000000..2eb54ea
--- /dev/null
+++ b/icons/create-harder.svg
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY fill_color "#FFFFFF">
+ <!ENTITY stroke_color "#010101">
+]>
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="50"
+ height="50"
+ viewBox="0 0 50 50"
+ id="svg2">
+ <path
+ d="m 25,5 0,5 0,5 -5,0 0,-5 -5,0 -5,0 -5,0 0,5 5,0 5,0 0,5 0,5 -5,0 0,-5 -5,0 0,5 0,5 5,0 5,0 0,5 -5,0 -5,0 0,5 0,5 5,0 0,-5 5,0 5,0 0,-5 0,-5 5,0 0,5 0,5 5,0 0,5 5,0 0,-5 0,-5 -5,0 0,-5 5,0 0,-5 -5,0 -5,0 -5,0 0,-5 5,0 5,0 5,0 5,0 0,5 0,5 5,0 0,-5 0,-5 0,-5 -5,0 -5,0 -5,0 0,-5 5,0 5,0 5,0 0,-5 -5,0 -5,0 -5,0 -5,0 z m 15,30 0,5 0,5 5,0 0,-5 0,-5 -5,0 z"
+ id="rect2992"
+ style="color:#000000;fill:&fill_color;;fill-opacity:1;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
+</svg>