Пример #1
0
    def test_set_relative_position(self, _init_pygame, default_ui_manager, _display_surface_return_none):
        loaded_image = pygame.image.load(os.path.join('tests', 'data', 'images', 'splat.png'))
        ui_image = UIImage(relative_rect=pygame.Rect(100, 100, 150, 30),
                           image_surface=loaded_image,
                           manager=default_ui_manager)

        ui_image.set_relative_position((200, 200))

        assert ui_image.relative_rect.topleft == (200, 200)
Пример #2
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.DIMS[0] + 230, self.DIMS[1] + 110)),
            manager=manager,
            window_display_title="Sysmon",
            object_id="#sysmonterm",
            resizable=True,
        )

        self.textbox_ram = pygame_gui.elements.UITextBox(
            "",
            relative_rect=pygame.Rect(200, 100, 200, 100),
            manager=manager,
            container=self,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom",
            },
        )

        self.textbox_cpu = pygame_gui.elements.UITextBox(
            "",
            relative_rect=pygame.Rect(0, 100, 200, 100),
            manager=manager,
            container=self,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom",
            },
        )

        self.surf_cpu = UIImage(
            pygame.Rect((0, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.surf_ram = UIImage(
            pygame.Rect((200, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.cpu = pygame.Surface(self.DIMS)
        self.cpu.fill(GRAY)
        self.ram = pygame.Surface(self.DIMS)
        self.ram.fill(GRAY)
        self.last_time = 0
Пример #3
0
    def test_hide(self, _init_pygame, default_ui_manager,
                  _display_surface_return_none):
        loaded_image = pygame.image.load(
            os.path.join('tests', 'data', 'images', 'splat.png'))
        ui_image = UIImage(relative_rect=pygame.Rect(100, 100, 150, 30),
                           image_surface=loaded_image,
                           manager=default_ui_manager)

        assert ui_image.visible == 1
        ui_image.hide()
        assert ui_image.visible == 0
Пример #4
0
    def test_set_dimensions(self, _init_pygame, default_ui_manager, _display_surface_return_none):
        loaded_image = pygame.image.load(os.path.join('tests', 'data', 'images', 'splat.png'))
        ui_image = UIImage(relative_rect=pygame.Rect(100, 100, 150, 30),
                           image_surface=loaded_image,
                           manager=default_ui_manager)

        assert ui_image.image.get_size() == (150, 30) and ui_image.rect.size == (150, 30)

        ui_image.set_dimensions((200, 200))

        assert ui_image.image.get_size() == (200, 200) and ui_image.rect.size == (200, 200)
Пример #5
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)),
            manager=manager,
            window_display_title="BusDance",
            object_id="#busdance",
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )

        app_path = os.path.dirname(os.path.abspath(__file__))
        frames_path = app_path + "/frames/"

        for x in range(180):
            # load each frame from the GIF into the frame list
            frame = pygame.image.load(frames_path + "frame-" + str(x) + ".png")
            frame = pygame.transform.scale(frame, self.DIMS)

            # add each frame twice for half speed
            self.FRAMES.append(frame)
            self.FRAMES.append(frame)

        self.FRAMES_LEN = len(self.FRAMES)
Пример #6
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (RES[0] + 32, RES[1] + 60)),
            manager=manager,
            window_display_title="midi",
            object_id="#midi",
            resizable=False,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), RES),
            pygame.Surface(RES).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.screen = pygame.Surface(RES)
        self.screen.fill(BACKGROUND)
        pygame.mixer.init()
        ini(self.screen, RES)
        self.calib = 10
        self.samp = []
        self.last = 0
        self.mlist = sorted(glob.glob(SONG_DIR + "/*.mid"))
        self.mselect = 0
        load_song(self.screen, RES, self.mlist[self.mselect])
        self.tempo = 1
        self.paused = False
Пример #7
0
 def __init__(self, pos, manager):
     super().__init__(
         pygame.Rect(pos, (352, 300)),
         manager=manager,
         window_display_title="animation",
         object_id="#animation",
     )
     self.FRAMES = []
     self.FRAMES_LEN = 0
     self.FRAME_INDEX = 0
     self.dsurf = UIImage(
         pygame.Rect((0, 0), (320, 240)),
         pygame.Surface((320, 240)).convert(),
         manager=manager,
         container=self,
         parent_element=self,
     )
     app_path = os.path.dirname(os.path.abspath(__file__))
     frames_path = app_path + "/frames/"
     [
         self.FRAMES.append(
             pygame.transform.scale(
                 pygame.image.load(frames_path + "frame-" +
                                   str(floor(x / 2)) + ".png"), (320, 240)))
         for x in range(
             len([name
                  for name in os.listdir('.') if os.path.isfile(name)]) *
             2 - 1)
     ]
     self.FRAMES_LEN = len(self.FRAMES)
Пример #8
0
    def __init__(self, pos, uiManager, title, id, menu, size):
        if pos[0] is None:
            pos[0] = (uiManager.get_root_container().get_size()[0] /
                      2) - (size[0] / 2)

        if pos[1] is None:
            pos[1] = (uiManager.get_root_container().get_size()[1] /
                      2) - (size[1] / 2)

        self.width = size[0]
        self.height = size[1]

        #// This might not stay here
        self.uiManager = uiManager

        self.id = id
        self.active = True

        super().__init__(pygame.Rect(pos, (self.width, self.height)),
                         uiManager,
                         window_display_title=title,
                         object_id=id)

        drawSurfaceSize = self.get_container().get_size()
        self.drawSurface = pygame.Surface(drawSurfaceSize).convert()

        self.drawImage = UIImage(pygame.Rect((0, 0), drawSurfaceSize),
                                 self.drawSurface,
                                 manager=self.uiManager,
                                 container=self,
                                 parent_element=self)

        self.menu = menu(uiManager, self.get_container())
        self.show()
        self.enable()
