Example #1
0
    def __init__(self, main_window, name, player) -> None:
        Scene.__init__(self, main_window=main_window, name=name, player=player)
        self.main_image = pygame.image.load("{0}/images/main_img.jpg".format(self._res_dir))
        self.bg_image = pygame.image.load("{0}/images/main_bg.jpg".format(self._res_dir))
        self.main_rect = self.main_image.get_rect()
        self.bg_rect = self.bg_image.get_rect()
        self.main_rect.center = (Constants.WINDOW_W / 2, Constants.WINDOW_H / 2)

        start_label = TextLabel(parent=self, font_size=18, bold=True)
        settings_label = TextLabel(parent=self, font_size=18, bold=True)
        exit_label = TextLabel(parent=self, font_size=18, bold=True)

        self.start_button = TextButton(parent=self, text_label=start_label,
                                       normal_image_path="start_quest_btn_normal.png")
        self.start_button.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")

        self.settings_button = TextButton(parent=self, text_label=settings_label,
                                          normal_image_path="start_quest_btn_normal.png")
        self.settings_button.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")

        self.exit_button = TextButton(parent=self, text_label=exit_label,
                                      normal_image_path="start_quest_btn_normal.png")
        self.exit_button.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")

        self.start_button.add_action({ButtonEventType.ON_CLICK_LB: lambda: self.change_scene("Farm")})
        self.settings_button.add_action({ButtonEventType.ON_CLICK_LB: lambda: self.show_settings()})
        self.exit_button.add_action({ButtonEventType.ON_CLICK_LB: lambda: self.exit_game()})
Example #2
0
    def __init__(self, parent: Scene, bg_name):
        RenderObject.__init__(self, parent=parent)
        self.parent.remove_render(
            self.parent.find_child_of(child=self, base=Menu))
        self._close_btn = Button(parent=self,
                                 normal_image_path="close_button1.png")
        self._close_btn.set_image_by_state(ButtonState.HOVERED,
                                           "close_button1_hover.png")
        self._close_btn.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.destroy()})

        self._bg_image = pygame.image.load("{0}/{1}.png".format(
            self._res_dir, bg_name)).convert_alpha()
        self._rect.width = self._bg_image.get_rect().width
        self._rect.height = self._bg_image.get_rect().height
        position = (Constants.WINDOW_W / 2 -
                    self._bg_image.get_rect().width / 2, 70)
        self.set_position(position)
        self._close_btn.set_position(position=(self._rect.topright[0] - 50,
                                               self._rect.topright[1] - 10))

        self._title_label = TextLabel(parent=self,
                                      position=self.position,
                                      font_size=16,
                                      bold=True)

        self.parent.add_render(self)
Example #3
0
 def add_hive_to_list(self, h):
     h_b = Button(parent=self, normal_image_path="hive/hive1_normal.png")
     socket_group = RadioGroup()
     sock_pos = 42, 0
     for socket in h.nest_group.buttons[:-1]:
         bs = BeeSocket(parent=self, group=socket_group, socket_type=socket.full_socket_type, position=sock_pos,
                        local_id=socket.local_id)
         bs.set_image_by_state(ButtonState.LOCKED, "socket3_normal.png")
         bs.set_image_by_state(ButtonState.SELECTED, "socket5_normal.png")
         if socket.is_locked:
             bs.lock()
         bs.change_image_size((28, 25))
         sock_pos = sock_pos[0] + bs.size[0] + 12, sock_pos[1]
     upg_label = TextLabel(parent=self, font_size=14, text=self.parent.localization.get_string("upgrade_button"))
     upg_btn = TextButton(parent=self, text_label=upg_label, normal_image_path="start_quest_btn_normal.png",
                          text_padding=(10, 0))
     upg_btn.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")
     upg_btn.set_image_by_state(ButtonState.LOCKED, "start_quest_btn_locked.png")
     upg_btn.set_position((h_b.size[0] + 20, 57))
     upg_btn.change_image_size((106, 25))
     price_label = TextLabel(parent=self, font_size=14,
                             text="{0} {1}/{2}".format(self.parent.localization.get_string("price"),
                                                       self.__wax_amount, 50))
     upg_btn.add_action({ButtonEventType.ON_CLICK_LB: lambda: self.upgrade_socket(socket_group=socket_group,
                                                                                  hive=h, price_label=price_label)})
     price_label.set_position((upg_btn.get_rect().right + 12, upg_btn.position[1]))
     hive_info_group = RenderGroup(parent=self, data={"img": h_b, "sockets": socket_group, "upg": upg_btn,
                                                      "price": price_label})
     i = ListItem(parent=self, data=hive_info_group, normal_image_path="hive_placeholder.png")
     self.hives_list_view.add_item(i)
Example #4
0
    def __init__(self, parent: Scene):
        Menu.__init__(self, parent=parent, bg_name="popup3")
        self._title_label = TextLabel(parent=self, text=self.parent.localization.get_string("hives"),
                                      position=self.position, font_size=16, bold=True)
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self._title_label.size[0] / 2 + 10,
             self.position[1] + 3)
        )

        self.hives_list_view = ListView(parent=self, size=(315, 410), item_padding=(8, 8), item_distance=(0, 15),
                                        position=(self.position[0] + 35, self.position[1] + 53))

        db = Database.get_instance()
        wax = db.get_resource_by_id(1)
        self.__wax_amount = 0

        for r in self.parent.player.resources.bag:
            if r.locale_name == wax.locale_name:
                self.__wax_amount = r.value

        self.hover_index = -1

        for h in self.parent.nest_group.buttons:
            if not h.hive:
                continue
            self.add_hive_to_list(h)

        self.parent.nest_group.stop_handle()
Example #5
0
 def generate_rewards_labels(self) -> None:
     self.rewards_labels.clear()
     pos_x = self.rewards_rect.x + 20
     pos_y = self.rewards_rect.y + 10
     for r in self.quest.rewards.bag:
         r_l = TextLabel(parent=self, text="{0}: {1}".format(r.locale_name, int(r.value)), bold=True, font_size=12)
         r_l.set_position((pos_x, pos_y))
         pos_y += r_l.size[1] - 5
         self.rewards_labels.append(r_l)
Example #6
0
 def __init__(self, main_window, name, player, quest: Quest) -> None:
     Scene.__init__(self, main_window=main_window, name=name, player=player)
     self._bg_image = pygame.image.load("{0}/images/{1}_bg.png".format(
         self._res_dir, name)).convert_alpha()
     self._quest = quest
     self._sec_to_finish = 60 + self._quest.time - len(
         self._quest.bee_list) * 5
     self._start_time = 0
     self.score = 0
     self._timer_label = TextLabel(parent=self,
                                   font_size=32,
                                   color=(255, 255, 255))
     self._timer_val_label = TextLabel(parent=self,
                                       font_size=32,
                                       color=(255, 255, 255))
     self._time_over = False
     self._score_label = TextLabel(parent=self,
                                   font_size=32,
                                   color=(255, 255, 255))
     self._score_val_label = TextLabel(parent=self,
                                       font_size=32,
                                       color=(255, 255, 255))
     finish_label = TextLabel(parent=self, font_size=24)
     self._finish_button = TextButton(
         parent=self,
         text_label=finish_label,
         normal_image_path="start_quest_btn_normal.png")
     self._finish_button.set_image_by_state(ButtonState.HOVERED,
                                            "start_quest_btn_hover.png")
     self._finish_button.add_action(
         {ButtonEventType.ON_CLICK_LB: lambda: self._finish_quest()})
Example #7
0
class Menu(RenderObject):
    __slots__ = ("_close_btn", "_bg_image", "_title_label")

    def __init__(self, parent: Scene, bg_name):
        RenderObject.__init__(self, parent=parent)
        self.parent.remove_render(
            self.parent.find_child_of(child=self, base=Menu))
        self._close_btn = Button(parent=self,
                                 normal_image_path="close_button1.png")
        self._close_btn.set_image_by_state(ButtonState.HOVERED,
                                           "close_button1_hover.png")
        self._close_btn.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.destroy()})

        self._bg_image = pygame.image.load("{0}/{1}.png".format(
            self._res_dir, bg_name)).convert_alpha()
        self._rect.width = self._bg_image.get_rect().width
        self._rect.height = self._bg_image.get_rect().height
        position = (Constants.WINDOW_W / 2 -
                    self._bg_image.get_rect().width / 2, 70)
        self.set_position(position)
        self._close_btn.set_position(position=(self._rect.topright[0] - 50,
                                               self._rect.topright[1] - 10))

        self._title_label = TextLabel(parent=self,
                                      position=self.position,
                                      font_size=16,
                                      bold=True)

        self.parent.add_render(self)

    def set_position(self, position: (int, int)) -> None:
        super().set_position(position)
        self._close_btn.set_position(position=(self._rect.topright[0] - 50,
                                               self._rect.topright[1] - 10))

    def destroy(self):
        self.parent.remove_render(self)

    def draw(self, screen: pygame.Surface) -> None:
        screen.blit(self._bg_image, self._rect)
        self._close_btn.draw(screen)
        self._title_label.draw(screen)

    def handle_event(self, event: Event) -> None:
        self._close_btn.handle_event(event)
