def __init__(self, manager):
        """
        @type manager: slg.application.manager.Manager
        """
        super().__init__(manager)
        self.group = GameSceneGroup(self)
        image = pygame.image.load(os.path.join(GUI_DIR, 'loading_screen.jpg'))
        self.image = Surface(self._manager.get_display().get_size())
        self.rect = pygame.rect.Rect(self.image.get_rect())
        image_size = image.get_size()
        surface_size = self.image.get_size()
        x = int((image_size[0] - surface_size[0]) / 2)
        y = int((image_size[1] - surface_size[1]) / 2)
        if x < 0 and y < 0:
            image = pygame.transform.scale(image, surface_size)
            x, y = 0, 0
        elif x <= 0 <= y:
            image = pygame.transform.scale(image, (surface_size[0], image_size[1]))
            x = 0
        elif y <= 0 <= x:
            image = pygame.transform.scale(image, (image_size[0], surface_size[1]))
            y = 0
        styles = {'font': 'alger', 'font_size': 40, 'align': [TextWidget.CENTER, TextWidget.CENTER]}
        text = TextWidget(**styles)
        text.set_text("""Loading...
Please wait""")
        self.image.blit(image, (-x, -y))
        text.draw(self.image)
Example #2
0
class Dialog(slg.ui.bar.Bar):

    _layer = 'gui'

    _type = ''

    def __init__(self, name, size, surface, *groups, **styles):
        close_styles = {'text_color': styles.get('border_color', self.styles['border_color']),
                  'font_size': int(styles.get('font_size', self.styles['font_size']) +
                                   styles.get('font_size', self.styles['font_size']) * 20 / 100),
                  'font': 'alger',
                  'align': (TextWidget.RIGHT, TextWidget.TOP),
                  'border': styles.get('border', self.styles['border'])}
        self.close_button = TextWidget(*groups, **close_styles)
        self.close_button.set_text('X')
        size = (size[0]+self.close_button.get_rect().width, max(size[1], self.close_button.get_rect().height))
        self.image = pygame.Surface(size)

        super().__init__(name, size, *groups, **styles)
        surface_rect = pygame.rect.Rect(surface.get_rect())
        self.rect.move_ip(surface_rect.centerx - self.rect.w/2, surface_rect.centery - self.rect.h/2)
        self.close_button.draw(self.image)
        ChangeState(GAME_STATE_PAUSED).post()
        self.events['click'].connect(self._click)

    def _click(self, *args, **kwargs):
        rect = self.get_close_button()
        if rect.collidepoint(*kwargs['mouse_pos']):
            self.visible = 0
            self.dirty = 1
            self.kill()
            ChangeState(GAME_STATE_RUNNING).post()

    def get_name(self):
        return self._name

    def get_type(self):
        return self._type