diff clients/editor/plugins/LayerTool.py @ 340:7e5717105212

* Added setId to Layer, Map, Object and Camera * Added setCellGrid to Layer * LayerTool now supports changing layer IDs and cellgrids on existing layers * LayerTool can now create layers with hexagonal tilegrids
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 24 Aug 2009 23:08:53 +0000
parents e249fa887259
children 8e71629c4c43
line wrap: on
line diff
--- a/clients/editor/plugins/LayerTool.py	Mon Aug 24 18:52:49 2009 +0000
+++ b/clients/editor/plugins/LayerTool.py	Mon Aug 24 23:08:53 2009 +0000
@@ -350,7 +350,7 @@
 		self._widget = pychan.loadXML('gui/layereditor.xml')
 
 		# TODO: Add access method for adopted grid types?
-		self._widget.findChild(name="gridBox").items = ['square']#, 'hex'] # Hex does not work?
+		self._widget.findChild(name="gridBox").items = ['square', 'hexagonal']
 		
 		# TODO: Ditto for pather?
 		self._widget.findChild(name="pathingBox").items = ['cell_edges_only', 'cell_edges_and_diagonals', 'freeform']
@@ -358,7 +358,7 @@
 		if layer:
 			cg = layer.getCellGrid()
 			cgtype = 0
-			if cg.getType() == 'hex':
+			if cg.getType() == 'hexagonal':
 				cgtype = 1
 			
 			self._widget.distributeData({
@@ -423,24 +423,24 @@
 		if grid_type == 0:
 			grid_type = "square"
 		else:
-			grid_type = "hex"
+			grid_type = "hexagonal"
 
 		# Set up layer
 		layer = self.layer
 		cellgrid = None
-		if not self.layer:
-			# TODO: FIFE currently does not support setting layer ID and cellgrid after the layer has been created
-			cellgrid = self.model.getCellGrid(grid_type)
-			if not cellgrid:
-				print "Invalid grid type"
-				return
+		
+		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)
+		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)
 				
@@ -448,12 +448,12 @@
 				print 'The layer ' + str(layerId) + ' already exists!'
 				return
 		else:
-			cellgrid = layer.getCellGrid()
-			cellgrid.setRotation(rotation)
-			cellgrid.setXScale(x_scale)
-			cellgrid.setYScale(y_scale)
-			cellgrid.setXShift(x_offset)
-			cellgrid.setYShift(y_offset)
+			layer.setCellGrid(cellgrid)
+			try:
+				layer.setId(str(layerId))
+			except fife.NameClash:
+				print 'The layer ' + str(layerId) + ' already exists!'
+				return
 		
 		layer.setPathingStrategy(pathing)