Example #8
0
 def __init__(self,
              parent,
              position: (int, int),
              font_size: int,
              line_length: int,
              bold=False,
              color: tuple = (159, 80, 17),
              font_name: str = "segoeprint",
              text: str = "") -> None:
     self.__rendered_text = []
     self.line_length = line_length
     self.line_spacing = 2
     TextLabel.__init__(self,
                        parent=parent,
                        text=text,
                        position=position,
                        font_name=font_name,
                        font_size=font_size,
                        color=color,
                        bold=bold)
Example #9
0
class SettingsMenu(Menu):
    __slots__ = ("resolution_label", "resolution_val_bg",
                 "resolution_val_bg_rect", "lang_val_bg", "lang_bg_rect",
                 "right_resolution_button", "left_resolution_button",
                 "lang_label", "right_lang_button", "left_lang_button",
                 "current_resolution_label", "current_lang_label")

    def __init__(self, parent):
        Menu.__init__(self, parent=parent, bg_name="settings_bg")
        self._title_label.set_text(
            text=self.parent.localization.get_string("settings"))
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx -
             self._title_label.size[0] / 2 + 10, self.position[1] + 3))

        self.resolution_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=self.parent.localization.get_string("resolution"))

        right1 = TextLabel(parent=self, font_size=18, bold=True, text=">")
        self.right_resolution_button = TextButton(
            parent=self,
            text_label=right1,
            normal_image_path="left_right.png",
            text_padding=(10, -5))
        self.right_resolution_button.set_position(
            (self._rect.right - self.right_resolution_button.size[0] - 20,
             self.position[1] + 75))

        self.resolution_val_bg = pygame.image.load("{0}/settings.png".format(
            self._res_dir))
        self.resolution_val_bg_rect = self.resolution_val_bg.get_rect()
        self.resolution_val_bg_rect.right = self.right_resolution_button._rect.left - 6
        self.resolution_val_bg_rect.y = self.position[1] + 75

        self.lang_val_bg = pygame.image.load("{0}/settings.png".format(
            self._res_dir))
        self.lang_bg_rect = self.lang_val_bg.get_rect()
        self.lang_bg_rect.right = self.resolution_val_bg_rect.right
        self.lang_bg_rect.y = self.resolution_val_bg_rect.bottom + 15

        left1 = TextLabel(parent=self, font_size=18, bold=True, text="<")
        self.left_resolution_button = TextButton(
            parent=self,
            text_label=left1,
            normal_image_path="left_right.png",
            text_padding=(10, -5))
        self.left_resolution_button.set_position(
            (self.resolution_val_bg_rect.left -
             self.left_resolution_button.size[0] - 6, self.position[1] + 75))

        self.resolution_label.set_position(
            (self.left_resolution_button.get_rect().left -
             self.resolution_label.size[0] - 20, self.position[1] + 72))

        self.lang_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=self.parent.localization.get_string("lang"))

        right2 = TextLabel(parent=self, font_size=18, bold=True, text=">")
        self.right_lang_button = TextButton(parent=self,
                                            text_label=right2,
                                            normal_image_path="left_right.png",
                                            text_padding=(10, -5))
        self.right_lang_button.set_position(
            (self.right_resolution_button.position[0],
             self.right_resolution_button.get_rect().bottom + 15))

        left2 = TextLabel(parent=self, font_size=18, bold=True, text="<")

        self.left_lang_button = TextButton(parent=self,
                                           text_label=left2,
                                           normal_image_path="left_right.png",
                                           text_padding=(10, -5))
        self.left_lang_button.set_position(
            (self.left_resolution_button.position[0],
             self.left_resolution_button.get_rect().bottom + 15))

        self.lang_label.set_position(
            (self.left_lang_button.get_rect().left - self.lang_label.size[0] -
             20, self.resolution_label.get_rect().bottom + 8))

        self.left_resolution_button.set_image_by_state(ButtonState.HOVERED,
                                                       "left_right_hover.png")
        self.right_resolution_button.set_image_by_state(
            ButtonState.HOVERED, "left_right_hover.png")
        self.left_lang_button.set_image_by_state(ButtonState.HOVERED,
                                                 "left_right_hover.png")
        self.right_lang_button.set_image_by_state(ButtonState.HOVERED,
                                                  "left_right_hover.png")

        self.right_resolution_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_resolution(right=True)
        })
        self.left_resolution_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_resolution(right=False)
        })

        self.current_resolution_label = TextLabel(parent=self,
                                                  font_size=18,
                                                  bold=True,
                                                  text="{0}x{1}".format(
                                                      Constants.WINDOW_W,
                                                      Constants.WINDOW_H))
        self.current_resolution_label.get_rect(
        ).center = self.resolution_val_bg_rect.center

        self.current_lang_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=Localization.get_current_locale().upper())
        self.current_lang_label.get_rect().center = self.lang_bg_rect.center

        self.right_lang_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_lang(right=True)
        })
        self.left_lang_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_lang(right=False)
        })

        self.parent.stop_handle()

    def destroy(self):
        self.parent.remove_render(
            self.parent.find_render_by_type(SettingsMenu))
        super().destroy()
        self.parent.start_handle()

    def change_lang(self, right: bool) -> None:
        if right:
            self.parent.main_window.change_lang(
                Localization.get_full_locale().get_next())
        else:
            self.parent.main_window.change_lang(
                Localization.get_full_locale().get_prev())

        self.current_lang_label.set_text(
            Localization.get_current_locale().upper())
        db = Database.get_instance()
        old_resources = []
        for r in self.parent.player.resources.bag:
            old_resources.append(r)
        self.parent.player.resources.bag.clear()

        for i in range(len(old_resources)):
            r = db.get_resource_by_id(old_resources[i].r_id)
            r.value = old_resources[i].value
            self.parent.player.resources.append(r)

        for b in itertools.chain(self.parent.player.farm.bees_from_all_hives,
                                 self.parent.player.farm.out_of_hive_bee_list):
            b.set_locale_to_bonus()

    def change_resolution(self, right: bool) -> None:
        index = Constants.SIZE.index((Constants.WINDOW_W, Constants.WINDOW_H))
        index = index + (1 if right else -1)
        if index == len(Constants.SIZE):
            index = 0
        print("Next", Constants.SIZE[index])
        Constants.WINDOW_W, Constants.WINDOW_H = Constants.SIZE[index]
        self.current_resolution_label.set_text(
            text="{0}x{1}".format(Constants.WINDOW_W, Constants.WINDOW_H))
        self.current_resolution_label.get_rect(
        ).center = self.resolution_val_bg_rect.center
        self.parent.main_window.change_resolution(Constants.SIZE[index])

    def handle_event(self, event: Event) -> None:
        super().handle_event(event)
        self.left_resolution_button.handle_event(event)
        self.right_resolution_button.handle_event(event)
        self.left_lang_button.handle_event(event)
        self.right_lang_button.handle_event(event)

    def draw(self, screen: pygame.Surface) -> None:
        super().draw(screen)
        self.resolution_label.draw(screen)
        screen.blit(self.resolution_val_bg, self.resolution_val_bg_rect)
        screen.blit(self.lang_val_bg, self.lang_bg_rect)
        self.right_resolution_button.draw(screen)
        self.left_resolution_button.draw(screen)
        self.lang_label.draw(screen)
        self.right_lang_button.draw(screen)
        self.left_lang_button.draw(screen)
        self.current_resolution_label.draw(screen)
        self.current_lang_label.draw(screen)
