コード例 #1
0
    def __load_items(self, text, data, top, height):
        self.items = []

        def create_text(stage, next, text, top, height):
            text_item = stage.create_text(data.text)[0]
            text_item.break_text_into(next)
            text_item.set_text(text)
            text_item.set_top(top)
            text_item.set_dimensions(data.text.width, height)
            text_item.break_text_into(None)
            return text_item

        # Usamos una clase que tiene el metodo set_text para saber si hay que dividir el texto
        class Next:
            def __init__(self):
                self.text = None

            def set_text(self, text):
                self.text = text

        next = Next()
        layer = Layer()
        layer.add(create_text(self.stage, next, text, top, height))
        self.items.append(layer)
        while next.text:
            layer = Layer()
            layer.add(create_text(self.stage, next, next.text, top, height))
            self.items.append(layer)
コード例 #2
0
    def view_post_web_cb(self, result):
        if result.error:
            self.error_try_again_later()
            return
        data = DictClass(result.data)
        self.layers.view_post.title.set_text(self.title)
        self.layers.view_post.author.set_text(data.author_name + ":")
        # Usamos una clase que tiene el metodo set_text para saber si hay que dividir el texto
        items = []
        next = Next()
        layer = Layer()

        def create_text(stage, next, text, data):
            text_item = stage.create_text(data)[0]
            set_text(next, text, text_item)
            return text_item

        layer.add(
            create_text(self.stage, next, data.text,
                        self.layers.view_post.post.data))
        items.append(layer)
        while next.text:
            layer = Layer()
            layer.add(
                create_text(self.stage, next, next.text,
                            self.layers.view_post.post.data))
            items.append(layer)
        paginator = Paginator(self.stage, items, self.data.pager_post)
        self.change_layer([self.layers.view_post.layer] +
                          paginator.get_layers() + [self.layers.logged.layer])
コード例 #3
0
    def __init__(self, stage, elements):
        self.stage = stage
        self.layer = Layer()
        self.elements_layer = Layer()
        from yaml import load
        data = load(file('data/common/backpack.yaml'))
        self.elements = elements
        self.close_button = stage.create_button(data["close"], self)[0]
        self.next_button = stage.create_button(data["next"], self)[0]
        self.previous_button = stage.create_button(data["previous"], self)[0]
        self.description_text = stage.create_text(data["description"])[0]
        self.element_count_text = stage.create_text_count(
            data["element_count"], len(elements))[0]
        self.previous_button.set_visible(False)
        self.current_page = 0
        self.create_elements(data, elements)
        if len(elements) <= self.ITEMS_PER_PAGE:
            self.next_button.set_visible(False)
        self.set_elements()

        self.other = stage.create_items_from_yaml(data["other"])
        for other in self.other:
            self.layer.add(other)
        self.layer.add(self.close_button)
        self.layer.add(self.next_button)
        self.layer.add(self.previous_button)
        self.layer.add(self.description_text)
        self.layer.add(self.element_count_text)
        self.current_items = []
コード例 #4
0
 def __init__(self, stage, on_no=None):
     self.stage = stage
     layer = self.layer = Layer()
     data = load(file('data/common/quit_dialog.yaml'))
     items = stage.create_items_from_yaml(data['items'], self)
     self.on_no = on_no
     for item in items:
         layer.add(item)
コード例 #5
0
 def show_items(self, items):
     if items:
         if hasattr(self, "actual_layer") and self.actual_layer:
             self.actual_layer.exit()
         self.actual_layer = Layer()
         layer = self.actual_layer
         for item in items:
             layer.add(item)
         self.add_layer(layer)
コード例 #6
0
 def __init__(self, stage, tests):
     self.layer = Layer()
     self.stage = stage
     self.tests = tests
     data = DictClass(load(file('data/common/tests_viewer.yaml')))
     layers = [test.get_layer() for test in tests]
     self.paginator = Paginator(self.stage, layers,
                                data.get("pagination", None))
     for item in self.stage.create_items_from_yaml(data.other, self):
         self.layer.add(item)
