# HG changeset patch
# User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
# Date 1251163260 0
# Node ID 8e71629c4c43fd2142db7d65379b052a4ed34162
# Parent 7be6293f13d11a1d42f89650634a6a8e6b331577
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
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/gui/cameradialog.xml
--- /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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/gui/cameraedit.xml
--- 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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/gui/layerdialog.xml
--- /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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/gui/layereditor.xml
--- 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 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/plugins/LayerTool.py
--- 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)
-
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/scripts/gui/filemanager.py
--- 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()
diff -r 7be6293f13d1 -r 8e71629c4c43 clients/editor/scripts/gui/layerdialog.py
--- /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