Beispiel #1
0
    def test_rebuild_shape_ellipse(self, _init_pygame, _display_surface_return_none):
        manager = UIManager((800, 600),
                            os.path.join("tests", "data", "themes", "ui_button_non_default_2.json"))
        button = UIButton(relative_rect=pygame.Rect(10, 10, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=manager)
        button.rebuild()

        assert button.image is not None
    def test_cannot_hover(self, _init_pygame, default_ui_manager,
                          _display_surface_return_none):
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test Button",
                          manager=default_ui_manager)

        button.is_enabled = True
        button.held = True

        assert button.can_hover() is False
    def test_set_dimensions(self, _init_pygame, default_ui_manager,
                            _display_surface_return_none):
        button = UIButton(relative_rect=pygame.Rect(0, 0, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=default_ui_manager)

        button.set_dimensions(pygame.math.Vector2(250.0, 60.0))

        assert button.drawable_shape.containing_rect.width == 250 and button.drawable_shape.containing_rect.height == 60
    def test_in_hold_range_outside_button(self, _init_pygame: None, default_ui_manager: UIManager,
                                          _display_surface_return_none):
        button = UIButton(relative_rect=pygame.Rect(10, 10, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=default_ui_manager)

        button.set_hold_range((150, 50))

        assert button.in_hold_range(pygame.math.Vector2(200.0, 50.0)) is True
Beispiel #5
0
    def __init__(self, rect, text, messagebox_type, result_callback=None):
        super().__init__(
            rect,
            ui_manager,
            window_display_title="Message"
        )

        self.result_callback = result_callback
        self.text_box = UITextBox(
            text,
            pygame.Rect(5, 5, 350, 80),
            ui_manager,
            container=self,
            anchors={
                "left" : "left",
                "right" : "right",
                "top" : "top",
                "bottom" : "top"
            }
        )

        buttons_right_anchor = {
            "left" : "right",
            "right" : "right",
            "top" : "bottom",
            "bottom" : "bottom"
        }

        if messagebox_type == MESSAGEBOX_TYPE_OK:
            self.ok_btn = UIButton(pygame.Rect(-110, -50, 100, 40), "OK", ui_manager, container=self, anchors=buttons_right_anchor)
            register_ui_callback(self.ok_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: (
                #unregister_ui_callback(self.ok_btn, pygame_gui.UI_BUTTON_PRESSED),
                self.result_callback(MESSAGEBOX_RESULT_OK) if self.result_callback else (),
                self.kill(),
            ))
        else:
            self.yes_btn = UIButton(pygame.Rect(-110, -50, 100, 40), "YES", ui_manager, container=self, anchors=buttons_right_anchor)
            register_ui_callback(self.yes_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: (
                self.result_callback(MESSAGEBOX_RESULT_YES) if self.result_callback else (),
                self.kill(),
            ))

            self.no_btn = UIButton(pygame.Rect(10, -50, 100, 40), "NO", ui_manager, container=self, anchors={
                "left" : "left",
                "right" : "left",
                "top" : "bottom",
                "bottom" : "bottom"
            })
            register_ui_callback(self.no_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: (
                self.result_callback(MESSAGEBOX_RESULT_NO) if self.result_callback else (),
                self.kill(),
            ))

        self.set_blocking(True)
Beispiel #6
0
    def start(self):
        self.title_label = UILabel(pygame.Rect((87, 40), (850, 178)),
                                   "Turret Warfare",
                                   self.ui_manager,
                                   object_id="#game_title")

        self.play_game_button = UIButton(
            pygame.Rect((437, 515), (150, 35)),
            "Start Game",
            self.ui_manager,
            tool_tip_text="<b>Click to Start.</b>")
Beispiel #7
0
    def test_set_position(self, _init_pygame, default_ui_manager):
        test_container = UIContainer(relative_rect=pygame.Rect(100, 100, 300, 60), manager=default_ui_manager)
        button = UIButton(relative_rect=pygame.Rect(0, 0, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          container=test_container,
                          manager=default_ui_manager)

        button.set_position(pygame.math.Vector2(150.0, 30.0))

        assert button.relative_rect.topleft == (50, -70) and button.drawable_shape.containing_rect.topleft == (150, 30)
Beispiel #8
0
    def test_while_not_hovering(self, _init_pygame, default_ui_manager):
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=default_ui_manager)

        # fail to create the tool tip
        button.hover_time = 0.0
        button.while_hovering(0.01, pygame.math.Vector2(250.0, 250.0))

        assert button.tool_tip is None
Beispiel #9
0
 def test_hidden_container_children_behaviour_on_hide(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                                                      _display_surface_return_none):
     container = UIContainer(pygame.Rect(100, 100, 200, 200), manager=default_ui_manager, visible=0)
     button = UIButton(relative_rect=pygame.Rect(0, 0, 50, 50), text="",
                       manager=default_ui_manager, container=container)
     button.show()
     assert container.visible == 0
     assert button.visible == 1
     container.hide()
     assert container.visible == 0
     assert button.visible == 1
    def test_while_hovering(self, _init_pygame, default_ui_manager,
                            _display_surface_return_none):
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=default_ui_manager)

        # create the tool tip
        button.hover_time = 9999.0
        button.while_hovering(0.01, pygame.math.Vector2(150.0, 115.0))

        assert button.tool_tip is not None
Beispiel #11
0
    def test_update_containing_rect_position(self, _init_pygame, default_ui_manager):
        test_container = UIContainer(relative_rect=pygame.Rect(100, 100, 300, 60), manager=default_ui_manager)
        button = UIButton(relative_rect=pygame.Rect(10, 10, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          container=test_container,
                          manager=default_ui_manager)

        test_container.rect.topleft = (50, 50)
        button.update_containing_rect_position()

        assert button.rect.topleft == (60, 60)
Beispiel #12
0
    def test_on_hovered(self, _init_pygame, default_ui_manager,
                        _display_surface_return_none):
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test Button",
                          manager=default_ui_manager)
        button.on_hovered()

        confirm_on_hovered_event_fired = any((event.type == pygame_gui.UI_BUTTON_ON_HOVERED and
                                              event.ui_element == button) for event in
                                             pygame.event.get())

        assert button.hover_time == 0.0
        assert confirm_on_hovered_event_fired
    def recreate_ui(self):
        self.ui_manager.set_window_resolution(self.options.resolution)
        self.ui_manager.clear_and_reset()

        self.background_surface = pygame.Surface(self.options.resolution)
        self.background_surface.fill(self.ui_manager.get_theme().get_colour(None, None, 'dark_bg'))

        self.test_button = UIButton(pygame.Rect((int(self.options.resolution[0] / 2),
                                                 int(self.options.resolution[1] * 0.90)),
                                                (100, 40)),
                                    '',
                                    self.ui_manager,
                                    tool_tip_text="<font face=fira_code color=normal_text size=2>"
                                                  "<b><u>Test Tool Tip</u></b>"
                                                  "<br><br>"
                                                  "A little <i>test</i> of the "
                                                  "<font color=#FFFFFF><b>tool tip</b></font>"
                                                  " functionality."
                                                  "<br><br>"
                                                  "Unleash the Kraken!"
                                                  "</font>",
                                    object_id='#hover_me_button')

        self.test_button_2 = UIButton(pygame.Rect((int(self.options.resolution[0] / 3),
                                                   int(self.options.resolution[1] * 0.90)),
                                                  (100, 40)),
                                      'EVERYTHING',
                                      self.ui_manager,
                                      object_id='#everything_button')

        self.test_slider = UIHorizontalSlider(pygame.Rect((int(self.options.resolution[0] / 2),
                                                           int(self.options.resolution[1] * 0.70)),
                                                          (240, 25)),
                                              100.0,
                                              (0.0, 100.0),
                                              self.ui_manager,
                                              object_id='#cool_slider')

        self.test_text_entry = UITextEntryLine(pygame.Rect((int(self.options.resolution[0] / 2),
                                                            int(self.options.resolution[1] * 0.50)),
                                                           (200, -1)),
                                               self.ui_manager,
                                               object_id='#main_text_entry')

        current_resolution_string = str(self.options.resolution[0]) + 'x' + str(self.options.resolution[1])
        self.test_drop_down_menu = UIDropDownMenu(['640x480', '800x600', '1024x768'],
                                                  current_resolution_string,
                                                  pygame.Rect((int(self.options.resolution[0] / 2),
                                                               int(self.options.resolution[1] * 0.3)),
                                                              (200, 25)),
                                                  self.ui_manager)
Beispiel #14
0
class MainMenu(BaseAppState):
    def __init__(self, ui_manager: pygame_gui.UIManager, state_manger):
        super().__init__('main_menu', 'select_level', state_manger)

        self.ui_manager = ui_manager
        self.background_image = pygame.image.load(
            "images/menu_background.png").convert()

        self.title_label = None
        self.play_game_button = None

    def start(self):
        self.title_label = UILabel(pygame.Rect((87, 40), (850, 178)),
                                   "Turret Warfare",
                                   self.ui_manager,
                                   object_id="#game_title")

        self.play_game_button = UIButton(
            pygame.Rect((437, 515), (150, 35)),
            "Start Game",
            self.ui_manager,
            tool_tip_text="<b>Click to Start.</b>")

    def end(self):
        self.title_label.kill()
        self.play_game_button.kill()

    def run(self, surface, time_delta):
        for event in pygame.event.get():
            if event.type == QUIT:
                self.set_target_state_name('quit')
                self.trigger_transition()

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.set_target_state_name('quit')
                    self.trigger_transition()

            self.ui_manager.process_events(event)

            if event.type == pygame.USEREVENT:
                if event.user_type == "ui_button_pressed":
                    if event.ui_element == self.play_game_button:
                        self.set_target_state_name('select_level')
                        self.trigger_transition()

        self.ui_manager.update(time_delta)

        surface.blit(self.background_image, (0, 0))  # draw the background

        self.ui_manager.draw_ui(surface)
    def test_clear(self, _init_pygame, default_ui_manager,
                   _display_surface_return_none):
        container = UIContainer(pygame.Rect(100, 100, 200, 200), manager=default_ui_manager)
        container_2 = UIContainer(pygame.Rect(50, 50, 50, 50), manager=default_ui_manager,
                                  container=container)

        button = UIButton(relative_rect=pygame.Rect(20, 20, 30, 20), text="X",
                          manager=default_ui_manager, container=container_2)

        container.clear()

        assert not button.alive()
        assert not container_2.alive()
        assert len(container.elements) == 0
Beispiel #16
0
    def test_update(self, _init_pygame, default_ui_manager):
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test Button",
                          tool_tip_text="This is a test of the button's tool tip functionality.",
                          manager=default_ui_manager)

        # test the 'one frame' button press flag
        button.pressed_event = True

        redraw_queue_length_pre_update = len(button.drawable_shape.states_to_redraw_queue)
        button.update(0.01)
        redraw_queue_length_post_update = len(button.drawable_shape.states_to_redraw_queue)

        assert button.pressed is True and redraw_queue_length_post_update == (redraw_queue_length_pre_update - 1)