Example #10
0
    def __init__(self, parent, quest: Quest) -> None:
        Menu.__init__(self, parent=parent, bg_name="popup3")
        self.quest = quest
        self._title_label.set_text(text=self.quest.title)
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self._title_label.size[0] / 2 + 10,
             self.position[1] + 3)
        )

        self.panel_rect = pygame.Rect((self.position[0] + 15, self.position[1] + 155, self.size[0] - 15 * 2, 277))

        ll = self._bg_image.get_rect().width - self.parent.localization.get_params_by_string("desc_label")[
            "line_length"] * 2 - 35
        self.description_label = MultilineTextLabel(parent=self, text=self.quest.description, line_length=ll,
                                                    position=(self.position[0] + 35, self.position[1] + 75),
                                                    font_size=14)
        self.difficult_label = TextLabel(parent=self, text=self.parent.localization.get_string("difficult_label"),
                                         position=(self.position[0], self.panel_rect.y + 10), font_size=14)

        self.rewards_label = TextLabel(parent=self, text=self.parent.localization.get_string("reward_label"),
                                       position=self.position, font_size=14, )

        easy_label = TextLabel(parent=self, text=self.parent.localization.get_string("easy"), font_size=14)
        self.easy_button = TextButton(parent=self, normal_image_path="difficult/easy_normal.png",
                                      text_label=easy_label, text_padding=(19, 0))
        self.easy_button.set_position(
            (self.position[0] + 35, self.difficult_label.position[1] + self.difficult_label.size[1] + 9)
        )
        self.easy_button.set_image_by_state(ButtonState.HOVERED, "difficult/easy_hovered.png")

        medium_label = TextLabel(parent=self, text=self.parent.localization.get_string("medium"), font_size=14,
                                 color=(138, 36, 12))
        self.medium_button = TextButton(parent=self,
                                        normal_image_path="difficult/medium_normal.png",
                                        text_label=medium_label, text_padding=(19, 0))
        self.medium_button.set_position(
            (self.easy_button.position[0], self.easy_button.position[1] + self.easy_button.size[1])
        )
        self.medium_button.set_image_by_state(ButtonState.HOVERED,
                                              "difficult/medium_hovered.png")

        hard_label = TextLabel(parent=self, text=self.parent.localization.get_string("hard"), font_size=14,
                               color=(159, 17, 17))
        self.hard_button = TextButton(parent=self, normal_image_path="difficult/hard_normal.png",
                                      text_label=hard_label, text_padding=(19, 0))
        self.hard_button.set_position(
            (self.medium_button.position[0], self.medium_button.position[1] + self.medium_button.size[1])
        )
        self.hard_button.set_image_by_state(ButtonState.HOVERED, "difficult/hard_hovered.png")

        self.rewards_panel = pygame.image.load("{0}/rewards_list_bg.png".format(self._res_dir))

        self.bonuses_panel = pygame.image.load(
            "{0}/buttons/difficult/bonuses.png".format(self._res_dir)).convert_alpha()
        self.bonuses_rect = self.bonuses_panel.get_rect()
        self.bonuses_rect.x = self.easy_button.position[0] + self.easy_button.size[0]
        self.bonuses_rect.y = self.easy_button.position[1]

        self.difficult_label.set_position(
            (self.easy_button.position[0] + (self.easy_button.size[0] + self.bonuses_rect.width) / 2
             - self.difficult_label.size[0] / 2, self.difficult_label.position[1])
        )

        self.bonus_list = []

        self.rewards_rect = self.rewards_panel.get_rect()

        bs_start_y = self.bonuses_rect.y
        self.bee_socket_group = RadioGroup()
        all_bees = self.parent.player.farm.bees_from_all_hives
        for i in range(3):
            b = BeeSocket(parent=self, can_change_id=False,
                          group=self.bee_socket_group, socket_type=BeeSocketType.WORKER,
                          position=(self.bonuses_rect.x + self.bonuses_rect.width + 46, bs_start_y))
            b.show_select_panel(self, all_bees)
            b.remove(self)
            bs_start_y += b.size[1] + 8

        self.bee_socket_hard = BeeSocket(parent=self,
                                         socket_type=BeeSocketType.WARRIOR, group=self.bee_socket_group,
                                         state=ButtonState.LOCKED, can_change_id=False,
                                         position=(self.bonuses_rect.x + self.bonuses_rect.width + 46, bs_start_y + 15))
        self.bee_socket_hard.set_image_by_state(ButtonState.LOCKED, "socket3_normal.png")

        self.bee_socket_hard.show_select_panel(self, all_bees)

        start_label = TextLabel(parent=self, text=self.parent.localization.get_string("start_button"), position=(0, 0),
                                font_size=24)
        self.start_button = TextButton(parent=self, text_label=start_label, text_padding=(
            self.parent.localization.get_params_by_string("start_button")["x_off"], 0),
                                       normal_image_path="start_quest_btn_normal.png")
        self.start_button.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self.start_button.size[0] / 2,
             self.panel_rect.y + self.panel_rect.height + 33)
        )
        self.start_button.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")

        self.rewards_labels = []

        self.rewards_rect.x = self.position[0] + 35
        self.rewards_rect.y = self.bonuses_rect.y + self.bonuses_rect.height + 41

        self.rewards_label.set_position(
            (self.rewards_rect.centerx - self.rewards_label.size[0] / 2,
             self.bonuses_rect.y + self.bonuses_rect.height + 8)
        )

        self.easy_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.EASY: self.change_difficult(d)}
        )
        self.medium_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.MEDIUM: self.change_difficult(d)}
        )
        self.hard_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.HARD: self.change_difficult(d)}
        )
        self.start_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.start_quest()}
        )

        self.change_difficult(QuestDifficult.EASY)

        for z in self.parent.zones:
            z.stop_handle()
