changeset 343:8e71629c4c43

Several changes to layer, camera and map dialogs: * Renamed CameraEditor and LayerEditor to CameraDialog and LayerDialog * Moved CameraDialog and LayerDialog into their own modules in scripts.gui so other components can use them. * Prettier camera dialog * Added LayerDialog to map wizard
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 25 Aug 2009 01:21:00 +0000
parents 7be6293f13d1
children 5a9e5f1c897d
files clients/editor/gui/cameradialog.xml clients/editor/gui/cameraedit.xml clients/editor/gui/layerdialog.xml clients/editor/gui/layereditor.xml clients/editor/plugins/LayerTool.py clients/editor/scripts/gui/filemanager.py clients/editor/scripts/gui/layerdialog.py
diffstat 7 files changed, 239 insertions(+), 307 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clients/editor/gui/cameradialog.xml	Tue Aug 25 01:21:00 2009 +0000
@@ -0,0 +1,50 @@
+<Panel title="Camera Editor" min_size="300, 250">
+	<VBox hexpand="1">
+		<HBox>
+			<!-- Should be replaced with a dropdown box containing open maps -->
+			<Label name="mapLabel" text="Map ID:" min_size="100, 10" />
+			<TextField name="mapBox" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<!-- Should be replaced with a dropdown box containing available layers in map -->
+			<Label name="layerLabel" text="Layer ID:" min_size="100, 10" />
+			<TextField name="layerBox" min_size="100, 10" />
+		</HBox>
+
+		<Spacer fixed_size="10" />
+		<HBox>
+			<Spacer />
+			<Label text="Camera settings" />
+			<Spacer />
+		</HBox>
+		<HBox>
+			<Label name="idLabel" text="Camera ID:" min_size="100, 10" />
+			<TextField name="idBox" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<Label name="viewLabel" text="Viewport ('x,y,w,h'):" min_size="100, 10" />
+			<TextField name="viewBox" text="0,0,640,480" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<Label name="refhLabel" text="Reference cell height:" min_size="100, 10" />
+			<TextField name="refhBox" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<Label name="refwLabel" text="Reference cell width:" min_size="100, 10" />
+			<TextField name="refwBox" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<Label name="rotLabel" text="Rotation:" min_size="100, 10" />
+			<TextField name="rotBox" text="0" min_size="100, 10" />
+		</HBox>
+		<HBox>
+			<Label name="tiltLabel" text="Tilt:" min_size="100, 10" />
+			<TextField name="tiltBox" text="0" min_size="100, 10" />
+		</HBox>
+	</VBox>
+	<Spacer />
+	<HBox>
+		<Button name="okButton" text="OK"/>
+		<Button name="cancelButton" text="Cancel"/>
+	</HBox>
+</Panel>
--- a/clients/editor/gui/cameraedit.xml	Tue Aug 25 00:31:16 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-<Panel title="Camera Editor">
-	<VBox hexpand="1">
-		<HBox>
-			<Label name="idLabel" text="Camera ID:" min_size="125,10"/>
-			<TextField name="idBox" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="mapLabel" text="Camera Map ID:" min_size="125,10"/>
-      <TextField name="mapBox" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="layerLabel" text="Camera Layer ID:" min_size="125,10"/>
-      <TextField name="layerBox" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="viewLabel" text="Viewport ('x,y,w,h'):" min_size="125,10"/>
-		  <TextField name="viewBox" text="0,0,640,480" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="refhLabel" text="Reference cell height:" min_size="125,10"/>
-			<TextField name="refhBox" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="refwLabel" text="Reference cell width:" min_size="125,10"/>
-			<TextField name="refwBox" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="rotLabel" text="Rotation:" min_size="125,10"/>
-			<TextField name="rotBox" text="0" min_size="100,10"/>
-		</HBox>
-		<HBox>
-			<Label name="tiltLabel" text="Tilt:" min_size="125,10"/>
-			<TextField name="tiltBox" text="0" min_size="100,10"/>
-		</HBox>
-	</VBox>
-	<HBox>
-		<Button name="okButton" text="OK"/>
-		<Button name="cancelButton" text="Cancel"/>
-	</HBox>
-</Panel>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clients/editor/gui/layerdialog.xml	Tue Aug 25 01:21:00 2009 +0000
@@ -0,0 +1,40 @@
+<Panel title="Layer Editor" min_size="200, 220">
+	<VBox hexpand="1">
+		<HBox>
+			<Label name="layerLabel" text="Layer ID:" />
+			<TextField name="layerBox" hexpand="3" />
+		</HBox>
+		<Label name="pathingLabel" text="Pathfinding strategy:"/>
+		<DropDown name="pathingBox"/>
+
+		<Spacer fixed_size="10" />
+		
+		<Label name="gridLabel" text="Grid type:" />
+		<DropDown name="gridBox"/>
+		<HBox>
+			<Label name="rotLabel" text="Rotation:" />
+			<TextField name="rotBox" text="0.0" hexpand="3" />
+		</HBox>
+		<HBox>
+			<Label name="scaleLabel" text="Scale:" />
+			<Label name="xScaleLabel" text="X:" hexpand="0"/>
+			<TextField name="xScaleBox" text="1.0"  min_size="45,10" />
+			<Label name="yScaleLabel" text="Y:" hexpand="0"/>
+			<TextField name="yScaleBox" text="1.0"  min_size="45,10" />
+		</HBox>
+		<HBox>
+			<Label name="offsetLabel" text="Offset:" />
+			<Label name="xOffsetLabel" text="X:" hexpand="0" />
+			<TextField name="xOffsetBox" text="0.0" min_size="45,10" />
+			<Label name="yOffsetLabel" text="Y:" hexpand="0" />
+			<TextField name="yOffsetBox" text="0.0" min_size="45,10" />
+		</HBox>
+	</VBox>
+	
+	<HBox>
+		<Spacer />
+		<Button name="okButton" text="OK" />
+		<Button name="cancelButton" text="Cancel" />
+	</HBox>
+	
+</Panel>
--- a/clients/editor/gui/layereditor.xml	Tue Aug 25 00:31:16 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-<Panel title="Layer Editor" min_size="200, 220">
-	<VBox hexpand="1">
-		<HBox>
-			<Label name="layerLabel" text="Layer ID:" />
-			<TextField name="layerBox" hexpand="3" />
-		</HBox>
-		<Label name="pathingLabel" text="Pathfinding strategy:"/>
-		<DropDown name="pathingBox"/>
-
-		<Spacer fixed_size="10" />
-		
-		<Label name="gridLabel" text="Grid type:" />
-		<DropDown name="gridBox"/>
-		<HBox>
-			<Label name="rotLabel" text="Rotation:" />
-			<TextField name="rotBox" text="0.0" hexpand="3" />
-		</HBox>
-		<HBox>
-			<Label name="scaleLabel" text="Scale:" />
-			<Label name="xScaleLabel" text="X:" hexpand="0"/>
-			<TextField name="xScaleBox" text="1.0"  min_size="45,10" />
-			<Label name="yScaleLabel" text="Y:" hexpand="0"/>
-			<TextField name="yScaleBox" text="1.0"  min_size="45,10" />
-		</HBox>
-		<HBox>
-			<Label name="offsetLabel" text="Offset:" />
-			<Label name="xOffsetLabel" text="X:" hexpand="0" />
-			<TextField name="xOffsetBox" text="0.0" min_size="45,10" />
-			<Label name="yOffsetLabel" text="Y:" hexpand="0" />
-			<TextField name="yOffsetBox" text="0.0" min_size="45,10" />
-		</HBox>
-	</VBox>
-	
-	<HBox>
-		<Spacer />
-		<Button name="okButton" text="OK" />
-		<Button name="cancelButton" text="Cancel" />
-	</HBox>
-	
-</Panel>
--- a/clients/editor/plugins/LayerTool.py	Tue Aug 25 00:31:16 2009 +0000
+++ b/clients/editor/plugins/LayerTool.py	Tue Aug 25 01:21:00 2009 +0000
@@ -31,6 +31,7 @@
 import pychan
 import pychan.widgets as widgets
 from pychan.tools import callbackWithArguments as cbwa