Пример #9
0
    def __init__(self, position, ui_manager):

        super().__init__(pygame.Rect(position, (800, 600)),
                         ui_manager,
                         window_display_title='EDITOR!',
                         object_id='#window',
                         resizable=True)

        surface_size = self.get_container().get_size()
        self.surface_element = UIImage(
            pygame.Rect((0, 0), surface_size),
            pygame.Surface(surface_size).convert(),
            manager=ui_manager,
            container=self,
            parent_element=self,
        )

        self.background = pygame.Surface(surface_size)
        self.background = self.background.convert()
        self.background.fill((0, 0, 0))
        self.parent = self
        self.now = 0

        self.app_path = os.path.dirname(os.path.abspath(__file__))
        print('Current Path:', self.app_path)

        create_gui_variables(self, position)
        create_assets(self, ui_manager)

        self.CATH = PyEdit_no_gui(self.EditorX, self.EditorY, self.Ewidth,
                                  self.Eheight, self.FPS, self.FONT,
                                  self.text_size, "white", self.parent)
Пример #10
0
    def test_creation(self, _init_pygame: None, default_ui_manager: UIManager,
                      default_display_surface: pygame.Surface):

        loaded_image = pygame.image.load(os.path.join('tests', 'data', 'images', 'splat.png'))
        ui_image = UIImage(relative_rect=pygame.Rect(100, 100, 150, 30),
                           image_surface=loaded_image,
                           manager=default_ui_manager)
        assert ui_image.image is not None
Пример #11
0
    def __init__(self, position, ui_manager):
        super().__init__(pygame.Rect(position, (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_width = 15
        shadow_padding = (shadow_width, shadow_width)
        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, shadow_width, corner_radius=shadow_width)
        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().rect.width = self.rect.width - shadow_padding[0] * 2
        self.get_container().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,
                                 object_id='#menu_bar'
                                 )
        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)

        self.is_active = False
Пример #12
0
    def __init__(self, game_resolution, ui_manager):
        super().__init__(pygame.Rect((0, 0), game_resolution), ui_manager, ['game_window'])
        x_res, y_res = game_resolution

        self.game = Ball(game_resolution, x_res/2, y_res/2, rad=5)
        self.game_surface_element = UIImage(pygame.Rect((0, 0), game_resolution),
                                            pygame.Surface(game_resolution).convert(),
                                            manager=ui_manager,
                                            container=self.get_container(),
                                            parent_element=self)
Пример #13
0
 def __init__(self, position, ui_manager):
     super().__init__(pygame.Rect(position, (320, 240)),
                      ui_manager,
                      object_id='#window')
     game_surface_size = self.get_container().get_size()
     self.game_surface_element = UIImage(
         pygame.Rect((0, 0), game_surface_size),
         pygame.Surface(game_surface_size).convert(),
         manager=ui_manager,
         container=self,
         parent_element=self)
Пример #14
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.res[0] + 32, self.res[1] + 60)),
            manager=manager,
            window_display_title="zap",
            object_id="#zap",
            resizable=True,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.res),
            pygame.Surface(self.res).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.dazz = pygame.Surface((RES, RESY))
        self.paused = False
        self.step = False
        self.dir = 0
        self.hiscore = 0
        self.phot = [1000, 1000, 1000, 1000]
        self.newgame()
        pygame.mixer.init()
        path = os.path.dirname(os.path.abspath(__file__))
        self.audio = {
            "fanfare": pygame.mixer.Sound(path + "/snd/fanfare.ogg"),
            "start": pygame.mixer.Sound(path + "/snd/start.ogg"),
            "fire": pygame.mixer.Sound(path + "/snd/shot.ogg"),
            "shiphit": pygame.mixer.Sound(path + "/snd/enemy.ogg"),
            "end": pygame.mixer.Sound(path + "/snd/stationdest.ogg"),
            "pfire": pygame.mixer.Sound(path + "/snd/photon.ogg"),
            "pdest": pygame.mixer.Sound(path + "/snd/photondest.ogg"),
            "satdest": pygame.mixer.Sound(path + "/snd/sat.ogg"),
        }
        self.img = {
            "station": pygame.image.load(path + "/img/station.png"),
            "photon": pygame.image.load(path + "/img/photon.png"),
            "fighter2": pygame.image.load(path + "/img/fighter.png"),
            "sat": pygame.image.load(path + "/img/satellite.png"),
            "num": pygame.image.load(path + "/img/numbers.png"),
            "text": pygame.image.load(path + "/img/text.png"),
        }
        self.img["fighter1"] = pygame.transform.rotate(self.img["fighter2"],
                                                       90)
        self.img["fighter0"] = pygame.transform.rotate(self.img["fighter2"],
                                                       180)
        self.img["fighter3"] = pygame.transform.rotate(self.img["fighter2"],
                                                       270)
        self.attractimg = pygame.image.load(path + "/img/title.png")
        self.audio["fanfare"].play()
        self.attract = True
        self.manager = manager
Пример #15
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)
        loaded_image = pygame.image.load(
            os.path.join('tests', 'data', 'images', 'splat.png'))
        ui_image = UIImage(relative_rect=pygame.Rect(25, 25, 375, 150),
                           image_surface=loaded_image,
                           manager=manager,
                           visible=0)
        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)

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

        surface.fill(pygame.Color(0, 0, 0))
        ui_image.hide()
        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)
Пример #16
0
 def __init__(self, pos, manager):
     super().__init__(
         pygame.Rect(pos, (352, 300)),
         manager=manager,
         window_display_title="camera",
         object_id="#camera",
     )
     self.dsurf = UIImage(
         pygame.Rect((0, 0), (320, 240)),
         pygame.Surface((320, 240)).convert(),
         manager=manager,
         container=self,
         parent_element=self,
     )
