Beispiel #1
0
 def __init__(self, game,
              x: int, y: int, width: int, height: int,
              function: Callable[[None], None] = None,
              text: str = 'Define me!',
              button_type: str = 'multi',
              color: pygame.color.Color = None) -> None:
     super().__init__(game)
     # if color is None:
     #     color = self.game.settings[button_type + '_btn_style']["bg_color"]
     button_style = {
         "hover_color": self.game.settings[button_type + '_btn_style']["hover_color"],
         "clicked_color": self.game.settings[button_type + '_btn_style']["clicked_color"],
         "font_color": self.game.settings[button_type + '_btn_style']["font_color"],
         "clicked_font_color": self.game.settings[button_type + '_btn_style']["clicked_font_color"],
         "hover_font_color": self.game.settings[button_type + '_btn_style']["hover_font_color"],
         "font": pygame.font.SysFont(self.game.settings[button_type + '_btn_style']["font"],
                                     self.game.settings[button_type + '_btn_style']["font_size"],
                                     self.game.settings[button_type + '_btn_style']["font_bold"],
                                     self.game.settings[button_type + '_btn_style']["font_italic"], )
     }
     self.color = color if color else self.game.settings[button_type + '_btn_style']["bg_color"]
     self.function = function if function else ButtonObject.no_action
     self.text = text
     self.rect = pygame.rect.Rect(x, y, width, height)
     self.button = Button(
         rect=self.rect,
         color=self.color,
         function=self.function,
         text=self.text,
         **button_style
     )
Beispiel #2
0
 def __init__(self,
              game,
              geometry=(10, 10, 100, 40),
              color=(255, 255, 0),
              font_size=20,
              text='Test',
              function=None):
     super().__init__(game)
     self.geometry = geometry
     self.color = color
     self.font_size = font_size
     self.function = function if function else Btn.no_action
     self.internal_button = Button(self.geometry, self.color, self.function,
                                   self.font_size, **Btn.BUTTON_STYLE)
     self.internal_button.text = text
     self.internal_button.render_text()
Beispiel #3
0
class ButtonObject(DrawableObject):
    BUTTON_STYLE = {
        "hover_color": BLUE,
        "clicked_color": GREEN,
        "clicked_font_color": BLACK,
        "hover_font_color": ORANGE,
    }

    def __init__(self, game, x, y, width, height, color, function, text):
        super().__init__(game)
        self.rect = pygame.rect.Rect(x, y, width, height)
        self.button = Button((x, y, width, height), color, function, text=text, **self.BUTTON_STYLE)

    def process_event(self, event):
        self.button.check_event(event)

    def process_draw(self):
        self.button.update(self.game.screen)
Beispiel #4
0
 def __init__(self,
              game,
              x: int,
              y: int,
              width: int,
              height: int,
              color: pygame.color.Color = None,
              function: Callable[[None], None] = None,
              text: str = 'Define me!') -> None:
     super().__init__(game)
     self.color = color if color else Color.WHITE
     self.function = function if function else ButtonObject.no_action
     self.text = text
     self.rect = pygame.rect.Rect(x, y, width, height)
     self.button = Button(rect=self.rect,
                          color=self.color,
                          function=self.function,
                          text=self.text,
                          **self.BUTTON_STYLE)