Example #11
0
class QuestMenu(Menu):
    __slots__ = ("quest", "quest_settings", "panel_rect", "description_label", "difficult_label", "rewards_label",
                 "easy_button", "medium_button", "hard_button", "rewards_panel", "bonuses_panel", "bonuses_rect",
                 "bonus_list", "bee_socket_group", "bee_socket_hard", "start_button", "rewards_labels", "rewards_rect")

    def __init__(self, parent, quest: Quest) -> None:
        Menu.__init__(self, parent=parent, bg_name="popup3")
        self.quest = quest
        self._title_label.set_text(text=self.quest.title)
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self._title_label.size[0] / 2 + 10,
             self.position[1] + 3)
        )

        self.panel_rect = pygame.Rect((self.position[0] + 15, self.position[1] + 155, self.size[0] - 15 * 2, 277))

        ll = self._bg_image.get_rect().width - self.parent.localization.get_params_by_string("desc_label")[
            "line_length"] * 2 - 35
        self.description_label = MultilineTextLabel(parent=self, text=self.quest.description, line_length=ll,
                                                    position=(self.position[0] + 35, self.position[1] + 75),
                                                    font_size=14)
        self.difficult_label = TextLabel(parent=self, text=self.parent.localization.get_string("difficult_label"),
                                         position=(self.position[0], self.panel_rect.y + 10), font_size=14)

        self.rewards_label = TextLabel(parent=self, text=self.parent.localization.get_string("reward_label"),
                                       position=self.position, font_size=14, )

        easy_label = TextLabel(parent=self, text=self.parent.localization.get_string("easy"), font_size=14)
        self.easy_button = TextButton(parent=self, normal_image_path="difficult/easy_normal.png",
                                      text_label=easy_label, text_padding=(19, 0))
        self.easy_button.set_position(
            (self.position[0] + 35, self.difficult_label.position[1] + self.difficult_label.size[1] + 9)
        )
        self.easy_button.set_image_by_state(ButtonState.HOVERED, "difficult/easy_hovered.png")

        medium_label = TextLabel(parent=self, text=self.parent.localization.get_string("medium"), font_size=14,
                                 color=(138, 36, 12))
        self.medium_button = TextButton(parent=self,
                                        normal_image_path="difficult/medium_normal.png",
                                        text_label=medium_label, text_padding=(19, 0))
        self.medium_button.set_position(
            (self.easy_button.position[0], self.easy_button.position[1] + self.easy_button.size[1])
        )
        self.medium_button.set_image_by_state(ButtonState.HOVERED,
                                              "difficult/medium_hovered.png")

        hard_label = TextLabel(parent=self, text=self.parent.localization.get_string("hard"), font_size=14,
                               color=(159, 17, 17))
        self.hard_button = TextButton(parent=self, normal_image_path="difficult/hard_normal.png",
                                      text_label=hard_label, text_padding=(19, 0))
        self.hard_button.set_position(
            (self.medium_button.position[0], self.medium_button.position[1] + self.medium_button.size[1])
        )
        self.hard_button.set_image_by_state(ButtonState.HOVERED, "difficult/hard_hovered.png")

        self.rewards_panel = pygame.image.load("{0}/rewards_list_bg.png".format(self._res_dir))

        self.bonuses_panel = pygame.image.load(
            "{0}/buttons/difficult/bonuses.png".format(self._res_dir)).convert_alpha()
        self.bonuses_rect = self.bonuses_panel.get_rect()
        self.bonuses_rect.x = self.easy_button.position[0] + self.easy_button.size[0]
        self.bonuses_rect.y = self.easy_button.position[1]

        self.difficult_label.set_position(
            (self.easy_button.position[0] + (self.easy_button.size[0] + self.bonuses_rect.width) / 2
             - self.difficult_label.size[0] / 2, self.difficult_label.position[1])
        )

        self.bonus_list = []

        self.rewards_rect = self.rewards_panel.get_rect()

        bs_start_y = self.bonuses_rect.y
        self.bee_socket_group = RadioGroup()
        all_bees = self.parent.player.farm.bees_from_all_hives
        for i in range(3):
            b = BeeSocket(parent=self, can_change_id=False,
                          group=self.bee_socket_group, socket_type=BeeSocketType.WORKER,
                          position=(self.bonuses_rect.x + self.bonuses_rect.width + 46, bs_start_y))
            b.show_select_panel(self, all_bees)
            b.remove(self)
            bs_start_y += b.size[1] + 8

        self.bee_socket_hard = BeeSocket(parent=self,
                                         socket_type=BeeSocketType.WARRIOR, group=self.bee_socket_group,
                                         state=ButtonState.LOCKED, can_change_id=False,
                                         position=(self.bonuses_rect.x + self.bonuses_rect.width + 46, bs_start_y + 15))
        self.bee_socket_hard.set_image_by_state(ButtonState.LOCKED, "socket3_normal.png")

        self.bee_socket_hard.show_select_panel(self, all_bees)

        start_label = TextLabel(parent=self, text=self.parent.localization.get_string("start_button"), position=(0, 0),
                                font_size=24)
        self.start_button = TextButton(parent=self, text_label=start_label, text_padding=(
            self.parent.localization.get_params_by_string("start_button")["x_off"], 0),
                                       normal_image_path="start_quest_btn_normal.png")
        self.start_button.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self.start_button.size[0] / 2,
             self.panel_rect.y + self.panel_rect.height + 33)
        )
        self.start_button.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")

        self.rewards_labels = []

        self.rewards_rect.x = self.position[0] + 35
        self.rewards_rect.y = self.bonuses_rect.y + self.bonuses_rect.height + 41

        self.rewards_label.set_position(
            (self.rewards_rect.centerx - self.rewards_label.size[0] / 2,
             self.bonuses_rect.y + self.bonuses_rect.height + 8)
        )

        self.easy_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.EASY: self.change_difficult(d)}
        )
        self.medium_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.MEDIUM: self.change_difficult(d)}
        )
        self.hard_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda d=QuestDifficult.HARD: self.change_difficult(d)}
        )
        self.start_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.start_quest()}
        )

        self.change_difficult(QuestDifficult.EASY)

        for z in self.parent.zones:
            z.stop_handle()

    def start_quest(self) -> None:
        bee_list = []
        for b in self.bee_socket_group.buttons:
            if b.bee:
                bee_list.append(b.bee)

        self.quest.bee_list = bee_list
        if self.quest.q_type == 1:
            q = Match3Scene(main_window=self.parent.main_window, name="Match3", player=self.parent.player,
                            quest=self.quest)
        elif self.quest.q_type == 4:
            q = BeenixScene(main_window=self.parent.main_window, name="Beenix", player=self.parent.player,
                            quest=self.quest)
        else:
            q = Match3Scene(main_window=self.parent.main_window, name="Match3", player=self.parent.player,
                            quest=self.quest)

        self.parent.add_scene(scene_name=q.name, scene=q)
        self.parent.change_scene(q.name)

    def remove_bee_from_socket(self, socket) -> None:
        socket.bee.remove_bonus(self.quest)
        self.change_difficult(self.quest.difficult)

    def add_bee_to_socket(self, b: Bee) -> None:
        b.setup_bonus(self.quest)
        self.change_difficult(self.quest.difficult)

    def generate_bonuses_labels(self) -> None:
        start_pos_y = self.bonuses_rect.y
        self.bonus_list.clear()
        for bs in self.bee_socket_group.buttons:
            if bs.bee:
                b_l = MultilineTextLabel(parent=self, text=bs.bee.bonus.description, bold=True, line_length=130,
                                         font_size=12, position=(self.bonuses_rect.x + 5, start_pos_y))
                self.bonus_list.append(b_l)
                start_pos_y += b_l.size[1]
        self.generate_rewards_labels()

    def generate_rewards_labels(self) -> None:
        self.rewards_labels.clear()
        pos_x = self.rewards_rect.x + 20
        pos_y = self.rewards_rect.y + 10
        for r in self.quest.rewards.bag:
            r_l = TextLabel(parent=self, text="{0}: {1}".format(r.locale_name, int(r.value)), bold=True, font_size=12)
            r_l.set_position((pos_x, pos_y))
            pos_y += r_l.size[1] - 5
            self.rewards_labels.append(r_l)

    def change_difficult(self, difficult: QuestDifficult) -> None:
        self.quest.difficult = difficult
        bag = self.quest.rewards.bag
        if difficult == QuestDifficult.EASY:
            percent = self.quest.resources_modifier * 0
        elif difficult == QuestDifficult.MEDIUM:
            percent = self.quest.resources_modifier + 15
        else:
            percent = self.quest.resources_modifier + 35

        for r in bag:
            r.increase_by_percent(percent)

        self.bee_socket_hard.lock() if difficult != QuestDifficult.HARD else self.bee_socket_hard.unlock()

        self.rewards_labels.clear()
        self.generate_rewards_labels()

    def destroy(self) -> None:
        for z in self.parent.zones:
            z.start_handle()
        self.parent.remove_render(self.parent.find_render_by_type(BeeSelectPanel))
        super().destroy()

    def draw(self, screen: pygame.Surface) -> None:
        super().draw(screen)
        pygame.draw.rect(screen, (24, 15, 7), self.panel_rect)
        self.description_label.draw(screen)
        self.difficult_label.draw(screen)
        self.easy_button.draw(screen)
        self.medium_button.draw(screen)
        self.hard_button.draw(screen)
        self.start_button.draw(screen)
        screen.blit(self.rewards_panel, self.rewards_rect)
        [r_l.draw(screen) for r_l in self.rewards_labels]
        self.rewards_label.draw(screen)
        screen.blit(self.bonuses_panel, self.bonuses_rect)
        [b_l.draw(screen) for b_l in self.bonus_list]
        self.bee_socket_group.draw(screen)

    def update(self, dt: float) -> None:
        self.generate_bonuses_labels()

    def handle_event(self, event: Event) -> None:
        super().handle_event(event)
        self.easy_button.handle_event(event)
        self.medium_button.handle_event(event)
        self.hard_button.handle_event(event)
        self.start_button.handle_event(event)
        self.bee_socket_group.handle_event(event)
