comparison 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
comparison
equal deleted inserted replaced
339:0fd74235b34d 340:7e5717105212
348 self.callback = callback 348 self.callback = callback
349 self.onCancel = onCancel 349 self.onCancel = onCancel
350 self._widget = pychan.loadXML('gui/layereditor.xml') 350 self._widget = pychan.loadXML('gui/layereditor.xml')
351 351
352 # TODO: Add access method for adopted grid types? 352 # TODO: Add access method for adopted grid types?
353 self._widget.findChild(name="gridBox").items = ['square']#, 'hex'] # Hex does not work? 353 self._widget.findChild(name="gridBox").items = ['square', 'hexagonal']
354 354
355 # TODO: Ditto for pather? 355 # TODO: Ditto for pather?
356 self._widget.findChild(name="pathingBox").items = ['cell_edges_only', 'cell_edges_and_diagonals', 'freeform'] 356 self._widget.findChild(name="pathingBox").items = ['cell_edges_only', 'cell_edges_and_diagonals', 'freeform']
357 357
358 if layer: 358 if layer:
359 cg = layer.getCellGrid() 359 cg = layer.getCellGrid()
360 cgtype = 0 360 cgtype = 0
361 if cg.getType() == 'hex': 361 if cg.getType() == 'hexagonal':
362 cgtype = 1 362 cgtype = 1
363 363
364 self._widget.distributeData({ 364 self._widget.distributeData({
365 "layerBox" : unicode(layer.getId()), 365 "layerBox" : unicode(layer.getId()),
366 "xScaleBox" : unicode(cg.getXScale()), 366 "xScaleBox" : unicode(cg.getXScale()),
421 pathing = int(self._widget.collectData('pathingBox')) 421 pathing = int(self._widget.collectData('pathingBox'))
422 422
423 if grid_type == 0: 423 if grid_type == 0:
424 grid_type = "square" 424 grid_type = "square"
425 else: 425 else:
426 grid_type = "hex" 426 grid_type = "hexagonal"
427 427
428 # Set up layer 428 # Set up layer
429 layer = self.layer 429 layer = self.layer
430 cellgrid = None 430 cellgrid = None
431
432 cellgrid = self.model.getCellGrid(grid_type)
433 if not cellgrid:
434 print "Invalid grid type"
435 return
436
437 cellgrid.setRotation(rotation)
438 cellgrid.setXScale(x_scale)
439 cellgrid.setYScale(y_scale)
440 cellgrid.setXShift(x_offset)
441 cellgrid.setYShift(y_offset)
442
431 if not self.layer: 443 if not self.layer:
432 # TODO: FIFE currently does not support setting layer ID and cellgrid after the layer has been created
433 cellgrid = self.model.getCellGrid(grid_type)
434 if not cellgrid:
435 print "Invalid grid type"
436 return
437
438 cellgrid.setRotation(rotation)
439 cellgrid.setXScale(x_scale)
440 cellgrid.setYScale(y_scale)
441 cellgrid.setXShift(x_offset)
442 cellgrid.setYShift(y_offset)
443
444 try: 444 try:
445 layer = self.map.createLayer(str(layerId), cellgrid) 445 layer = self.map.createLayer(str(layerId), cellgrid)
446 446
447 except fife.NameClash: 447 except fife.NameClash:
448 print 'The layer ' + str(layerId) + ' already exists!' 448 print 'The layer ' + str(layerId) + ' already exists!'
449 return 449 return
450 else: 450 else:
451 cellgrid = layer.getCellGrid() 451 layer.setCellGrid(cellgrid)
452 cellgrid.setRotation(rotation) 452 try:
453 cellgrid.setXScale(x_scale) 453 layer.setId(str(layerId))
454 cellgrid.setYScale(y_scale) 454 except fife.NameClash:
455 cellgrid.setXShift(x_offset) 455 print 'The layer ' + str(layerId) + ' already exists!'
456 cellgrid.setYShift(y_offset) 456 return
457 457
458 layer.setPathingStrategy(pathing) 458 layer.setPathingStrategy(pathing)
459 459
460 self.engine.getView().resetRenderers() 460 self.engine.getView().resetRenderers()
461 461