[Sugar-devel] [PATCH Maze v2] Buttons to generate a harder or an easier level
Manuel Kaufmann
humitos at gmail.com
Thu Mar 29 10:43:51 EDT 2012
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 at gmail.com>
---
activity.py | 36 +++++++++++++++++++++++++++++++++++-
game.py | 7 ++++++-
icons/create-easier.svg | 17 +++++++++++++++++
icons/create-harder.svg | 17 +++++++++++++++++
4 files changed, 75 insertions(+), 2 deletions(-)
create mode 100644 icons/create-easier.svg
create mode 100644 icons/create-harder.svg
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>
--
1.7.9.1
More information about the Sugar-devel
mailing list