annotate clients/editor/plugins/mapeditor.py @ 183:fcef34d67ad9

- fixed small but silly bug for the objectedit plugin (forgot to complete renaming) @wenlin This should fix the "when the object is beach02 ..." issue - and some more ... ^^
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 19 Feb 2009 06:24:58 +0000
parents bcc93e17f978
children bec4b69ad83a
rev   line source
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 # MapEditor is a plugin for Fifedit. It allows for selection and visual editing of maps.
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 import math
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 import fife
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 import plugin
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 import pychan
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 import pychan.widgets as widgets
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 from pychan.tools import callbackWithArguments as cbwa
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 from selection import Selection, ClickSelection
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 from plugins.objectselector import ObjectSelector
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 from pychan.manager import DEFAULT_STYLE
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 DEFAULT_STYLE['default']['base_color'] = fife.Color(85,128,151)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
16 SCROLL_TOLERANCE = 10
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
17 SCROLL_SPEED = 1.0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
18
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 states = ('NOTHING_LOADED', 'VIEWING', 'INSERTING', 'REMOVING', 'MOVING')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 for s in states:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 globals()[s] = s
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 NOT_INITIALIZED = -9999999
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24 class EditorLogicError(Exception):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 class MapSelection(object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 def __init__(self, onLayerSelect, onObjectSelect):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 self._mapedit = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 self._onLayerSelect = onLayerSelect
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31 self._onObjectSelect = onObjectSelect
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33 def show(self, map):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 if not self._mapedit:
179
28532ae6f9f6 Moved all editor content out of content, as chewie says it's deprecated as hell ;-)
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 177
diff changeset
35 self._mapedit = pychan.loadXML('gui/mapeditor.xml')
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 self._mapedit.mapEvents({
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 'layerButton' : self._onLayerSelect,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38 'objButton' : self._onObjectSelect,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 'closeButton' : self.hide
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40 })
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 fields = self._mapedit.findChild(name='Properties')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 # Clear previously added children
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 fields.removeChildren(*fields.children)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 hbox = widgets.HBox()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 fields.addChild(hbox)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 label = widgets.Label(text='ID',min_size=(80,0))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 hbox.addChild(label)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48 field = widgets.TextField(text=map.getId(),min_size=(100,0))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 hbox.addChild(field)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 self._mapedit.adaptLayout()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 self._mapedit.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52 self._mapedit.x = 10
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 self._mapedit.y = 580
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 def hide(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 self._mapedit.hide()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 class Toolbar(object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 def __init__(self, onSelect, onMove, onInsert, onDelete, onBtnEnter, onBtnExit):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self._onSelect, self._onMove, self._onInsert, self._onDelete = onSelect, onMove, onInsert, onDelete
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61 self.onBtnEnter, self.onBtnExit = onBtnEnter, onBtnExit
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 self._toolbar = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 def show(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 if not self._toolbar:
179
28532ae6f9f6 Moved all editor content out of content, as chewie says it's deprecated as hell ;-)
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 177
diff changeset
66 self._toolbar = pychan.loadXML('gui/tools.xml')
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 evtmap = {
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68 'btnSelect' : self._onSelect,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 'btnMove' : self._onMove,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 'btnInsert' : self._onInsert,
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71 'btnDelete' : self._onDelete
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 }
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73 self._toolbar.mapEvents(evtmap)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 for k in evtmap.keys():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 btn = self._toolbar.findChild(name=k)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 btn.setEnterCallback(self.onBtnEnter)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 btn.setExitCallback(self.onBtnExit)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 #self._toolbar.adaptLayout()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 self._toolbar.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 self._toolbar.x = 10
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82 self._toolbar.y = 50
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 def hide(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 self._toolbar.hide()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 def _enableBtn(self, enabled, btn):
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
88 btn.toggled = enabled;
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
89
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
90 def enableSelect(self, enabled):
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
91 self._enableBtn(enabled, self._toolbar.findChild(name='btnSelect'))
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
92
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
93 def enableMove(self, enabled):
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
94 self._enableBtn(enabled, self._toolbar.findChild(name='btnMove'))
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
95
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96 def enableInsert(self, enabled):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self._enableBtn(enabled, self._toolbar.findChild(name='btnInsert'))
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
98
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 def enableDelete(self, enabled):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 self._enableBtn(enabled, self._toolbar.findChild(name='btnDelete'))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
102 def disableAll(self):
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
103 self.enableDelete(False)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
104 self.enableSelect(False)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
105 self.enableInsert(False)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
106 self.enableMove(False)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 class StatusBar(object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109 def __init__(self, screenw, screenh):
179
28532ae6f9f6 Moved all editor content out of content, as chewie says it's deprecated as hell ;-)
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 177
diff changeset
110 self._statusbar = pychan.loadXML('gui/statuspanel.xml')
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 self._statusbar.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 height = 25
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113 self._statusbar.position = (0, screenh - height)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 self._statusbar.size = (screenw, height)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115 self.statustxt = ''
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 self.lbl = self._statusbar.findChild(name='lblStatus')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118 def setStatus(self, msg):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 self.statustxt = msg
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 self.lbl.text = ' ' + msg
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 self.lbl.resizeToContent()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 def showTooltip(self, elem):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 self.lbl.text = elem.helptext
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 self.lbl.resizeToContent()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 def hideTooltip(self, elem):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 self.lbl.text = self.statustxt
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 self.lbl.resizeToContent()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 class MapEditor(plugin.Plugin,fife.IMouseListener, fife.IKeyListener):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 def __init__(self, engine):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134 self._engine = engine
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 eventmanager = self._engine.getEventManager()
157
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 134
diff changeset
136 #eventmanager.setNonConsumableKeys([
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 134
diff changeset
137 #fife.Key.LEFT,
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 134
diff changeset
138 #fife.Key.RIGHT,
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 134
diff changeset
139 #fife.Key.UP,
bb9902910067 input_rework merged!
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 134
diff changeset
140 #fife.Key.DOWN])
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 fife.IMouseListener.__init__(self)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 eventmanager.addMouseListener(self)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 fife.IKeyListener.__init__(self)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144 eventmanager.addKeyListener(self)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 # Fifedit plugin data
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 self.menu_items = { 'Select Map' : self._selectMap }
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149 self._camera = None # currently selected camera
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 self._map = None # currently selected map
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 self._layer = None # currently selected layer
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 self._object = None # currently selected object
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 self._selection = None # currently selected coordinates
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 self._instances = None # currently selected instances
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 self._ctrldown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 self._shiftdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 self._altdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159 self._dragx = NOT_INITIALIZED
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 self._dragy = NOT_INITIALIZED
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
161 self._scrollx = 0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
162 self._scrolly = 0
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 self._mapselector = MapSelection(self._selectLayer, self._selectObject)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165 self._objectselector = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 rb = self._engine.getRenderBackend()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 self._statusbar = StatusBar(rb.getWidth(), rb.getHeight())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 self._toolbar = Toolbar(cbwa(self._setMode, VIEWING), cbwa(self._setMode, MOVING),
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
169 cbwa(self._setMode, INSERTING), cbwa(self._setMode, REMOVING),
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
170 self._statusbar.showTooltip, self._statusbar.hideTooltip)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 self._toolbar.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 self._setMode(NOTHING_LOADED)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
174 self._undoStack = []
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
175 self._undo = False # tracks whether current action is an undo
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
176
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 def _assert(self, statement, msg):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178 if not statement:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 print msg
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 raise EditorLogicError(msg)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 def _setMode(self, mode):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 if (mode != NOTHING_LOADED) and (not self._camera):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184 self._statusbar.setStatus('Please load map first')
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
185 self._toolbar.disableAll()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 return
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 if (mode == INSERTING) and (not self._object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 self._statusbar.setStatus('Please select object first')
177
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
189 mode = self._mode
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
190
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
191 # Update toolbox buttons
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
192 if (mode == INSERTING):
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
193 self._toolbar.enableInsert(True)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
194 elif mode == VIEWING:
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
195 self._toolbar.enableSelect(True)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
196 elif mode == REMOVING:
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
197 self._toolbar.enableDelete(True)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
198 elif mode == MOVING:
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
199 self._toolbar.enableMove(True)
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
200 else:
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
201 self._toolbar.disableAll()
3fb17daa1b27 * Added ToggleButton widget
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 157
diff changeset
202
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203 self._mode = mode
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 print "Entered mode " + mode
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 self._statusbar.setStatus(mode.replace('_', ' ').capitalize())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 # gui for selecting a map
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 def _selectMap(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 Selection([map.getId() for map in self._engine.getModel().getMaps()], self.editMap)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 def _selectDefaultCamera(self, map):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 self._camera = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214 self._engine.getView().resetRenderers()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 for cam in self._engine.getView().getCameras():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 cam.setEnabled(False)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 for cam in self._engine.getView().getCameras():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 if cam.getLocationRef().getMap().getId() == map.getId():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 rb = self._engine.getRenderBackend()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 cam.setViewPort(fife.Rect(0, 0, rb.getScreenWidth(), rb.getScreenHeight()))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 cam.setEnabled(True)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 self._camera = cam
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 break
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 if not self._camera:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 raise AttributeError('No cameras found associated with this map: ' + map.getId())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228 def editMap(self, mapid):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 self._camera = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 self._map = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231 self._layer = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
232 self._object = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233 self._selection = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 self._instances = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 self._setMode(NOTHING_LOADED)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
237 self._map = self._engine.getModel().getMap(mapid)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238 if not self._map.getLayers():
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 raise AttributeError('Editor error: map ' + self._map.getId() + ' has no layers. Cannot edit.')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241 self._layer = self._map.getLayers()[0]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
242 self._selectDefaultCamera(self._map)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 self._mapselector.show(self._map)
182
bcc93e17f978 - added new plugin to FIFedit (Layertool)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 179
diff changeset
246
bcc93e17f978 - added new plugin to FIFedit (Layertool)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 179
diff changeset
247 # zero-projekt plugin
bcc93e17f978 - added new plugin to FIFedit (Layertool)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 179
diff changeset
248 if self.layertool is not None:
bcc93e17f978 - added new plugin to FIFedit (Layertool)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 179
diff changeset
249 self.layertool.update()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 def _selectLayer(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 Selection([layer.getId() for layer in self._map.getLayers()], self._editLayer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254 def _editLayer(self, layerid):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255 self._layer = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 layers = [l for l in self._map.getLayers() if l.getId() == layerid]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257 self._assert(len(layers) == 1, 'Layer amount != 1')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 self._layer = layers[0]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
259
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 def _selectObject(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 if not self._objectselector:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 self._objectselector = ObjectSelector(self._engine, self._map, self._editObject)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263 self._objectselector.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
265 def _editObject(self, object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266 self._object = object
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 def _selectCell(self, screenx, screeny, preciseCoords=False):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 self._assert(self._camera, 'No camera bind yet, cannot select any cell')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 self._selection = self._camera.toMapCoordinates(fife.ScreenPoint(screenx, screeny), False)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 self._selection.z = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 loc = fife.Location(self._layer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274 if preciseCoords:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275 self._selection = self._layer.getCellGrid().toExactLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276 loc.setExactLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278 self._selection = self._layer.getCellGrid().toLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
279 loc.setLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
280 fife.CellSelectionRenderer.getInstance(self._camera).selectLocation(loc)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
281 return loc
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
282
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
283 def _getInstancesFromPosition(self, position, top_only):
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
284 self._assert(self._layer, 'No layer assigned in _getInstancesFromPosition')
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
285 self._assert(position, 'No position assigned in _getInstancesFromPosition')
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
286 self._assert(self._camera, 'No camera assigned in _getInstancesFromPosition')
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288 loc = fife.Location(self._layer)
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
289 if type(position) == fife.ExactModelCoordinate:
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
290 loc.setExactLayerCoordinates(position)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 else:
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
292 loc.setLayerCoordinates(position)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
293 instances = self._camera.getMatchingInstances(loc)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
294 if top_only and (len(instances) > 0):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
295 instances = [instances[0]]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
296 return instances
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
297
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
298 def undo(self):
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
299 if self._undoStack != []:
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
300 # execute inverse of last action
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
301 self._undo = True
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
302 self._undoStack.pop()()
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
303 self._undo = False
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
304
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
305 def _placeInstance(self,position,object):
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
306 mname = '_placeInstance'
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
307 self._assert(object, 'No object assigned in %s' % mname)
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
308 self._assert(position, 'No position assigned in %s' % mname)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
309 self._assert(self._layer, 'No layer assigned in %s' % mname)
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
310
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
311 print 'Placing instance of ' + object.getId() + ' at ' + str(position)
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
312 print object
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
313
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
314 # don't place repeat instances
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
315 for i in self._getInstancesFromPosition(position, False):
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
316 if i.getObject().getId() == object.getId():
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
317 print 'Warning: attempt to place duplicate instance of object %s. Ignoring request.' % object.getId()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
318 return
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
319
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
320 inst = self._layer.createInstance(object, position)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
321 fife.InstanceVisual.create(inst)
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
322 if not self._undo:
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
323 self._undoStack.append(lambda: self._removeInstances(position))
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
324
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
325 def _removeInstances(self,position):
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
326 mname = '_removeInstances'
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
327 self._assert(position, 'No position assigned in %s' % mname)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
328 self._assert(self._layer, 'No layer assigned in %s' % mname)
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
329
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
330 for i in self._getInstancesFromPosition(position, top_only=True):
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
331 print 'Deleting instance ' + str(i) + ' at ' + str(position)
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
332 if not self._undo:
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
333 print '>>> ' + i.getObject().getId()
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
334 print '>>> ' + str(i.getObject())
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
335 object = i.getObject()
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
336 self._undoStack.append(lambda: self._placeInstance(position,object))
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
337 self._layer.deleteInstance(i)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
338
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
339 def _moveInstances(self):
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
340 mname = '_moveInstances'
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
341 self._assert(self._selection, 'No selection assigned in %s' % mname)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
342 self._assert(self._layer, 'No layer assigned in %s' % mname)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
343 self._assert(self._mode == MOVING, 'Mode is not MOVING in %s (is instead %s)' % (mname, str(self._mode)))
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
344
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
345 loc = fife.Location(self._layer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
346 if self._shiftdown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
347 loc.setExactLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
348 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
349 loc.setLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
350 for i in self._instances:
101
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
351 f = fife.Location(self._layer)
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
352 f.setExactLayerCoordinates(i.getFacingLocation().getExactLayerCoordinates() + fife.ExactModelCoordinate(float(self._selection.x), float(self._selection.y)) - i.getLocation().getExactLayerCoordinates())
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
353 i.setLocation(loc)
101
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
354 i.setFacingLocation(f)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
355
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
356 def _rotateInstances(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
357 mname = '_rotateInstances'
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
358 self._assert(self._selection, 'No selection assigned in %s' % mname)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
359 self._assert(self._layer, 'No layer assigned in %s' % mname)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
360
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
361 for i in self._getInstancesFromPosition(self._selection, top_only=True):
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
362 # by c 09/11/08
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
363 # FIXME:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
364 # "hardcoded" rotation is bad for offset editing
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
365 # instead we should use the angle list given from the object
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
366 # animations are an issue, as a workaround settings.py provides
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
367 # project specific animation angles
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
368 try:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
369 if self._objectedit_rotations is not None:
183
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
370 # print "available angles: ", self._objectedit_rotations
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
371 rotation_prev = i.getRotation()
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
372 # print "previous rotation: ", rotation_prev
183
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
373 length = len(self._objectedit_rotations)
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
374 # print "length: ", length
183
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
375 index = self._objectedit_rotations.index( str(rotation_prev) )
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
376 # print "index, old: ", index
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
377 if index < length - 1:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
378 index += 1
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
379 elif index == length:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
380 index = 0
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
381 else:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
382 index = 0
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
383 # print "index, new: ", index
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
384
183
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
385 i.setRotation( int(self._objectedit_rotations[index]) )
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
386 # print "new rotation: ", self._objectedit_rotations[index]
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
387 except:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
388 # Fallback
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
389 i.setRotation((i.getRotation() + 90) % 360)
183
fcef34d67ad9 - fixed small but silly bug for the objectedit plugin (forgot to complete renaming)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 182
diff changeset
390
134
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
391 # end FIXME
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
392 # end edit c
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
393
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
394 ## Surprisingly, the following "snap-to-rotation" code is actually incorrect. Object
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
395 ## rotation is independent of the camera, whereas the choice of an actual rotation image
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
396 ## depends very much on how the camera is situated. For example, suppose an object has
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
397 ## rotations defined for 45,135,225,315. And suppose the camera position results in an
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
398 ## effective 60 degree rotation. If the object is given a rotation of 0, then the (correct)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
399 ## final rotation value of 45 (which is closest to 60 = 0 + 60) will be chosen. If we try
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
400 ## to snap to the closest value to 0 (45), then an incorrect final rotation value will be
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
401 ## chosen: 135, which is closest to 105 = 45 + 60. --jwt
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
402 # ovis = i.getObject().get2dGfxVisual()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
403 # curUsedAngle = ovis.getClosestMatchingAngle(i.getRotation())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
404 # angles = ovis.getStaticImageAngles()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
405 # if angles:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
406 # ind = list(angles).index(curUsedAngle)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
407 # if ind == (len(angles) - 1):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
408 # ind = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
409 # else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
410 # ind += 1
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
411 # i.setRotation(angles[ind])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
412 # else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
413 # print "rotation not supported for this instance"
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
414
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
415 def changeRotation(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
416 currot = self._camera.getRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
417 self._camera.setRotation((currot + 90) % 360)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
418
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
419 def _moveCamera(self, screen_x, screen_y):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
420 coords = self._camera.getLocationRef().getMapCoordinates()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
421 z = self._camera.getZoom()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
422 r = self._camera.getRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
423 if screen_x:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
424 coords.x -= screen_x / z * math.cos(r / 180.0 * math.pi) / 100;
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
425 coords.y -= screen_x / z * math.sin(r / 180.0 * math.pi) / 100;
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
426 if screen_y:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
427 coords.x -= screen_y / z * math.sin(-r / 180.0 * math.pi) / 100;
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
428 coords.y -= screen_y / z * math.cos(-r / 180.0 * math.pi) / 100;
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
429 coords = self._camera.getLocationRef().setMapCoordinates(coords)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
430 self._camera.refresh()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
431
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
432 def mousePressed(self, evt):
50
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
433 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
434 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
435
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
436 if self._ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
437 if evt.getButton() == fife.MouseEvent.LEFT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
438 self._dragx = evt.getX()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
439 self._dragy = evt.getY()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
440 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
441 if self._camera:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
442 self._selectCell(evt.getX(), evt.getY(), self._shiftdown)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
443 if self._mode == VIEWING:
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
444 self._instances = self._getInstancesFromPosition(self._selection, top_only=True)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
445 elif self._mode == INSERTING:
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
446 self._placeInstance(self._selection,self._object)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
447 elif self._mode == REMOVING:
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
448 self._removeInstances(self._selection)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
449 elif self._mode == MOVING:
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
450 self._instances = self._getInstancesFromPosition(self._selection, top_only=True)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
451 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
452 self._setMode(self._mode) # refresh status
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
453
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
454 def mouseDragged(self, evt):
50
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
455 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
456 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
457
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
458 if self._ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
459 if (self._dragx != NOT_INITIALIZED) and (self._dragy != NOT_INITIALIZED):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
460 self._moveCamera(evt.getX() - self._dragx, evt.getY() - self._dragy)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
461 self._dragx = evt.getX()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
462 self._dragy = evt.getY()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
463 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
464 if self._mode == INSERTING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
465 self._selectCell(evt.getX(), evt.getY())
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
466 self._placeInstance(self._selection,self._object)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
467 elif self._mode == REMOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
468 self._selectCell(evt.getX(), evt.getY())
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
469 self._removeInstances(self._selection)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
470 elif self._mode == MOVING and self._instances:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
471 self._selectCell(evt.getX(), evt.getY(), self._shiftdown)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
472 self._moveInstances()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
473
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
474 def mouseReleased(self, evt):
50
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
475 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
476 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
477
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
478 self._dragx = NOT_INITIALIZED
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
479 self._dragy = NOT_INITIALIZED
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
480
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
481 def mouseMoved(self, evt):
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
482 if self._camera:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
483 screen_x = self._engine.getRenderBackend().getWidth()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
484 screen_y = self._engine.getRenderBackend().getHeight()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
485 ratio = float(screen_x) / screen_y
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
486
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
487 mouse_x = evt.getX()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
488 mouse_y = evt.getY()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
489
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
490 self._scrollx = 0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
491 self._scrolly = 0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
492
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
493 if mouse_y <= SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
494 # up
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
495 self._scrolly = SCROLL_SPEED * ratio
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
496 if mouse_x >= screen_x - SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
497 # right
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
498 self._scrollx = -SCROLL_SPEED
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
499 if mouse_y >= screen_y - SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
500 # bottom
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
501 self._scrolly = -SCROLL_SPEED * ratio
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
502 if mouse_x <= SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
503 # left
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
504 self._scrollx = SCROLL_SPEED
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
505
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
506 def mouseEntered(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
507 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
508 def mouseExited(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
509 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
510 def mouseClicked(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
511 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
512
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
513 def mouseWheelMovedUp(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
514 if self._ctrldown and self._camera:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
515 self._camera.setZoom(self._camera.getZoom() * 1.05)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
516
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
517 def mouseWheelMovedDown(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
518 if self._ctrldown and self._camera:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
519 self._camera.setZoom(self._camera.getZoom() / 1.05)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
520
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
521
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
522 def keyPressed(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
523 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
524 keystr = evt.getKey().getAsString().lower()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
525
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
526 if keyval == fife.Key.LEFT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
527 self._moveCamera(50, 0)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
528 elif keyval == fife.Key.RIGHT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
529 self._moveCamera(-50, 0)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
530 elif keyval == fife.Key.UP:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
531 self._moveCamera(0, 50)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
532 elif keyval == fife.Key.DOWN:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
533 self._moveCamera(0, -50)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
534 elif keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
535 self._ctrldown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
536 elif keyval in (fife.Key.LEFT_SHIFT, fife.Key.RIGHT_SHIFT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
537 self._shiftdown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
538 elif keyval in (fife.Key.LEFT_ALT, fife.Key.RIGHT_ALT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
539 self._altdown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
540
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
541 elif keyval == fife.Key.INSERT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
542 if self._mode != INSERTING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
543 self._setMode(INSERTING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
544 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
545 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
546
115
c94c76346027 * Key event fix for map editor by chewie
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 108
diff changeset
547 elif keyval == fife.Key.DELETE:
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
548 if self._mode != REMOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
549 self._setMode(REMOVING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
550 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
551 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
552
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
553 elif keystr == 'm':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
554 if self._mode != MOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
555 self._setMode(MOVING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
556 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
557 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
558
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
559 elif keystr == 't':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
560 gridrenderer = self._camera.getRenderer('GridRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
561 gridrenderer.setEnabled(not gridrenderer.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
562
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
563 elif keystr == 'b':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
564 blockrenderer = self._camera.getRenderer('BlockingInfoRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
565 blockrenderer.setEnabled(not blockrenderer.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
566
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
567 elif keystr == 'r':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
568 if self._selection:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
569 self._rotateInstances()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
570
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
571 elif keystr == 'o':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
572 self.changeRotation()
108
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
573
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
574 elif keystr == 'u':
0c017b8e4ab2 Added an undo feature to the map editor. Just press u to undo insert placement/removals.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 101
diff changeset
575 self.undo()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
576
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
577 def keyReleased(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
578 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
579 if keyval in (fife.Key.LEFT_CONTROL, fife.Key.RIGHT_CONTROL):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
580 self._ctrldown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
581 elif keyval in (fife.Key.LEFT_SHIFT, fife.Key.RIGHT_SHIFT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
582 self._shiftdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
583 elif keyval in (fife.Key.LEFT_ALT, fife.Key.RIGHT_ALT):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
584 self._altdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
585
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
586 def pump(self):
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
587 if self._scrollx != 0 or self._scrolly != 0:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
588 self._moveCamera(self._scrollx * self._engine.getTimeManager().getTimeDelta(), self._scrolly * self._engine.getTimeManager().getTimeDelta())