+from scripts.gui.layerdialog import LayerDialog
 
 # default should be pychan default, highlight can be choosen (format: r,g,b)
 _DEFAULT_BACKGROUND_COLOR = pychan.internal.DEFAULT_STYLE['default']['base_color']
@@ -162,7 +163,7 @@
 		if not self._mapview: return
 		
 		if self._layer_wizard: self._layer_wizard._widget.hide()
-		self._layer_wizard = LayerEditor(self._editor.getEngine(), self._mapview.getMap(), callback=self._layerCreated)
+		self._layer_wizard = LayerDialog(self._editor.getEngine(), self._mapview.getMap(), callback=self._layerCreated)
 		
 	def _layerCreated(self, layer):
 		self.update(self._mapview)
@@ -174,7 +175,7 @@
 		if not layer: return
 		
 		if self._layer_wizard: self._layer_wizard._widget.hide()
-		self._layer_wizard = LayerEditor(self._editor.getEngine(), self._mapview.getMap(), layer=layer, callback=cbwa(self.update, self._mapview))
+		self._layer_wizard = LayerDialog(self._editor.getEngine(), self._mapview.getMap(), layer=layer, callback=cbwa(self.update, self._mapview))
 		
 	def clear(self):
 		""" remove all subwrappers """
@@ -243,7 +244,7 @@
 			self.wrapper.addChild(subwrapper)
 			self.subwrappers.append(subwrapper)
 		