Beispiel #17
0
    def start(self, should_rebuild: bool = True):
        """
        Called each time we enter the closed state. It creates the necessary elements, the
        selected option and the open button.
        """
        if should_rebuild:
            self.rebuild()

        self.should_transition = False

        border_and_shadow = (self.drop_down_menu_ui.shadow_width +
                             self.drop_down_menu_ui.border_width)
        self.active_buttons = []
        self.selected_option_button = UIButton(
            pygame.Rect(
                (border_and_shadow, border_and_shadow),
                (self.base_position_rect.width - self.open_button_width,
                 self.base_position_rect.height)),
            self.selected_option,
            self.ui_manager,
            self.ui_container,
            starting_height=2,
            parent_element=self.drop_down_menu_ui,
            object_id='#selected_option',
            visible=self.visible)
        self.drop_down_menu_ui.join_focus_sets(self.selected_option_button)
        self.active_buttons.append(self.selected_option_button)

        if self.open_button_width > 0:
            open_button_x = (border_and_shadow +
                             self.base_position_rect.width -
                             self.open_button_width)
            expand_button_symbol = '▼'
            if self.expand_direction is not None:
                if self.expand_direction == 'up':
                    expand_button_symbol = '▲'
                elif self.expand_direction == 'down':
                    expand_button_symbol = '▼'
            self.open_button = UIButton(pygame.Rect(
                (open_button_x, border_and_shadow),
                (self.open_button_width, self.base_position_rect.height)),
                                        expand_button_symbol,
                                        self.ui_manager,
                                        self.ui_container,
                                        starting_height=2,
                                        parent_element=self.drop_down_menu_ui,
                                        object_id='#expand_button',
                                        visible=self.visible)
            self.drop_down_menu_ui.join_focus_sets(self.open_button)
            self.active_buttons.append(self.open_button)
    def __init__(self, ui_manager):
        super().__init__(pygame.Rect((25, 25), (320, 240)), ui_manager, ['pong_window'])

        self.bg_colour = self.ui_manager.get_theme().get_colour(self.object_ids, self.element_ids, 'dark_bg')

        # create shadow
        shadow_padding = (2, 2)
        background_surface = pygame.Surface((self.rect.width - shadow_padding[0] * 2,
                                             self.rect.height - shadow_padding[1] * 2))
        background_surface.fill(self.bg_colour)
        self.image = self.ui_manager.get_shadow(self.rect.size)
        self.image.blit(background_surface, shadow_padding)

        self.get_container().relative_rect.width = self.rect.width - shadow_padding[0] * 2
        self.get_container().relative_rect.height = self.rect.height - shadow_padding[1] * 2
        self.get_container().relative_rect.x = self.get_container().relative_rect.x + shadow_padding[0]
        self.get_container().relative_rect.y = self.get_container().relative_rect.y + shadow_padding[1]
        self.get_container().update_containing_rect_position()

        self.menu_bar = UIButton(relative_rect=pygame.Rect((0, 0),
                                                           ((self.rect.width - shadow_padding[0] * 2) - 20, 20)),
                                 text='Super Awesome Pong!',
                                 manager=ui_manager,
                                 container=self.get_container(),
                                 parent_element=self
                                 )
        self.menu_bar.set_hold_range((100, 100))

        self.grabbed_window = False
        self.starting_grab_difference = (0, 0)

        self.close_window_button = UIButton(relative_rect=pygame.Rect(((self.rect.width - shadow_padding[0] * 2) - 20,
                                                                       0),
                                                                      (20, 20)),
                                            text='╳',
                                            manager=ui_manager,
                                            container=self.get_container(),
                                            parent_element=self
                                            )

        game_surface_size = (self.get_container().rect.width - 4, self.get_container().rect.height - 24)
        self.game_surface_element = UIImage(pygame.Rect((2, 22),
                                                        game_surface_size),
                                            pygame.Surface(game_surface_size).convert(),
                                            manager=ui_manager,
                                            container=self.get_container(),
                                            parent_element=self)

        self.pong_game = PongGame(game_surface_size)
    def test_get_top_layer(self, _init_pygame, default_ui_manager,
                           _display_surface_return_none):
        container = UIContainer(pygame.Rect(100, 100, 200, 200), manager=default_ui_manager)

        UIButton(relative_rect=pygame.Rect(0, 0, 50, 50), text="",
                 manager=default_ui_manager, container=container)
        assert container.get_top_layer() == 3