コード例 #7
0
 def create_items(self, data):
     items = DictClass()
     layer = Layer()
     self.stage._items_manager = self
     for i in data:
         item = items[i.name] = self.stage.create_item(i)[0]
         item.data = i
         layer.add(item)
     self.stage._items_manager = None
     items["layer"] = layer
     return items
コード例 #8
0
 def __init__(self, stage, on_ok=None):
     self.stage = stage
     layer = self.layer = Layer()
     data = self.get_data()
     items = stage.create_items_from_yaml(data['items'], self)
     self.on_ok = on_ok
     self.items = DictClass()
     for item in items:
         layer.add(item)
     self.message = stage.create_item(data["message"])[0]
     layer.add(self.message)
コード例 #9
0
    def __init__(self, stage, items, optional_data=None):
        self.layer = Layer()
        self.items_layer = Layer()
        self.items = items
        self.stage = stage
        from yaml import load
        data = load(file('data/common/pagination.yaml'))
        if optional_data is not None:
            data.update(optional_data)
        self.current = 1
        if len(self.items):
            self.current_layer = self.items[0]
        else:
            self.current_layer = Layer()
        self.min = 1
        self.max = len(self.items)
        self.count = len(self.items)
        for item in items:
            item.set_visible(False)
        self.previous = stage.create_button(data["previous"], self)[0]
        self.next = stage.create_button(data["next"], self)[0]
        self.last = None
        if "last" in data:
            self.last = stage.create_button(data["last"], self)[0]
        if "page_count" in data and data["page_count"]:
            self.page_count_text = stage.create_text(data["page_count"])[0]
            self.page_count_base_text = data["page_count"]["text"]
        else:
            self.page_count_text = None
        self.update_page_count()
        self.update_items()
        self.update_buttons()

        self.layer.add(self.previous)
        self.layer.add(self.next)
        if self.page_count_text:
            self.layer.add(self.page_count_text)
        if self.last:
            self.layer.add(self.last)
コード例 #10
0
    def __init__(self, stage):
        global DEFAULT_NAME, DEFAULT_ROOM

        self.go_to_last = False
        self.dialog = None
        self.paginator = None
        self.background = Layer()
        self.foreground = Layer()
        self.focus_group = FocusGroup()
        self.stage = stage
        self.current_callback = None
        self.current_id = None
        data = self.data = DictClass(load(file('data/common/activity.yaml')))
        self.clock_image = ItemImage(0, 0, assets.load_image(data.clock.src))
        layers = self.layers = DictClass()
        for k, i in data.layers.items():
            layers[k] = self.create_items(i)
        self.layers.main.name_input.set_focus_group(self.focus_group)
        self.layers.main.name_input.set_on_enter(self.handle_next)
        self.layers.main.name_input.set_text(DEFAULT_NAME)
        self.layers.main.room_input.set_focus_group(self.focus_group)
        self.layers.main.room_input.set_on_enter(self.handle_next)
        self.layers.main.room_input.set_text(DEFAULT_ROOM)
        self.current_layers = [layers.main.layer]
        text_box = self.layers.post.text_box = self.create_text_box(
            data.text_box)
        self.layers.post.layer.add(text_box)

        for item in self.stage.create_items_from_yaml(data["background"],
                                                      self):
            self.background.add(item)
        for item in self.stage.create_items_from_yaml(data["foreground"],
                                                      self):
            self.foreground.add(item)

        self.stage.start_timer('msgclock', 15000, self.update_messages_tick)
コード例 #11
0
    def __init__(self, stage):
        self.stage = stage
        layer = self.layer = Layer()
        data = DictClass(load(file('data/common/next_level.yaml')))
        items = stage.create_items_from_yaml(data.other, self)
        for item in items:
            layer.add(item)
        text = stage.create_text(data.text)[0]
        text.set_text(
            data.text.texts[self.stage.game.datastore.datamodel.level])
        layer.add(text)

        # Load the sound
        item_found_sound = assets.load_sound('DGI_item_found.ogg')
        item_found_sound.play()
