Esempio n. 1
0
    def _finished(self):
        """ """
        # Collect and validate data
        regionId = self._widget.collectData('regionBox')
        if regionId == '':
            dialogs.message(message=unicode("Please enter a region id."),
                            caption=unicode("Error"))
            return

        try:
            x_pos = float(self._widget.collectData('xPosBox'))
            y_pos = float(self._widget.collectData('yPosBox'))
            width = float(self._widget.collectData('widthBox'))
            height = float(self._widget.collectData('heightBox'))
            rect = fife.DoubleRect(x_pos, y_pos, width, height)
        except ValueError:
            dialogs.message(message=unicode(
                "Please enter integer or decimal values for scale."),
                            caption=unicode("Error"))
            return

        # Set up region
        region = self.region

        if not self.region:
            if not self.regions.has_key(regionId):
                region = Region(str(regionId), rect)
            else:
                print 'The region ' + str(regionId) + ' already exists!'
                return
        else:
            if region.name == regionId or not self.regions.has_key(regionId):
                region.name = (str(regionId))
                region.rect = rect
            else:
                print 'The region ' + str(regionId) + ' already exists!'
                return

        # Hide dialog and call back
        self._widget.hide()

        if self.callback:
            pychan.tools.applyOnlySuitable(self.callback, region=region)
