Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-12-26 18:25:00 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-12-26 18:25:00 (GMT)
commited0fd0e1a6f0304be79e0db51807482a3122c253 (patch)
treebd1789e5d37483f73173a820f68f1107e5878b3f
parent0976fe99bb530974161fd78d6ed0577e6dd1214b (diff)
i18n of levels help
-rw-r--r--activity.py13
-rw-r--r--data/levels/help1.pngbin219753 -> 65557 bytes
-rw-r--r--data/levels/level1.py (renamed from data/levels/level1.level)12
-rw-r--r--levels.py49
4 files changed, 49 insertions, 25 deletions
diff --git a/activity.py b/activity.py
index 8cf5aba..5df90a2 100644
--- a/activity.py
+++ b/activity.py
@@ -19,22 +19,17 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os
-import sys
import gtk
-import pygame
from sugar.activity import activity
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.activity.widgets import ActivityToolbarButton
-from sugar.graphics.toolbutton import ToolButton
from sugar.activity.widgets import StopButton
import sugargame.canvas
from gettext import gettext as _
import gambiarra
-from gambiarra import Game
class GambiarraActivity(activity.Activity):
@@ -42,7 +37,7 @@ class GambiarraActivity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
self.max_participants = 1
- self.game = Game()
+ self.game = gambiarra.Game()
self.build_toolbar()
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self._pygamecanvas)
@@ -68,9 +63,3 @@ class GambiarraActivity(activity.Activity):
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
- def read_file(self, file_path):
- pass
-
- def write_file(self, file_path):
- pass
-
diff --git a/data/levels/help1.png b/data/levels/help1.png
index 7156fbe..2e7ebb7 100644
--- a/data/levels/help1.png
+++ b/data/levels/help1.png
Binary files differ
diff --git a/data/levels/level1.level b/data/levels/level1.py
index 441059a..618008c 100644
--- a/data/levels/level1.level
+++ b/data/levels/level1.py
@@ -1,4 +1,8 @@
-{
+# -*- coding: utf-8 -*-
+
+from gettext import gettext as _
+
+LEVEL = {
"id" : "first level",
"placed" : [
{
@@ -29,5 +33,9 @@
"goals" : [
["bola", "alvo"]
],
- "help" : "help1.png"
+ "helpImage" : "help1.png",
+ "helpTitle" : _("Nível 1: Acerte o alvo!"),
+ "helpMes" : [_("O objetivo é acertar a bola de futebol\nna marca de mira vermelha e branca!"),
+ _("Dica: é só clicar no triângulo branco\nabaixo à direita")]
}
+
diff --git a/levels.py b/levels.py
index c35d677..0525f4c 100644
--- a/levels.py
+++ b/levels.py
@@ -22,11 +22,14 @@
import gtk
import pygame
import os
-#import simplejson as json
+import imp
import json
from objects import *
from command import Play, Help, Quit
+HELP_TITLE_COLOR = (38, 34, 63)
+HELP_MES_COLOR = (177, 165, 255)
+
class SimulationView(object):
""" This widget holds the objects being simulated. """
running = None
@@ -124,12 +127,31 @@ class Level(object):
on the screen"""
objects = None
- def __init__(self, obj_in_place, obj_to_add, goals, help_img):
+ def __init__(self, obj_in_place, obj_to_add, goals, help_img, help_title, help_mes):
self.simulator = SimulationView(obj_in_place)
self.objbar = ObjectBar(obj_to_add)
self.cmdbar = CommandBar()
self.goals = goals
self.help_img = help_img
+ self.help_title = help_title
+ self.help_mes = help_mes
+ self._create_help()
+
+ def _create_help(self):
+ f = pygame.font.Font(None, 60)
+ title = unicode(self.help_title, "UTF-8")
+ msg = f.render(title, 1, HELP_TITLE_COLOR)
+ self.help_img.blit(msg, (40, 40))
+ f = pygame.font.Font(None, 50)
+ y = 100
+ for msg in self.help_mes:
+ lines = msg.split('\n')
+ for l in lines:
+ m_utf = unicode(l, "UTF-8")
+ m = f.render(m_utf, 1, HELP_MES_COLOR)
+ self.help_img.blit(m, (40, y))
+ y = y + 40
+ y = y + 20
def goal_reached(self):
for obj, goal in self.goals:
@@ -160,14 +182,15 @@ def init_levels():
def load_levels():
level_dir = os.path.join('data', 'levels')
files = os.listdir(level_dir)
+ files.sort()
levels = []
- for level_file in sorted(f for f in files if f.split(".")[-1] == "level"):
- raw = open(os.path.join(level_dir, level_file))
+ for level_file in sorted(f for f in files if f.endswith('.py')):
+ name = level_file.replace('.py', '')
+ abs_path = os.path.join(level_dir, level_file)
try:
- level = json.load(raw)
- except ValueError, error:
- print level_file, "-> invalid json file: ", error
- raw.close()
+ level = imp.load_source(name, abs_path)
+ except Exception, error:
+ print level_file, "-> invalid file: ", error
else:
lvl = load_level(level, level_dir, level_file)
if lvl:
@@ -175,7 +198,8 @@ def load_levels():
return levels
-def load_level(level, level_dir, level_name):
+def load_level(l, level_dir, level_name):
+ level = getattr(l, 'LEVEL')
objs = {}
for obj in level["placed"]:
try:
@@ -211,12 +235,15 @@ def load_level(level, level_dir, level_name):
return None
goals.append( (proj, trg) )
- img_file = os.path.join(level_dir, level['help'])
+ img_file = os.path.join(level_dir, level['helpImage'])
if os.path.isfile(img_file):
help_image = pygame.image.load(img_file)
else:
print level_name, "-> Invalid help file:", level['help']
return None
- return Level(objs, toadd, goals, help_image)
+ help_title = level['helpTitle']
+ help_mes = level['helpMes']
+
+ return Level(objs, toadd, goals, help_image, help_title, help_mes)