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
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