Beispiel #5
0
class ButtonObject(DrawableObject):
    def __init__(self, game,
                 x: int, y: int, width: int, height: int,
                 function: Callable[[None], None] = None,
                 text: str = 'Define me!',
                 button_type: str = 'multi',
                 color: pygame.color.Color = None) -> None:
        super().__init__(game)
        # if color is None:
        #     color = self.game.settings[button_type + '_btn_style']["bg_color"]
        button_style = {
            "hover_color": self.game.settings[button_type + '_btn_style']["hover_color"],
            "clicked_color": self.game.settings[button_type + '_btn_style']["clicked_color"],
            "font_color": self.game.settings[button_type + '_btn_style']["font_color"],
            "clicked_font_color": self.game.settings[button_type + '_btn_style']["clicked_font_color"],
            "hover_font_color": self.game.settings[button_type + '_btn_style']["hover_font_color"],
            "font": pygame.font.SysFont(self.game.settings[button_type + '_btn_style']["font"],
                                        self.game.settings[button_type + '_btn_style']["font_size"],
                                        self.game.settings[button_type + '_btn_style']["font_bold"],
                                        self.game.settings[button_type + '_btn_style']["font_italic"], )
        }
        self.color = color if color else self.game.settings[button_type + '_btn_style']["bg_color"]
        self.function = function if function else ButtonObject.no_action
        self.text = text
        self.rect = pygame.rect.Rect(x, y, width, height)
        self.button = Button(
            rect=self.rect,
            color=self.color,
            function=self.function,
            text=self.text,
            **button_style
        )

    def set_center(self, x: int, y: int) -> None:
        super(ButtonObject, self).set_center(x, y)
        self.button.rect = self.rect

    def set_position(self, x: int, y: int) -> None:
        super().set_position(x, y)
        self.button.rect = self.rect

    @staticmethod
    def no_action() -> None:
        pass

    def set_text(self, text) -> None:
        self.text = text
        self.button.text = text
        self.button.render_text()

    def process_event(self, event) -> None:
        self.button.check_event(event)

    def process_draw(self) -> None:
        self.button.update(self.game.screen)
Beispiel #6
0
class ButtonObject(DrawableObject):
    BUTTON_STYLE = {
        "hover_color": Color.BLUE,
        "clicked_color": Color.GREEN,
        "font_color": Color.WHITE,
        "clicked_font_color": Color.BLACK,
        "hover_font_color": Color.ORANGE,
    }

    def __init__(self,
                 game,
                 x: int,
                 y: int,
                 width: int,
                 height: int,
                 color: pygame.color.Color = None,
                 function: Callable[[None], None] = None,
                 text: str = 'Define me!') -> None:
        super().__init__(game)
        self.color = color if color else Color.WHITE
        self.function = function if function else ButtonObject.no_action
        self.text = text
        self.rect = pygame.rect.Rect(x, y, width, height)
        self.button = Button(rect=self.rect,
                             color=self.color,
                             function=self.function,
                             text=self.text,
                             **self.BUTTON_STYLE)

    def move_center(self, x: int, y: int) -> None:
        super(ButtonObject, self).move_center(x, y)
        self.button.rect = self.rect

    def move(self, x: int, y: int) -> None:
        super().move(x, y)
        self.button.rect = self.rect

    @staticmethod
    def no_action(self) -> None:
        pass

    def set_text(self, text) -> None:
        self.text = text
        self.button.text = text
        self.button.render_text()

    def process_event(self, event) -> None:
        self.button.check_event(event)

    def process_draw(self) -> None:
        self.button.update(self.game.screen)
Beispiel #7
0
class Btn(DrawObject):
    BUTTON_STYLE = {
        "hover_color": Color.BLUE,
        "font_color": Color.RED,
        "clicked_color": Color.GREEN,
        "clicked_font_color": Color.BLACK,
        "hover_font_color": Color.ORANGE
    }

    def __init__(self,
                 game,
                 geometry=(10, 10, 100, 40),
                 color=(255, 255, 0),
                 font_size=20,
                 text='Test',
                 function=None):
        super().__init__(game)
        self.geometry = geometry
        self.color = color
        self.font_size = font_size
        self.function = function if function else Btn.no_action
        self.internal_button = Button(self.geometry, self.color, self.function,
                                      self.font_size, **Btn.BUTTON_STYLE)
        self.internal_button.text = text
        self.internal_button.render_text()

    @staticmethod
    def no_action(self):
        pass

    def process_event(self, event):
        if event == pg.MOUSEBUTTONDOWN and self.game.settings.sounds:
            pg.mixer_music.load(Sounds.CLICK)
            pg.mixer_music.play()

        self.internal_button.check_event(event)

    def process_draw(self):
        self.internal_button.update(self.game.screen)
Beispiel #8
0
 def __init__(self, game, x, y, width, height, color, function, text):
     super().__init__(game)
     self.rect = pygame.rect.Rect(x, y, width, height)
     self.button = Button((x, y, width, height), color, function, text=text, **self.BUTTON_STYLE)