comparison clients/editor/scripts/mapview.py @ 255:51cc05d862f2

Merged editor_rewrite branch to trunk. This contains changes that may break compatibility against existing clients. For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 08 Jun 2009 16:00:02 +0000
parents
children 0adf9423062e
comparison
equal deleted inserted replaced
254:10b5f7f36dd4 255:51cc05d862f2
1 import fife
2 import editor
3 import loaders, savers
4 from events import events
5 from mapcontroller import MapController
6
7 class MapView:
8 """ MapView represents a map in the editor.
9
10 It handles opening, saving and closing of a map,
11 as well as displaying it on screen.
12 """
13 def __init__(self, map):
14 self._map = map
15 self._editor = editor.getEditor()
16 self._controller = MapController(self._map)
17
18 if map is None:
19 print "No map passed to MapView!"
20 else:
21 if not self._map.getLayers():
22 raise AttributeError('Editor error: map ' + self._map.getId() + ' has no layers. Cannot edit.')
23
24 self.importlist = []
25 if hasattr(map, "importDirs"):
26 self.importlist.extend(map.importDirs)
27
28 # Copied from mapeditor.py
29 def show(self):
30 """ Sets up the camera to display the map. Size of the camera is equal to the
31 screen size """
32 _camera = None
33
34 engine = self._editor.getEngine()
35 engine.getView().resetRenderers()
36 for cam in engine.getView().getCameras():
37 cam.setEnabled(False)
38
39 for cam in engine.getView().getCameras():
40 if cam.getLocationRef().getMap().getId() == self._map.getId():
41 rb = engine.getRenderBackend()
42 cam.setViewPort(fife.Rect(0, 0, rb.getScreenWidth(), rb.getScreenHeight()))
43 cam.setEnabled(True)
44 self._camera = cam
45 break
46 else:
47 raise AttributeError('No cameras found associated with this map: ' + self._map.getId())
48
49 def getCamera(self):
50 return self._camera
51
52 def getController(self):
53 return self._controller
54
55 def getMap(self):
56 return self._map
57
58 def save(self):
59 """ Saves the map using the previous filename.
60
61 Emits preSave and postSave signals.
62 """
63 curname = ""
64 try:
65 curname = self._map.getResourceLocation().getFilename()
66 except RuntimeError:
67 print "Map has no filename yet, can't save."
68 return
69
70 events.preSave.send(sender=self, mapview=self)
71 savers.saveMapFile(curname, self._editor.getEngine(), self._map, importList=self.importlist)
72 events.postSave.send(sender=self, mapview=self)
73
74 def saveAs(self, filename):
75 """ Saves the map using a specified filename.
76
77 Emits preSave and postSave signals.
78 """
79 events.preSave.send(sender=self, mapview=self)
80 savers.saveMapFile(str(filename), self._editor.getEngine(), self._map, importList=self.importlist)
81 events.postSave.send(sender=self, mapview=self)
82
83 def close(self):
84 """ Closes the mapview """
85 pass
86
87
88 def importFile(self, path):
89 """ Imports a file supported by the provided loaders. """
90 loaders.loadImportFile(path, self._editor.getEngine())
91
92 def importDir(self, path, recursive=True):
93 """ Imports an entire directory supported by the provided loaders. """
94 self.importlist.append(path)
95 if recursive is True:
96 loaders.loadImportDirRec(path, self._editor.getEngine())
97 else:
98 loaders.loadImportDir(path, self._editor.getEngine())
99