コード例 #12
0
 def create_layers(self, data):
     class ExtraLayers:
         pass
     layers = ExtraLayers()
     layer_list = []
     for layer in data:
         new_layer = Layer()
         layer_list.append(new_layer)
         if "name" in layer:
             setattr(layers, layer["name"], new_layer)
         items = self.create_items_from_yaml(layer["items"])
         if items:
             for item in items:
                 new_layer.add(item)
     return layers, layer_list
コード例 #13
0
 def __init__(self, stage, title, text):
     self.layer = Layer()
     self.stage = stage
     data = DictClass(load(file('data/common/content_viewer.yaml')))
     title_item = self.title_text = stage.create_text(data.title)[0]
     title_item.set_top(data.container.top)
     self.title_text.set_text(title)
     text_top = title_item.get_top() + title_item.get_height() + 10
     text_height = data.container.height - (text_top - data.container.top)
     self.close = stage.create_button(data.close, self)[0]
     self.__load_items(text, data, text_top, text_height)
     self.paginator = Paginator(self.stage, self.items,
                                data.get("pagination", None))
     for item in self.stage.create_items_from_yaml(data.other):
         self.layer.add(item)
     self.layer.add(self.title_text)
     self.layer.add(self.close)
コード例 #14
0
    def __init__(self, stage, amount):
        self.stage = stage
        layer = self.layer = Layer()
        self.amount = amount
        data = DictClass(load(file('data/common/fail_tests.yaml')))
        text = stage.create_text(data.text)[0]
        if amount == 1:
            text.set_text(data.text.singular)
        else:
            text.set_text(data.text.plural % dict(amount=amount))
        items = stage.create_items_from_yaml(data.other, self)
        for item in items:
            layer.add(item)
        layer.add(text)

        # Load the sound
        wrong_sound = assets.load_sound('DGI_wrong.ogg')
        wrong_sound.play()
コード例 #15
0
 def __init__(self, stage):
     self.layer = Layer()
     self.stage = stage
     data = DictClass(load(file('data/common/games_viewer.yaml')))
     for item in stage.create_items_from_yaml(data.other):
         self.layer.add(item)
     self.close = stage.create_button(data.close, self)[0]
     self.layer.add(self.close)
     quantity = stage.game.datastore.datamodel.unlocked_level - 1
     if quantity == 1:
         data.header['text'] = data.header.singular.pre + str(
             quantity) + data.header.singular.pos
     else:
         data.header['text'] = data.header.plural.pre + str(
             quantity) + data.header.plural.pos
     self.header = stage.create_text(data.header)[0]
     self.layer.add(self.header)
     self.footer = stage.create_text(data.footer)[0]
     for data_game in data.games:
         Game(stage, self.layer, data_game, self.footer)
コード例 #16
0
ファイル: map.py プロジェクト: sugar-activities/4444-activity
 def prepare(self):
     data = DictClass(load(file('data/map/common.yaml')))
     self.gui = Layer()
     for item in self.create_items_from_yaml(data.gui):
         self.gui.add(item)
     self.create_selected_map_character(data.character)
     self.load_quadrant()
     self.tests_counter = self.create_text(data.counters.tests)[0]
     self.backpack_counter = self.create_text(data.counters.backpack)[0]
     self.games_counter = self.create_text(data.counters.games)[0]
     self.gui.add(self.tests_counter)
     self.gui.add(self.backpack_counter)
     self.gui.add(self.games_counter)
     self.backpack_counter.set_text(
         str(
             len(self.game.datastore.datamodel.backpack[
                 self.game.datastore.datamodel.level - 1])))
     self.tests_counter.set_text(
         str(
             len(self.game.datastore.levels[
                 self.game.datastore.datamodel.level].tests)))
     self.games_counter.set_text(
         str(self.game.datastore.datamodel.unlocked_level - 1))
コード例 #17
0
 def __init__(self, stage, title, description, data):
     self.stage = stage
     layer = self.layer = Layer()
     if title:
         title_item = stage.create_text(data.title)[0]
         title.set_top(data.top_container.top)
         title_item.set_text(title)
         layer.add(title_item)
     else:
         title_item = Item(0, data.top_container.top, 0, 0)
     if description:
         description_item = self.description = stage.create_text(
             data.description)[0]
         extra = 0
         if title:
             extra = data.top_container.after_title
         description_item.set_top(title_item.get_top() +
                                  title_item.get_height() + extra)
         description_item.set_text(description)
         layer.add(description_item)
     else:
         self.description = Item(
             0,
             title_item.get_top() + title_item.get_height(), 0, 0)