Example #12
0
    def __init__(self, parent: Scene) -> None:
        Menu.__init__(self, parent=parent, bg_name="modify_popup1")
        self._title_label.set_text(
            text=self.parent.localization.get_string("modify_title"))
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx -
             self._title_label.size[0] / 2 + 10, self.position[1] + 3))
        self.socket_group = RadioGroup()
        self.socket1 = BeeSocket(parent=self,
                                 socket_type=BeeSocketType.ALL,
                                 group=self.socket_group,
                                 position=(self.position[0] + 102,
                                           self.position[1] + 135))
        self.socket1.set_image_by_state(ButtonState.SELECTED,
                                        "socket5_normal.png")
        self.dna_image = pygame.image.load("{0}/dna1.png".format(
            self._res_dir)).convert_alpha()
        self.dna_rect = self.dna_image.get_rect()
        self.dna_rect.x = self.socket1.position[0] + self.socket1.size[1] + 12
        self.dna_rect.y = self.socket1.get_rect(
        ).centery - self.dna_rect.height / 2
        self.socket2 = BeeSocket(
            parent=self,
            socket_type=BeeSocketType.ALL,
            group=self.socket_group,
            position=(self.dna_rect.x + self.dna_rect.width + 7,
                      self.socket1.position[1]))
        self.socket2.set_image_by_state(ButtonState.SELECTED,
                                        "socket5_normal.png")

        upgrade_label = TextLabel(
            parent=self,
            text=self.parent.localization.get_string("upgrade_button"),
            font_size=18)
        self.upgrade_button = TextButton(
            parent=self,
            normal_image_path="start_quest_btn_normal.png",
            text_label=upgrade_label,
            text_padding=(40, 4))
        self.upgrade_button.set_image_by_state(ButtonState.HOVERED,
                                               "start_quest_btn_hover.png")
        self.upgrade_button.set_image_by_state(ButtonState.LOCKED,
                                               "start_quest_btn_locked.png")
        self.upgrade_button.lock()
        self.upgrade_button.set_position(
            (self.socket1.position[0],
             self.socket2.position[1] + self.socket2.size[1] + 15))
        self.upgrade_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.upgrade()})

        self.result_socket = BeeSocket(parent=self,
                                       group=self.socket_group,
                                       position=(0, 0),
                                       socket_type=BeeSocketType.ALL)
        self.result_socket.set_image_by_state(ButtonState.SELECTED,
                                              "socket5_normal.png")
        self.result_socket.set_image_by_state(ButtonState.LOCKED,
                                              "socket3_normal.png")
        self.result_socket.lock()
        self.result_socket.set_position(
            (self.upgrade_button.get_rect().centerx -
             self.result_socket.size[1] / 2, self.upgrade_button.position[1] +
             self.upgrade_button.size[1] + 15))
        self.result_socket.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.pick_new_bee()})

        self.info_block_image = pygame.image.load(
            "{0}/modify_popup1_info.png".format(self._res_dir))
        self.info_block_rect = self.info_block_image.get_rect()
        self.info_text_label = TextLabel(
            parent=self,
            text=self.parent.localization.get_string("info_label"),
            font_size=14)

        self.info_block_rect.x = self.upgrade_button.position[
            0] + self.upgrade_button.size[0] + 95
        self.info_block_rect.y = self.position[1] + 71
        self.info_text_label.set_position(
            (self.info_block_rect.centerx - self.info_text_label.size[0] / 2,
             self.info_block_rect.y))

        name_label = MultilineTextLabel(parent=self,
                                        font_size=14,
                                        line_length=220,
                                        position=(self.info_block_rect.x + 25,
                                                  self.info_block_rect.y + 40))

        generation_label = TextLabel(
            parent=self,
            font_size=14,
            position=(name_label.position[0],
                      name_label.position[1] + name_label.size[1]))

        level_label = TextLabel(
            parent=self,
            font_size=14,
            position=(generation_label.position[0],
                      generation_label.position[1] + generation_label.size[1]))

        xp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(level_label.position[0],
                      level_label.position[1] + level_label.size[1]))

        speed_label = TextLabel(
            parent=self,
            font_size=14,
            position=(xp_label.position[0],
                      xp_label.position[1] + xp_label.size[1]))

        hp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(speed_label.position[0],
                      speed_label.position[1] + speed_label.size[1]))

        bonus_list_label = MultilineTextLabel(
            parent=self,
            font_size=14,
            line_length=220,
            position=(hp_label.position[0],
                      hp_label.position[1] + hp_label.size[1]))

        self.info_group = RenderGroup(parent=self,
                                      data={
                                          "b_name": name_label,
                                          "b_gen": generation_label,
                                          "b_level": level_label,
                                          "b_exp": xp_label,
                                          "b_speed": speed_label,
                                          "b_hp": hp_label,
                                          "b_bonus": bonus_list_label
                                      })

        self.bee_list_view = ListView(
            parent=self,
            size=(625, 253),
            padding=(30, 9),
            item_distance=(15, 15),
            position=(self.position[0] + 9, self.info_block_rect.y +
                      self.info_block_rect.height - 6))
        self.bee_list_view.set_image("{0}/modify_popup1_bee_list.png".format(
            self._res_dir))

        db = Database.get_instance()
        worker_dna_name = db.get_resource_by_id(3).locale_name
        warrior_dna_name = db.get_resource_by_id(4).locale_name
        queen_dna_name = db.get_resource_by_id(5).locale_name
        jelly_name = db.get_resource_by_id(2).locale_name

        dna_list = []
        for r in self.parent.player.resources.bag:
            if r.locale_name == worker_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="worker", r=r))
            if r.locale_name == warrior_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="warrior", r=r))
            if r.locale_name == queen_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="queen", r=r))
            if r.locale_name == jelly_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="jelly", r=r))

        for b in itertools.chain(dna_list,
                                 self.parent.player.farm.out_of_hive_bee_list,
                                 self.parent.player.farm.bees_from_all_hives):
            self.add_bee_to_list(b)

        self.socket1.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.add_bee_to_socket()})
        self.socket1.add_action({
            ButtonEventType.ON_CLICK_RB:
            lambda: self.remove_bee_from_socket(self.socket1)
        })
        self.socket1.add_action({
            ButtonEventType.ON_HOVER_OUT:
            lambda: self.reload_bee_info(self.socket1.bee)
        })

        self.socket2.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.add_bee_to_socket()})
        self.socket2.add_action({
            ButtonEventType.ON_CLICK_RB:
            lambda: self.remove_bee_from_socket(self.socket2)
        })
        self.socket2.add_action({
            ButtonEventType.ON_HOVER_OUT:
            lambda: self.reload_bee_info(self.socket2.bee)
        })

        self.clear_bee_info()

        self.parent.nest_group.stop_handle()
