class Button(Image): def __init__(self, position_name, name_img, obj, vertical_shift=0): """ Args: position_name ('str'): The key to obtain the position of this button. name_img ('str'): The key to obtain name of the button image. obj (class:'Object_Into'): The object to be displayed by the button. Note: Object_Into is a general class. Some of the classes that extends this class are Pokemon or Move. vertical_shift ('int'): Vertical shift where display the button Action: Create an General Button to show relevant information of 'obj' and allows to detect if it has been clicked. """ top_left_location = Select_Config[position_name] height = Display_Config['BATTLE_SIZE'][1] + Display_Config['LOG_SIZE'][ 1] height_shift = (vertical_shift, height) self.location_pre_scale = shift(top_left_location, height_shift) Image.__init__(self, name_img, self.location_pre_scale) self.obj = obj button_shift = Select_Config['BUTTON_NAME_SHIFT'] self.font_name = Font(self.location_pre_scale, button_shift) self.font_name.set_text('' if obj == None else obj.name()) """ Funcion to display this button. """ def display(self, SCREEN): Image.display(self, SCREEN) self.font_name.display(SCREEN) """ Funtion that returns True if 'point' is inside of this button. (tuple:('int','int') --> 'bool') """ def point_inside(self, point): left, top = self._location width, height = self._image.get_size() return Rect(left, top, width, height).collidepoint(point)
class Button_Move(Button): def __init__(self, position_name, move, vertical_shift=0): """ Args: position_name ('str'): The key to obtain the position. move (class:'Move'): The move to be displayed by the button. vertical_shift ('int'): Vertical shift where display the button Action: Create an extencion of 'Button' to show relevant information abount 'move'. """ if move != None: name_img = Directory['CELL_NAME'].format( move.type().name().lower()) else: name_img = Directory['NONE_CELL_FILE'] Button.__init__(self, position_name, name_img, move, vertical_shift) if move != None: a_pp_shift = Select_Config['BUTTON_A_PP_SHIFT'] self.font_actual_pp = Font(self.location_pre_scale, a_pp_shift) m_pp_shift = Select_Config['BUTTON_M_PP_SHIFT'] self.font_max_pp = Font(self.location_pre_scale, m_pp_shift) self.font_max_pp.set_text(num_to_text(move.max_pp())) """ Funcion to display this button. """ def display(self, SCREEN): Button.display(self, SCREEN) if self.obj != None: pct = self.obj.actual_pp() / self.obj.max_pp() color = 'BLACK' if pct > 0.5 else 'YELLOW' if pct > 0.25 else 'RED' text_num = num_to_text(self.obj.actual_pp()) self.font_actual_pp.set_text(text_num, color) self.font_actual_pp.display(SCREEN) self.font_max_pp.display(SCREEN)
class Move_Info(Button_Move): def __init__(self, position_name, move, vertical_shift=0): """ Args: position_name ('str'): The key to obtain the position. move (class:'Move'): The move to be displayed by the button. vertical_shift ('int'): Vertical shift where display the button Action: Create an extencion of 'Button' to show relevant information abount 'move'. """ Button_Move.__init__(self, position_name, move, vertical_shift) x, y = scale( shift(self.location_pre_scale, Select_Config['SHIFT_RECT_EFF'])) width, height = scale(Select_Config['SIZE_RECT_EFF']) # Create rectangles width_1 = width / 2 self.bar_0 = Rect(x, y, width_1, height) self.bar_1 = Rect(x + width_1, y, width_1, height) y += height + scale([1, Select_Config['V_SPACE_RECTS']])[1] self.bar_2 = Rect(x, y, width, height) #Create text effectiveness text_shift = shift( Select_Config['SHIFT_RECT_EFF'],\ Select_Config['SHIFT_TEXT_EFF']) self.text_0 = Font(self.location_pre_scale, text_shift) text_shift_1 = shift(text_shift, [Select_Config['SIZE_RECT_EFF'][0] / 2, 0]) self.text_1 = Font(self.location_pre_scale, text_shift_1) #Create text info move aux = Select_Config['SIZE_RECT_EFF'][1] + Select_Config['V_SPACE_RECTS'] text_shift_2 = shift(text_shift, [-Select_Config['SHIFT_TEXT_EFF'][0] / 2, aux]) self.text_2 = Font(self.location_pre_scale, text_shift_2) #Set text info move string_pattern = 'P: {pow} A: {acc} {tp}' pow = self.obj.power() acc = self.obj.accuracy() if self.obj.accuracy() != None else '-' dmg_class = ' Sp.' if self.obj.damage_class() == 'special' else 'Ph.' string = string_pattern.format(pow=pow, acc=acc, tp=dmg_class) self.text_2.set_text(string) """ Set enemies types to calculate effectiveness """ def set_type_enemies(self, types): effectiveness_0 = int(self.obj.type().multiplier(types[0]) * 100) effectiveness_1 = int(self.obj.type().multiplier(types[1]) * 100) pattern = Select_Config['EFFECTIVENESS_TO_COLOR_PATTERN'] self.color_name_0 = Select_Config[pattern.format(str(effectiveness_0))] self.color_name_1 = Select_Config[pattern.format(str(effectiveness_1))] self.text_0.set_text('x' + str(float(effectiveness_0) / 100.0)) self.text_1.set_text('x' + str(float(effectiveness_1) / 100.0)) """ Funcion to display this button. """ def display(self, SCREEN): Button_Move.display(self, SCREEN) draw.rect(SCREEN, Display_Config[self.color_name_0], self.bar_0) draw.rect(SCREEN, Display_Config[self.color_name_1], self.bar_1) draw.rect(SCREEN, Display_Config['GRAY'], self.bar_2) self.text_0.display(SCREEN) self.text_1.display(SCREEN) self.text_2.display(SCREEN)