Beispiel #20
0
    def test_set_dimensions(self, _init_pygame,
                            default_ui_manager: IUIManagerInterface,
                            _display_surface_return_none):
        window = UIWindow(pygame.Rect(200, 200, 200, 200),
                          window_display_title="Test Window",
                          manager=default_ui_manager)

        button_rect = pygame.Rect(0, 0, 150, 30)
        button_rect.topright = (-10, 10)
        button = UIButton(
            relative_rect=button_rect,
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=window,
            anchors={
                'left': 'right',
                'right': 'right',
                'top': 'top',
                'bottom': 'top'
            })

        assert button.rect.topright == (window.get_container().rect.right - 10,
                                        window.get_container().rect.top + 10)
        assert button.rect.topright == (374, 253)

        window.set_dimensions((300, 400))

        assert button.rect.topright == (window.get_container().rect.right - 10,
                                        window.get_container().rect.top + 10)
        assert button.rect.topright == (474, 253)
Beispiel #21
0
    def test_using_theme_prototype(self, _init_pygame,
                                   _display_surface_return_none):
        manager = UIManager((800, 600),
                            os.path.join("tests", "data", "themes",
                                         "ui_window_prototype.json"))
        window = UIWindow(pygame.Rect(0, 0, 200, 200),
                          window_display_title="Test Window",
                          manager=manager)

        button_rect = pygame.Rect(0, 0, 150, 30)
        button_rect.topright = (-10, 10)
        button = UIButton(
            relative_rect=button_rect,
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=manager,
            container=window,
            anchors={
                'left': 'right',
                'right': 'right',
                'top': 'top',
                'bottom': 'top'
            })

        assert window.image is not None
        assert window.shadow_width == 1
        assert window.border_width == 2
        assert window.shape_corner_radius == 10
        assert button.shadow_width == 1
        assert button.border_width == 2
        assert button.shape_corner_radius == 4
