Exemplo n.º 1
0
 def on_break(self, pos):
     data = game_vars.get_block_data(pos)
     if data:
         inv = Inventory((1, 1))
         inv.load(data)
         item = inv.get_item(0, 0)
         if item.is_item:
             game_vars.drop_item(DroppedItem(item), c.random_sign(),
                                 [p * BLOCK_W for p in pos])
     game_vars.write_block_data(pos, None)
     return True
Exemplo n.º 2
0
        def __init__(self, pos, data):
            self.inv = Inventory(Chest.INV_DIM)
            ActiveUI.__init__(self,
                              None,
                              self.inv.rect.move(0, self.inv.rect.h),
                              pos=pos)
            self.can_drag = False
            self.inv.load(data)

            if not game_vars.player.inventory.open:
                game_vars.player.inventory.toggle()
Exemplo n.º 3
0
        def __init__(self, pos, data):
            rect = pg.Rect(0, 0, c.MIN_W // 2, c.MIN_H // 2)
            rect.center = c.screen_center
            super().__init__(pg.Surface(rect.size), rect, pos=pos)

            # Set up inventory for item
            whitelist = [
                item_id for item_id, item in game_vars.items.items()
                if isinstance(item, ItemTypes.Upgradable)
            ]
            self.inv = Inventory((1, 1), whitelist=whitelist, max_stack=1)
            self.inv.rect.move_ip((self.rect.w - c.INV_W) // 2, c.INV_W // 2)
            self.inv.load(data)
            # Set up upgrade section with offsets, rect, and surface
            self.dragging = False
            self.off_x = self.off_y = 0
            self.max_x = self.max_y = 0
            y = self.inv.rect.bottom
            self.tree_r = pg.Rect(0, y, self.rect.w, self.rect.h - y)
            self.upgrade_tree = self.tree_s = None
            # Load the data
            self.load_tree()
Exemplo n.º 4
0
        def __init__(self, pos, data, max_stack):
            self.max_stack = max_stack
            # Generate text
            font = c.get_scaled_font(-1, c.INV_IMG_W, "Crush!",
                                     "Times New Roman")
            text = font.render("Crush!", 1, (255, 255, 255))
            self.text_rect = text.get_rect(centery=c.INV_W * 3 // 2)
            w = max(self.text_rect.w, c.INV_W)
            self.text_rect.centerx = w // 2
            # Draw surface
            s = pg.Surface((w, c.INV_W * 2))
            s.blit(text, self.text_rect)
            # This is where we will take/add items
            self.inv = Inventory((1, 1),
                                 whitelist=Objects.CRUSH_DROPS.keys(),
                                 max_stack=9)
            self.inv.rect = pg.Rect((w - c.INV_W) // 2, 0, c.INV_W, c.INV_W)
            self.inv.load(data)

            ActiveUI.__init__(self, s, s.get_rect(), pos=pos)

            self.rect.center = c.screen_center
Exemplo n.º 5
0
        def __init__(self, pos, data):
            self.name = c.WorldFile(game_vars.universe())
            self.cursor = False
            # Load inventories
            self.invs = {
                self.BIOME:
                Inventory((2, 2),
                          max_stack=1,
                          whitelist=game_vars.biomes.keys()),
                self.STRUCTURE:
                Inventory((1, 1), max_stack=4, whitelist=[i.BONUS_STRUCTURE]),
                self.SIZE:
                Inventory((1, 1),
                          max_stack=1,
                          whitelist=WorldGenerator.WORLD_DIMS.keys())
            }
            for idx in self.INV_ORDER:
                data = self.invs[idx].load(data)
            # Set text height
            text_h = c.INV_W // 2
            # Text
            text = {
                self.BIOME: "Biome Cards",
                self.STRUCTURE: "Bonus Structure",
                self.SIZE: "Size Card"
            }
            # Get font and inventory section width
            longest = c.get_widest_string(text.values())
            font = c.get_scaled_font(-1, text_h, longest)
            inv_w = font.size(longest)[0]
            # Get all surfaces to draw
            surfaces = []
            y = 0
            for idx in self.INV_ORDER:
                text_s = font.render(text[idx], 1, (255, 255, 255))
                text_rect = text_s.get_rect(centerx=inv_w // 2,
                                            centery=y + text_h // 2)
                surfaces.append([text_s, text_rect])
                y += text_h
                inv = self.invs[idx]
                inv.rect.y, inv.rect.centerx = y, inv_w // 2
                y += inv.rect.h
            # Draw world name text
            text_h = y // 7
            font = c.get_scaled_font(inv_w, text_h, "World Name:")
            text = font.render("World Name:", 1, (255, 255, 255))
            surfaces.append([
                text,
                text.get_rect(center=(inv_w * 3 // 2, text_h * 3 // 2))
            ])
            # Draw create button text
            font = c.get_scaled_font(inv_w, text_h * 2, "Create!")
            text = font.render("Create!", 1, (0, 200, 0))
            self.create_rect = text.get_rect(center=(inv_w * 3 // 2,
                                                     text_h * 5))
            surfaces.append([text, self.create_rect])
            # Used to enter world name
            self.name_rect = pg.Rect(inv_w, text_h * 2, inv_w, text_h)
            # Draw surface
            s = pg.Surface((inv_w * 2, y))
            for surface, rect in surfaces:
                s.blit(surface, rect)
            super().__init__(s, s.get_rect(), pos=pos)
            self.rect.center = c.screen_center

            if not game_vars.player.inventory.open:
                game_vars.player.inventory.toggle()