comparison clients/editor/plugins/mapwizard.py @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children 28532ae6f9f6
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 # MapWizard is a plugin for Fifedit. It is a step-by-step map creation utility.
2
3 import math
4
5 import fife
6 import plugin
7 import pychan
8 import pychan.widgets as widgets
9 from input import Input
10 from selection import Selection,ClickSelection
11
12 class CameraEditor():
13 """
14 CameraEditor provides a gui dialog for camera creation. The callback is called when camera creation is complete. A
15 partial specification of the camera parameters may optionally be given.
16 """
17 def __init__(self, engine, callback=None, map=None, layer=None):
18 self.engine = engine
19 self.callback = callback
20 self._widget = pychan.loadXML('content/gui/cameraedit.xml')
21
22 if map:
23 self._widget.distributeData({
24 'mapBox' : map.getId(),
25 })
26
27 if layer:
28 self._widget.distributeData({
29 'layerBox' : layer.getId(),
30 })
31
32 self._widget.mapEvents({
33 'okButton' : self._finished,
34 'cancelButton' : self._widget.hide
35 })
36
37 self._widget.show()
38
39 def _finished(self):
40 id = self._widget.collectData('idBox')
41 if id == '':
42 print 'Please enter a camera id.'
43 return
44
45 try:
46 map = self.engine.getModel().getMap(str(self._widget.collectData('mapBox')))
47 except fife.Exception:
48 print 'Cannot find the specified map id.'
49 return
50
51 try:
52 layer = map.getLayer(str(self._widget.collectData('layerBox')))
53 except fife.Exception:
54 print 'Cannot find the specified layer id.'
55 return
56
57 try:
58 vals = self._widget.collectData('viewBox').split(',')
59 if len(vals) != 4:
60 raise ValueError
61
62 viewport = fife.Rect(*[int(c) for c in vals])
63 except ValueError:
64 print 'Please enter 4 comma (,) delimited values for viewport x,y,width,height.'
65 return
66
67 try:
68 refh = int(self._widget.collectData('refhBox'))
69 refw = int(self._widget.collectData('refwBox'))
70 except ValueError:
71 print 'Please enter positive integer values for reference width and height.'
72 return
73
74 try:
75 rot = int(self._widget.collectData('rotBox'))
76 tilt = int(self._widget.collectData('tiltBox'))
77 except ValueError:
78 print 'Please enter positive integer values for rotation and tilt.'
79 return
80
81 cam = self.engine.getView().addCamera(id, layer, viewport, fife.ExactModelCoordinate(0,0,0))
82 cam.setCellImageDimensions(refw, refh)
83 cam.setRotation(rot)
84 cam.setTilt(tilt)
85
86 self._widget.hide()
87
88 if self.callback:
89 self.callback()
90
91 class MapWizard(plugin.Plugin):
92 def __init__(self, engine):
93 self.engine = engine
94
95 # Fifedit plugin data
96 self.menu_items = { 'Map Wizard' : self._buildMap }
97
98 self.newMap = False
99 self.map = None
100
101 def _buildMap(self):
102 def newMap(id):
103 def newLayer(id):
104 def newCamera():
105 self.newMap = True
106
107 grid = fife.SquareGrid()
108 layer = self.map.createLayer(id, grid)
109 grid.thisown = 0
110
111 CameraEditor(self.engine, newCamera, self.map, layer)
112
113 self.map = self.engine.getModel().createMap(id)
114 Input('Enter a layer identifier for a default layer:', newLayer)
115
116 Input('Enter a map identifier:', newMap)