Exemplo n.º 1
0
    def show_cards(self, cards):
        """
        Create the card widgets.
        :param cards: the cards
        """
        # Hide the said tricks widgets.
        for w in self._said_tricks_widgets.values():
            w.clear_actions()
            w.add_action(actions.FadeOutAction(0.5))

        self._card_widgets = {}
        card_size = (130, 184)
        x_min = 290
        x_delta = 50
        y = 400
        cards.sort(cmp_colors_first)

        class HandleCardClicked(object):
            def __init__(self, view, card):
                self._view = view
                self._card = card

            def __call__(self, x, y):
                self._view._handle_say_card(self._card)

        for i, card in enumerate(cards):
            card_image_name = get_card_image_filename(card)
            im = self._rm.get_image(card_image_name)
            w = ImageWidget((x_min + i * x_delta, y), card_size, i, im)
            w.handle_clicked = HandleCardClicked(self, card)
            self._background_widget.add_widget(w)
            self._card_widgets[card] = w
Exemplo n.º 2
0
    def show_cards(self, cards):
        """
        Create the card widgets.
        :param cards: the cards
        """
        # Hide the said tricks widgets.
        for w in self._said_tricks_widgets.values():
            w.clear_actions()
            w.add_action(actions.FadeOutAction(0.5))

        self._card_widgets = {}
        card_size = (130, 184)
        x_min = 290
        x_delta = 50
        y = 400
        cards.sort(cmp_colors_first)
        class HandleCardClicked(object):
            def __init__(self, view, card):
                self._view = view
                self._card = card
            def __call__(self, x, y):
                self._view._handle_say_card(self._card)
        for i, card in enumerate(cards):
            card_image_name = get_card_image_filename(card)
            im = self._rm.get_image(card_image_name)
            w = ImageWidget((x_min+i*x_delta, y), card_size, i, im)
            w.handle_clicked = HandleCardClicked(self, card)
            self._background_widget.add_widget(w)
            self._card_widgets[card] = w
Exemplo n.º 3
0
def warning_widget(position, size, text, font, screen_size=None, text_color=(255, 255, 255, 255), z_index=99,
                   fill=(0, 0, 0, 160), close_on_click=True):
    """
    Create an ImageWidget with the given text. If screen_size is given, position is ignored and the widget is centered.
    :param position: the position
    :param size: the widget size
    :param text: the text
    :param font: the font
    :param screen_size: the screen size
    :param text_color: the text color
    :param z_index: the z index
    :param fill: the fill color
    :return: the widget
    """
    # Create the widget.
    if screen_size is None:
        x, y = position
    else:
        x = (screen_size[0] - size[0]) / 2
        y = (screen_size[1] - size[1]) / 2
    font_obj = font.render(text, True, text_color)
    offset_x = (size[0] - font_obj.get_width()) / 2
    offset_y = (size[1] - font_obj.get_height()) / 2
    warning_bg = pygame.Surface(size, flags=pygame.SRCALPHA)
    warning_bg.fill(fill)
    warning_bg.blit(font_obj, (offset_x, offset_y))
    warning = ImageWidget((x, y), size, z_index, warning_bg, visible=False)

    # Attach the click function.
    if close_on_click:
        def warning_clicked(xx, yy):
            warning.hide()
            warning.clear_actions()
        warning.handle_clicked = warning_clicked

    return warning
