Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-07-01 16:50:58 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-07-01 16:50:58 (GMT)
commita8855d90d63bb0f96219f3135f8088fb4dab3462 (patch)
treed3280d65e322a3e9bb68f535ee4f94734898a1c2
parent8f2150fb89684b58bccf67623a85390bb144363e (diff)
add rotation support
-rw-r--r--.gitignore4
-rw-r--r--Dimensions.py (renamed from VisualMatchActivity.py)26
-rw-r--r--NEWS5
-rw-r--r--activity/activity-dimensions.svg (renamed from activity/activity-visualmatch.svg)0
-rw-r--r--activity/activity.info11
-rw-r--r--game.py45
-rw-r--r--grid.py44
-rw-r--r--icons/number-tools.svg28
8 files changed, 107 insertions, 56 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..39417cc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.pyc
+*~
+*.pyo
+
diff --git a/VisualMatchActivity.py b/Dimensions.py
index 9c249a1..99f8f0e 100644
--- a/VisualMatchActivity.py
+++ b/Dimensions.py
@@ -1,4 +1,4 @@
-#Copyright (c) 2009-12 Walter Bender
+#Copyright (c) 2009-13 Walter Bender
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ from sugar3.presence.tubeconn import TubeConnection
from gettext import gettext as _
import os.path
import logging
-_logger = logging.getLogger('visualmatch-activity')
+_logger = logging.getLogger('dimensions-activity')
import json
from json import load as jload
from json import dump as jdump
@@ -63,9 +63,9 @@ NUMBER_O_BUTTONS = {}
NUMBER_C_BUTTONS = {}
LEVEL_BUTTONS = {}
-SERVICE = 'org.sugarlabs.VisualMatchActivity'
+SERVICE = 'org.sugarlabs.Dimensions'
IFACE = SERVICE
-PATH = '/org/augarlabs/VisualMatchActivity'
+PATH = '/org/augarlabs/Dimensions'
PROMPT_DICT = {'pattern': _('New pattern game'),
'number': _('New number game'),
@@ -73,11 +73,11 @@ PROMPT_DICT = {'pattern': _('New pattern game'),
'custom': _('Import custom cards')}
-class VisualMatchActivity(activity.Activity):
+class Dimensions(activity.Activity):
''' Dimension matching game '''
def __init__(self, handle):
''' Initialize the Sugar activity '''
- super(VisualMatchActivity, self).__init__(handle)
+ super(Dimensions, self).__init__(handle)
self.ready_to_play = False
self._prompt = ''
self._read_journal_data()
@@ -266,9 +266,9 @@ class VisualMatchActivity(activity.Activity):
self.numbers_toolbar_button = ToolbarButton(
page=numbers_toolbar,
icon_name='number-tools')
- numbers_toolbar.show()
- toolbox.toolbar.insert(self.numbers_toolbar_button, -1)
- self.numbers_toolbar_button.show()
+ # numbers_toolbar.show()
+ # toolbox.toolbar.insert(self.numbers_toolbar_button, -1)
+ # self.numbers_toolbar_button.show()
self.tools_toolbar_button = ToolbarButton(
page=tools_toolbar,
@@ -303,21 +303,25 @@ class VisualMatchActivity(activity.Activity):
self.button_pattern = button_factory(
'new-pattern-game', games_toolbar, self._select_game_cb,
cb_arg='pattern', tooltip=PROMPT_DICT['pattern'])
+ '''
self.button_number = button_factory(
'new-number-game', games_toolbar, self._select_game_cb,
cb_arg='number', tooltip=PROMPT_DICT['number'])
self.button_word = button_factory(
'new-word-game', games_toolbar, self._select_game_cb,
cb_arg='word', tooltip=PROMPT_DICT['word'])
+ '''
self.button_custom = button_factory(
'no-custom-game', games_toolbar, self._select_game_cb,
cb_arg='custom', tooltip=PROMPT_DICT['custom'])
self._set_extras(games_toolbar)
+ '''
self.words_tool_button = button_factory(
'word-tools', tools_toolbar, self._edit_words_cb,
tooltip=_('Edit word lists.'))
+ '''
self.import_button = button_factory(
'image-tools', tools_toolbar, self.image_import_cb,
@@ -624,7 +628,7 @@ class VisualMatchActivity(activity.Activity):
help_box = self._new_help_box('activity-toolbar',
self.activity_toolbar_button)
- add_section(help_box, _('Visual Match'), icon='activity-visualmatch')
+ add_section(help_box, _('Dimensions'), icon='activity-dimensions')
add_paragraph(help_box, _('Export scores to clipboard'), icon='score-copy')
help_box = self._new_help_box('game-toolbar',
@@ -656,7 +660,7 @@ class VisualMatchActivity(activity.Activity):
add_paragraph(help_box, _('dots in a line'), icon='lines')
help_box = self._new_help_box('main-toolbar')
- add_section(help_box, _('Visual Match'), icon='activity-visualmatch')
+ add_section(help_box, _('Dimensions'), icon='activity-dimensions')
add_paragraph(help_box, _('Game'), icon='new-game')
add_paragraph(help_box, _('Numbers'), icon='number-tools')
add_paragraph(help_box, _('Tools'), icon='view-source')
diff --git a/NEWS b/NEWS
index ed7bd04..db2cbeb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+51
+
+* Add support for screen rotation
+* Make separate games for shapes, numbers, and words
+
49
* New translations
diff --git a/activity/activity-visualmatch.svg b/activity/activity-dimensions.svg
index fa3f393..fa3f393 100644
--- a/activity/activity-visualmatch.svg
+++ b/activity/activity-dimensions.svg
diff --git a/activity/activity.info b/activity/activity.info
index dc4334b..ace83db 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,10 +1,9 @@
[Activity]
-#TRANS: Please translate Visual Match as Dimensions
-name = Visual Match
-activity_version = 49
+name = Dimensions
+activity_version = 51
license = GPLv3
-bundle_id = org.sugarlabs.VisualMatchActivity
-exec = sugar-activity VisualMatchActivity.VisualMatchActivity
-icon = activity-visualmatch
+bundle_id = org.sugarlabs.Dimensions
+exec = sugar-activity Dimensions.Dimensions
+icon = activity-dimensions
show_launcher = yes
summary = a pattern-matching game
diff --git a/game.py b/game.py
index 0760ca9..19a08d9 100644
--- a/game.py
+++ b/game.py
@@ -30,7 +30,7 @@ from sugar3 import mime
from sugar3.activity import activity
import logging
-_logger = logging.getLogger('visualmatch-activity')
+_logger = logging.getLogger('dimensions-activity')
from sugar3.graphics import style
GRID_CELL_SIZE = style.GRID_CELL_SIZE
@@ -126,8 +126,14 @@ class Game():
self._canvas.connect('draw', self.__draw_cb)
self._width = Gdk.Screen.width()
- self._height = Gdk.Screen.height() - GRID_CELL_SIZE
- self._scale = 0.8 * self._height / (CARD_HEIGHT * 5.5)
+ self._height = Gdk.Screen.height() - GRID_CELL_SIZE * 2
+ if self._width < self._height:
+ self.portrait = True
+ self._scale = 0.8 * self._width / (CARD_HEIGHT * 5.5)
+ else:
+ self.portrait = False
+ self._scale = 0.8 * self._height / (CARD_HEIGHT * 5.5)
+
self._card_width = CARD_WIDTH * self._scale
self._card_height = CARD_HEIGHT * self._scale
self.custom_paths = [None, None, None, None, None, None, None, None,
@@ -211,6 +217,26 @@ class Game():
generate_frowny_number(self._scale), sprites=self._sprites)
self._frowny[-1].spr.move(self.grid.match_to_xy(3))
+ Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
+
+ def _configure_cb(self, event):
+ self._width = Gdk.Screen.width()
+ self._height = Gdk.Screen.height() - GRID_CELL_SIZE * 2
+
+ if self._width < self._height:
+ self.portrait = True
+ else:
+ self.portrait = False
+
+ self.grid.rotate(self._width, self._height)
+
+ for i in range(CARDS_IN_A_MATCH):
+ self._match_area[i].spr.move(self.grid.match_to_xy(i))
+
+ for i, c in enumerate(self.clicked):
+ if c.spr is not None:
+ c.spr.move(self.grid.match_to_xy(i))
+
def new_game(self, saved_state=None, deck_index=0):
''' Start a new game '''
# If we were editing the word list, time to stop
@@ -575,6 +601,7 @@ class Game():
else:
_logger.error('WARNING: Cannot find last click')
self.last_click = None
+
self.process_selection(self._press)
self._press = None
return
@@ -602,7 +629,9 @@ class Game():
new slot. '''
move = 'drag'
if self.grid.spr_to_grid(spr) is None:
- if x > self.grid.left: # Returning a card to the grid
+ # Returning a card to the grid
+ if (self.portrait and y < self.grid.bottom) or \
+ (not self.portrait and x > self.grid.left):
i = self.grid.xy_to_grid((x, y))
if self.grid.grid[i] is not None:
i = self.grid.find_an_empty_slot()
@@ -613,7 +642,8 @@ class Game():
self.clicked[i].reset()
self._hide_frowny()
self._failure = None
- else: # Move a click to a different match slot
+ # Move a click to a different match slot
+ else:
i = self._where_in_clicked(spr)
j = self.grid.xy_to_match((x, y))
if i == j:
@@ -631,7 +661,9 @@ class Game():
i = self._where_in_clicked(spr)
if i is None:
move = 'abort'
- elif x < self.grid.left: # Moving a card to the match area
+ # Moving a card to the match area
+ elif (self.portrait and y > self.grid.bottom) or \
+ (not self.portrait and x < self.grid.left):
self.grid.grid[self.grid.spr_to_grid(spr)] = None
spr.move(self._match_area[i].spr.get_xy())
else: # Shuffle positions in match area
@@ -652,6 +684,7 @@ class Game():
self.grid.grid[k] = None
move = 'abort'
self.clicked[i].reset()
+
self._consistency_check()
return move
diff --git a/grid.py b/grid.py
index 03e2078..5bfd6a2 100644
--- a/grid.py
+++ b/grid.py
@@ -17,7 +17,7 @@ import random
from constants import ROW, COL, MATCH_POSITION, DEAL
import logging
-_logger = logging.getLogger('visualmatch-activity')
+_logger = logging.getLogger('dimensions-activity')
def _distance_squared(pos1, pos2):
@@ -35,10 +35,16 @@ class Grid:
for i in range(ROW * COL):
self.grid.append(None)
# Card spacing
- self.left = int((width - (card_width * 2)) / 2)
+ if width < height:
+ self.left = MATCH_POSITION
+ self.portrait = True
+ else:
+ self.left = int((width - (card_width * 2)) / 2)
+ self.portrait = False
self.xinc = int(card_width * 1.2)
self.top = 10
self.yinc = int(card_height * 1.33)
+ self.bottom = int(self.top + 5 * self.yinc)
self.dx = [0, 0, 0, 0, 0, 0]
self.dy = [0, 0, 0, 0, 0, 0]
self.sx = [0, 0, 0, 0, 0, 0]
@@ -48,6 +54,17 @@ class Grid:
self.stop_animation = False
self.animation_lock = [False, False, False, False, False, False]
+ def rotate(self, width, height):
+ if width < height:
+ self.left = MATCH_POSITION
+ self.portrait = True
+ else:
+ self.left = int((width - (card_width * 2)) / 2)
+ self.portrait = False
+ for i in range(ROW * COL):
+ self.place_a_card(self.grid[i], self.grid_to_xy(i)[0],
+ self.grid_to_xy(i)[1])
+
def deal(self, deck):
''' Deal an initial set of cards. '''
for i in range(ROW * COL):
@@ -110,8 +127,12 @@ class Grid:
''' Move card to the match area. '''
self.stop_animation = False
spr.set_layer(2000)
- self.ex[i] = MATCH_POSITION
- self.ey[i] = self.top + i * self.yinc
+ if not self.portrait:
+ self.ex[i] = MATCH_POSITION
+ self.ey[i] = self.top + i * self.yinc
+ else:
+ self.ex[i] = self.left + i * self.xinc
+ self.ey[i] = self.bottom
self.sx[i] = spr.get_xy()[0]
self.sy[i] = spr.get_xy()[1]
self.dx[i] = int((self.ex[i] - self.sx[i]) / 10)
@@ -120,7 +141,7 @@ class Grid:
100, self._move_to_position, spr, i)
def return_to_grid(self, spr, i, j):
- ''' Move card to the match area. '''
+ ''' Move card from the match area. '''
self.stop_animation = False
self.animation_lock[j] = True
spr.set_layer(2000)
@@ -182,7 +203,10 @@ class Grid:
def xy_to_match(self, pos):
''' Convert from sprite x,y to match index. '''
- return int((pos[1] - self.top) / self.yinc)
+ if self.portrait:
+ return int((pos[0] - self.left) / self.xinc)
+ else:
+ return int((pos[1] - self.top) / self.yinc)
def xy_in_match(self, pos):
''' Is a position at one of the match points? '''
@@ -194,7 +218,13 @@ class Grid:
def match_to_xy(self, i):
''' Convert from match index to x, y position. '''
- return ((MATCH_POSITION, self.top + i * self.yinc))
+ if self.portrait:
+ if i > 2:
+ return ((self.left + self.xinc, self.bottom + self.yinc))
+ else:
+ return ((self.left + i * self.xinc, self.bottom))
+ else:
+ return ((MATCH_POSITION, self.top + i * self.yinc))
def xy_in_grid(self, pos):
''' Is a position at one of the grid points? '''
diff --git a/icons/number-tools.svg b/icons/number-tools.svg
index 7e6d62d..756dbc7 100644
--- a/icons/number-tools.svg
+++ b/icons/number-tools.svg
@@ -15,24 +15,7 @@
xml:space="preserve"><metadata
id="metadata19"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
- id="defs25">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- </defs>
-
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata>
<text
x="27.571924"
y="28.453243"
@@ -43,13 +26,6 @@
y="28.453243"
id="tspan2839"
style="font-size:36px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#ffffff;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">5</tspan></text>
-
-
-
-
-
-
-
<g
transform="translate(-0.2743801,0.51351)"
id="g3036"><path
@@ -66,4 +42,4 @@
transform="matrix(-0.469241,0.469241,-0.469241,-0.469241,66.2906,1019.03)" /><path
d="m 39.363241,1033.1291 -0.05636,9.9115 -8.750608,0.067"
id="path4776"
- style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></g></svg> \ No newline at end of file
+ style="fill:none;stroke:#ffffff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" /></g></g></g></svg>