Пример #17
0
    def __init__(self, position, size, ui_manager):
        super().__init__(pg.Rect(position, size),
                         manager=ui_manager,
                         object_id='#drawing_window',
                         starting_layer_height=5)

        draw_surface_size = self.get_container().get_size()
        self.draw_surface_element = UIImage(
            pg.Rect((0, 0), draw_surface_size),
            pg.Surface(draw_surface_size).convert(),
            manager=ui_manager,
            container=self,
            parent_element=self)

        self.is_active = True
Пример #18
0
 def __init__(self, pos, manager):
     super().__init__(
         pygame.Rect(pos, (352, 300)),
         manager=manager,
         window_display_title="Video",
         object_id="#video",
     )
     self.dsurf = UIImage(
         pygame.Rect((0, 0), (320, 240)),
         pygame.Surface((320, 240)).convert(),
         manager=manager,
         container=self,
         parent_element=self,
     )
     self.video = cv2.VideoCapture(
         os.path.dirname(os.path.abspath(__file__)) + '\\video.mp4')
Пример #19
0
 def __init__(self, position, ui_manager):
     super().__init__(
         pygame.Rect(position, (640, 480)),
         ui_manager,
         window_display_title="Maze 3D",
         object_id="#maze3d_window",
     )
     game_surface_size = self.get_container().get_size()
     self.game_surface_element = UIImage(
         pygame.Rect((0, 0), game_surface_size),
         pygame.Surface(game_surface_size).convert(),
         manager=ui_manager,
         container=self,
         parent_element=self,
     )
     self.maze3d = Maze3D(game_surface_size)
Пример #20
0
    def __init__(self, position, ui_manager):
        super().__init__(pygame.Rect(position, (320, 240)), ui_manager,
                         window_display_title='Super Awesome Pong!',
                         object_id='#pong_window')

        game_surface_size = self.get_container().rect.size
        self.game_surface_element = UIImage(pygame.Rect((0, 0),
                                                        game_surface_size),
                                            pygame.Surface(game_surface_size).convert(),
                                            manager=ui_manager,
                                            container=self,
                                            parent_element=self)

        self.pong_game = PongGame(game_surface_size)

        self.is_active = False
Пример #21
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (DIMS[0] + 32, DIMS[1] + 60)),
            manager=manager,
            window_display_title="earth",
            object_id="#earth",
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), DIMS),
            pygame.Surface(DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.last = 0
        self.start = True
Пример #22
0
 def __init__(self, pos, manager):
     super().__init__(
         pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)),
         manager=manager,
         window_display_title="clock",
         object_id="#aclock",
         resizable=True,
     )
     self.dsurf = UIImage(
         pygame.Rect((0, 0), self.DIMS),
         pygame.Surface(self.DIMS).convert(),
         manager=manager,
         container=self,
         parent_element=self,
     )
     self.draw_dial()
     self.clean_dial = self.dial.copy()
     self.manager = manager
Пример #23
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)),
            manager=manager,
            window_display_title="cpumon",
            object_id="#cpumonterm",
            resizable=False,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.cpu = pygame.Surface(self.DIMS)
        self.cpu.fill(GRAY)
        self.last_time = 0
Пример #24
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.res[0] + 32, self.res[1] + 60)),
            manager=manager,
            window_display_title="tix",
            object_id="#tix",
            resizable=True,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.res),
            pygame.Surface(self.res).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.screen = pygame.Surface(self.res)
        self.screen.fill(BACKGROUND)
        self.manager = manager
        self.last = 0
Пример #25
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)),
            manager=manager,
            window_display_title="dazzler",
            object_id="#dazzler",
            resizable=True,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.dazz = pygame.Surface((RES, RES))
        self.pow = 1
        self.lastpow = 0
        self.lastframe = 0
        self.paused = False
        self.step = False
        self.manager = manager