Exemplo n.º 4
0
    def _create_widgets(self):
        """
        Create the widgets and return the background widget.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the waiting text.
        wait_box = special_widgets.warning_widget(
            None, (400, 100),
            "Waiting for other players",
            self._font,
            screen_size=self.screen.get_size(),
            close_on_click=False)
        wait_box.visible = True
        bg_widget.add_widget(wait_box)
        self._warnings["wait_box"] = wait_box

        # Create the "invalid num tricks" warning.
        invalid_num_warning = special_widgets.warning_widget(
            None, (400, 100),
            "Invalid number of tricks",
            self._font,
            screen_size=self.screen.get_size())
        bg_widget.add_widget(invalid_num_warning)
        self._warnings["invalid_num_tricks"] = invalid_num_warning

        # Create the chat widget.
        chat_box = special_widgets.warning_widget(
            (10, self.screen.get_height() - 260), (260, 200),
            "chat",
            self._font,
            close_on_click=False)
        chat_box.visible = True
        bg_widget.add_widget(chat_box)

        # Create the "Your move" box.
        your_move_w = Text(
            (self.screen.get_width() - 140, self.screen.get_height() - 110),
            (120, 40),
            0,
            "Your move",
            self._font,
            fill=(0, 0, 0, 160))
        your_move_w.opacity = 0
        bg_widget.add_widget(your_move_w)
        self._user_move_widget = your_move_w

        # Create the trump widgets.
        trump_pos = (180, 180)
        trump_size = (125, 125)
        for color in ["W", "H", "D", "S", "C"]:
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, trump_size)
            im_w = ImageWidget(trump_pos, trump_size, 0, im)
            im_w.opacity = 0
            bg_widget.add_widget(im_w)
            self._trump_widgets[color] = im_w

        # Create the "choose trump" widgets.
        class ChooseHandler(object):
            def __init__(self, view, trump):
                self._view = view
                self._trump = trump

            def __call__(self, x, y):
                self._view._handle_choose_trump(self._trump)

        choose_size = (90, 90)
        choose_trump_bg = pygame.Surface((400, 170), flags=pygame.SRCALPHA)
        choose_trump_bg.fill((0, 0, 0, 160))
        font_obj = self._font.render("Choose the trump:", True,
                                     (255, 255, 255, 255))
        choose_trump_bg.blit(
            font_obj,
            ((choose_trump_bg.get_width() - font_obj.get_width()) / 2, 20))
        choose_trump_container = ImageWidget(
            (self.screen.get_width() / 2 - 200, 200),
            choose_trump_bg.get_size(),
            99,
            choose_trump_bg,
            visible=False)
        for i, color in enumerate(["D", "S", "H", "C"]):
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, choose_size)
            im_w = ImageWidget((i * (choose_size[0] + 10), 70), choose_size, 0,
                               im)
            choose_trump_container.add_widget(im_w)
            im_w.handle_clicked = ChooseHandler(self, color)
        bg_widget.add_widget(choose_trump_container)
        self._choose_trump_widget = choose_trump_container

        return bg_widget
Exemplo n.º 5
0
    def _create_widgets(self):
        """
        Create the widgets and return the background widget.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the waiting text.
        wait_box = special_widgets.warning_widget(None, (400, 100), "Waiting for other players", self._font,
                                                  screen_size=self.screen.get_size(), close_on_click=False)
        wait_box.visible = True
        bg_widget.add_widget(wait_box)
        self._warnings["wait_box"] = wait_box

        # Create the "invalid num tricks" warning.
        invalid_num_warning = special_widgets.warning_widget(None, (400, 100), "Invalid number of tricks", self._font,
                                                             screen_size=self.screen.get_size())
        bg_widget.add_widget(invalid_num_warning)
        self._warnings["invalid_num_tricks"] = invalid_num_warning

        # Create the chat widget.
        chat_box = special_widgets.warning_widget((10, self.screen.get_height()-260), (260, 200), "chat", self._font,
                                                  close_on_click=False)
        chat_box.visible = True
        bg_widget.add_widget(chat_box)

        # Create the "Your move" box.
        your_move_w = Text((self.screen.get_width()-140, self.screen.get_height()-110), (120, 40), 0, "Your move",
                           self._font, fill=(0, 0, 0, 160))
        your_move_w.opacity = 0
        bg_widget.add_widget(your_move_w)
        self._user_move_widget = your_move_w

        # Create the trump widgets.
        trump_pos = (180, 180)
        trump_size = (125, 125)
        for color in ["W", "H", "D", "S", "C"]:
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, trump_size)
            im_w = ImageWidget(trump_pos, trump_size, 0, im)
            im_w.opacity = 0
            bg_widget.add_widget(im_w)
            self._trump_widgets[color] = im_w

        # Create the "choose trump" widgets.
        class ChooseHandler(object):
            def __init__(self, view, trump):
                self._view = view
                self._trump = trump
            def __call__(self, x, y):
                self._view._handle_choose_trump(self._trump)
        choose_size = (90, 90)
        choose_trump_bg = pygame.Surface((400, 170), flags=pygame.SRCALPHA)
        choose_trump_bg.fill((0, 0, 0, 160))
        font_obj = self._font.render("Choose the trump:", True, (255, 255, 255, 255))
        choose_trump_bg.blit(font_obj, ((choose_trump_bg.get_width()-font_obj.get_width())/2, 20))
        choose_trump_container = ImageWidget((self.screen.get_width()/2 - 200, 200), choose_trump_bg.get_size(), 99,
                                             choose_trump_bg, visible=False)
        for i, color in enumerate(["D", "S", "H", "C"]):
            im_filename = get_color_image_filename(color)
            im = self._rm.get_image(im_filename, choose_size)
            im_w = ImageWidget((i*(choose_size[0]+10), 70), choose_size, 0, im)
            choose_trump_container.add_widget(im_w)
            im_w.handle_clicked = ChooseHandler(self, color)
        bg_widget.add_widget(choose_trump_container)
        self._choose_trump_widget = choose_trump_container

        return bg_widget