annotate clients/editor/plugins/mapeditor.py @ 177:3fb17daa1b27

* Added ToggleButton widget * Modified editor to use togglebuttons in toolbox
author cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 25 Jan 2009 20:17:41 +0000
parents bb9902910067
children 28532ae6f9f6
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:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 self._mapedit = pychan.loadXML('content/gui/mapeditor.xml')
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:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66 self._toolbar = pychan.loadXML('content/gui/tools.xml')
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):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 self._statusbar = pychan.loadXML('content/gui/statuspanel.xml')
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)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
246
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247 def _selectLayer(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 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
249
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250 def _editLayer(self, layerid):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 self._layer = None
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 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
253 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
254 self._layer = layers[0]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 def _selectObject(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257 if not self._objectselector:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 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
259 self._objectselector.show()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 def _editObject(self, object):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 self._object = object
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 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
265 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
266
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 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
268 self._selection.z = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 loc = fife.Location(self._layer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270 if preciseCoords:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 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
272 loc.setExactLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274 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
275 loc.setLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276 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
277 return loc
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278
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
279 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
280 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
281 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
282 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
283
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
284 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
285 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
286 loc.setExactLayerCoordinates(position)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287 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
288 loc.setLayerCoordinates(position)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
289 instances = self._camera.getMatchingInstances(loc)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
290 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
291 instances = [instances[0]]
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292 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
293
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
294 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
295 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
296 # 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
297 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
298 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
299 self._undo = False
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
300
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
301 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
302 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
303 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
304 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
305 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
306
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 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
308 print object
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
309
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
310 # 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
311 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
312 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
313 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
314 return
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
315
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
316 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
317 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
318 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
319 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
320
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
321 def _removeInstances(self,position):
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
322 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
323 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
324 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
325
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
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333 self._layer.deleteInstance(i)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
334
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
335 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
336 mname = '_moveInstances'
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
337 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
338 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
339 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
340
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
341 loc = fife.Location(self._layer)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
342 if self._shiftdown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
343 loc.setExactLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
344 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
345 loc.setLayerCoordinates(self._selection)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
346 for i in self._instances:
101
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
347 f = fife.Location(self._layer)
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
348 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
349 i.setLocation(loc)
101
adf0f2b6d1b0 fixed rotating instances when moving them
spq@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 50
diff changeset
350 i.setFacingLocation(f)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
351
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
352 def _rotateInstances(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
353 mname = '_rotateInstances'
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
354 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
355 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
356
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
357 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
358 # by c 09/11/08
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
359 # FIXME:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
360 # "hardcoded" rotation is bad for offset editing
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
361 # 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
362 # 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
363 # project specific animation angles
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
364 try:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
365 if self._objectedit_rotations is not None:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
366 # print "available angles: ", self._offsetedit_rotations
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
367 rotation_prev = i.getRotation()
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
368 # print "previous rotation: ", rotation_prev
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
369 length = len(self._offsetedit_rotations)
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
370 # print "length: ", length
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
371 index = self._offsetedit_rotations.index( str(rotation_prev) )
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
372 # print "index, old: ", index
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
373 if index < length - 1:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
374 index += 1
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
375 elif index == length:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
376 index = 0
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
377 else:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
378 index = 0
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
379 # print "index, new: ", index
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
380
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
381 i.setRotation( int(self._offsetedit_rotations[index]) )
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
382 # print "new rotation: ", self._offsetedit_rotations[index]
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
383 except:
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
384 # Fallback
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
385 i.setRotation((i.getRotation() + 90) % 360)
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
386 # end FIXME
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
387 # end edit c
ade070598fd1 - added object editor plugin
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 124
diff changeset
388
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
389 ## 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
390 ## 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
391 ## 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
392 ## 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
393 ## 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
394 ## 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
395 ## 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
396 ## 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
397 # ovis = i.getObject().get2dGfxVisual()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
398 # curUsedAngle = ovis.getClosestMatchingAngle(i.getRotation())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
399 # angles = ovis.getStaticImageAngles()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
400 # if angles:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
401 # ind = list(angles).index(curUsedAngle)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
402 # if ind == (len(angles) - 1):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
403 # ind = 0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
404 # else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
405 # ind += 1
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
406 # i.setRotation(angles[ind])
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
407 # else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
408 # 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
409
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
410 def changeRotation(self):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
411 currot = self._camera.getRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
412 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
413
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
414 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
415 coords = self._camera.getLocationRef().getMapCoordinates()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
416 z = self._camera.getZoom()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
417 r = self._camera.getRotation()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
418 if screen_x:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
419 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
420 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
421 if screen_y:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
422 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
423 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
424 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
425 self._camera.refresh()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
426
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
427 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
428 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
429 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
430
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
431 if self._ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
432 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
433 self._dragx = evt.getX()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
434 self._dragy = evt.getY()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
435 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
436 if self._camera:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
437 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
438 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
439 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
440 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
441 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
442 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
443 self._removeInstances(self._selection)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
444 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
445 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
446 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
447 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
448
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
449 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
450 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
451 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
452
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
453 if self._ctrldown:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
454 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
455 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
456 self._dragx = evt.getX()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
457 self._dragy = evt.getY()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
458 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
459 if self._mode == INSERTING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
460 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
461 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
462 elif self._mode == REMOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
463 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
464 self._removeInstances(self._selection)
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
465 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
466 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
467 self._moveInstances()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
468
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
469 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
470 if evt.isConsumedByWidgets():
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
471 return
9d0a21184c13 fix for editor, gui event consumption was not checked properly
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 0
diff changeset
472
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
473 self._dragx = NOT_INITIALIZED
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
474 self._dragy = NOT_INITIALIZED
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
475
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
476 def mouseMoved(self, evt):
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
477 if self._camera:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
478 screen_x = self._engine.getRenderBackend().getWidth()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
479 screen_y = self._engine.getRenderBackend().getHeight()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
480 ratio = float(screen_x) / screen_y
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
481
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
482 mouse_x = evt.getX()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
483 mouse_y = evt.getY()
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
484
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
485 self._scrollx = 0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
486 self._scrolly = 0
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
487
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
488 if mouse_y <= SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
489 # up
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
490 self._scrolly = SCROLL_SPEED * ratio
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
491 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
492 # right
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
493 self._scrollx = -SCROLL_SPEED
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
494 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
495 # bottom
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
496 self._scrolly = -SCROLL_SPEED * ratio
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
497 if mouse_x <= SCROLL_TOLERANCE:
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
498 # left
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
499 self._scrollx = SCROLL_SPEED
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
500
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
501 def mouseEntered(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
502 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
503 def mouseExited(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
504 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
505 def mouseClicked(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
506 pass
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
507
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
508 def mouseWheelMovedUp(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
509 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
510 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
511
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
512 def mouseWheelMovedDown(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
513 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
514 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
515
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 keyPressed(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
518 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
519 keystr = evt.getKey().getAsString().lower()
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 if keyval == fife.Key.LEFT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
522 self._moveCamera(50, 0)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
523 elif keyval == fife.Key.RIGHT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
524 self._moveCamera(-50, 0)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
525 elif keyval == fife.Key.UP:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
526 self._moveCamera(0, 50)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
527 elif keyval == fife.Key.DOWN:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
528 self._moveCamera(0, -50)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
529 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
530 self._ctrldown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
531 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
532 self._shiftdown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
533 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
534 self._altdown = True
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
535
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
536 elif keyval == fife.Key.INSERT:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
537 if self._mode != INSERTING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
538 self._setMode(INSERTING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
539 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
540 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
541
115
c94c76346027 * Key event fix for map editor by chewie
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 108
diff changeset
542 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
543 if self._mode != REMOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
544 self._setMode(REMOVING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
545 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
546 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
547
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
548 elif keystr == 'm':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
549 if self._mode != MOVING:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
550 self._setMode(MOVING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
551 else:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
552 self._setMode(VIEWING)
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
553
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
554 elif keystr == 't':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
555 gridrenderer = self._camera.getRenderer('GridRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
556 gridrenderer.setEnabled(not gridrenderer.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
557
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
558 elif keystr == 'b':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
559 blockrenderer = self._camera.getRenderer('BlockingInfoRenderer')
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
560 blockrenderer.setEnabled(not blockrenderer.isEnabled())
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
561
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
562 elif keystr == 'r':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
563 if self._selection:
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
564 self._rotateInstances()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
565
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
566 elif keystr == 'o':
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
567 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
568
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
569 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
570 self.undo()
0
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
571
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
572 def keyReleased(self, evt):
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
573 keyval = evt.getKey().getValue()
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
574 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
575 self._ctrldown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
576 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
577 self._shiftdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
578 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
579 self._altdown = False
4a0efb7baf70 * Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
580
124
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
581 def pump(self):
d5658e6c34f5 Added scrolling support the the editor client.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents: 115
diff changeset
582 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
583 self._moveCamera(self._scrollx * self._engine.getTimeManager().getTimeDelta(), self._scrolly * self._engine.getTimeManager().getTimeDelta())