-		self.container.adaptLayout(False)		
+		self.container.adaptLayout()		
 			
 	def toggle_layer_visibility(self, event, widget):
 		""" Callback for ToggleButtons 
@@ -314,7 +315,6 @@
 		widget.background_color = _HIGHLIGHT_BACKGROUND_COLOR
 		widget.foreground_color = _HIGHLIGHT_BACKGROUND_COLOR
 		widget.base_color = _HIGHLIGHT_BACKGROUND_COLOR
-		self.container.adaptLayout(False)
 		
 		self._mapview.getController().selectLayer(layerid)
 
@@ -333,135 +333,4 @@
 			self._adjust_position()
 
 
-class LayerEditor(object):
-	""" The B{LayerEditor} provides a gui dialog for creating and editing layers.
-	
-		FIXME:
-			- gridtypes can only be square for now
-			- pathing strategy 
-	"""
-	def __init__(self, engine, map, callback=None, onCancel=None, layer=None):
-		self.engine = engine
-		self.model = engine.getModel()
-		self.map = map
-		self.layer = layer
-		self.callback = callback
-		self.onCancel = onCancel
-		self._widget = pychan.loadXML('gui/layereditor.xml')
 
-		# TODO: Add access method for adopted grid types?
-		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']
-
-		if layer:
-			cg = layer.getCellGrid()
-			cgtype = 0
-			if cg.getType() == 'hexagonal':
-				cgtype = 1
-			
-			self._widget.distributeData({
-				"layerBox" : unicode(layer.getId()),
-				"xScaleBox" : unicode(cg.getXScale()),
-				"yScaleBox" : unicode(cg.getYScale()),
-				"rotBox" : unicode(cg.getRotation()),
-				"xOffsetBox" : unicode(cg.getXShift()),
-				"yOffsetBox" : unicode(cg.getYShift())
-			})
-			
-			self._widget.findChild(name="pathingBox").selected = int(layer.getPathingStrategy())
-			self._widget.findChild(name="gridBox").selected = int(cgtype)
-		else:
-			self._widget.findChild(name="pathingBox").selected = 0
-			self._widget.findChild(name="gridBox").selected = 0
-
-		self._widget.mapEvents({
-			'okButton'     : self._finished,
-			'cancelButton' : self._cancelled
-		})
-
-		self._widget.show()
-		
-	def _cancelled(self):
-		""" """
-		if self.onCancel:
-			self.onCancel()
-		self._widget.hide()		
-
-	def _finished(self):
-		""" """
-		# Collect and validate data
-		layerId = self._widget.collectData('layerBox')
-		if layerId == '':
-			print 'Please enter a layer id.'
-			return
-			
-		try:
-			x_offset = float(self._widget.collectData('xOffsetBox'))
-			y_offset = float(self._widget.collectData('yOffsetBox'))
-		except ValueError:
-			print 'Please enter integer or decimal values for offset.'
-			return
-
-		try:
-			x_scale = float(self._widget.collectData('xScaleBox'))
-			y_scale = float(self._widget.collectData('yScaleBox'))
-		except ValueError:
-			print 'Please enter integer or decimal values for scale.'
-			return
-
-		try:
-			rotation = float(self._widget.collectData('rotBox'))
-		except ValueError:
-			print 'Please enter integer or decimal value for rotation.'
-			return
-			
-		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)
-		
-		self.engine.getView().resetRenderers()
-		
-		# Hide dialog and call back
-		self._widget.hide()
-		
-		if self.callback:
-			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
-
--- a/clients/editor/scripts/gui/filemanager.py	Tue Aug 25 00:31:16 2009 +0000
+++ b/clients/editor/scripts/gui/filemanager.py	Tue Aug 25 01:21:00 2009 +0000
@@ -9,6 +9,8 @@
 from input import InputDialog
 from selection import SelectionDialog, ClickSelectionDialog
 from scripts.events import events
+from scripts.gui.cameradialog import CameraDialog
+from scripts.gui.layerdialog import LayerDialog
 
 class FileManager(object):
 	def __init__(self):
@@ -119,18 +121,20 @@
 			self._newMap()
 
 	def _newMap(self):
-		self._mapdlg = InputDialog(u'Enter a map identifier:', self._newLayer, self._clean)
+		self._mapdlg = InputDialog(u'Enter a map name:', self._newLayer, self._clean)
 		
 	def _newLayer(self, mapId):
+		if mapId == '':
+			print "Please enter a map ID"
+			return self._newMap()
+			
 		self._map = self.engine.getModel().createMap(str(mapId))
-		self._layerdlg = InputDialog(u'Enter a layer identifier for a default layer:', self._newCamera, self._clean)
+		self._layerdlg = LayerDialog(self.engine, self._map, self._newCamera, self._clean)
 		
-	def _newCamera(self, layerId):
-		grid = fife.SquareGrid()
-		self._layer = self._map.createLayer(str(layerId), grid)
-		grid.thisown = 0
+	def _newCamera(self, layer):
+		self._layer = layer
 		
-		self._cameradlg = CameraEditor(self.engine, self._addMap, self._clean, self._map, self._layer)
+		self._cameradlg = CameraDialog(self.engine, self._addMap, self._clean, self._map, self._layer)
 		
 	def _addMap(self):
 		self.editor.newMapView(self._map)
@@ -205,88 +209,3 @@
 			
 		events.onObjectsImported.send(sender=self)
 
-class CameraEditor(object):
-	"""
-	CameraEditor provides a gui dialog for camera creation. The callback is called when camera creation is complete. A
-	partial specification of the camera parameters may optionally be given.
-	"""
-	def __init__(self, engine, callback=None, onCancel=None, map=None, layer=None):
-		self.engine = engine
-		self.callback = callback
-		self.onCancel = onCancel
-		self._widget = pychan.loadXML('gui/cameraedit.xml')
-
-		if map:
-			self._widget.distributeData({
-				'mapBox'	: unicode(map.getId()),
-			})
-
-		if layer:
-			self._widget.distributeData({
-				'layerBox'	: unicode(layer.getId()),
-			})
-
-		self._widget.mapEvents({
-			'okButton'     : self._finished,
-			'cancelButton' : self._cancelled
-		})
-
-		self._widget.show()
-		
-	def _cancelled(self):
-		if self.onCancel:
-			self.onCancel()
-		self._widget.hide()
-		
-
-	def _finished(self):
-		id = self._widget.collectData('idBox')
-		if id == '':
-			print 'Please enter a camera id.'
-			return
-
-		try:
-			map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
-		except fife.Exception:
-			print 'Cannot find the specified map id.'
-			return
-
-		try:
-			layer = map.getLayer(str(self._widget.collectData('layerBox')))
-		except fife.Exception:
-			print 'Cannot find the specified layer id.'	
-			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:
-			print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.'
-			return
-
-		try:
-			refh = int(self._widget.collectData('refhBox'))
-			refw = int(self._widget.collectData('refwBox'))
-		except ValueError:
-			print 'Please enter positive integer values for reference width and height.'
-			return
-
-		try:
-			rot = int(self._widget.collectData('rotBox'))
-			tilt = int(self._widget.collectData('tiltBox'))
-		except ValueError:
-			print 'Please enter positive integer values for rotation and tilt.'
-			return
-
-		cam = self.engine.getView().addCamera(str(id), layer, viewport, fife.ExactModelCoordinate(0,0,0))
-		cam.setCellImageDimensions(refw, refh)
-		cam.setRotation(rot)
-		cam.setTilt(tilt)
-	
-		self._widget.hide()
-
-		if self.callback:
-			self.callback()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clients/editor/scripts/gui/layerdialog.py	Tue Aug 25 01:21:00 2009 +0000
@@ -0,0 +1,134 @@
+import fife
+import pychan
+
+class LayerDialog(object):
+	""" The B{LayerDialog} provides a gui dialog for creating and editing layers.
+	
+		FIXME:
+			- gridtypes can only be square for now
+			- pathing strategy 
+	"""
+	def __init__(self, engine, map, callback=None, onCancel=None, layer=None):
+		self.engine = engine
+		self.model = engine.getModel()
+		self.map = map
+		self.layer = layer
+		self.callback = callback
+		self.onCancel = onCancel
+		self._widget = pychan.loadXML('gui/layerdialog.xml')
+
+		# TODO: Add access method for adopted grid types?
+		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']
+
+		if layer:
+			cg = layer.getCellGrid()
+			cgtype = 0
+			if cg.getType() == 'hexagonal':
+				cgtype = 1
+			
+			self._widget.distributeData({
+				"layerBox" : unicode(layer.getId()),
+				"xScaleBox" : unicode(cg.getXScale()),
+				"yScaleBox" : unicode(cg.getYScale()),
+				"rotBox" : unicode(cg.getRotation()),
+				"xOffsetBox" : unicode(cg.getXShift()),
+				"yOffsetBox" : unicode(cg.getYShift())
+			})
+			
+			self._widget.findChild(name="pathingBox").selected = int(layer.getPathingStrategy())
+			self._widget.findChild(name="gridBox").selected = int(cgtype)
+		else:
+			self._widget.findChild(name="pathingBox").selected = 0
+			self._widget.findChild(name="gridBox").selected = 0
+
+		self._widget.mapEvents({
+			'okButton'     : self._finished,
+			'cancelButton' : self._cancelled
+		})
+
+		self._widget.show()
+		
+	def _cancelled(self):
+		""" """
+		if self.onCancel:
+			self.onCancel()
+		self._widget.hide()		
+
+	def _finished(self):
+		""" """
+		# Collect and validate data
+		layerId = self._widget.collectData('layerBox')
+		if layerId == '':
+			print 'Please enter a layer id.'
+			return
+			
+		try:
+			x_offset = float(self._widget.collectData('xOffsetBox'))
+			y_offset = float(self._widget.collectData('yOffsetBox'))
+		except ValueError:
+			print 'Please enter integer or decimal values for offset.'
+			return
+
+		try:
+			x_scale = float(self._widget.collectData('xScaleBox'))
+			y_scale = float(self._widget.collectData('yScaleBox'))
+		except ValueError:
+			print 'Please enter integer or decimal values for scale.'
+			return
+
+		try:
+			rotation = float(self._widget.collectData('rotBox'))
+		except ValueError:
+			print 'Please enter integer or decimal value for rotation.'
+			return
+			
+		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)
+		
+		self.engine.getView().resetRenderers()
+		
+		# Hide dialog and call back
+		self._widget.hide()
+		
+		if self.callback:
+			pychan.tools.applyOnlySuitable(self.callback, layer=layer)
\ No newline at end of file