Exemplo n.º 1
0
        def tick(self):
            if self.x <= cursor.position[0] <= self.x + self.surface.get_width(
            ) and self.y <= cursor.position[
                    1] <= self.y + self.surface.get_height():
                if cursor.epressed[0]:
                    if self.argument[0] in (shutdown.Shutdown, surfer.Surfer,
                                            setting.Setting):
                        self.command(self.argument[0](*self.argument[1:]))
                    elif self.argument[0] == buckerwindow.BuckerWindow:
                        self.command(self.argument[0](0,
                                                      0,
                                                      500,
                                                      500,
                                                      title=str(time.time())))
                    else:
                        self.command(*self.argument)
                self.text_appear = True
            else:
                self.text_appear = False

            self.x = self.original_x + self.dock_bucker.dock_x
            self.y = self.original_y + self.dock_bucker.dock_y

            self.text_x = rootobject.center(
                self.surface.get_width(),
                self.text_surface.get_width()) + self.x
            self.text_y = rootobject.center(
                self.surface.get_height(), self.text_surface.get_height(
                )) + self.y - self.surface.get_height()
Exemplo n.º 2
0
    def __init__(self, title: str, message: str, kind=None, background_color=color.background, background_opacity=127, title_text_format=textformat.TextFormat(slo.slo['appearance']['font'], 32, color.text), text_format=rootobject.default_text_format, gap=20):
        self.title = title
        self.messages = message + '\n\n\n화면을 왼쪽 클릭 해서 계속합니다.'
        self.kind = kind
        self.background_color = background_color
        self.background_opacity = background_opacity
        self.title_text_format = title_text_format
        self.message_text_format = text_format
        self.gap = gap

        self.background_surface = pygame.Surface(root.display.size)
        self.background_surface.blit(root.window, (0, 0))
        black_surface = pygame.Surface(root.display.size)
        black_surface.fill(self.background_color)
        black_surface.set_alpha(self.background_opacity)
        self.background_surface.blit(black_surface, (0, 0))

        self.title_surface = self.title_text_format.render(self.title)
        self.title_x = rootobject.center(root.display.size[0], self.title_surface.get_width())

        self.message_surfaces = []
        self.message_xs = []
        for message in self.messages.split('\n'):
            self.message_surfaces.append(self.message_text_format.render(message))
            self.message_xs.append(rootobject.center(root.display.size[0], self.message_surfaces[-1].get_width()))

        self.title_y = rootobject.center(root.display.size[1], self.title_surface.get_height() + self.gap + len(self.message_surfaces) * self.message_text_format.size)
        self.message_ys = []
        for I in range(len(self.message_surfaces)):
            self.message_ys.append(self.title_y + self.title_surface.get_height() + self.gap + I * self.message_surfaces[I].get_height())

        audioplayer.playsound('./res/sound/alert.wav')
Exemplo n.º 3
0
        def tick(self):
            if self.shutdown.moving:
                self.x = rootobject.center(
                    root.display.size[0], 108 * len(self.shutdown.buttons) -
                    36) + 108 * self.shutdown.buttons.index(self)
                self.y = rootobject.center(root.display.size[1],
                                           108) + self.shutdown.y * 2

                self.text_x = rootobject.center(
                    root.display.size[0],
                    len(self.shutdown.buttons) * 108 -
                    36) - self.text_surface.get_width(
                    ) / 2 + 108 * self.shutdown.buttons.index(self) + 36
                self.text_y = rootobject.center(
                    root.display.size[1], 108
                ) + 108 - self.text_surface.get_height() + self.shutdown.y * 3

            if cursor.epressed[0]:
                if self.x <= cursor.position[
                        0] <= self.x + 72 and self.y <= cursor.position[
                            1] <= self.y + 72:
                    self.command(*self.argument)
Exemplo n.º 4
0
    def __init__(self):
        self.dock_items = []
        for item in slo.bucker['dock']['items']:
            self.dock_items.append(eval(item))

        self.dock_width = len(self.dock_items) * 92 + 20
        self.dock_height = 92
        self.dock_x = rootobject.center(root.display.size[0], self.dock_width)
        self.dock_y = root.display.size[1]
        self.dock_target_y = root.display.size[1]
        self.dock_color = color.gray

        self.dock_surface = pygame.Surface((self.dock_width, self.dock_height))
        self.dock_surface.fill(slo.bucker['dock']['background_color'])
        self.dock_surface.set_alpha(slo.bucker['dock']['opacity'])