Beispiel #22
0
    def test_get_top_layer(self, _init_pygame, default_ui_manager,
                           _display_surface_return_none):
        window = UIWindow(pygame.Rect(0, 0, 400, 300),
                          window_display_title="Test Window",
                          manager=default_ui_manager)

        button_rect = pygame.Rect(0, 0, 150, 30)
        button_rect.topright = (-10, 10)
        button = UIButton(
            relative_rect=button_rect,
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=window,
            anchors={
                'left': 'right',
                'right': 'right',
                'top': 'top',
                'bottom': 'top'
            })

        menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'],
                              starting_option='eggs',
                              relative_rect=pygame.Rect(10, 10, 150, 30),
                              manager=default_ui_manager,
                              container=window)

        assert window.get_top_layer() == 4
        window.update(0.05)
        assert window.get_top_layer() == 6
Beispiel #23
0
    def test_show_hide_rendering(self, _init_pygame, default_ui_manager,
                                 _display_surface_return_none):
        resolution = (400, 400)
        empty_surface = pygame.Surface(resolution)
        empty_surface.fill(pygame.Color(0, 0, 0))

        surface = empty_surface.copy()
        manager = UIManager(resolution)

        panel = UIPanel(pygame.Rect(25, 25, 375, 150),
                        manager=manager,
                        visible=0,
                        starting_layer_height=1)
        button = UIButton(relative_rect=pygame.Rect(0, 0, 50, 50),
                          text="",
                          manager=manager,
                          container=panel)

        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)

        surface.fill(pygame.Color(0, 0, 0))
        panel.show()
        manager.update(0.01)
        manager.draw_ui(surface)
        assert not compare_surfaces(empty_surface, surface)

        surface.fill(pygame.Color(0, 0, 0))
        panel.hide()
        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)
 def test_creation(self, _init_pygame, default_ui_manager,
                   _display_surface_return_none):
     button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                       text="Test Button",
                       tool_tip_text="This is a test of the button's tool tip functionality.",
                       manager=default_ui_manager)
     assert button.image is not None
