Mercurial > fife-parpg
comparison clients/editor/scripts/gui/layerdialog.py @ 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 | |
children | 8b125ec749d7 |
comparison
equal
deleted
inserted
replaced
342:7be6293f13d1 | 343:8e71629c4c43 |
---|---|
1 import fife | |
2 import pychan | |
3 | |
4 class LayerDialog(object): | |
5 """ The B{LayerDialog} provides a gui dialog for creating and editing layers. | |
6 | |
7 FIXME: | |
8 - gridtypes can only be square for now | |
9 - pathing strategy | |
10 """ | |
11 def __init__(self, engine, map, callback=None, onCancel=None, layer=None): | |
12 self.engine = engine | |
13 self.model = engine.getModel() | |
14 self.map = map | |
15 self.layer = layer | |
16 self.callback = callback | |
17 self.onCancel = onCancel | |
18 self._widget = pychan.loadXML('gui/layerdialog.xml') | |
19 | |
20 # TODO: Add access method for adopted grid types? | |
21 self._widget.findChild(name="gridBox").items = ['square', 'hexagonal'] | |
22 | |
23 # TODO: Ditto for pather? | |
24 self._widget.findChild(name="pathingBox").items = ['cell_edges_only', 'cell_edges_and_diagonals', 'freeform'] | |
25 | |
26 if layer: | |
27 cg = layer.getCellGrid() | |
28 cgtype = 0 | |
29 if cg.getType() == 'hexagonal': | |
30 cgtype = 1 | |
31 | |
32 self._widget.distributeData({ | |
33 "layerBox" : unicode(layer.getId()), | |
34 "xScaleBox" : unicode(cg.getXScale()), | |
35 "yScaleBox" : unicode(cg.getYScale()), | |
36 "rotBox" : unicode(cg.getRotation()), | |
37 "xOffsetBox" : unicode(cg.getXShift()), | |
38 "yOffsetBox" : unicode(cg.getYShift()) | |
39 }) | |
40 | |
41 self._widget.findChild(name="pathingBox").selected = int(layer.getPathingStrategy()) | |
42 self._widget.findChild(name="gridBox").selected = int(cgtype) | |
43 else: | |
44 self._widget.findChild(name="pathingBox").selected = 0 | |
45 self._widget.findChild(name="gridBox").selected = 0 | |
46 | |
47 self._widget.mapEvents({ | |
48 'okButton' : self._finished, | |
49 'cancelButton' : self._cancelled | |
50 }) | |
51 | |
52 self._widget.show() | |
53 | |
54 def _cancelled(self): | |
55 """ """ | |
56 if self.onCancel: | |
57 self.onCancel() | |
58 self._widget.hide() | |
59 | |
60 def _finished(self): | |
61 """ """ | |
62 # Collect and validate data | |
63 layerId = self._widget.collectData('layerBox') | |
64 if layerId == '': | |
65 print 'Please enter a layer id.' | |
66 return | |
67 | |
68 try: | |
69 x_offset = float(self._widget.collectData('xOffsetBox')) | |
70 y_offset = float(self._widget.collectData('yOffsetBox')) | |
71 except ValueError: | |
72 print 'Please enter integer or decimal values for offset.' | |
73 return | |
74 | |
75 try: | |
76 x_scale = float(self._widget.collectData('xScaleBox')) | |
77 y_scale = float(self._widget.collectData('yScaleBox')) | |
78 except ValueError: | |
79 print 'Please enter integer or decimal values for scale.' | |
80 return | |
81 | |
82 try: | |
83 rotation = float(self._widget.collectData('rotBox')) | |
84 except ValueError: | |
85 print 'Please enter integer or decimal value for rotation.' | |
86 return | |
87 | |
88 grid_type = int(self._widget.collectData('gridBox')) | |
89 pathing = int(self._widget.collectData('pathingBox')) | |
90 | |
91 if grid_type == 0: | |
92 grid_type = "square" | |
93 else: | |
94 grid_type = "hexagonal" | |
95 | |
96 # Set up layer | |
97 layer = self.layer | |
98 cellgrid = None | |
99 | |
100 cellgrid = self.model.getCellGrid(grid_type) | |
101 if not cellgrid: | |
102 print "Invalid grid type" | |
103 return | |
104 | |
105 cellgrid.setRotation(rotation) | |
106 cellgrid.setXScale(x_scale) | |
107 cellgrid.setYScale(y_scale) | |
108 cellgrid.setXShift(x_offset) | |
109 cellgrid.setYShift(y_offset) | |
110 | |
111 if not self.layer: | |
112 try: | |
113 layer = self.map.createLayer(str(layerId), cellgrid) | |
114 | |
115 except fife.NameClash: | |
116 print 'The layer ' + str(layerId) + ' already exists!' | |
117 return | |
118 else: | |
119 layer.setCellGrid(cellgrid) | |
120 try: | |
121 layer.setId(str(layerId)) | |
122 except fife.NameClash: | |
123 print 'The layer ' + str(layerId) + ' already exists!' | |
124 return | |
125 | |
126 layer.setPathingStrategy(pathing) | |
127 | |
128 self.engine.getView().resetRenderers() | |
129 | |
130 # Hide dialog and call back | |
131 self._widget.hide() | |
132 | |
133 if self.callback: | |
134 pychan.tools.applyOnlySuitable(self.callback, layer=layer) |