Пример #26
0
    def __init__(self, pos, manager):
        super().__init__(
            pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)),
            manager=manager,
            window_display_title="cell",
            object_id="#cell",
            resizable=True,
        )

        self.dsurf = UIImage(
            pygame.Rect((0, 0), self.DIMS),
            pygame.Surface(self.DIMS).convert(),
            manager=manager,
            container=self,
            parent_element=self,
        )
        self.screen = pygame.Surface(self.DIMS)
        self.manager = manager
        self.cell = [random.randint(0, 1) for q in range(2 + NCELL)]
        self.rule = random.choice(RULES)
        self.gen = 1
        self.line = 0
        self.COL = getcol(), getcol()
    def __init__(self, rect, ui_manager):

        element_ids = ['everything_window']

        super().__init__(rect, ui_manager, element_ids=element_ids)

        # create shadow
        shadow_padding = (2, 2)

        self.image = self.ui_manager.get_shadow(self.rect.size)
        self.image.fill(self.ui_manager.get_theme().get_colour(self.object_ids, self.element_ids, 'dark_bg'),
                        pygame.Rect(shadow_padding,
                                    (self.rect.width - shadow_padding[0] * 2,
                                     self.rect.height - shadow_padding[1] * 2)
                                    ))

        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.close_window_button = UIButton(relative_rect=pygame.Rect((self.get_container().rect.width-20, 0),
                                                                      (20, 20)),
                                            text='╳',
                                            manager=ui_manager,
                                            container=self.get_container(),
                                            parent_element=self
                                            )
        self.menu_bar = UIButton(relative_rect=pygame.Rect((0, 0),
                                                           (self.get_container().rect.width-20, 20)),
                                 text='Everything Container',
                                 manager=ui_manager,
                                 container=self.get_container(),
                                 parent_element=self,
                                 object_id='#message_window_title_bar'
                                 )
        self.menu_bar.set_hold_range((100, 100))

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

        self.test_slider = UIHorizontalSlider(pygame.Rect((int(self.rect.width / 2),
                                                           int(self.rect.height * 0.70)),
                                                          (240, 25)),
                                              50.0,
                                              (0.0, 100.0),
                                              self.ui_manager,
                                              container=self.get_container(),
                                              parent_element=self)

        self.slider_label = UILabel(pygame.Rect((int(self.rect.width / 2) + 250,
                                                 int(self.rect.height * 0.70)),
                                                (27, 25)),
                                    str(int(self.test_slider.get_current_value())),
                                    self.ui_manager,
                                    container=self.get_container(),
                                    parent_element=self)

        self.test_text_entry = UITextEntryLine(pygame.Rect((int(self.rect.width / 2),
                                                            int(self.rect.height * 0.50)),
                                                           (200, -1)),
                                               self.ui_manager,
                                               container=self.get_container(),
                                               parent_element=self)
        self.test_text_entry.set_forbidden_characters('numbers')

        current_resolution_string = 'Item 1'
        self.test_drop_down_menu = UIDropDownMenu(['Item 1',
                                                   'Item 2',
                                                   'Item 3',
                                                   'Item 4',
                                                   'Item 5',
                                                   'Item 6'],
                                                  current_resolution_string,
                                                  pygame.Rect((int(self.rect.width / 2),
                                                               int(self.rect.height * 0.3)),
                                                              (200, 25)),
                                                  self.ui_manager,
                                                  container=self.get_container(),
                                                  parent_element=self)

        self.health_bar = UIScreenSpaceHealthBar(pygame.Rect((int(self.rect.width / 9),
                                                              int(self.rect.height * 0.7)),
                                                             (200, 20)),
                                                 self.ui_manager,
                                                 container=self.get_container(),
                                                 parent_element=self)

        loaded_test_image = pygame.image.load('data/images/splat.png').convert_alpha()

        self.test_image = UIImage(pygame.Rect((int(self.rect.width / 9),
                                               int(self.rect.height * 0.3)),
                                              loaded_test_image.get_rect().size),
                                  loaded_test_image, self.ui_manager,
                                  container=self.get_container(),
                                  parent_element=self)
        self.is_selected = False
