diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2012-05-01 07:03:00 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2012-05-01 07:03:00 (GMT) |
commit | 8957651e74154850c9caddb36339d5abe3ad9538 (patch) | |
tree | 9b6ec18b188e3da665aa85cd4fbe5559d08a18aa | |
parent | 1dfcca8cf751ed78e81b8efa9e2d137dbd593826 (diff) |
Add the StateView to the MapNavView in play mode
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | activity.py | 5 | ||||
-rw-r--r-- | editmap.py | 3 | ||||
-rw-r--r-- | mapnav.py | 14 | ||||
-rw-r--r-- | model.py | 14 | ||||
-rw-r--r-- | stateview.py | 19 |
5 files changed, 38 insertions, 17 deletions
diff --git a/activity.py b/activity.py index d4f061e..a55692d 100644 --- a/activity.py +++ b/activity.py @@ -139,7 +139,7 @@ class IngeniumMachinaActivity(activity.Activity): self.game_map = GameMap() else: self.game_map = GameMap(self.model.data['map_data']) - self.mapnav_game = MapNavView(self.game_map) + self.mapnav_game = MapNavView(self.game_map, self.model) self.mapnav_game.view_mode = MapNavView.MODE_PLAY self.mapnav_game.show() self.mapnav_game.connect('resource-clicked', @@ -277,9 +277,12 @@ class IngeniumMachinaActivity(activity.Activity): question_dialog.set_transient_for(self.get_toplevel()) question_dialog.connect('reply-selected', self.__question_replied_cb) question_dialog.show_all() + self.model.register_displayed_question(id_question) def __question_replied_cb(self, dialog, id_question, valid): logging.error('** Question %s replied %s', id_question, valid) + if valid: + self.model.register_replied_question(id_question) def read_file(self, file_path): '''Read file from Sugar Journal.''' @@ -26,7 +26,8 @@ class EditMapWin(gtk.HBox): self.model.data['map_data'] = self.game_map.data left_vbox = gtk.VBox() - self.nav_view = MapNavView(self.game_map, mode=MapNavView.MODE_EDIT) + self.nav_view = MapNavView(self.game_map, self.model, + mode=MapNavView.MODE_EDIT) self.top_view = TopMapView(self.game_map, 150, 150) self.top_view.show_position(self.nav_view.x, self.nav_view.y, self.nav_view.direction) @@ -11,10 +11,11 @@ import cairo import logging import rsvg -from sugar.graphics.style import Color +from sugar.graphics import style from game_map import GameMap from character import Character +from stateview import StateView import mapview WIDTH_CONTROL_LINES = 2 @@ -48,8 +49,9 @@ class MapNavView(gtk.DrawingArea): MODE_PLAY = 0 MODE_EDIT = 1 - def __init__(self, game_map, mode=MODE_PLAY): + def __init__(self, game_map, model, mode=MODE_PLAY): self._game_map = game_map + self._model = model self.x = 0 self.y = 0 self.direction = 'S' @@ -79,7 +81,10 @@ class MapNavView(gtk.DrawingArea): self._setup_handle = self.connect('size_allocate', size_allocate_cb) + self._state_view = None if self.view_mode == self.MODE_PLAY: + cell = style.GRID_CELL_SIZE / 2 + self._state_view = StateView(self._model, cell, cell, cell) gobject.timeout_add(100, self._update_timer) def _update_timer(self): @@ -251,6 +256,7 @@ class MapNavView(gtk.DrawingArea): view_data = {'width': 150, 'height': 150, 'show_position': position, 'x': rect.width - 150, 'y': 30} mapview.draw(ctx, self._game_map, view_data) + self._state_view.draw(ctx) self._character.draw(ctx) return False @@ -441,7 +447,7 @@ class MapNavView(gtk.DrawingArea): y = self._height - self._grid_size * (self._door_height + 1) ctx.rectangle(x, y, self._grid_size * self._door_width, self._grid_size * self._door_height) - fill = (Color('#8B6914').get_rgba()) + fill = (style.Color('#8B6914').get_rgba()) stroke = (0, 0, 0) ctx.set_source_rgba(*fill) ctx.fill_preserve() @@ -450,7 +456,7 @@ class MapNavView(gtk.DrawingArea): # frame frame_width = self._grid_size * self._door_width / 8 - fill = (Color('#6B4904').get_rgba()) + fill = (style.Color('#6B4904').get_rgba()) ctx.set_source_rgba(*fill) ctx.rectangle(x, y, self._grid_size * self._door_width, frame_width) ctx.fill() @@ -34,6 +34,12 @@ class GameModel: self.data['map_data'] = None + state = {'displayed_questions': [], + 'replied_questions': [], + 'actions_log': []} + + self.data['state'] = state + def get_new_resource_id(self): self.data['last_resource_id'] = self.data['last_resource_id'] + 1 return self.data['last_resource_id'] @@ -42,6 +48,14 @@ class GameModel: self.data['last_question_id'] = self.data['last_question_id'] + 1 return self.data['last_question_id'] + def register_displayed_question(self, id_question): + if id_question not in self.data['state']['displayed_questions']: + self.data['state']['displayed_questions'].append(id_question) + + def register_replied_question(self, id_question): + if id_question not in self.data['state']['replied_questions']: + self.data['state']['replied_questions'].append(id_question) + def get_resource(self, id_resource): for resource in self.data['resources']: if resource['id_resource'] == int(id_resource): diff --git a/stateview.py b/stateview.py index a27ab8d..894fff3 100644 --- a/stateview.py +++ b/stateview.py @@ -15,12 +15,11 @@ import math class StateView(): - def __init__(self, model, x, y, width, height): + def __init__(self, model, x, y, cell_size): self.model = model self._x = x self._y = y - self._width = width - self._height = height + self._cell_size = cell_size svg = rsvg.Handle(file='./icons/question.svg') self._tmp_image = cairo.ImageSurface(cairo.FORMAT_ARGB32, svg.props.width, svg.props.height) @@ -33,19 +32,17 @@ class StateView(): cant_questions = len(self.model.data['questions']) if cant_questions == 0: return - icon_size = int(self._width / cant_questions) # margin - print "icon_size", icon_size state = self.model.data['state'] - displayed_questions = state['displayed_questions'] - replied_questions = state['replied_questions'] + displayed_questions = len(state['displayed_questions']) + replied_questions = len(state['replied_questions']) - scale = float(self._svg_width) / float(icon_size) + scale = float(self._svg_width) / float(self._cell_size) print "scale", scale ctx.translate(self._x, self._y) for n in range(cant_questions): if n < replied_questions: - radio = icon_size / 2.0 + radio = self._cell_size / 2.0 ctx.arc(radio, radio, radio, 0., 2 * math.pi) ctx.set_source_rgb(0.913, 0.733, 0.0) # eebb00 ctx.fill() @@ -57,13 +54,13 @@ class StateView(): else: ctx.paint_with_alpha(0.25) ctx.scale(scale, scale) - ctx.translate(icon_size, 0) + ctx.translate(self._cell_size, 0) def main(): window = gtk.Window() _model = model.GameModel() - state_view = StateView(_model, 10, 10, 150, 200) + state_view = StateView(_model, 10, 10, 20) area = gtk.DrawingArea() # add fake questions to test |