diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-06-11 17:09:08 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-06-16 15:26:38 (GMT) |
commit | 2afdfc54f29ed69f1bb5231c87a5df3c2e14241a (patch) | |
tree | cae16813b313a4f41cd2419656ff62e6cb9401d1 | |
parent | 28da248a2bbc1e0f7b816e02ba0fb7db317e3c59 (diff) |
Add a option to show/hide the trail
I drawing a smaller point with the user color.
-rwxr-xr-x | activity.py | 14 | ||||
-rw-r--r-- | game.py | 20 | ||||
-rw-r--r-- | icons/show-trail.svg | 69 |
3 files changed, 97 insertions, 6 deletions
diff --git a/activity.py b/activity.py index 1a358f4..fb32c7e 100755 --- a/activity.py +++ b/activity.py @@ -11,6 +11,7 @@ from sugar3.activity.widgets import ActivityToolbarButton from sugar3.activity.widgets import StopButton from sugar3.graphics.toolbarbox import ToolbarBox from sugar3.graphics.toolbutton import ToolButton +from sugar3.graphics.toggletoolbutton import ToggleToolButton from sugar3.graphics.alert import ErrorAlert from sugar3 import profile from gettext import gettext as _ @@ -76,6 +77,16 @@ class MazeActivity(activity.Activity): toolbar_box.toolbar.insert(harder_button, -1) separator = Gtk.SeparatorToolItem() + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + show_trail_button = ToggleToolButton('show-trail') + show_trail_button.set_tooltip(_('Show trail')) + show_trail_button.set_active(True) + show_trail_button.connect('toggled', self._toggled_show_trail_cb) + toolbar_box.toolbar.insert(show_trail_button, -1) + + separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) @@ -97,6 +108,9 @@ class MazeActivity(activity.Activity): def _harder_button_cb(self, button): self.game.harder() + def _toggled_show_trail_cb(self, button): + self.game.set_show_trail(button.get_active()) + def _shared_cb(self, activity): logging.debug('Maze was shared') self._add_alert(_('Sharing'), _('This maze is shared.')) @@ -92,6 +92,7 @@ class MazeGame(Gtk.DrawingArea): self.reset() self.frame = 0 + self._show_trail = True # self.font = pygame.font.Font(None, 30) @@ -222,12 +223,15 @@ class MazeGame(Gtk.DrawingArea): ctx.rectangle(*rect.get_bounds()) ctx.fill() - if tile == self.maze.SEEN: - ctx.set_source_rgb(*self.TRAIL_COLOR) - radius = self.tileSize / 2 - self.outline - center = self.tileSize / 2 - ctx.arc(rect.x + center, rect.y + center, radius, 0, 2 * pi) - ctx.fill() + if self._show_trail: + if tile == self.maze.SEEN: + ctx.set_source_rgb(*self.TRAIL_COLOR) + radius = self.tileSize / 3 - self.outline + center = self.tileSize / 2 + ctx.set_source_rgba(*self.localplayers[0].bg.get_rgba()) + ctx.arc(rect.x + center, rect.y + center, radius, 0, + 2 * pi) + ctx.fill() ctx.restore() # re-draw the dirty rectangle @@ -290,6 +294,10 @@ class MazeGame(Gtk.DrawingArea): # self.dirtyRect = None # self.dirtyPoints = [] + def set_show_trail(self, show_trail): + self._show_trail = show_trail + self.queue_draw() + def markRectDirty(self, rect): """Mark an area that needs to be redrawn. This lets us play really big mazes without needing to re-draw the whole diff --git a/icons/show-trail.svg b/icons/show-trail.svg new file mode 100644 index 0000000..76a62ed --- /dev/null +++ b/icons/show-trail.svg @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + version="1.1" + width="50" + height="50" + viewBox="0 0 50 50" + id="svg2"> + <defs + id="defs6" /> + <g + id="g3123" style="fill:#FFFFFF;fill-rule:evenodd;stroke:#000000;stroke-width:0px"> + <path + transform="matrix(1.0730156,0,0,0.98918627,-0.35857722,0.40515738)" + d="m 14.409449,24.724409 a 4.6456695,5.0393701 0 1 1 -9.2913388,0 4.6456695,5.0393701 0 1 1 9.2913388,0 z" + sodipodi:ry="5.0393701" + sodipodi:rx="4.6456695" + sodipodi:cy="24.724409" + sodipodi:cx="9.7637796" + id="path3035" + sodipodi:type="arc" /> + <path + transform="matrix(1.0730156,0,0,0.98918627,28.34221,0.40515738)" + d="m 14.409449,24.724409 a 4.6456695,5.0393701 0 1 1 -9.2913388,0 4.6456695,5.0393701 0 1 1 9.2913388,0 z" + sodipodi:ry="5.0393701" + sodipodi:rx="4.6456695" + sodipodi:cy="24.724409" + sodipodi:cx="9.7637796" + id="path3035-6" + sodipodi:type="arc" /> + <path + inkscape:transform-center-y="1.4173228" + inkscape:transform-center-x="21.023622" + transform="matrix(1.0730156,0,0,0.98918627,13.991816,0.40515738)" + d="m 14.409449,24.724409 a 4.6456695,5.0393701 0 1 1 -9.2913388,0 4.6456695,5.0393701 0 1 1 9.2913388,0 z" + sodipodi:ry="5.0393701" + sodipodi:rx="4.6456695" + sodipodi:cy="24.724409" + sodipodi:cx="9.7637796" + id="path3035-7" + sodipodi:type="arc" /> + <path + transform="matrix(0,1.0730156,-0.98918627,0,63.354685,28.755595)" + d="m 14.409449,24.724409 a 4.6456695,5.0393701 0 1 1 -9.2913388,0 4.6456695,5.0393701 0 1 1 9.2913388,0 z" + sodipodi:ry="5.0393701" + sodipodi:rx="4.6456695" + sodipodi:cy="24.724409" + sodipodi:cx="9.7637796" + id="path3035-6-1" + sodipodi:type="arc" /> + <path + transform="matrix(0,1.0730156,-0.98918627,0,34.535787,0.05480828)" + d="m 14.409449,24.724409 a 4.6456695,5.0393701 0 1 1 -9.2913388,0 4.6456695,5.0393701 0 1 1 9.2913388,0 z" + sodipodi:ry="5.0393701" + sodipodi:rx="4.6456695" + sodipodi:cy="24.724409" + sodipodi:cx="9.7637796" + id="path3035-2" + sodipodi:type="arc" /> + </g> +</svg> |