コード例 #18
0
 def __init__(self, stage, data, next_cb):
     self.next_cb = next_cb
     self.layer = Layer()
     self.stage = stage
     self.layer.add(stage.create_image(data.intro)[0])
     self.layer.add(stage.create_button(data.next, self)[0])
コード例 #19
0
    def load_items(self, data, items):
        layer = Layer()

        left = self.data.post_box.left
        top = self.data.post_box.top
        cant_items = 0
        i = 0
        for item in data:
            if cant_items >= self.data.post_box.items_per_page:
                items.append(layer)
                layer = Layer()
                top = self.data.post_box.top
                cant_items = 0
            self.stage._items_manager = self
            text_item = self.stage.create_item(self.data.post_item)[0]
            text_item.data_item = item
            text_item.set_top(top)
            text_item.set_left(left)

            def set_post_text(text_item, text):
                next = Next()
                set_text(next, text, text_item)
                if next.text:
                    new_dict = dict(self.data.post_item)
                    new_dict["width"] = -1
                    ellipsis = self.stage.create_item(new_dict)[0]
                    ellipsis.set_text("...")
                    ellipsis.set_top(text_item.get_top())
                    ellipsis.set_left(text_item.get_left() +
                                      text_item.lines[0])
                    return ellipsis
                return None

            def on_enter(text_item, *args, **kwargs):
                item = text_item.data_item
                text_item.set_text("&#c200,0,0!%s&#c!: %s" %
                                   (item.author_name, item.text))

            def on_leave(text_item, *args, **kwargs):
                item = text_item.data_item
                text_item.set_text("&#c58,129,188!%s&#c!: %s" %
                                   (item.author_name, item.text))

            text_item.add_event_handler(ItemEvent.MOUSE_ENTER, on_enter)
            text_item.add_event_handler(ItemEvent.MOUSE_LEAVE, on_leave)
            text_item.add_event_handler(ItemEvent.CLICK,
                                        self.handle_post_click)
            text_item.post_id = item.id
            text_item.post_index = i
            self.stage._items_manager = None
            other_item = set_post_text(
                text_item,
                "&#c58,129,188!%s&#c!: %s" % (item.author_name, item.text))
            if other_item:
                layer.add(other_item)
            layer.add(text_item)
            top += self.data.post_box.inter_line
            cant_items += 1
            i += 1

        if len(layer.items) > 0:
            items.append(layer)
コード例 #20
0
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')
        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/memory.yaml')))

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.time = self.data.time.max
        self.timer = DictClass({})
        image = assets.load_image(self.data.time.src)
        self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top,
                                       image)
        self.timer['value'] = ItemText(self.data.time.left,
                                       self.data.time.top,
                                       self.font,
                                       0,
                                       format_time(self.time),
                                       width=image.get_width(),
                                       height=image.get_height(),
                                       h_align=2,
                                       v_align=2)
        self.top_layer.add(self.timer.skin)
        self.top_layer.add(self.timer.value)

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        self.deck = []
        image_back = assets.load_image(self.data.board.card_back)
        for k in range(0, len(self.data.board.cards)):
            image = assets.load_image(self.data.board.cards[k])
            self.deck.append([
                Card(self, k, image, image_back),
                Card(self, k, image, image_back)
            ])

        self.range = self.data.start
        self.cards = []
        self.deal()

        # Load the sound
        self.card_flip_sound = assets.load_sound('DGI_card_flip.ogg')
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.wrong_sound = assets.load_sound('DGI_wrong.ogg')
        self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