Example #13
0
class ModifyMenu(Menu):
    __slots__ = ("socket_group", "socket1", "socket2", "upgrade_button",
                 "result_socket", "info_block_image", "info_block_rect",
                 "info_text_label", "info_group", "bee_list_view", "dna_image",
                 "dna_rect")

    def __init__(self, parent: Scene) -> None:
        Menu.__init__(self, parent=parent, bg_name="modify_popup1")
        self._title_label.set_text(
            text=self.parent.localization.get_string("modify_title"))
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx -
             self._title_label.size[0] / 2 + 10, self.position[1] + 3))
        self.socket_group = RadioGroup()
        self.socket1 = BeeSocket(parent=self,
                                 socket_type=BeeSocketType.ALL,
                                 group=self.socket_group,
                                 position=(self.position[0] + 102,
                                           self.position[1] + 135))
        self.socket1.set_image_by_state(ButtonState.SELECTED,
                                        "socket5_normal.png")
        self.dna_image = pygame.image.load("{0}/dna1.png".format(
            self._res_dir)).convert_alpha()
        self.dna_rect = self.dna_image.get_rect()
        self.dna_rect.x = self.socket1.position[0] + self.socket1.size[1] + 12
        self.dna_rect.y = self.socket1.get_rect(
        ).centery - self.dna_rect.height / 2
        self.socket2 = BeeSocket(
            parent=self,
            socket_type=BeeSocketType.ALL,
            group=self.socket_group,
            position=(self.dna_rect.x + self.dna_rect.width + 7,
                      self.socket1.position[1]))
        self.socket2.set_image_by_state(ButtonState.SELECTED,
                                        "socket5_normal.png")

        upgrade_label = TextLabel(
            parent=self,
            text=self.parent.localization.get_string("upgrade_button"),
            font_size=18)
        self.upgrade_button = TextButton(
            parent=self,
            normal_image_path="start_quest_btn_normal.png",
            text_label=upgrade_label,
            text_padding=(40, 4))
        self.upgrade_button.set_image_by_state(ButtonState.HOVERED,
                                               "start_quest_btn_hover.png")
        self.upgrade_button.set_image_by_state(ButtonState.LOCKED,
                                               "start_quest_btn_locked.png")
        self.upgrade_button.lock()
        self.upgrade_button.set_position(
            (self.socket1.position[0],
             self.socket2.position[1] + self.socket2.size[1] + 15))
        self.upgrade_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.upgrade()})

        self.result_socket = BeeSocket(parent=self,
                                       group=self.socket_group,
                                       position=(0, 0),
                                       socket_type=BeeSocketType.ALL)
        self.result_socket.set_image_by_state(ButtonState.SELECTED,
                                              "socket5_normal.png")
        self.result_socket.set_image_by_state(ButtonState.LOCKED,
                                              "socket3_normal.png")
        self.result_socket.lock()
        self.result_socket.set_position(
            (self.upgrade_button.get_rect().centerx -
             self.result_socket.size[1] / 2, self.upgrade_button.position[1] +
             self.upgrade_button.size[1] + 15))
        self.result_socket.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.pick_new_bee()})

        self.info_block_image = pygame.image.load(
            "{0}/modify_popup1_info.png".format(self._res_dir))
        self.info_block_rect = self.info_block_image.get_rect()
        self.info_text_label = TextLabel(
            parent=self,
            text=self.parent.localization.get_string("info_label"),
            font_size=14)

        self.info_block_rect.x = self.upgrade_button.position[
            0] + self.upgrade_button.size[0] + 95
        self.info_block_rect.y = self.position[1] + 71
        self.info_text_label.set_position(
            (self.info_block_rect.centerx - self.info_text_label.size[0] / 2,
             self.info_block_rect.y))

        name_label = MultilineTextLabel(parent=self,
                                        font_size=14,
                                        line_length=220,
                                        position=(self.info_block_rect.x + 25,
                                                  self.info_block_rect.y + 40))

        generation_label = TextLabel(
            parent=self,
            font_size=14,
            position=(name_label.position[0],
                      name_label.position[1] + name_label.size[1]))

        level_label = TextLabel(
            parent=self,
            font_size=14,
            position=(generation_label.position[0],
                      generation_label.position[1] + generation_label.size[1]))

        xp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(level_label.position[0],
                      level_label.position[1] + level_label.size[1]))

        speed_label = TextLabel(
            parent=self,
            font_size=14,
            position=(xp_label.position[0],
                      xp_label.position[1] + xp_label.size[1]))

        hp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(speed_label.position[0],
                      speed_label.position[1] + speed_label.size[1]))

        bonus_list_label = MultilineTextLabel(
            parent=self,
            font_size=14,
            line_length=220,
            position=(hp_label.position[0],
                      hp_label.position[1] + hp_label.size[1]))

        self.info_group = RenderGroup(parent=self,
                                      data={
                                          "b_name": name_label,
                                          "b_gen": generation_label,
                                          "b_level": level_label,
                                          "b_exp": xp_label,
                                          "b_speed": speed_label,
                                          "b_hp": hp_label,
                                          "b_bonus": bonus_list_label
                                      })

        self.bee_list_view = ListView(
            parent=self,
            size=(625, 253),
            padding=(30, 9),
            item_distance=(15, 15),
            position=(self.position[0] + 9, self.info_block_rect.y +
                      self.info_block_rect.height - 6))
        self.bee_list_view.set_image("{0}/modify_popup1_bee_list.png".format(
            self._res_dir))

        db = Database.get_instance()
        worker_dna_name = db.get_resource_by_id(3).locale_name
        warrior_dna_name = db.get_resource_by_id(4).locale_name
        queen_dna_name = db.get_resource_by_id(5).locale_name
        jelly_name = db.get_resource_by_id(2).locale_name

        dna_list = []
        for r in self.parent.player.resources.bag:
            if r.locale_name == worker_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="worker", r=r))
            if r.locale_name == warrior_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="warrior", r=r))
            if r.locale_name == queen_dna_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="queen", r=r))
            if r.locale_name == jelly_name:
                for i in range(r.value):
                    dna_list.append(
                        DNAEntity(parent=self, dna_type="jelly", r=r))

        for b in itertools.chain(dna_list,
                                 self.parent.player.farm.out_of_hive_bee_list,
                                 self.parent.player.farm.bees_from_all_hives):
            self.add_bee_to_list(b)

        self.socket1.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.add_bee_to_socket()})
        self.socket1.add_action({
            ButtonEventType.ON_CLICK_RB:
            lambda: self.remove_bee_from_socket(self.socket1)
        })
        self.socket1.add_action({
            ButtonEventType.ON_HOVER_OUT:
            lambda: self.reload_bee_info(self.socket1.bee)
        })

        self.socket2.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.add_bee_to_socket()})
        self.socket2.add_action({
            ButtonEventType.ON_CLICK_RB:
            lambda: self.remove_bee_from_socket(self.socket2)
        })
        self.socket2.add_action({
            ButtonEventType.ON_HOVER_OUT:
            lambda: self.reload_bee_info(self.socket2.bee)
        })

        self.clear_bee_info()

        self.parent.nest_group.stop_handle()

    def destroy(self):
        if not self.result_socket.is_locked:
            self.pick_new_bee()
        self.parent.nest_group.start_handle()
        super().destroy()

    def kill_bee(self, socket: BeeSocket) -> None:
        self.parent.player.farm.kill_bee(socket.bee)
        for h in self.parent.nest_group.buttons:
            for bs in h.nest_group.buttons:
                if bs.bee:
                    if bs.bee == socket.bee:
                        del bs.bee
                        break
        del socket.bee

    def pick_new_bee(self):
        self.parent.player.farm.add_out_of_hive_bee(self.result_socket.bee)
        self.add_bee_to_list(self.result_socket.bee)
        del self.result_socket.bee
        self.result_socket.lock()

    def upgrade(self):
        self.upgrade_button.lock()

        bee = self.socket1.bee + self.socket2.bee

        if not bee:
            return

        remove_bag = ResourceBag()
        db = Database.get_instance()
        if not isinstance(self.socket1.bee, Bee):
            r1 = db.get_resource_by_id(self.socket1.bee.resource.r_id)
            r1.value = 1
            remove_bag.append(r1)

        if not isinstance(self.socket2.bee, Bee):
            r2 = db.get_resource_by_id(self.socket2.bee.resource.r_id)
            r2.value = 1
            remove_bag.append(r2)

        self.parent.player.resources -= remove_bag

        self.kill_bee(self.socket1)
        self.kill_bee(self.socket2)
        self.result_socket.unlock()
        self.result_socket.select()
        self.result_socket.bee = bee
        self.reload_bee_info()

    def add_bee_to_list(self, b: Bee) -> None:
        i = ListItem(parent=self,
                     data=b,
                     normal_image_path="holder1.png",
                     center=True)
        i.set_image_by_state(ButtonState.LOCKED, "holder1_lock.png")
        i.set_image_by_state(ButtonState.HOVERED, "holder1_hover.png")
        i.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda e=i: self.select_bee(e)})
        i.add_action({
            ButtonEventType.ON_HOVER_ON:
            lambda e=i.data: self.reload_bee_info(e)
        })
        i.add_action(
            {ButtonEventType.ON_HOVER_OUT: lambda: self.reload_bee_info()})
        self.bee_list_view.add_item(i)

    def remove_bee_from_socket(self, socket: BeeSocket) -> None:
        socket.select()
        if self.socket_group.current_button.bee:
            self.add_bee_to_list(self.socket_group.current_button.bee)
            del self.socket_group.current_button.bee
            self.clear_bee_info()
            self.upgrade_button.lock()

    def select_bee(self, list_item: ListItem) -> None:
        if self.socket_group.current_button:
            if self.socket_group.current_button.bee:
                self.remove_bee_from_socket(self.socket_group.current_button)

            self.socket_group.current_button.bee = list_item.data
            self.bee_list_view.remove_item(list_item)

        if self.socket1.bee and self.socket2.bee:
            self.upgrade_button.unlock()
        else:
            self.upgrade_button.lock()

        self.reload_bee_info()

    def add_bee_to_socket(self) -> None:
        if self.socket_group.current_button:
            if self.socket_group.current_button.bee:
                self.reload_bee_info()
            else:
                self.clear_bee_info()

    def clear_bee_info(self) -> None:
        for k, v in self.info_group.group.items():
            v.set_text(text=self.parent.localization.get_string(k))
        self.set_info_position()

    def set_info_position(self):
        self.info_group["b_name"].set_position(
            (self.info_block_rect.x + 25, self.info_block_rect.y + 40))

        self.info_group["b_gen"].set_position(
            (self.info_group["b_name"].position[0],
             self.info_group["b_name"].position[1] +
             self.info_group["b_name"].size[1]))

        self.info_group["b_level"].set_position(
            (self.info_group["b_gen"].position[0],
             self.info_group["b_gen"].position[1] +
             self.info_group["b_gen"].size[1]))
        self.info_group["b_exp"].set_position(
            (self.info_group["b_level"].position[0],
             self.info_group["b_level"].position[1] +
             self.info_group["b_level"].size[1]))
        self.info_group["b_speed"].set_position(
            (self.info_group["b_exp"].position[0],
             self.info_group["b_exp"].position[1] +
             self.info_group["b_exp"].size[1]))
        self.info_group["b_hp"].set_position(
            (self.info_group["b_speed"].position[0],
             self.info_group["b_speed"].position[1] +
             self.info_group["b_speed"].size[1]))
        self.info_group["b_bonus"].set_position(
            (self.info_group["b_hp"].position[0],
             self.info_group["b_hp"].position[1] +
             self.info_group["b_hp"].size[1]))

    def reload_bee_info(self, b: Bee = None) -> None:
        if b is None and self.socket_group.current_button:
            b = self.socket_group.current_button.bee
        if not b:
            return

        if isinstance(b, DNAEntity):
            self.info_group.hide()
            self.info_group["b_name"].set_text(text="{0} {1}".format(
                self.parent.localization.get_string("b_desc"),
                b.resource.locale_desc))

            self.info_group["b_name"].show()
        else:
            self.info_group.show()

        try:
            self.info_group["b_name"].set_text(text="{0} {1}".format(
                self.parent.localization.get_string("b_name"), b.name))

            self.info_group["b_gen"].set_text(text="{0} {1}".format(
                self.parent.localization.get_string("b_gen"), b.generation))

            self.info_group["b_level"].set_text(text="{0} {1}".format(
                self.parent.localization.get_string("b_level"),
                b.current_level))

            self.info_group["b_exp"].set_text(text="{0} {1}/{2}".format(
                self.parent.localization.get_string("b_exp"), b.current_xp,
                b.max_xp))

            if isinstance(b, BeeQueen):
                self.info_group["b_speed"].hide()
                self.info_group["b_hp"].hide()
                self.info_group["b_bonus"].hide()
            else:
                self.info_group["b_speed"].show()
                self.info_group["b_hp"].show()
                self.info_group["b_bonus"].show()

                self.info_group["b_speed"].set_text(text="{0} {1}".format(
                    self.parent.localization.get_string("b_speed"), b.speed))

                self.info_group["b_hp"].set_text(text="{0} {1}/{2}".format(
                    self.parent.localization.get_string("b_hp"), b.current_hp,
                    b.max_hp))
                self.info_group["b_bonus"].set_text(text="{0} {1}".format(
                    self.parent.localization.get_string("b_bonus"),
                    b.bonus.description))
        except AttributeError:
            pass
        except KeyError as ky:
            field = str(ky).replace('\'', '')
            print(field)
            self.info_group[field].hide()

    def draw(self, screen: pygame.Surface) -> None:
        super().draw(screen)
        self.socket_group.draw(screen)
        self.upgrade_button.draw(screen)
        screen.blit(self.dna_image, self.dna_rect)
        screen.blit(self.info_block_image, self.info_block_rect)
        self.info_text_label.draw(screen)
        self.bee_list_view.draw(screen)
        self.info_group.draw(screen)

    def handle_event(self, event: Event) -> None:
        super().handle_event(event)
        self.socket_group.handle_event(event)
        self.upgrade_button.handle_event(event)
        self.bee_list_view.handle_event(event)
