Exemplo n.º 1
0
    def __init__(self, game, settings):

        super(GameWidget, self).__init__()

        self.game = game
        self.level = LevelWidget(config.config['tile_size'])
        self.level.setParentItem(self)
        self.settings = settings

        self.turn_started.connect(self.level._onTurnStarted)

        game.events['game_started'].connect(self._onGameStarted)
        game.events['game_ended'].connect(self._onGameEnded)
        game.events['level_changed'].connect(self._onLevelChanged)
        game.events['map_changed'].connect(self._onMapChanged)

        game.events['being_moved'].connect(self.level._onBeingMoved)
        game.events['being_became_visible'].connect(self.level._onBeingBecameVisible)
        game.events['being_became_invisible'].connect(self.level._onBeingBecameInvisible)
        game.events['being_meleed'].connect(self.level._onBeingMeleed)
        game.events['being_kicked'].connect(self.level._onBeingKicked)
        game.events['being_spell_damage'].connect(self.level._onBeingSpellDamage)
        game.events['being_spell_resistance'].connect(self.level._onBeingSpellResistance)
        game.events['being_died'].connect(self.level._onBeingDied)

        game.events['tile_inventory_changed'].connect(self.level._onTileInventoryChanged)
        game.events['tiles_changed_state'].connect(self.level._onTilesChangedState)
        game.events['tile_changed'].connect(self.level._onTileChanged)

        game.events['wand_zapped'].connect(self.level._onWandZapped)

        game.events['redraw'].connect(self._onRedraw)
Exemplo n.º 2
0
class GameWidget(QtGui.QGraphicsWidget):

    turn_started = QtCore.pyqtSignal()
    menu_names = ['game', 'wizard', 'settings']

    def __init__(self, game, settings):

        super(GameWidget, self).__init__()

        self.game = game
        self.level = LevelWidget(config.config['tile_size'])
        self.level.setParentItem(self)
        self.settings = settings

        self.turn_started.connect(self.level._onTurnStarted)

        game.events['game_started'].connect(self._onGameStarted)
        game.events['game_ended'].connect(self._onGameEnded)
        game.events['level_changed'].connect(self._onLevelChanged)
        game.events['map_changed'].connect(self._onMapChanged)

        game.events['being_moved'].connect(self.level._onBeingMoved)
        game.events['being_became_visible'].connect(self.level._onBeingBecameVisible)
        game.events['being_became_invisible'].connect(self.level._onBeingBecameInvisible)
        game.events['being_meleed'].connect(self.level._onBeingMeleed)
        game.events['being_kicked'].connect(self.level._onBeingKicked)
        game.events['being_spell_damage'].connect(self.level._onBeingSpellDamage)
        game.events['being_spell_resistance'].connect(self.level._onBeingSpellResistance)
        game.events['being_died'].connect(self.level._onBeingDied)

        game.events['tile_inventory_changed'].connect(self.level._onTileInventoryChanged)
        game.events['tiles_changed_state'].connect(self.level._onTilesChangedState)
        game.events['tile_changed'].connect(self.level._onTileChanged)

        game.events['wand_zapped'].connect(self.level._onWandZapped)

        game.events['redraw'].connect(self._onRedraw)


    @property
    def player_tile(self): return self.level.player_tile
    @property
    def use_svg(self): return self.settings['view', 'use_svg']
    @property
    def use_iso(self): return self.settings['view', 'use_iso']
    @property
    def use_char(self): return self.settings['view', 'use_char']
    @property
    def seethrough(self): return self.settings['view', 'seethrough']
    @property
    def debug(self): return self.settings['view', 'debug']

    def _onAction(self, kind, name):
        if kind == 'game':
            getattr(self.game, name)()
        else:
            self.turn_started.emit()
            self.game.player.dispatch_command(name)

    def _onGameStarted(self, level):
        self.level.setEnabled(True)
        self._onLevelChanged(level)

    def _onGameEnded(self):
        self.level.setEnabled(False)

    def toggleSeethrough(self):
        self.settings['view', 'seethrough'] = not self.seethrough
        self._toggle()

    def toggleIso(self):
        self.settings['view', 'use_iso'] = not self.use_iso
        self._toggle()

    def toggleChar(self):
        self.settings['view', 'use_char'] = not self.use_char
        self._toggle()

    def toggleSvg(self):
        self.settings['view', 'use_svg'] = not self.use_svg
        self._toggle()

    def toggleDebug(self):
        self.settings['view', 'debug'] = not self.debug
        self._toggle()


    def _onLevelChanged(self, level):
        self._toggle(level)

    def _onRedraw(self, level):
        SvgRenderer.cached.clear()
        self._toggle(level)

    def _onMapChanged(self, level):
        self.level.reset(level.tiles())

    def _toggle(self, level=None):
        if not level:
            level = self.game.level
        self.level.setTiles(level, self.use_iso, self.use_svg, self.seethrough, self.debug, self.use_char)