コード例 #21
0
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')

        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/invaders.yaml')))

        self.good = self.data.start.good
        self.velocity = self.data.start.velocity
        self.interval = self.data.start.interval

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.bad[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.bad.left, self.data.bad.top, image)
        self.game_over_layer.add(item)
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        image = assets.load_image(
            self.data.good[self.game.datastore.datamodel.character].src)
        self.good_indicator = ItemImage(self.data.good.left,
                                        self.data.good.top, image)

        self.text_indicators = []

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        data = DictClass(load(file('data/map/common.yaml')))
        params = data.character[self.game.datastore.datamodel.character]
        params['base'] = data.character.base[
            self.game.datastore.datamodel.character].big
        self.character_animation = Character(**params)
        self.character = self.character_animation.item
        self.character.set_left(
            (SCREEN_WIDTH - self.character.get_width()) / 2)
        self.character.set_top(SCREEN_HEIGHT - self.character.get_height())
        left = self.character.get_left() + self.data.collision.left
        top = self.character.get_top() + self.data.collision.top
        width = self.character.get_width(
        ) - self.data.collision.left - self.data.collision.right
        height = self.character.get_height(
        ) - self.data.collision.top - self.data.collision.bottom
        if DEBUG:
            self.debug_character = ItemRect(left,
                                            top,
                                            width,
                                            height,
                                            border=(255, 255, 255))
        self.invaders = []

        # Load the sound
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.lose_hit_sound = assets.load_sound('DGI_lose_hit.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')
コード例 #22
0
    def initialize(self):
        GameStage.initialize(self)
        stream = file('data/fonts.yaml', 'r')
        fonts = load(stream)
        for font in fonts:
            setattr(
                self, font,
                assets.load_font(fonts[font]['file_name'],
                                 fonts[font]['size']))

        self.data = DictClass(load(file('data/asteroids.yaml')))

        self.game_over_layer = Layer()
        image = assets.load_image(
            self.data.game_over[self.game.datastore.datamodel.character].src)
        item = ItemImage(self.data.game_over.left, self.data.game_over.top,
                         image)
        self.game_over_layer.add(item)

        self.main_layer = Layer()
        self.top_layer = Layer()

        self.time = self.data.time.max
        self.timer = DictClass({})
        image = assets.load_image(self.data.time.src)
        self.timer['skin'] = ItemImage(self.data.time.left, self.data.time.top,
                                       image)
        self.timer['value'] = ItemText(self.data.time.left,
                                       self.data.time.top,
                                       self.font,
                                       0,
                                       format_time(self.time),
                                       width=image.get_width(),
                                       height=image.get_height(),
                                       h_align=2,
                                       v_align=2)
        self.top_layer.add(self.timer.skin)
        self.top_layer.add(self.timer.value)

        self.score = 0
        self.score_board = DictClass({})
        image = assets.load_image(self.data.score.src)
        self.score_board['skin'] = ItemImage(self.data.score.left,
                                             self.data.score.top, image)
        self.score_board['value'] = ItemText(self.data.score.left,
                                             self.data.score.top,
                                             self.font,
                                             0,
                                             str(self.score),
                                             width=image.get_width(),
                                             height=image.get_height(),
                                             h_align=2,
                                             v_align=2)
        self.top_layer.add(self.score_board.skin)
        self.top_layer.add(self.score_board.value)

        self.level = self.data.start
        self.asteroids = []

        self.max_width = 0
        self.max_height = 0
        for a in self.data.asteroids:
            item = assets.load_image(a)
            if self.max_width < item.get_width():
                self.max_width = item.get_width()
            if self.max_height < item.get_height():
                self.max_height = item.get_height()
        self.max_col = int(SCREEN_WIDTH / self.max_width)
        self.max_row = int(SCREEN_HEIGHT / self.max_height)
        self.margin_left = (SCREEN_WIDTH % self.max_width) / 2
        self.margin_top = (SCREEN_HEIGHT % self.max_height) / 2

        # Load the sound
        self.click_sound = assets.load_sound('DGI_Click.ogg')
        self.item_found_sound = assets.load_sound('DGI_item_found.ogg')
        self.wrong_sound = assets.load_sound('DGI_wrong.ogg')
        self.lose_bell_sound = assets.load_sound('DGI_lose_bell.ogg')
        self.lose_music_sound = assets.load_sound('DGI_lose_music.ogg')