def __init__(self, title, message, buttons={}): frame_title = "dialogue_{0}".format(title) self.frame = Frame(frame_title, x, y, width, height, z) self.frame.title = title self.buttons = buttons self.frame.closeable = True background = pygame.surface.Surface((width, height)) background.blit(gradients.vertical((width, height), colors.OPAQUE_GRAY, colors.OPAQUE_BLACK), (0, 0)) self.frame.background = background textbox = self.frame.background.subsurface(pygame.Rect(50, 40, text_width, text_height)) button_rect = pygame.Rect(25, 60 + text_height, button_width, 25) button_area = self.frame.background.subsurface(button_rect) textrect(message, ui.typography["title"], text_width, colors.WHITE, surface=textbox) created_buttons = [] for button_create in buttons: created_buttons.append(Button(button_create[0], button_create[1])) total = len(created_buttons) padding = (button_width - (total * button.width)) / (total + 1) button_index = 0 for btn in created_buttons: btn_offset = button_area.get_abs_offset() btn_rect = pygame.Rect((padding * (button_index + 1)) + (button.width * button_index), 0, button.width, button.height) button_area.blit(btn.image, (btn_rect.x, btn_rect.y)) btn_rect.x += btn_offset[0] + x btn_rect.y += btn_offset[1] + y game.addClickableFrame(btn_rect, self.frame, btn.action, 2) button_index += 1
def _renderClose(self): image = pygame.image.load(iconPath("cross")) rect = image.get_rect() rect.x = self.rect.x + self.rect.w - rect.w - close_padding rect.y = self.rect.y + close_padding game.addClickableFrame(rect, self, self.close, self.z) self._close_button = image, rect return self._close_button