Example #14
0
    def __init__(self, parent):
        Menu.__init__(self, parent=parent, bg_name="settings_bg")
        self._title_label.set_text(
            text=self.parent.localization.get_string("settings"))
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx -
             self._title_label.size[0] / 2 + 10, self.position[1] + 3))

        self.resolution_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=self.parent.localization.get_string("resolution"))

        right1 = TextLabel(parent=self, font_size=18, bold=True, text=">")
        self.right_resolution_button = TextButton(
            parent=self,
            text_label=right1,
            normal_image_path="left_right.png",
            text_padding=(10, -5))
        self.right_resolution_button.set_position(
            (self._rect.right - self.right_resolution_button.size[0] - 20,
             self.position[1] + 75))

        self.resolution_val_bg = pygame.image.load("{0}/settings.png".format(
            self._res_dir))
        self.resolution_val_bg_rect = self.resolution_val_bg.get_rect()
        self.resolution_val_bg_rect.right = self.right_resolution_button._rect.left - 6
        self.resolution_val_bg_rect.y = self.position[1] + 75

        self.lang_val_bg = pygame.image.load("{0}/settings.png".format(
            self._res_dir))
        self.lang_bg_rect = self.lang_val_bg.get_rect()
        self.lang_bg_rect.right = self.resolution_val_bg_rect.right
        self.lang_bg_rect.y = self.resolution_val_bg_rect.bottom + 15

        left1 = TextLabel(parent=self, font_size=18, bold=True, text="<")
        self.left_resolution_button = TextButton(
            parent=self,
            text_label=left1,
            normal_image_path="left_right.png",
            text_padding=(10, -5))
        self.left_resolution_button.set_position(
            (self.resolution_val_bg_rect.left -
             self.left_resolution_button.size[0] - 6, self.position[1] + 75))

        self.resolution_label.set_position(
            (self.left_resolution_button.get_rect().left -
             self.resolution_label.size[0] - 20, self.position[1] + 72))

        self.lang_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=self.parent.localization.get_string("lang"))

        right2 = TextLabel(parent=self, font_size=18, bold=True, text=">")
        self.right_lang_button = TextButton(parent=self,
                                            text_label=right2,
                                            normal_image_path="left_right.png",
                                            text_padding=(10, -5))
        self.right_lang_button.set_position(
            (self.right_resolution_button.position[0],
             self.right_resolution_button.get_rect().bottom + 15))

        left2 = TextLabel(parent=self, font_size=18, bold=True, text="<")

        self.left_lang_button = TextButton(parent=self,
                                           text_label=left2,
                                           normal_image_path="left_right.png",
                                           text_padding=(10, -5))
        self.left_lang_button.set_position(
            (self.left_resolution_button.position[0],
             self.left_resolution_button.get_rect().bottom + 15))

        self.lang_label.set_position(
            (self.left_lang_button.get_rect().left - self.lang_label.size[0] -
             20, self.resolution_label.get_rect().bottom + 8))

        self.left_resolution_button.set_image_by_state(ButtonState.HOVERED,
                                                       "left_right_hover.png")
        self.right_resolution_button.set_image_by_state(
            ButtonState.HOVERED, "left_right_hover.png")
        self.left_lang_button.set_image_by_state(ButtonState.HOVERED,
                                                 "left_right_hover.png")
        self.right_lang_button.set_image_by_state(ButtonState.HOVERED,
                                                  "left_right_hover.png")

        self.right_resolution_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_resolution(right=True)
        })
        self.left_resolution_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_resolution(right=False)
        })

        self.current_resolution_label = TextLabel(parent=self,
                                                  font_size=18,
                                                  bold=True,
                                                  text="{0}x{1}".format(
                                                      Constants.WINDOW_W,
                                                      Constants.WINDOW_H))
        self.current_resolution_label.get_rect(
        ).center = self.resolution_val_bg_rect.center

        self.current_lang_label = TextLabel(
            parent=self,
            font_size=18,
            bold=True,
            text=Localization.get_current_locale().upper())
        self.current_lang_label.get_rect().center = self.lang_bg_rect.center

        self.right_lang_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_lang(right=True)
        })
        self.left_lang_button.add_action({
            ButtonEventType.ON_CLICK_LB:
            lambda: self.change_lang(right=False)
        })

        self.parent.stop_handle()
Example #15
0
class UpgradeHiveMenu(Menu):
    __slots__ = ("hives_list_view", "hover_index", "__wax_amount")

    def __init__(self, parent: Scene):
        Menu.__init__(self, parent=parent, bg_name="popup3")
        self._title_label = TextLabel(parent=self, text=self.parent.localization.get_string("hives"),
                                      position=self.position, font_size=16, bold=True)
        self._title_label.set_position(
            (self.position[0] + self._bg_image.get_rect().centerx - self._title_label.size[0] / 2 + 10,
             self.position[1] + 3)
        )

        self.hives_list_view = ListView(parent=self, size=(315, 410), item_padding=(8, 8), item_distance=(0, 15),
                                        position=(self.position[0] + 35, self.position[1] + 53))

        db = Database.get_instance()
        wax = db.get_resource_by_id(1)
        self.__wax_amount = 0

        for r in self.parent.player.resources.bag:
            if r.locale_name == wax.locale_name:
                self.__wax_amount = r.value

        self.hover_index = -1

        for h in self.parent.nest_group.buttons:
            if not h.hive:
                continue
            self.add_hive_to_list(h)

        self.parent.nest_group.stop_handle()

    def add_hive_to_list(self, h):
        h_b = Button(parent=self, normal_image_path="hive/hive1_normal.png")
        socket_group = RadioGroup()
        sock_pos = 42, 0
        for socket in h.nest_group.buttons[:-1]:
            bs = BeeSocket(parent=self, group=socket_group, socket_type=socket.full_socket_type, position=sock_pos,
                           local_id=socket.local_id)
            bs.set_image_by_state(ButtonState.LOCKED, "socket3_normal.png")
            bs.set_image_by_state(ButtonState.SELECTED, "socket5_normal.png")
            if socket.is_locked:
                bs.lock()
            bs.change_image_size((28, 25))
            sock_pos = sock_pos[0] + bs.size[0] + 12, sock_pos[1]
        upg_label = TextLabel(parent=self, font_size=14, text=self.parent.localization.get_string("upgrade_button"))
        upg_btn = TextButton(parent=self, text_label=upg_label, normal_image_path="start_quest_btn_normal.png",
                             text_padding=(10, 0))
        upg_btn.set_image_by_state(ButtonState.HOVERED, "start_quest_btn_hover.png")
        upg_btn.set_image_by_state(ButtonState.LOCKED, "start_quest_btn_locked.png")
        upg_btn.set_position((h_b.size[0] + 20, 57))
        upg_btn.change_image_size((106, 25))
        price_label = TextLabel(parent=self, font_size=14,
                                text="{0} {1}/{2}".format(self.parent.localization.get_string("price"),
                                                          self.__wax_amount, 50))
        upg_btn.add_action({ButtonEventType.ON_CLICK_LB: lambda: self.upgrade_socket(socket_group=socket_group,
                                                                                     hive=h, price_label=price_label)})
        price_label.set_position((upg_btn.get_rect().right + 12, upg_btn.position[1]))
        hive_info_group = RenderGroup(parent=self, data={"img": h_b, "sockets": socket_group, "upg": upg_btn,
                                                         "price": price_label})
        i = ListItem(parent=self, data=hive_info_group, normal_image_path="hive_placeholder.png")
        self.hives_list_view.add_item(i)

    def handle_event(self, event: Event) -> None:
        super().handle_event(event)
        self.hives_list_view.handle_event(event)

    def upgrade_socket(self, socket_group, hive, price_label):
        if not socket_group.current_button:
            return
        modifier = 1
        for bs in socket_group.buttons:
            if bs.full_socket_type == BeeSocketType.WARRIOR:
                modifier += 1
        price = 50 * modifier

        if self.__wax_amount < price:
            return
        modifier += 1
        price = 50 * modifier
        price_label.set_text(
            text="{0} {1}/{2}".format(self.parent.localization.get_string("price"), self.__wax_amount, price))
        socket_group.current_button.socket_type = BeeSocketType.WARRIOR
        socket_group.current_button.change_image_size((28, 25))
        for h in self.parent.nest_group.buttons:
            if h.local_id == hive.local_id:
                for s in h.nest_group.buttons:
                    if s.local_id == socket_group.current_button.local_id:
                        s.socket_type = BeeSocketType.WARRIOR
                        break
                break

        socket_group.unselect_all()

    def destroy(self):
        self.parent.nest_group.start_handle()
        super().destroy()

    def draw(self, screen: pygame.Surface) -> None:
        super().draw(screen)
        self.hives_list_view.draw(screen)
