コード例 #1
0
ファイル: mapview.py プロジェクト: ajventer/mirthless
 def tileicons(self, x, y, scn_x, scn_y, scale):
     rect = pygame.Rect(scn_x, scn_y, scale, scale)
     if self.frontend.mode != 'editor':
         if not self.gamemap.tile(x,y).get('revealed', False):
             return
         player = self.frontend.game.player
         loc = player.location()
         if loc['x'] == x and loc['y'] == y and not 'player' in self.frontend.sprites:
             playerbtn = ButtonSprite(
                 self.frontend.tilemaps,
                 rect,
                 self.frontend.eventstack,
                 onclick = self.click,
                 onclick_params = [(scn_x,scn_y)],
                 animations = player.getsubtree('animations'),
                 layer=self._layer+2,
                 fps=5,
                 mouseover=player.displayname(),
                 frontend=self.frontend)
             self.frontend.sprites['player'] = playerbtn
     scn_x = 50+(self.tilesize*x)
     scn_y = 65+(self.tilesize*y)
     npc = None
     animations = {'view':[]}
     for objtype, item in self.gamemap.tile_objects(x,y):
         if objtype != 'npc':
             animations['view'] += item.get('animations/view')
         else:
             npc = ButtonSprite(
                 self.frontend.tilemaps,
                 rect,
                 self.frontend.eventstack,
                 onclick = self.click,
                 onclick_params = [(scn_x,scn_y)],
                 animations = item.getsubtree('animations'),
                 layer=self._layer+2,
                 fps=5,
                 mouseover=item.displayname(),
                 frontend=self.frontend)
     if animations['view'] and npc is None:
         itemsprite = ButtonSprite(
             self.frontend.tilemaps,
             rect,
             self.frontend.eventstack,
             onclick = self.click,
             onclick_params = [(scn_x,scn_y)],
             animations = animations,
             layer=self._layer+1,
             fps=3,
             frontend=self.frontend)
         self._addtemp(make_hash(), itemsprite)
     if npc is not None and not npc.get_hash() in self.frontend.sprites:
         self.frontend.sprites[npc.get_hash()] = npc
         if not npc in self.frontend.game.characters: 
             self.frontend.game.characters.append(npc)
コード例 #2
0
ファイル: inventory.py プロジェクト: ajventer/mirthless
    def layout(self):
        self._rmtemp()

        itemlist = []
        for itemfile in file_list('items'):
            itemfile = os.path.basename(itemfile)
            itemlist.append(Item(load_yaml('items',itemfile)))
        inventory_rect = pygame.Rect(self.rect.x,self.rect.y, self.rect.w - 523, self.rect.h)
        pack = ContainerDialog(
            inventory_rect,
            self.frontend,
            'Pack:',
            layer=self._layer +1,
            items=[Item(i) for i in self.char.get('inventory/pack',[])],
            onclose=self.update_inventory,
            onselect=self.equip_item,
            onselect_parms=[],
            can_add=False,
            can_remove=False,
            addfrom=itemlist
            )
        self._addtemp('Inventory_pack_dialog', pack)
        image_x = self.rect.w - 522
        image_y = 10
        self.image.blit(self.frontend.imagecache['inventory_background.png'], (image_x, image_y))
        rects = load_yaml('images','gui_rects.yaml')
        debug(self.char())
        portrait = self.frontend.imagecache[self.char.get('personal/portrait')]
        portrait = pygame.transform.smoothscale(portrait, (256,256))
        prect = rects['inventory_portrait']
        self.image.blit(portrait,(image_x + prect['x'],image_y + prect['y']))
        image_x += self.rect.x
        image_y += self.rect.y
        for itemtuple in self.char.inventory_generator(['equiped']):
            debug(itemtuple)
            item, slot = itemtuple[1], itemtuple[2]
            irect = rects[slot]
            irect = pygame.Rect(image_x + irect['x'], image_y + irect['y'], irect['w'], irect['h'])
            debug(slot, irect)
            sprite = ButtonSprite(
                self.frontend.tilemaps,
                irect,
                self.frontend.eventstack,
                onclick=self.unequip_item,
                onclick_params=[slot],
                animations=item.getsubtree('animations'),
                layer=self._layer + 2,
                fps=5,
                mouseover=item.displayname(),
                frontend=self.frontend,
                sendself=True
                )
            sprite.setanimation('view')
            self._addtemp(make_hash(), sprite)
コード例 #3
0
ファイル: mapview.py プロジェクト: ajventer/mirthless
 def zoomicons(self, x, y, scn_x, scn_y):
     objlist = list(self.gamemap.tile_objects(x,y))
     n = len(objlist)
     if not n:
         return
     col, row = 0, 0
     if n%2 != 0:
         n += 1
     colcount = n/2
     if n < 4:
         scale = int(128/n)
     else:
         scale = int(128/colcount)
     for objtype,item in objlist:
         s_x = scn_x + col*scale
         s_y = scn_y + row*scale
         rect = pygame.Rect(s_x, s_y, scale, scale)
         if objtype != 'money':
             animations = item.getsubtree('animations')
             name=item.displayname()
         else:
             animations = item
             name='Money'
         itemsprite = ButtonSprite(
         self.frontend.tilemaps,
         rect,
         self.frontend.eventstack,
         onclick = self.targetclick,
         onclick_params = [x,y,objtype, item],
         animations = animations,
         layer=self._layer+2,
         mouseover=name,
         fps=5,
         frontend=self.frontend)
         if objtype == 'npc':
             itemsprite.setanimation('stand')
         else:
             itemsprite.setanimation('view')
         self._addtemp(make_hash(), itemsprite)
         col += 1
         if col == colcount:
             col = 0
             row += 1