Exemplo n.º 5
0
    def build_surface(self):
        title_surface = self.text_format.render(self.title)

        border_color = self.highlighted_border_color if rootobject.highlighted_object == self else self.normal_border_color

        self.surface = pygame.Surface(
            (round(self.width - 2),
             round(self.height - 1 - self.title_height)))

        self.window = pygame.Surface((self.width, self.height))
        self.window.fill(self.background_color)
        pygame.draw.rect(self.window, border_color,
                         ((0, 0), (self.width, self.title_height)))
        pygame.draw.line(self.window, border_color, (0, 0), (0, self.height),
                         1)
        pygame.draw.line(self.window, border_color, (0, self.height),
                         (self.width, self.height), 3)
        pygame.draw.line(self.window, border_color, (self.width, 0),
                         (self.width, self.height), 3)
        self.window.blit(self.close,
                         (self.width - self.close.get_width() - 2, 2))
        self.window.blit(
            title_surface,
            (rootobject.center(self.width, title_surface.get_width()), 0))
Exemplo n.º 6
0
class Surfer(rootobject.RootObject):
    width = (root.display.size[0] - 400) / 108
    height = (root.display.size[1] - 360) / 144

    x_button_start = rootobject.center(root.display.size[0], width * 108 - 36)
    y_button_start = rootobject.center(root.display.size[1], height * 144 - 72)

    left = 'Surfer.left'
    right = 'Surfer.right'

    class Button(rootobject.RootObject):
        text_format = rootobject.default_text_format

        def __init__(self, surface, text, surfer, command=None):
            self.surface = surface
            self.command = command
            self.text = text
            self.surfer = surfer

            self.func = command[0]
            self.arguments = command[1:]

            self.x, self.y = 0, 0

            if self.surface.get_width() != 72:
                self.surface = pygame.transform.smoothscale(
                    self.surface, (72, self.surface.get_height()))
            if self.surface.get_height() != 72:
                self.surface = pygame.transform.smoothscale(
                    self.surface, (self.surface.get_width(), 72))

            self.text_surface = self.text_format.render(self.text)
            self.text_x, self.text_y = 0, 0

        def tick(self):
            if self.surfer.moving:
                number = self.surfer.buttons.index(self)
                x = number % self.surfer.width
                y = max(0, round(number / self.surfer.width + 0.5) - 1)

                self.x = self.surfer.x_button_start + 108 * x + self.surfer.x * 2
                self.y = self.surfer.y_button_start + 144 * y

                self.text_x = self.surfer.x_button_start + 108 * x + 36 - self.text_surface.get_width(
                ) / 2 + self.surfer.x * 3
                self.text_y = self.y + self.surface.get_height(
                ) + self.text_surface.get_height()

            if cursor.epressed[0]:
                if self.x <= cursor.position[
                        0] <= self.x + self.surface.get_width(
                        ) and self.y <= cursor.position[
                            1] <= self.y + self.surface.get_height():
                    self.func(*self.arguments)

        def render(self):
            root.window.blit(self.surface, (self.x, self.y))
            root.window.blit(self.text_surface, (self.text_x, self.text_y))

    def __init__(self, side='Surfer.left'):
        self.side = side

        self.close_x = -root.display.size[
            0] if self.side == self.left else root.display.size[0]

        self.x = self.close_x
        self.target_x = 0
        self.moving = True

        self.background = pygame.Surface(root.display.size)

        self.buttons = []
        for item in slo.surfer['item']['items']:
            self.buttons.append(eval(item))

        self.back_button_surface = pygame.transform.smoothscale(
            pygame.image.load('./res/image/icon/left_arrow.png'), (32, 32))
        self.back_button_surface.convert()
        self.back_button_position_x = 16
        self.back_button_position_y = 16

        rootobject.highlight = Surfer

    def tick(self):
        if self.moving:
            self.x += (self.target_x -
                       self.x) / (root.display.display_fps /
                                  slo.slo['appearance']['motion_speed'])

            if math.fabs(self.x - self.target_x) < 1:
                self.x = self.target_x
                self.moving = False

        for button in self.buttons:
            button.tick()

        self.back_button_position_x = 16 + self.x * 2
        if cursor.epressed[0] and self.back_button_position_x <= cursor.position[
                0] <= self.back_button_position_x + self.back_button_surface.get_width(
                ) and self.back_button_position_y <= cursor.position[
                    1] <= self.back_button_position_y + self.back_button_surface.get_height(
                    ) or keyboard.escape:
            self.quit()

        if (self.x < -root.display.size[0] - 1 and self.side == self.left) or (
                self.x > root.display.size[0] + 1 and self.side == self.right):
            self.destroy()

    def render(self):
        root.window.blit(self.background, (self.x, 0))

        for button in self.buttons:
            button.render()

        root.window.blit(
            self.back_button_surface,
            (self.back_button_position_x, self.back_button_position_y))

    def start(self, _object, *args):
        rootobject.add_object(_object(*args))
        self.quit()

    def quit(self):
        rootobject.highlight = None
        self.moving = True
        if self.side == self.left:
            self.target_x = -root.display.size[0] - 2
        else:
            self.target_x = root.display.size[0] + 2