Example #16
0
class QuestScene(Scene):
    __slots__ = ("_bg_image", "_quest", "_sec_to_finish", "_start_time",
                 "_timer_label", "_timer_val_label", "_time_over",
                 "_score_label", "_score_val_label", "_finish_button", "score")

    def __init__(self, main_window, name, player, quest: Quest) -> None:
        Scene.__init__(self, main_window=main_window, name=name, player=player)
        self._bg_image = pygame.image.load("{0}/images/{1}_bg.png".format(
            self._res_dir, name)).convert_alpha()
        self._quest = quest
        self._sec_to_finish = 60 + self._quest.time - len(
            self._quest.bee_list) * 5
        self._start_time = 0
        self.score = 0
        self._timer_label = TextLabel(parent=self,
                                      font_size=32,
                                      color=(255, 255, 255))
        self._timer_val_label = TextLabel(parent=self,
                                          font_size=32,
                                          color=(255, 255, 255))
        self._time_over = False
        self._score_label = TextLabel(parent=self,
                                      font_size=32,
                                      color=(255, 255, 255))
        self._score_val_label = TextLabel(parent=self,
                                          font_size=32,
                                          color=(255, 255, 255))
        finish_label = TextLabel(parent=self, font_size=24)
        self._finish_button = TextButton(
            parent=self,
            text_label=finish_label,
            normal_image_path="start_quest_btn_normal.png")
        self._finish_button.set_image_by_state(ButtonState.HOVERED,
                                               "start_quest_btn_hover.png")
        self._finish_button.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self._finish_quest()})

    def _time_over_handle(self) -> None:
        self._finish_button.show()
        self._finish_button.start_handle()

    @staticmethod
    def __diff(bee_lvl: int) -> int:
        if bee_lvl <= 1:
            return 0
        elif bee_lvl == 2:
            return 1
        elif bee_lvl == 3:
            return 3
        else:
            return 6

    def __mxp(self, bee_lvl: int) -> int:
        if self._quest.zone == 1:
            mod = 5
        elif self._quest.zone == 2:
            mod = 25
        elif self._quest.zone == 3:
            mod = 65
        else:
            mod = 205
        return mod + (2 * bee_lvl)

    @staticmethod
    def rf(bee_lvl) -> float:
        if bee_lvl == 1:
            return 1
        elif bee_lvl <= 2 or bee_lvl <= 4:
            return 1 - (bee_lvl - 10) / 100
        elif bee_lvl == 5:
            return 0.82
        else:
            return 1

    def _calculate_xp(self, bee_lvl: int):
        xp = math.ceil(((8 * bee_lvl) + QuestScene.__diff(bee_lvl)) *
                       self.__mxp(bee_lvl) * QuestScene.rf(bee_lvl))
        return xp

    @staticmethod
    def _calculate_damage():
        return 16

    def _finish_quest(self) -> None:
        self.player.resources += self._quest.rewards
        self.player.resources += self._quest.additional_rewards
        for b in self._quest.bee_list:
            b.give_xp(self._calculate_xp(b.current_level))
            b.current_hp -= QuestScene._calculate_damage()
        self.score += self.score * self._quest.score_modifier_percent / 100

        self.main_window.prev_scene.complete_quest(self._quest.quest_id)
        self.main_window.change_scene(self.main_window.prev_scene.name)
        self.main_window.remove_scene(self.name)

    def update(self, dt: float) -> None:
        super().update(dt)

        if self._time_over:
            return
        self._sec_to_finish -= (1 * dt) / 1000
        if self._sec_to_finish > 0:
            self._timer_val_label.set_text(str(int(self._sec_to_finish)))
        else:
            self._time_over = True
            self._time_over_handle()

    def on_scene_started(self) -> None:
        self._localization = Localization(path="scenes/Quest")
        self._start_time = pygame.time.get_ticks()
        self._finish_button.hide()
        self._finish_button.stop_handle()

    def handle_events(self, event: Event) -> None:
        self._finish_button.handle_event(event)

    def draw(self, surface: pygame.Surface) -> None:
        super().draw(surface)
        surface.blit(self._bg_image, self._bg_image.get_rect())
        self._timer_label.draw(surface)
        self._timer_val_label.draw(surface)
        self._score_label.draw(surface)
        self._score_val_label.draw(surface)
        self._finish_button.draw(surface)
Example #17
0
    def __init__(self,
                 parent,
                 socket,
                 bee_list: list,
                 position: (int, int) = (0, 0)) -> None:
        RenderObject.__init__(self, parent=parent, position=position)
        self.__bee_list = bee_list
        self.__allowable_position_x = 100
        self.__allowable_position_y = 0
        self.__socket = socket
        self.__socket.add_action({
            ButtonEventType.ON_CLICK_RB:
            lambda: self.remove_from_socket(self.__socket)
        })
        self.__scene = parent.parent
        self.__scene.add_render(self)
        self.close_btn = Button(parent=self,
                                normal_image_path="close_button1.png")
        self.close_btn.set_image_by_state(ButtonState.HOVERED,
                                          "close_button1_hover.png")
        self.close_btn.add_action(
            {ButtonEventType.ON_CLICK_LB: lambda: self.destroy()})
        self._bg_image = pygame.image.load("{0}/select_bee_panel.png".format(
            self._res_dir)).convert_alpha()
        self._rect.width = self._bg_image.get_rect().width
        self._rect.height = self._bg_image.get_rect().height
        self.bee_list_view = ListView(parent=self,
                                      position=(0, 0),
                                      padding=(23, 21),
                                      item_padding=(10, 10),
                                      size=(308, 170),
                                      item_distance=(10, 15))

        name_label = TextLabel(parent=self,
                               position=(self.position[0] + 323,
                                         self.position[1] + 30),
                               font_size=14)

        level_label = TextLabel(
            parent=self,
            font_size=14,
            position=(name_label.position[0],
                      name_label.position[1] + name_label.size[1]))

        xp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(level_label.position[0],
                      level_label.position[1] + level_label.size[1]))

        speed_label = TextLabel(
            parent=self,
            font_size=14,
            position=(xp_label.position[0],
                      xp_label.position[1] + xp_label.size[1]))

        hp_label = TextLabel(
            parent=self,
            font_size=14,
            position=(speed_label.position[0],
                      speed_label.position[1] + speed_label.size[1]))

        bonus_list_label = MultilineTextLabel(
            parent=self,
            font_size=14,
            line_length=190,
            position=(hp_label.position[0],
                      hp_label.position[1] + hp_label.size[1]))
        self.info_group = RenderGroup(parent=self,
                                      data={
                                          "b_name": name_label,
                                          "b_level": level_label,
                                          "b_exp": xp_label,
                                          "b_speed": speed_label,
                                          "b_hp": hp_label,
                                          "b_bonus": bonus_list_label
                                      })
        for b in self.__bee_list:
            self.add_bee_to_list(b)

        self.show_info(self.__socket.bee)