Esempio n. 2
0
    def _finished(self):
        """ """
        # Collect and validate data
        regionId = self._widget.collectData('regionBox')
        if regionId == '':
            dialogs.message(message=unicode("Please enter a region id."), caption=unicode("Error"))
            return

        try:
            x_pos = float(self._widget.collectData('xPosBox'))
            y_pos = float(self._widget.collectData('yPosBox'))
            width = float(self._widget.collectData('widthBox'))
            height = float(self._widget.collectData('heightBox'))
            rect = fife.DoubleRect(x_pos, y_pos, width, height)
        except ValueError:
            dialogs.message(message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error"))
            return

        # Set up region
        region = self.region

        if not self.region:
            if not self.regions.has_key(regionId):
                region = Region(str(regionId), rect)
            else:
                print 'The region ' + str(regionId) + ' already exists!'
                return
        else:
            if region.name == regionId or not self.regions.has_key(regionId):
                region.name = (str(regionId))
                region.rect = rect
            else:
                print 'The region ' + str(regionId) + ' already exists!'
                return

        # Hide dialog and call back
        self._widget.hide()

        if self.callback:
            pychan.tools.applyOnlySuitable(self.callback, region=region)
Esempio n. 3
0
    def _finished(self):
        """ """
        # Collect and validate data
        layerId = self._widget.collectData("layerBox")
        if layerId == "":
            dialogs.message(message=unicode("Please enter a layer id."), caption=unicode("Error"))
            return

        try:
            x_offset = float(self._widget.collectData("xOffsetBox"))
            y_offset = float(self._widget.collectData("yOffsetBox"))
            z_offset = float(self._widget.collectData("zOffsetBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal values for offset."), caption=unicode("Error")
            )
            return

        try:
            x_scale = float(self._widget.collectData("xScaleBox"))
            y_scale = float(self._widget.collectData("yScaleBox"))
            z_scale = float(self._widget.collectData("zScaleBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error")
            )
            return

        try:
            rotation = float(self._widget.collectData("rotBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal value for rotation."), caption=unicode("Error")
            )
            return

        try:
            transparency = int(self._widget.collectData("transBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter an integer value in the range of 0-255 for transparency."),
                caption=unicode("Error"),
            )
            return

            # Clamp the transparency value between 0 and 255
        if transparency < 0:
            transparency = 0
        if transparency > 255:
            transparency = 255

        grid_type = int(self._widget.collectData("gridBox"))
        pathing = int(self._widget.collectData("pathingBox"))
        sorting = int(self._widget.collectData("sortingBox"))
        walkable = bool(self._widget.collectData("is_walkable"))
        interact = bool(self._widget.collectData("is_interact"))

        if grid_type == 0:
            grid_type = "square"
        else:
            grid_type = "hexagonal"

            # Set up layer
        layer = self.layer

        cellgrid = self.model.getCellGrid(grid_type)

        if not cellgrid:
            print "Invalid grid"
            return

        cellgrid.setRotation(rotation)
        cellgrid.setXScale(x_scale)
        cellgrid.setYScale(y_scale)
        cellgrid.setZScale(z_scale)
        cellgrid.setXShift(x_offset)
        cellgrid.setYShift(y_offset)
        cellgrid.setZShift(z_offset)

        if not self.layer:
            try:
                layer = self.map.createLayer(str(layerId), cellgrid)

            except fife.NameClash:
                print "The layer " + str(layerId) + " already exists!"
                del cellgrid
                return
        else:
            layer.setCellGrid(cellgrid)
            try:
                layer.setId(str(layerId))
            except fife.NameClash:
                print "The layer " + str(layerId) + " already exists!"
                return

        layer.setPathingStrategy(pathing)
        layer.setSortingStrategy(sorting)
        layer.setLayerTransparency(transparency)

        # destroy CellCache
        if layer.isWalkable() and not walkable:
            layer.destroyCellCache()
            # create CellCache
        elif not layer.isWalkable() and walkable:
            layer.setWalkable(walkable)
            layer.createCellCache()
            cache = layer.getCellCache()
            cache.createCells()
            cache.forceUpdate()

        for cam in self.map.getCameras():
            cam.resetRenderers()

            if layer:
                # make sure the layer is active for the various renderers
                fife.InstanceRenderer.getInstance(cam).addActiveLayer(layer)
                fife.GridRenderer.getInstance(cam).addActiveLayer(layer)
                fife.BlockingInfoRenderer.getInstance(cam).addActiveLayer(layer)
                fife.CoordinateRenderer.getInstance(cam).addActiveLayer(layer)
                fife.CellSelectionRenderer.getInstance(cam).addActiveLayer(layer)
                fife.LightRenderer.getInstance(cam).addActiveLayer(layer)
                fife.GenericRenderer.getInstance(cam).addActiveLayer(layer)
                fife.CellRenderer.getInstance(cam).addActiveLayer(layer)

                # Hide dialog and call back
        self._widget.hide()

        if self.callback:
            pychan.tools.applyOnlySuitable(self.callback, layer=layer)
Esempio n. 4
0
	def _finished(self):
		""" """
		# Collect and validate data
		layerId = self._widget.collectData('layerBox')
		if layerId == '':
			dialogs.message(message=unicode("Please enter a layer id."), caption=unicode("Error"))
			return
			
		try:
			x_offset = float(self._widget.collectData('xOffsetBox'))
			y_offset = float(self._widget.collectData('yOffsetBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal values for offset."), caption=unicode("Error"))
			return

		try:
			x_scale = float(self._widget.collectData('xScaleBox'))
			y_scale = float(self._widget.collectData('yScaleBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error"))
			return

		try:
			rotation = float(self._widget.collectData('rotBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal value for rotation."), caption=unicode("Error"))
			return
			
		try:
			transparency = int(self._widget.collectData('transBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter an integer value in the range of 0-255 for transparency."), caption=unicode("Error"))
			return
			
		
		#Clamp the transparency value between 0 and 255
		if transparency < 0:
			transparency = 0
		if transparency > 255:
			transparency = 255
		
		grid_type = int(self._widget.collectData('gridBox'))
		pathing = int(self._widget.collectData('pathingBox'))

		if grid_type == 0:
			grid_type = "square"
		else:
			grid_type = "hexagonal"

		# Set up layer
		layer = self.layer
		
		cellgrid = self.model.getCellGrid(grid_type)

		if not cellgrid:
			print "Invalid grid"
			return

		cellgrid.setRotation(rotation)
		cellgrid.setXScale(x_scale)
		cellgrid.setYScale(y_scale)
		cellgrid.setXShift(x_offset)
		cellgrid.setYShift(y_offset)
	
		if not self.layer:
			try:
				layer = self.map.createLayer(str(layerId), cellgrid)
				
			except fife.NameClash:
				print 'The layer ' + str(layerId) + ' already exists!'
				del cellgrid
				return
		else:
			layer.setCellGrid(cellgrid)
			try:
				layer.setId(str(layerId))
			except fife.NameClash:
				print 'The layer ' + str(layerId) + ' already exists!'
				return
		
		layer.setPathingStrategy(pathing)
		layer.setLayerTransparency(transparency)
		
		for cam in self.map.getCameras():
			cam.resetRenderers()
			
			if layer:
				# make sure the layer is active for the various renderers
				fife.InstanceRenderer.getInstance(cam).addActiveLayer(layer)
				fife.GridRenderer.getInstance(cam).addActiveLayer(layer)
				fife.BlockingInfoRenderer.getInstance(cam).addActiveLayer(layer)
				fife.CoordinateRenderer.getInstance(cam).addActiveLayer(layer)
				fife.CellSelectionRenderer.getInstance(cam).addActiveLayer(layer)
				fife.LightRenderer.getInstance(cam).addActiveLayer(layer)
				fife.GenericRenderer.getInstance(cam).addActiveLayer(layer)
		
		# Hide dialog and call back
		self._widget.hide()
		
		if self.callback:
			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
Esempio n. 5
0
	def _finished(self):
		id = self._widget.collectData('idBox')
		if id == '':
			dialogs.message(message=unicode("Please enter a camera ID."), caption=unicode("Error"))
			return

		try:
			map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
		except fife.Exception:
			dialogs.message(message=unicode("Cannot find the specified map id."), caption=unicode("Error"))
			return

		try:
			layer = map.getLayer(str(self._widget.collectData('layerBox')))
		except fife.Exception:
			dialogs.message(message=unicode("Cannot find the specified layer id."), caption=unicode("Error"))
			return

		try:
			vals = self._widget.collectData('viewBox').split(',')
			if len(vals) != 4:
				raise ValueError	

			viewport = fife.Rect(*[int(c) for c in vals])
		except ValueError:
			dialogs.message(message=unicode("Please enter 4 comma (,) delimited values for viewport x,y,width,height."), caption=unicode("Error"))
			return

		try:
			refh = int(self._widget.collectData('refhBox'))
			refw = int(self._widget.collectData('refwBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter positive integer values for reference width and height."), caption=unicode("Error"))
			return

		try:
			rot = int(self._widget.collectData('rotBox'))
			tilt = int(self._widget.collectData('tiltBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter positive integer values for rotation and tilt."), caption=unicode("Error"))

			return

		cam = map.addCamera(str(id), layer, viewport)
		cam.setCellImageDimensions(refw, refh)
		cam.setRotation(rot)
		cam.setTilt(tilt)
		
		renderer = fife.InstanceRenderer.getInstance(cam)
		renderer.activateAllLayers(map)
	
		self._widget.hide()

		if self.callback:
			self.callback()
Esempio n. 6
0
    def _finished(self):
        """ """
        # Collect and validate data
        layerId = self._widget.collectData("layerBox")
        if layerId == "":
            dialogs.message(message=unicode("Please enter a layer id."), caption=unicode("Error"))
            return

        try:
            x_offset = float(self._widget.collectData("xOffsetBox"))
            y_offset = float(self._widget.collectData("yOffsetBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal values for offset."), caption=unicode("Error")
            )
            return

        try:
            x_scale = float(self._widget.collectData("xScaleBox"))
            y_scale = float(self._widget.collectData("yScaleBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error")
            )
            return

        try:
            rotation = float(self._widget.collectData("rotBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter integer or decimal value for rotation."), caption=unicode("Error")
            )
            return

        try:
            transparency = int(self._widget.collectData("transBox"))
        except ValueError:
            dialogs.message(
                message=unicode("Please enter an integer value in the range of 0-255 for transparency."),
                caption=unicode("Error"),
            )
            return

            # Clamp the transparency value between 0 and 255
        if transparency < 0:
            transparency = 0
        if transparency > 255:
            transparency = 255

        grid_type = int(self._widget.collectData("gridBox"))
        pathing = int(self._widget.collectData("pathingBox"))

        if grid_type == 0:
            grid_type = "square"
        else:
            grid_type = "hexagonal"

            # Set up layer
        layer = self.layer
        cellgrid = None

        cellgrid = self.model.getCellGrid(grid_type)
        if not cellgrid:
            print "Invalid grid type"
            return

        cellgrid.setRotation(rotation)
        cellgrid.setXScale(x_scale)
        cellgrid.setYScale(y_scale)
        cellgrid.setXShift(x_offset)
        cellgrid.setYShift(y_offset)

        if not self.layer:
            try:
                layer = self.map.createLayer(str(layerId), cellgrid)

            except fife.NameClash:
                print "The layer " + str(layerId) + " already exists!"
                return
        else:
            layer.setCellGrid(cellgrid)
            try:
                layer.setId(str(layerId))
            except fife.NameClash:
                print "The layer " + str(layerId) + " already exists!"
                return

        layer.setPathingStrategy(pathing)
        layer.setLayerTransparency(transparency)

        for cam in self.map.getCameras():
            cam.resetRenderers()

            # Hide dialog and call back
        self._widget.hide()

        if self.callback:
            pychan.tools.applyOnlySuitable(self.callback, layer=layer)
Esempio n. 7
0
	def _finished(self):
		id = self._widget.collectData('idBox')
		if id == '':
			dialogs.message(message=unicode("Please enter a camera ID."), caption=unicode("Error"))
			return

		try:
			map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
		except fife.Exception:
			dialogs.message(message=unicode("Cannot find the specified map id."), caption=unicode("Error"))
			return

		try:
			layer = map.getLayer(str(self._widget.collectData('layerBox')))
		except fife.Exception:
			dialogs.message(message=unicode("Cannot find the specified layer id."), caption=unicode("Error"))
			return

		try:
			vals = self._widget.collectData('viewBox').split(',')
			if len(vals) != 4:
				raise ValueError	

			viewport = fife.Rect(*[int(c) for c in vals])
		except ValueError:
			dialogs.message(message=unicode("Please enter 4 comma (,) delimited values for viewport x,y,width,height."), caption=unicode("Error"))
			return

		try:
			refh = int(self._widget.collectData('refhBox'))
			refw = int(self._widget.collectData('refwBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter positive integer values for reference width and height."), caption=unicode("Error"))
			return

		try:
			rot = int(self._widget.collectData('rotBox'))
			tilt = int(self._widget.collectData('tiltBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter positive integer values for rotation and tilt."), caption=unicode("Error"))

			return

		cam = map.addCamera(str(id), layer, viewport)
		cam.setCellImageDimensions(refw, refh)
		cam.setRotation(rot)
		cam.setTilt(tilt)
		
		renderer = fife.InstanceRenderer.getInstance(cam)
		renderer.activateAllLayers(map)
	
		self._widget.hide()

		if self.callback:
			self.callback()
	def _finished(self):
		""" """
		# Collect and validate data
		layerId = self._widget.collectData('layerBox')
		if layerId == '':
			dialogs.message(message=unicode("Please enter a layer id."), caption=unicode("Error"))
			return
			
		try:
			x_offset = float(self._widget.collectData('xOffsetBox'))
			y_offset = float(self._widget.collectData('yOffsetBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal values for offset."), caption=unicode("Error"))
			return

		try:
			x_scale = float(self._widget.collectData('xScaleBox'))
			y_scale = float(self._widget.collectData('yScaleBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal values for scale."), caption=unicode("Error"))
			return

		try:
			rotation = float(self._widget.collectData('rotBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter integer or decimal value for rotation."), caption=unicode("Error"))
			return
			
		try:
			transparency = int(self._widget.collectData('transBox'))
		except ValueError:
			dialogs.message(message=unicode("Please enter an integer value in the range of 0-255 for transparency."), caption=unicode("Error"))
			return
			
		
		#Clamp the transparency value between 0 and 255
		if transparency < 0:
			transparency = 0
		if transparency > 255:
			transparency = 255
		
		grid_type = int(self._widget.collectData('gridBox'))
		pathing = int(self._widget.collectData('pathingBox'))

		if grid_type == 0:
			grid_type = "square"
		else:
			grid_type = "hexagonal"

		# Set up layer
		layer = self.layer
		cellgrid = None
		
		cellgrid = self.model.getCellGrid(grid_type)
		if not cellgrid:
			print "Invalid grid type"
			return

		cellgrid.setRotation(rotation)
		cellgrid.setXScale(x_scale)
		cellgrid.setYScale(y_scale)
		cellgrid.setXShift(x_offset)
		cellgrid.setYShift(y_offset)
	
		if not self.layer:
			try:
				layer = self.map.createLayer(str(layerId), cellgrid)
				
			except fife.NameClash:
				print 'The layer ' + str(layerId) + ' already exists!'
				return
		else:
			layer.setCellGrid(cellgrid)
			try:
				layer.setId(str(layerId))
			except fife.NameClash:
				print 'The layer ' + str(layerId) + ' already exists!'
				return
		
		layer.setPathingStrategy(pathing)
		layer.setLayerTransparency(transparency)
		
		for cam in self.map.getCameras():
			cam.resetRenderers()
		
		# Hide dialog and call back
		self._widget.hide()
		
		if self.callback:
			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
Esempio n. 9
0
    def _finished(self):
        """ """
        # Collect and validate data
        layerId = self._widget.collectData('layerBox')
        if layerId == '':
            dialogs.message(message=unicode("Please enter a layer id."),
                            caption=unicode("Error"))
            return

        try:
            x_offset = float(self._widget.collectData('xOffsetBox'))
            y_offset = float(self._widget.collectData('yOffsetBox'))
            z_offset = float(self._widget.collectData('zOffsetBox'))
        except ValueError:
            dialogs.message(message=unicode(
                "Please enter integer or decimal values for offset."),
                            caption=unicode("Error"))
            return

        try:
            x_scale = float(self._widget.collectData('xScaleBox'))
            y_scale = float(self._widget.collectData('yScaleBox'))
            z_scale = float(self._widget.collectData('zScaleBox'))
        except ValueError:
            dialogs.message(message=unicode(
                "Please enter integer or decimal values for scale."),
                            caption=unicode("Error"))
            return

        try:
            rotation = float(self._widget.collectData('rotBox'))
        except ValueError:
            dialogs.message(message=unicode(
                "Please enter integer or decimal value for rotation."),
                            caption=unicode("Error"))
            return

        try:
            transparency = int(self._widget.collectData('transBox'))
        except ValueError:
            dialogs.message(message=unicode(
                "Please enter an integer value in the range of 0-255 for transparency."
            ),
                            caption=unicode("Error"))
            return

        # Clamp the transparency value between 0 and 255
        if transparency < 0:
            transparency = 0
        if transparency > 255:
            transparency = 255

        grid_type = int(self._widget.collectData('gridBox'))
        pathing = int(self._widget.collectData('pathingBox'))
        sorting = int(self._widget.collectData('sortingBox'))
        walkable = bool(self._widget.collectData('is_walkable'))
        interact = bool(self._widget.collectData('is_interact'))

        if grid_type == 0:
            grid_type = "square"
        else:
            grid_type = "hexagonal"

        # Set up layer
        layer = self.layer

        cellgrid = self.model.getCellGrid(grid_type)

        if not cellgrid:
            print "Invalid grid"
            return

        cellgrid.setRotation(rotation)
        cellgrid.setXScale(x_scale)
        cellgrid.setYScale(y_scale)
        cellgrid.setZScale(z_scale)
        cellgrid.setXShift(x_offset)
        cellgrid.setYShift(y_offset)
        cellgrid.setZShift(z_offset)

        if not self.layer:
            try:
                layer = self.map.createLayer(str(layerId), cellgrid)

            except fife.NameClash:
                print 'The layer ' + str(layerId) + ' already exists!'
                del cellgrid
                return
        else:
            layer.setCellGrid(cellgrid)
            try:
                layer.setId(str(layerId))
            except fife.NameClash:
                print 'The layer ' + str(layerId) + ' already exists!'
                return

        layer.setPathingStrategy(pathing)
        layer.setSortingStrategy(sorting)
        layer.setLayerTransparency(transparency)

        # destroy CellCache
        if layer.isWalkable() and not walkable:
            layer.destroyCellCache()
        # create CellCache
        elif not layer.isWalkable() and walkable:
            layer.setWalkable(walkable)
            layer.createCellCache()
            cache = layer.getCellCache()
            cache.createCells()
            cache.forceUpdate()

        for cam in self.map.getCameras():
            cam.resetRenderers()

            if layer:
                # make sure the layer is active for the various renderers
                fife.InstanceRenderer.getInstance(cam).addActiveLayer(layer)
                fife.GridRenderer.getInstance(cam).addActiveLayer(layer)
                fife.BlockingInfoRenderer.getInstance(cam).addActiveLayer(
                    layer)
                fife.CoordinateRenderer.getInstance(cam).addActiveLayer(layer)
                fife.CellSelectionRenderer.getInstance(cam).addActiveLayer(
                    layer)
                fife.LightRenderer.getInstance(cam).addActiveLayer(layer)
                fife.GenericRenderer.getInstance(cam).addActiveLayer(layer)
                fife.CellRenderer.getInstance(cam).addActiveLayer(layer)

        # Hide dialog and call back
        self._widget.hide()

        if self.callback:
            pychan.tools.applyOnlySuitable(self.callback, layer=layer)