Пример #28
0
    def __init__(self):
        windowWidth = 1340
        windowHeight = 600
        super().__init__(pygame.Rect(
            SCREEN_WIDTH * 0.5 - windowWidth * 0.5,
            SCREEN_HEIGHT * 0.5 - windowHeight * 0.5,
            windowWidth,
            windowHeight,
        ),
                         ui_manager,
                         window_display_title="Settings",
                         resizable=False)

        UILabel(pygame.Rect(0, 0, 80, 30),
                "General",
                ui_manager,
                container=self)

        general_panel = UIPanel(pygame.Rect(10, 30, 250, 600 - 100),
                                starting_layer_height=4,
                                manager=ui_manager,
                                container=self,
                                object_id="#thicker_panel")
        UILabel(pygame.Rect(10, 10, 80, 30),
                "Start Gold",
                ui_manager,
                container=general_panel)

        self.start_gold_text_line = UITextEntryLine(
            pygame.Rect(100, 10, 60, 20),
            manager=ui_manager,
            container=general_panel,
            #object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'bottom'
            })

        register_ui_callback(self.start_gold_text_line,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_start_gold_text_changed(e))

        UILabel(pygame.Rect(10, 40, 80, 30),
                "Start Mana",
                ui_manager,
                container=general_panel)
        self.start_mana_text_line = UITextEntryLine(
            pygame.Rect(100, 40, 60, 20),
            manager=ui_manager,
            container=general_panel,
            #object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'bottom'
            })

        register_ui_callback(self.start_mana_text_line,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_start_mana_text_changed(e))

        UILabel(pygame.Rect(10, 70, 80, 30),
                "Max Tower",
                ui_manager,
                container=general_panel)

        self.max_tower_text_line = UITextEntryLine(
            pygame.Rect(100, 70, 60, 20),
            manager=ui_manager,
            container=general_panel,
            #object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'bottom'
            })

        register_ui_callback(self.max_tower_text_line,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_max_tower_text_changed(e))

        UILabel(pygame.Rect(10, 100, 80, 30),
                "Max Spell",
                ui_manager,
                container=general_panel)

        self.max_spell_text_line = UITextEntryLine(
            pygame.Rect(100, 100, 60, 20),
            manager=ui_manager,
            container=general_panel,
            #object_id='#file_path_text_line',
            anchors={
                'left': 'left',
                'right': 'left',
                'top': 'top',
                'bottom': 'bottom'
            })

        register_ui_callback(self.max_spell_text_line,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_max_spell_text_changed(e))

        # ---------------------------- falls

        UILabel(pygame.Rect(250, 0, 80, 30),
                "Falls",
                ui_manager,
                container=self)

        self.falls_list = ["Dummy", "Dummy"]
        self.current_selected_fall = 0
        self.falls_ui_list = UISelectionList(
            pygame.Rect(270, 30, 250, 220),
            item_list=self.falls_list,
            manager=ui_manager,
            container=self,
            object_id="#thicker_panel",
        )

        register_ui_callback(self.falls_ui_list,
                             pygame_gui.UI_SELECTION_LIST_NEW_SELECTION,
                             lambda e: self.on_fall_list_item_select())

        self.fall_add_btn = UIButton(pygame.Rect(270, 250, 125, 30),
                                     "Add Fall",
                                     ui_manager,
                                     container=self)
        self.fall_remove_btn = UIButton(pygame.Rect(395, 250, 125, 30),
                                        "Remove Fall",
                                        ui_manager,
                                        container=self)

        register_ui_callback(self.fall_add_btn, pygame_gui.UI_BUTTON_PRESSED,
                             lambda e: self.on_fall_add_btn_click())
        register_ui_callback(self.fall_remove_btn,
                             pygame_gui.UI_BUTTON_PRESSED,
                             lambda e: self.on_fall_remove_btn_click())

        UILabel(pygame.Rect(262, 290, 120, 30),
                "Fall Settings",
                ui_manager,
                container=self)

        self.fall_settings_panel = UIPanel(pygame.Rect(270, 320, 250, 210),
                                           starting_layer_height=4,
                                           object_id="#thicker_panel",
                                           manager=ui_manager,
                                           container=self)

        # gold reward

        UILabel(pygame.Rect(5, 10, 100, 30),
                "Gold Reward",
                ui_manager,
                container=self.fall_settings_panel)

        self.fall_gold_reward = UITextEntryLine(
            pygame.Rect(105, 10, 60, 20),
            manager=ui_manager,
            container=self.fall_settings_panel,
        )

        register_ui_callback(self.fall_gold_reward,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_fall_gold_text_changed(e))

        # ---------------------------- groups

        UILabel(pygame.Rect(515, 0, 80, 30),
                "Groups",
                ui_manager,
                container=self)

        self.groups_list = []
        self.current_selected_group = 0
        self.groups_ui_list = UISelectionList(
            pygame.Rect(530, 30, 380, 220),
            item_list=self.groups_list,
            manager=ui_manager,
            container=self,
            object_id="#thicker_panel",
        )

        register_ui_callback(self.groups_ui_list,
                             pygame_gui.UI_SELECTION_LIST_NEW_SELECTION,
                             lambda e: self.on_group_list_item_select(e))

        self.group_add_btn = UIButton(pygame.Rect(530, 250, 380 * 0.5, 30),
                                      "Add Group",
                                      ui_manager,
                                      container=self)
        self.group_remove_btn = UIButton(pygame.Rect(530 + 380 * 0.5, 250,
                                                     380 * 0.5, 30),
                                         "Remove Group",
                                         ui_manager,
                                         container=self)

        register_ui_callback(self.group_add_btn, pygame_gui.UI_BUTTON_PRESSED,
                             lambda e: self.on_group_add_btn_click())
        register_ui_callback(self.group_remove_btn,
                             pygame_gui.UI_BUTTON_PRESSED,
                             lambda e: self.on_group_remove_btn_click())

        UILabel(pygame.Rect(530, 290, 120, 30),
                "Group Settings",
                ui_manager,
                container=self)

        group_settings_panel = UIPanel(pygame.Rect(530, 320, 380, 210),
                                       starting_layer_height=4,
                                       object_id="#thicker_panel",
                                       manager=ui_manager,
                                       container=self)

        UILabel(pygame.Rect(5, 10, 100, 30),
                "Spawn After",
                ui_manager,
                container=group_settings_panel)

        self.group_spawn_mode_dropdown = UIDropDownMenu(
            ["End Of Previous Group Spawn", "Previous Group Destruction"],
            "End Of Previous Group Spawn",
            pygame.Rect(105, 15, 250, 20),
            ui_manager,
            container=group_settings_panel)

        # spawn delay

        UILabel(pygame.Rect(5, 45, 100, 30),
                "Spawn Delay",
                ui_manager,
                container=group_settings_panel)
        self.spawn_delay_entry_line = UITextEntryLine(
            pygame.Rect(105, 45, 40, 20),
            manager=ui_manager,
            container=group_settings_panel)
        UILabel(pygame.Rect(150, 45, 60, 30),
                "seconds",
                ui_manager,
                container=group_settings_panel)

        register_ui_callback(self.spawn_delay_entry_line,
                             pygame_gui.UI_TEXT_ENTRY_CHANGED,
                             lambda e: self.on_group_spawn_delay_changed(e))

        # interval

        UILabel(pygame.Rect(-2, 80, 100, 30),
                "Interval:",
                ui_manager,
                container=group_settings_panel)
        UILabel(pygame.Rect(2, 115, 50, 30),
                "From",
                ui_manager,
                container=group_settings_panel)
        self.interval_from_entry_line = UITextEntryLine(
            pygame.Rect(50, 115, 40, 20),
            manager=ui_manager,
            container=group_settings_panel)
        UILabel(pygame.Rect(95, 115, 20, 30),
                "To",
                ui_manager,
                container=group_settings_panel)
        self.interval_to_entry_line = UITextEntryLine(
            pygame.Rect(120, 115, 40, 20),
            manager=ui_manager,
            container=group_settings_panel)
        UILabel(pygame.Rect(165, 115, 60, 30),
                "seconds",
                ui_manager,
                container=group_settings_panel)

        register_ui_callback(
            self.interval_from_entry_line, pygame_gui.UI_TEXT_ENTRY_CHANGED,
            lambda e: self.on_group_spawn_interval_left_changed(e))

        register_ui_callback(
            self.interval_to_entry_line, pygame_gui.UI_TEXT_ENTRY_CHANGED,
            lambda e: self.on_group_spawn_interval_right_changed(e))

        # ---------------------------- enemies

        self.enemies_label = UILabel(pygame.Rect(910, 0, 80, 30),
                                     "Enemies",
                                     ui_manager,
                                     container=self)

        self.enemies_view_panel = UIPanel(relative_rect=pygame.Rect(
            920, 30, 385, 505),
                                          starting_layer_height=4,
                                          object_id="#thicker_panel",
                                          manager=ui_manager,
                                          container=self)
        #self.enemies_view_panel.hide()
        #self.enemies_label.hide()

        #250, 600 - 100
        self.enemy_container = UIScrollingContainer(
            pygame.Rect(0, 0, 380, 500),
            ui_manager,
            container=self.enemies_view_panel,
            object_id="#enemy_scrolling_container",
            starting_height=4)

        item_height = 165
        self.enemy_container.set_scrollable_area_dimensions(
            (360, 5 + len(enemy.enemies_definitions) * item_height + 10))
        """
        for n in range(0, 24):
            UIButton(
                pygame.Rect(5, 5 + 50 * n, 370, 45),
                "hi",
                ui_manager,
                self.enemy_container
            )
        """

        self.enemies_counts_entry_lines = []
        for n in range(0, len(enemy.enemies_definitions)):
            enemy_panel = UIPanel(relative_rect=pygame.Rect(
                5, 5 + item_height * n, 350, item_height),
                                  starting_layer_height=4,
                                  manager=ui_manager,
                                  container=self.enemy_container,
                                  object_id="#thicker_panel")
            enemy_stats_panel = UIPanel(relative_rect=pygame.Rect(
                10, 35, 325, 80),
                                        starting_layer_height=4,
                                        manager=ui_manager,
                                        container=enemy_panel)

            UITextBox(
                "<b>" + enemy.enemies_definitions[n].name + "</b>",
                pygame.Rect(5, 5, 340, 30),
                ui_manager,
                container=enemy_panel,
                object_id="#no_border_textbox",
            )
            definition = enemy.enemies_definitions[n]
            preview_sprite_path = ENEMIES_PATH + definition.sprites_directory + "/" + definition.preview_sprite + ".png"
            image_size = (720 * 0.15, 480 * 0.15)
            UIImage(relative_rect=pygame.Rect(5, 5, image_size[0],
                                              image_size[1]),
                    image_surface=resource_cache.get_resource(
                        preview_sprite_path,
                        resource_cache.SurfaceType,
                        alpha=True),
                    manager=ui_manager,
                    container=enemy_stats_panel)
            UITextBox("<font color=#00FF00><b>Health: </b></font>" +
                      str(definition.health) + "<br><br>"
                      "<font color=#BB0000><b>Damage: </b></font>" +
                      str(definition.damages) + "</br></br>" +
                      "<font color=#4488FF><b>Speed: </b></font>" +
                      str(definition.speed),
                      pygame.Rect(5 + image_size[0] + 5, 5, 120, 140),
                      ui_manager,
                      container=enemy_stats_panel,
                      object_id="#no_border_textbox")
            UITextBox("Count: ",
                      pygame.Rect(5, item_height - 45, 80, 30),
                      ui_manager,
                      container=enemy_panel,
                      object_id="#no_border_textbox")
            self.enemies_counts_entry_lines.append(
                UITextEntryLine(
                    pygame.Rect(65, item_height - 45, 50, 25),
                    manager=ui_manager,
                    container=enemy_panel,
                ))

            register_ui_callback(
                self.enemies_counts_entry_lines[n],
                pygame_gui.UI_TEXT_ENTRY_CHANGED,
                lambda e, i=n: self.on_change_enemy_count(e, i))

        self.set_blocking(True)
        self.update_settings()
