Beispiel #1
0
    def __init__(self, parent, tile_width, use_svg, is_player):
        super(BeingWidget, self).__init__(parent, tile_width)
        ResetItem.__init__(self, tile_width)

        if use_svg and is_player:
            klass = ChibiDirectionWidget
        elif use_svg:
            klass = SvgSpeciesItem
        else:
            klass = CharItem

        self._current = None
        self.items = {}
        for direction in Direction.viewable(use_svg):
            self.items[direction] = klass(self, tile_width, direction)
            #FIXME figure out some other place to do this
            if not use_svg:
                self.items[direction].setBold()

        self.animation = BeingAnimation(self)
Beispiel #2
0
class BeingWidget(BaseItemWidget, ResetItem):

    attrs = ('is_player', 'direction', 'guid')

    svg_klass = SvgSpeciesItem
    nonsvg_klass = CharItem
    player_svg_klass = ChibiDirectionWidget

    def __init__(self, parent, tile_width, use_svg, is_player):
        super(BeingWidget, self).__init__(parent, tile_width)
        ResetItem.__init__(self, tile_width)

        if use_svg and is_player:
            klass = ChibiDirectionWidget
        elif use_svg:
            klass = SvgSpeciesItem
        else:
            klass = CharItem

        self._current = None
        self.items = {}
        for direction in Direction.viewable(use_svg):
            self.items[direction] = klass(self, tile_width, direction)
            #FIXME figure out some other place to do this
            if not use_svg:
                self.items[direction].setBold()

        self.animation = BeingAnimation(self)

    def __repr__(self):
        return '<BeingWidget #{}>'.format(self['guid'])

    def reset(self, being):
        super(BeingWidget, self).reset(being)

        for direc, widget in self.items.items():
            widget.reset(being)
            widget.setOpacity(0)

        direc = Direction.toViewed(self['direction'])
        self.setDirection(direc)

    def updateUsing(self, using):
        for widget in self.items.values():
            widget.setUsing(using)

    def die(self):
        self.animation.fade_out()

    def teleport_in(self):
        self.animation.fade_in()

    def teleport_out(self):
        self.animation.fade_out()

    def melee(self, tile, direc):
        direc = Direction.toViewed(direc)
        self.setDirection(direc)
        self.animation.melee(tile)

    def walk(self, old_tile, new_tile, level, direction):
        direc = Direction.toViewed(direction)
        self.setDirection(direc)
        self.animation.walk(old_tile, new_tile, level)

    def setDirection(self, direction):
        #if not self.items.get(direction, self.items['sw']):
        #    return
        if self._current:
            #self.widgets[self._current].animation.fadeTo(0)
            self.items[self._current].setOpacity(0)
        self.items[direction].setOpacity(1) 
        self._current = direction