Beispiel #25
0
 def test_set_any_images_from_theme(self, _init_pygame, _display_surface_return_none):
     manager = UIManager((800, 600), os.path.join("tests", "data", "themes", "ui_button_with_images.json"))
     button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                       text="Test Button",
                       tool_tip_text="This is a test of the button's tool tip functionality.",
                       manager=manager)
     assert button.normal_image is not None and button.image is not None
    def test_draw_ui(self, _init_pygame):
        """
        Test that drawing the UI works.
        Note: the pygame comparison function here seems a little unreliable. Would not be surprised if it's behaviour
        changes.
        """
        test_surface = pygame.display.set_mode((150, 30))
        manager = UIManager((150, 30))
        UIButton(relative_rect=pygame.Rect(0, 0, 150, 30), text="Test", manager=manager)
        # manager.update(0.01)

        manager.draw_ui(test_surface)
        comparison_surface = pygame.image.load(os.path.join('tests', 'comparison_images', 'test_draw_ui.png')).convert()
        test_pixel_array = pygame.PixelArray(test_surface)
        comparison_pixel_array = pygame.PixelArray(comparison_surface)

        result_pixel_array = test_pixel_array.compare(comparison_pixel_array)
        result_surface = result_pixel_array.make_surface()
        test_pixel_array.close()
        comparison_pixel_array.close()

        pixel_mismatch = False
        for x in range(0, 150):
            for y in range(0, 30):
                if result_pixel_array[x, y] != result_surface.map_rgb((255, 255, 255, 255)):
                    pixel_mismatch = True
                    break

        result_pixel_array.close()

        assert pixel_mismatch is False
 def test_process_events(self, _init_pygame, default_ui_manager):
     """
     Fake a click button event on a button to check they are going through the ui event manager properly/
     """
     test_button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30), text="Test", manager=default_ui_manager)
     default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (125, 115)}))
     assert test_button.is_selected
Beispiel #28
0
    def test_add_button(self, _init_pygame, default_ui_manager):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        assert panel.layer_thickness == 1

        button = UIButton(
            relative_rect=pygame.Rect(100, 100, 150, 30),
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=panel)

        assert button.layer_thickness == 1
        assert panel.get_container(
        ).layer_thickness == 2  # happens 'cause elements added to container hover 1 layer up
        panel.update(0.05)
        assert panel.layer_thickness == 2
Beispiel #29
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        button = UIButton(
            relative_rect=pygame.Rect(100, 100, 150, 30),
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=panel)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 4
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), panel,
            panel.get_container(), button
        ]
        panel.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]
Beispiel #30
0
    def test_kill(self, _init_pygame, default_ui_manager,
                  _display_surface_return_none):
        container = UIScrollingContainer(pygame.Rect(100, 100, 200, 200),
                                         manager=default_ui_manager)
        container_2 = UIScrollingContainer(pygame.Rect(50, 50, 50, 50),
                                           manager=default_ui_manager,
                                           container=container)

        button = UIButton(relative_rect=pygame.Rect(20, 20, 30, 20), text="X",
                          manager=default_ui_manager, container=container_2)

        container.kill()

        assert not button.alive()
        assert not container_2.alive()
        assert not container.alive()