Пример #29
0
    def init_gui(self):
        # top panel
        top_panel = UIPanel(
            pygame.Rect(0, 0, SCREEN_WIDTH, 30),
            starting_layer_height=4,
            manager=ui_manager
        )

        # player's health bar
        self.player_hp_bar = UIPanel(
            relative_rect=pygame.Rect(SCREEN_WIDTH / 2, 5, SCREEN_WIDTH / 2 - 15, 15),
            manager=ui_manager,
            starting_layer_height=5,
            container=top_panel,
            object_id="#player_health_bar"
        )

        self.enemy_fall_bar = UIPanel(
            relative_rect=pygame.Rect(15, 5, SCREEN_WIDTH / 2 - 15, 15),
            manager=ui_manager,
            starting_layer_height=5,
            container=top_panel,
            object_id="#enemies_fall_bar"
        )

        # right panel
        right_panel_w = SCREEN_WIDTH - TILE_SIZE * MAP_W
        right_panel_h = SCREEN_HEIGHT - 30
        right_panel = UIPanel(
            pygame.Rect(TILE_SIZE * MAP_W, 30, right_panel_w, right_panel_h),
            starting_layer_height=4,
            manager=ui_manager
        )

        fall_info_panel = UIPanel(
            relative_rect=pygame.Rect(0, 0, right_panel_w - 5, 120),
            starting_layer_height=4,
            object_id="#thicker_panel",
            manager=ui_manager,
            container=right_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "top"
            }
        )

        self.fall_label = UITextBox(
            "<b>Fall:</b> 0 / 10",
            pygame.Rect(5, 5, 300, 35),
            ui_manager,
            container=fall_info_panel,
            object_id="#no_border_textbox",
        )

        self.fall_reward_label = UITextBox(
            "<b>Reward:</b> 1000 gold coins",
            pygame.Rect(5, 40, 400, 35),
            ui_manager,
            container=fall_info_panel,
            object_id="#no_border_textbox",
        )

        # build panel
        build_panel = UIPanel(
            relative_rect=pygame.Rect(0, 120, right_panel_w - 5, 600),
            starting_layer_height=4,
            object_id="#thicker_panel",
            manager=ui_manager,
            container=right_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom"
            }
        )

        self.gold_label = UITextBox(
            f"<b><font color=#DEAF21>Gold: </font>{session_data.player_gold}</b>, " +
            f"<b><font color=#4488FF>Mana: </font>{session_data.player_mana}</b>",
            pygame.Rect(5, 5, 500, 35),
            ui_manager,
            container=build_panel,
            object_id="#no_border_textbox",
        )

        """
        UITextBox(
            "<b>Towers</b>",
            pygame.Rect(5, 45, 300, 40),
            ui_manager,
            container=build_panel,
            object_id="#no_border_textbox",
        )
        """

        self.towers_btn = UIButton(
                pygame.Rect(5, 45, 145, 30),
                "Towers",
                ui_manager,
                container=build_panel,
        )
        register_ui_callback(self.towers_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: self.switch_right_panel(True))

        self.spells_btn = UIButton(
                pygame.Rect(155, 45, 145, 30),
                "Spells",
                ui_manager,
                container=build_panel,
        )
        register_ui_callback(self.spells_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: self.switch_right_panel(False))

        self.towers_view_panel = UIPanel(
            relative_rect=pygame.Rect(5, 80, right_panel_w - 20, 500),
            starting_layer_height=3,
            object_id="#thicker_panel",
            manager=ui_manager,
            container=build_panel
        )

        self.towers_container = UIScrollingContainer(
            pygame.Rect(0, 0, right_panel_w - 30, 500 * Y_RATIO),
            ui_manager,
            container=self.towers_view_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom"
            },
            object_id="#enemy_scrolling_container",
            starting_height=3
        )

        item_height = 200 * Y_RATIO
        self.towers_container.set_scrollable_area_dimensions((right_panel_w - 50, 2 + len(tower.tower_definitions) * item_height + 10 + 10))
        self.tower_build_buttons = []

        for n in range(0, len(tower.tower_definitions)):
            if n+1 > map_settings.settings.max_tower:
                break;

            definition = tower.tower_definitions[n]

            tower_panel = UIPanel(
                relative_rect=pygame.Rect(2, 5 + item_height * n, right_panel_w - 55, item_height),
                starting_layer_height=5,
                manager=ui_manager,
                container=self.towers_container,
                object_id="#tower_panel"
            )

            UITextBox(
                "<b>" + definition.name + "</b>",
                pygame.Rect(5, 5, 340 * X_RATIO, 30 * Y_RATIO),
                ui_manager,
                container=tower_panel,
                object_id="#no_border_textbox",
            )

            tower_stats_panel = UIPanel(
                relative_rect=pygame.Rect(7, 35, right_panel_w - 80, 120 * Y_RATIO),
                starting_layer_height=5,
                manager=ui_manager,
                container=tower_panel,
                anchors={
                    "left": "left",
                    "right": "right",
                    "top": "top",
                    "bottom": "bottom"
                }
            )

            image_path = TOWERS_PATH + definition.image + ".png"
            image_size = (76 * X_RATIO, 76 * Y_RATIO)
            image_panel = UIPanel(
                relative_rect=pygame.Rect(5, 5, image_size[0], image_size[1]),
                starting_layer_height=5,
                manager=ui_manager,
                container=tower_stats_panel,
            )

            UIImage(
                relative_rect=pygame.Rect(0, -8, image_size[0], image_size[1]),
                image_surface=resource_cache.get_resource(image_path,
                                                          resource_cache.SurfaceType, alpha=True),
                manager=ui_manager,
                container=image_panel
            )

            UITextBox(
                "<font color=#BB0000><b>Damages: </b></font>" + str(definition.damages) +
                "<br><br>"
                "<font color=#9141D1><b>Speed: </b></font>" + str(definition.projectile_speed) +
                "<br><br>" +
                "<font color=#4488FF><b>Reload Time: </b></font>" + str(definition.reload_time) +
                "<br><br>" +
                "<font color=#00FF00><b>Range: </b></font>" + str(definition.range) +
                "<br><br>" +
                "<font color=#DEAF21><b>Cost: </b></font>" + str(definition.cost)
                ,
                pygame.Rect(5 + image_size[0], 0, 160, 140),
                ui_manager,
                container=tower_stats_panel,
                object_id="#no_border_textbox"
            )

            tower_build_btn = UIButton(
                pygame.Rect(8, -34 * Y_RATIO, (right_panel_w - 80) * X_RATIO, 30 * Y_RATIO),
                "Build",
                ui_manager,
                container=tower_panel,
                anchors={
                    "left": "left",
                    "right": "right",
                    "top": "bottom",
                    "bottom": "bottom"
                }
            )
            self.tower_build_buttons.append(tower_build_btn)
            register_ui_callback(tower_build_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e, i=n: self.spawn_tower(i))


        # spells

        self.spells_view_panel = UIPanel(
            relative_rect=pygame.Rect(5, 80, right_panel_w - 20, 500),
            starting_layer_height=3,
            object_id="#thicker_panel",
            manager=ui_manager,
            container=build_panel
        )

        spells_container = UIScrollingContainer(
            pygame.Rect(0, 0, right_panel_w - 30, 500 * Y_RATIO),
            ui_manager,
            container=self.spells_view_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom"
            },
            object_id="#enemy_scrolling_container",
            starting_height=3
        )

        item_height = 320 * Y_RATIO
        spells_container.set_scrollable_area_dimensions(
            (right_panel_w - 50, 2 + len(spell.spells_definitions) * item_height + 10 + 10)
        )
        self.spell_research_buttons = []
        self.spell_use_buttons = []

        for n in range(0, len(spell.spells_definitions)):
            if n+1 > map_settings.settings.max_spell:
                break;

            definition = spell.spells_definitions[n]

            spell_panel = UIPanel(
                relative_rect=pygame.Rect(2, 5 + item_height * n, right_panel_w - 55, item_height),
                starting_layer_height=5,
                manager=ui_manager,
                container=spells_container,
                object_id="#tower_panel"
            )

            UITextBox(
                "<b>" + definition.name + "</b>",
                pygame.Rect(5, 5, 340 * X_RATIO, 30 * Y_RATIO),
                ui_manager,
                container=spell_panel,
                object_id="#no_border_textbox",
            )

            spell_stats_panel = UIPanel(
                relative_rect=pygame.Rect(7, 35, right_panel_w - 80, 240 * Y_RATIO),
                starting_layer_height=5,
                manager=ui_manager,
                container=spell_panel,
                anchors={
                    "left": "left",
                    "right": "right",
                    "top": "top",
                    "bottom": "bottom"
                }
            )

            image_path = EFFECTS_PATH + definition.icon_image + ".png"
            image_size = (76 * X_RATIO, 76 * Y_RATIO)
            image_panel = UIPanel(
                relative_rect=pygame.Rect((right_panel_w - 80) * 0.5 - image_size[0] * 0.5, 5, image_size[0], image_size[1]),
                starting_layer_height=5,
                manager=ui_manager,
                container=spell_stats_panel,
            )

            UIImage(
                relative_rect=pygame.Rect(0, -8, image_size[0], image_size[1]),
                image_surface=resource_cache.get_resource(image_path,
                                                          resource_cache.SurfaceType, alpha=True),
                manager=ui_manager,
                container=image_panel
            )

            UITextBox(
                spell.make_description(definition),
                pygame.Rect(5, 5 + image_size[1], right_panel_w - 80, item_height - image_size[1]),
                ui_manager,
                container=spell_stats_panel,
                object_id="#no_border_textbox"
            )

            spell_research_btn = UIButton(
                pygame.Rect(8, -34 * Y_RATIO, (right_panel_w - 200) * X_RATIO, 30 * Y_RATIO),
                "Research",
                ui_manager,
                container=spell_panel,
                anchors={
                    "left": "left",
                    "right": "right",
                    "top": "bottom",
                    "bottom": "bottom"
                }
            )
            self.spell_research_buttons.append(spell_research_btn)
            register_ui_callback(spell_research_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e, i=n: self.research_spell(i))

            spell_use_btn = UIButton(
                pygame.Rect(8 + (right_panel_w - 200) * X_RATIO, -34 * Y_RATIO, (right_panel_w - 200) * X_RATIO, 30 * Y_RATIO),
                "Use",
                ui_manager,
                container=spell_panel,
                anchors={
                    "left": "left",
                    "right": "right",
                    "top": "bottom",
                    "bottom": "bottom"
                }
            )
            self.spell_use_buttons.append(spell_use_btn)
            register_ui_callback(spell_use_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e, i=n: self.on_cast_spell_start(i))

        # bottom buttons section

        buttons_panel = UIPanel(
            relative_rect=pygame.Rect(0, -140 * Y_RATIO, right_panel_w - 5, 140 * Y_RATIO),
            starting_layer_height=100,
            object_id="#thicker_panel",
            manager=ui_manager,
            container=right_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "bottom",
                "bottom": "bottom"
            }
        )

        # start fall button
        self.start_fall_btn = UIButton(
            pygame.Rect(20, -120 * Y_RATIO, right_panel_w * 0.8, 40 * Y_RATIO),
            "Start Fall",
            ui_manager,
            container=buttons_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "bottom",
                "bottom": "bottom"
            }
        )
        register_ui_callback(self.start_fall_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: self.start_fall())

        # back button
        self.back_btn = UIButton(
            pygame.Rect(20, -60 * Y_RATIO, right_panel_w * 0.8, 40 * Y_RATIO),
            "Back To Menu",
            ui_manager,
            container=buttons_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "bottom",
                "bottom": "bottom"
            }
        )
        register_ui_callback(self.back_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: switch_mode(MODE_MENU))


        # building
        self.building_panel = UIPanel(
            pygame.Rect(TILE_SIZE * MAP_W, 30, right_panel_w, right_panel_h),
            starting_layer_height=200,
            manager=ui_manager
        )

        UITextBox(
            "<font size=5><b>Place Tower On Map</b></font>",
            pygame.Rect(right_panel_w/6, right_panel_h/4, right_panel_w, 40),
            ui_manager,
            container=self.building_panel,
            object_id="#no_border_textbox"
        )

        cancel_btn = UIButton(
            pygame.Rect(80, (right_panel_h/4)+50, right_panel_w * 0.5, 40),
            "Cancel",
            ui_manager,
            container=self.building_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom"
            }
        )
        register_ui_callback(cancel_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: self.on_calcel_build())

        self.building_panel.hide()

        # casting spell
        self.casting_panel = UIPanel(
            pygame.Rect(TILE_SIZE * MAP_W, 30, right_panel_w, right_panel_h),
            starting_layer_height=200,
            manager=ui_manager
        )

        UITextBox(
            "<font size=5><b>Click On Path To Cast Spell</b></font>",
            pygame.Rect(5, right_panel_h / 4, right_panel_w, 40),
            ui_manager,
            container=self.casting_panel,
            object_id="#no_border_textbox"
        )

        cancel_btn = UIButton(
            pygame.Rect(80, (right_panel_h / 4) + 50, right_panel_w * 0.5, 40),
            "Cancel",
            ui_manager,
            container=self.casting_panel,
            anchors={
                "left": "left",
                "right": "right",
                "top": "top",
                "bottom": "bottom"
            }
        )
        register_ui_callback(cancel_btn, pygame_gui.UI_BUTTON_PRESSED, lambda e: self.on_cancel_spell())

        self.casting_panel.hide()
Пример #30
0
 def __init__(self, pos, manager):super().__init__(pygame.Rect(pos, (352, 300)),manager=manager,window_display_title="camera",object_id="#camera",);self.dsurf = UIImage(pygame.Rect((0, 0),(320,240)),pygame.Surface((320,240)).convert(),manager=manager,container=self,parent_element=self,)
 def update(self, delta):super().update(delta);self.dsurf.image.blit(pygame.surfarray.make_surface(numpy.rot90(cv2.cvtColor(camera.read()[1],cv2.COLOR_BGR2RGB))), (0, 0))