Mercurial > fife-parpg
comparison tools/editor/plugins/LightEdit.py @ 680:60621d858548
* Fixed the image/animation functions in GenericRenderer and LightRenderer. The functions now consider the camera zoom level.
* Added the forgotten LightEdit plugin for the editor.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 21 Nov 2010 15:58:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
679:49fb0370f8e1 | 680:60621d858548 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2010 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 """ a tool for FIFEdit to test and set lighting """ | |
25 | |
26 from fife import fife | |
27 from fife.extensions import pychan | |
28 from fife.extensions.pychan import widgets as widgets | |
29 from fife.extensions.pychan.tools import callbackWithArguments as cbwa | |
30 | |
31 from fife.extensions.fife_timer import Timer | |
32 | |
33 import scripts | |
34 import scripts.plugin as plugin | |
35 from scripts.events import * | |
36 from scripts.gui.action import Action | |
37 | |
38 import os | |
39 try: | |
40 import xml.etree.cElementTree as ET | |
41 except: | |
42 import xml.etree.ElementTree as ET | |
43 | |
44 import math | |
45 import random | |
46 | |
47 WHITE = { | |
48 "r" : 205, | |
49 "g" : 205, | |
50 "b" : 205 | |
51 } | |
52 OUTLINE_SIZE = 1 | |
53 | |
54 DEFAULT_GLOBAL_LIGHT = { | |
55 "R" : 1.0, | |
56 "G" : 1.0, | |
57 "B" : 1.0, | |
58 "A" : 1.0, | |
59 } | |
60 | |
61 class LightEdit(plugin.Plugin): | |
62 """ The B{LightEdit} module is a plugin for FIFedit and allows to use Lighting | |
63 | |
64 current features: | |
65 - click instance to add SimpleLight, LightImage, LightAnimation | |
66 - outline highlighting of the selected object | |
67 - changeing all SimpleLigh values and Image, Animation source | |
68 | |
69 | |
70 """ | |
71 def __init__(self): | |
72 self.active = False | |
73 self._camera = None | |
74 self._layer = None | |
75 self._enabled = False | |
76 | |
77 self._light = {} | |
78 self._color = {} | |
79 self._color.update(DEFAULT_GLOBAL_LIGHT) | |
80 | |
81 random.seed() | |
82 | |
83 def _reset(self): | |
84 """ | |
85 resets all dynamic vars, but leaves out static ones (e.g. camera, layer) | |
86 | |
87 """ | |
88 self._instances = None | |
89 self._light["stencil"] = -1 | |
90 self._light["alpha"] = 0.0 | |
91 self._light["src"] = -1 | |
92 self._light["dst"] = -1 | |
93 | |
94 self._light["intensity"] = 0 | |
95 self._light["red"] = 0 | |
96 self._light["green"] = 0 | |
97 self._light["blue"] = 0 | |
98 self._light["radius"] = 0 | |
99 self._light["subdivisions"] = 32 | |
100 self._light["xstretch"] = 1 | |
101 self._light["ystretch"] = 1 | |
102 | |
103 self._light["image"] = "" | |
104 self._light["animation"] = "" | |
105 | |
106 self._simple_l = False | |
107 self._image_l = False | |
108 self._animation_l = False | |
109 self._global_l = False | |
110 | |
111 if self._camera is not None: | |
112 self.renderer.removeAllOutlines() | |
113 self._widgets["group"].text = unicode(str("")) | |
114 self._widgets["image"].text = unicode(str("")) | |
115 self._widgets["animation"].text = unicode(str("")) | |
116 | |
117 def enable(self): | |
118 """ plugin method """ | |
119 if self._enabled is True: | |
120 return | |
121 | |
122 self._editor = scripts.editor.getEditor() | |
123 self.engine = self._editor.getEngine() | |
124 | |
125 self.imagepool = self.engine.getImagePool() | |
126 self._animationpool = self.engine.getAnimationPool() | |
127 | |
128 self._showAction = Action(unicode(self.getName(),"utf-8"), checkable=True) | |
129 scripts.gui.action.activated.connect(self.toggle_gui, sender=self._showAction) | |
130 | |
131 self._editor._tools_menu.addAction(self._showAction) | |
132 | |
133 events.onInstancesSelected.connect(self.input) | |
134 | |
135 self._reset() | |
136 self.create_gui() | |
137 | |
138 def disable(self): | |
139 """ plugin method """ | |
140 if self._enabled is False: | |
141 return | |
142 | |
143 self._reset() | |
144 self.container.hide() | |
145 self.removeAllChildren() | |
146 | |
147 events.onInstancesSelected.disconnect(self.input) | |
148 | |
149 self._editor._toolsMenu.removeAction(self._showAction) | |
150 | |
151 def isEnabled(self): | |
152 """ plugin method """ | |
153 return self._enabled; | |
154 | |
155 def getName(self): | |
156 """ plugin method """ | |
157 return "Light editor" | |
158 | |
159 def create_gui(self): | |
160 """ | |
161 - creates the gui skeleton by loading the xml file | |
162 | |
163 FIXME: | |
164 - move all dynamic widgets to dict | |
165 """ | |
166 self.container = pychan.loadXML('gui/lightedit.xml') | |
167 self.container.mapEvents({ | |
168 "reset" : self.reset_light, | |
169 "use" : self.use_light, | |
170 "simple_but" : self.toggle_simple_gui, | |
171 "image_but" : self.toggle_image_gui, | |
172 "animation_but" : self.toggle_animation_gui, | |
173 "global_but" : self.toggle_global_gui, | |
174 "selec_image" : self.change_image, | |
175 "selec_animation" : self.change_animation, | |
176 | |
177 "stencil_up" : cbwa(self.change_light, value=1, option="stencil"), | |
178 "stencil_dn" : cbwa(self.change_light, value=-1, option="stencil"), | |
179 "stencil/mouseWheelMovedUp" : cbwa(self.change_light, value=10, option="stencil"), | |
180 "stencil/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="stencil"), | |
181 | |
182 "alpha_up" : cbwa(self.change_light, value=0.01, option="alpha"), | |
183 "alpha_dn" : cbwa(self.change_light, value=-0.01, option="alpha"), | |
184 "alpha/mouseWheelMovedUp" : cbwa(self.change_light, value=0.1, option="alpha"), | |
185 "alpha/mouseWheelMovedDown" : cbwa(self.change_light, value=-0.1, option="alpha"), | |
186 | |
187 "intensity_up" : cbwa(self.change_light, value=1, option="intensity"), | |
188 "intensity_dn" : cbwa(self.change_light, value=-1, option="intensity"), | |
189 "intensity/mouseWheelMovedUp" : cbwa(self.change_light, value=10, option="intensity"), | |
190 "intensity/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="intensity"), | |
191 | |
192 "radius_up" : cbwa(self.change_light, value= 1, option="radius"), | |
193 "radius_dn" : cbwa(self.change_light, value=-1, option="radius"), | |
194 "radius/mouseWheelMovedUp" : cbwa(self.change_light, value= 10, option="radius"), | |
195 "radius/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="radius"), | |
196 | |
197 "subdivisions_up" : cbwa(self.change_light, value= 1, option="subdivisions"), | |
198 "subdivisions_dn" : cbwa(self.change_light, value=-1, option="subdivisions"), | |
199 "subdivisions/mouseWheelMovedUp" : cbwa(self.change_light, value= 1, option="subdivisions"), | |
200 "subdivisions/mouseWheelMovedDown" : cbwa(self.change_light, value=-1, option="subdivisions"), | |
201 | |
202 "xstretch_up" : cbwa(self.change_light, value= 0.01, option="xstretch"), | |
203 "xstretch_dn" : cbwa(self.change_light, value=-0.01, option="xstretch"), | |
204 "xstretch/mouseWheelMovedUp" : cbwa(self.change_light, value= 0.1, option="xstretch"), | |
205 "xstretch/mouseWheelMovedDown" : cbwa(self.change_light, value=-0.1, option="xstretch"), | |
206 | |
207 "ystretch_up" : cbwa(self.change_light, value= 0.01, option="ystretch"), | |
208 "ystretch_dn" : cbwa(self.change_light, value=-0.01, option="ystretch"), | |
209 "ystretch/mouseWheelMovedUp" : cbwa(self.change_light, value= 0.1, option="ystretch"), | |
210 "ystretch/mouseWheelMovedDown" : cbwa(self.change_light, value=-0.1, option="ystretch"), | |
211 | |
212 "red_up" : cbwa(self.change_light, value= 1, option="red"), | |
213 "red_dn" : cbwa(self.change_light, value=-1, option="red"), | |
214 "red/mouseWheelMovedUp" : cbwa(self.change_light, value= 10, option="red"), | |
215 "red/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="red"), | |
216 | |
217 "green_up" : cbwa(self.change_light, value= 1, option="green"), | |
218 "green_dn" : cbwa(self.change_light, value=-1, option="green"), | |
219 "green/mouseWheelMovedUp" : cbwa(self.change_light, value= 10, option="green"), | |
220 "green/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="green"), | |
221 | |
222 "blue_up" : cbwa(self.change_light, value= 1, option="blue"), | |
223 "blue_dn" : cbwa(self.change_light, value=-1, option="blue"), | |
224 "blue/mouseWheelMovedUp" : cbwa(self.change_light, value= 10, option="blue"), | |
225 "blue/mouseWheelMovedDown" : cbwa(self.change_light, value=-10, option="blue"), | |
226 | |
227 "src_up" : cbwa(self.change_light, value= 1, option="src"), | |
228 "src_dn" : cbwa(self.change_light, value=-1, option="src"), | |
229 "src/mouseWheelMovedUp" : cbwa(self.change_light, value= 1, option="src"), | |
230 "src/mouseWheelMovedDown" : cbwa(self.change_light, value=-1, option="src"), | |
231 | |
232 "dst_up" : cbwa(self.change_light, value= 1, option="dst"), | |
233 "dst_dn" : cbwa(self.change_light, value=-1, option="dst"), | |
234 "dst/mouseWheelMovedUp" : cbwa(self.change_light, value= 1, option="dst"), | |
235 "dst/mouseWheelMovedDown" : cbwa(self.change_light, value=-1, option="dst"), | |
236 | |
237 "random_global_light" : self.random_color, | |
238 "reset_global_light" : self.reset_global_light, | |
239 | |
240 "increase_R" : cbwa(self.increase_color, r=True), | |
241 "decrease_R" : cbwa(self.decrease_color, r=True), | |
242 "value_R/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.1, r=True), | |
243 "value_R/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.1, r=True), | |
244 | |
245 "increase_G" : cbwa(self.increase_color, g=True), | |
246 "decrease_G" : cbwa(self.decrease_color, g=True), | |
247 "value_G/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.1, g=True), | |
248 "value_G/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.1, g=True), | |
249 | |
250 "increase_B" : cbwa(self.increase_color, b=True), | |
251 "decrease_B" : cbwa(self.decrease_color, b=True), | |
252 "value_B/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.1, b=True), | |
253 "value_B/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.1, b=True), | |
254 | |
255 "increase_A" : cbwa(self.increase_color, a=True), | |
256 "decrease_A" : cbwa(self.decrease_color, a=True), | |
257 "value_A/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.1, a=True), | |
258 "value_A/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.1, a=True), | |
259 }) | |
260 | |
261 self._widgets = { | |
262 "group" : self.container.findChild(name="group"), | |
263 "ins_id" : self.container.findChild(name="ins_id"), | |
264 "obj_id" : self.container.findChild(name="obj_id"), | |
265 "stencil" : self.container.findChild(name="stencil"), | |
266 "alpha" : self.container.findChild(name="alpha"), | |
267 | |
268 "intensity" : self.container.findChild(name="intensity"), | |
269 "red" : self.container.findChild(name="red"), | |
270 "green" : self.container.findChild(name="green"), | |
271 "blue" : self.container.findChild(name="blue"), | |
272 "radius" : self.container.findChild(name="radius"), | |
273 "subdivisions" : self.container.findChild(name="subdivisions"), | |
274 "xstretch" : self.container.findChild(name="xstretch"), | |
275 "ystretch" : self.container.findChild(name="ystretch"), | |
276 "src" : self.container.findChild(name="src"), | |
277 "dst" : self.container.findChild(name="dst"), | |
278 | |
279 "image" : self.container.findChild(name="image"), | |
280 "animation" : self.container.findChild(name="animation"), | |
281 | |
282 "value_R" : self.container.findChild(name="value_R"), | |
283 "value_G" : self.container.findChild(name="value_G"), | |
284 "value_B" : self.container.findChild(name="value_B"), | |
285 "value_A" : self.container.findChild(name="value_A"), | |
286 } | |
287 | |
288 self._gui_simple_panel_wrapper = self.container.findChild(name="simple_panel_wrapper") | |
289 self._gui_simple_panel = self._gui_simple_panel_wrapper.findChild(name="simple_panel") | |
290 self._gui_image_panel_wrapper = self.container.findChild(name="image_panel_wrapper") | |
291 self._gui_image_panel = self._gui_image_panel_wrapper.findChild(name="image_panel") | |
292 self._gui_animation_panel_wrapper = self.container.findChild(name="animation_panel_wrapper") | |
293 self._gui_animation_panel = self._gui_animation_panel_wrapper.findChild(name="animation_panel") | |
294 self._gui_global_panel_wrapper = self.container.findChild(name="global_panel_wrapper") | |
295 self._gui_global_panel = self._gui_global_panel_wrapper.findChild(name="global_panel") | |
296 | |
297 def update_gui(self): | |
298 """ | |
299 updates the gui | |
300 | |
301 """ | |
302 | |
303 self._widgets["ins_id"].text = unicode(str(self._instances[0].getId())) | |
304 self._widgets["obj_id"].text = unicode(str(self._instances[0].getObject().getId())) | |
305 self._widgets["stencil"].text = unicode(str(self._light["stencil"])) | |
306 self._widgets["alpha"].text = unicode(str(self._light["alpha"])) | |
307 self._widgets["src"].text = unicode(str(self._light["src"])) | |
308 self._widgets["dst"].text = unicode(str(self._light["dst"])) | |
309 | |
310 self._widgets["intensity"].text = unicode(str(self._light["intensity"])) | |
311 self._widgets["red"].text = unicode(str(self._light["red"])) | |
312 self._widgets["green"].text = unicode(str(self._light["green"])) | |
313 self._widgets["blue"].text = unicode(str(self._light["blue"])) | |
314 self._widgets["radius"].text = unicode(str(self._light["radius"])) | |
315 self._widgets["subdivisions"].text = unicode(str(self._light["subdivisions"])) | |
316 self._widgets["xstretch"].text = unicode(str(self._light["xstretch"])) | |
317 self._widgets["ystretch"].text = unicode(str(self._light["ystretch"])) | |
318 | |
319 self._widgets["value_R"].text = unicode(str(self._color["R"])) | |
320 self._widgets["value_G"].text = unicode(str(self._color["G"])) | |
321 self._widgets["value_B"].text = unicode(str(self._color["B"])) | |
322 self._widgets["value_A"].text = unicode(str(self._color["A"])) | |
323 | |
324 if self._simple_l: | |
325 if not self._gui_simple_panel_wrapper.findChild(name="simple_panel"): | |
326 self._gui_simple_panel_wrapper.addChild(self._gui_simple_panel) | |
327 else: | |
328 if self._gui_simple_panel_wrapper.findChild(name="simple_panel"): | |
329 self._gui_simple_panel_wrapper.removeChild(self._gui_simple_panel) | |
330 if self._image_l: | |
331 if not self._gui_image_panel_wrapper.findChild(name="image_panel"): | |
332 self._gui_image_panel_wrapper.addChild(self._gui_image_panel) | |
333 else: | |
334 if self._gui_image_panel_wrapper.findChild(name="image_panel"): | |
335 self._gui_image_panel_wrapper.removeChild(self._gui_image_panel) | |
336 if self._animation_l: | |
337 if not self._gui_animation_panel_wrapper.findChild(name="animation_panel"): | |
338 self._gui_animation_panel_wrapper.addChild(self._gui_animation_panel) | |
339 else: | |
340 if self._gui_animation_panel_wrapper.findChild(name="animation_panel"): | |
341 self._gui_animation_panel_wrapper.removeChild(self._gui_animation_panel) | |
342 if self._global_l: | |
343 if not self._gui_global_panel_wrapper.findChild(name="global_panel"): | |
344 self._gui_global_panel_wrapper.addChild(self._gui_global_panel) | |
345 else: | |
346 if self._gui_global_panel_wrapper.findChild(name="global_panel"): | |
347 self._gui_global_panel_wrapper.removeChild(self._gui_global_panel) | |
348 | |
349 self.container.adaptLayout(False) | |
350 | |
351 def toggle_gui(self): | |
352 """ | |
353 show / hide the gui | |
354 """ | |
355 if self.active is True: | |
356 self.active = False | |
357 if self.container.isVisible() or self.container.isDocked(): | |
358 self.container.setDocked(False) | |
359 self.container.hide() | |
360 self._showAction.setChecked(False) | |
361 else: | |
362 self.active = True | |
363 self._showAction.setChecked(True) | |
364 | |
365 def toggle_simple_gui(self): | |
366 if self._simple_l: | |
367 self._simple_l = False | |
368 else: | |
369 self._simple_l = True | |
370 self._image_l = False | |
371 self._animation_l = False | |
372 self.update_gui() | |
373 | |
374 def toggle_image_gui(self): | |
375 if self._image_l: | |
376 self._image_l = False | |
377 else: | |
378 self._simple_l = False | |
379 self._image_l = True | |
380 self._animation_l = False | |
381 self.update_gui() | |
382 | |
383 def toggle_animation_gui(self): | |
384 if self._animation_l: | |
385 self._animation_l = False | |
386 else: | |
387 self._simple_l = False | |
388 self._image_l = False | |
389 self._animation_l = True | |
390 self.update_gui() | |
391 | |
392 def toggle_global_gui(self): | |
393 if self._global_l: | |
394 self._global_l = False | |
395 else: | |
396 self._global_l = True | |
397 self.update_gui() | |
398 | |
399 def init_data(self): | |
400 color = self._camera.getLightingColor() | |
401 self._color["R"] = color[0] | |
402 self._color["G"] = color[1] | |
403 self._color["B"] = color[2] | |
404 self._color["A"] = color[3] | |
405 | |
406 groups = self.lightrenderer.getGroups() | |
407 for group in groups: | |
408 infos = self.lightrenderer.getLightInfo(group) | |
409 for info in infos: | |
410 node = info.getNode() | |
411 if node.getInstance() is None: continue | |
412 if node.getInstance().getId() == self._instances[0].getId(): | |
413 self._widgets["group"].text = unicode(str(group)) | |
414 self._light["stencil"] = info.getStencil() | |
415 self._light["alpha"] = info.getAlpha() | |
416 self._light["src"] = info.getSrcBlend() | |
417 self._light["dst"] = info.getDstBlend() | |
418 if str(info.getName()) == "simple": | |
419 self._light["red"] = info.getColor()[0] | |
420 self._light["green"] = info.getColor()[1] | |
421 self._light["blue"] = info.getColor()[2] | |
422 self._light["intensity"] = info.getColor()[3] | |
423 self._light["radius"] = info.getRadius() | |
424 self._light["subdivisions"] = info.getSubdivisions() | |
425 self._light["xstretch"] = info.getXStretch() | |
426 self._light["ystretch"] = info.getYStretch() | |
427 self.toggle_simple_gui() | |
428 elif str(info.getName()) == "image": | |
429 if info.getId() == -1: continue | |
430 img = self.imagepool.getImage(info.getId()); | |
431 name = img.getResourceFile() | |
432 self._widgets["image"].text = unicode(str(name)) | |
433 self._light["image"] = info.getId() | |
434 self.toggle_image_gui() | |
435 elif str(info.getName()) == "animation": | |
436 if info.getId() == -1: continue | |
437 ani = self._animationpool.getAnimation(info.getId()); | |
438 count = 0 | |
439 newstr = '' | |
440 image = ani.getFrame(ani.getActionFrame()) | |
441 fname = image.getResourceFile() | |
442 strings = ([str(s) for s in fname.split('/')]) | |
443 leng = len(strings) -1 | |
444 while count < leng: | |
445 newstr = str(newstr + strings[count] + '/') | |
446 count += 1 | |
447 self._widgets["animation"].text = unicode(str(newstr + 'animation.xml')) | |
448 self._light["animation"] = info.getId() | |
449 self.toggle_animation_gui() | |
450 | |
451 def change_image(self): | |
452 file = self._editor.getObject().getResourceFile() | |
453 tree = ET.parse(file) | |
454 img_lst = tree.findall("image") | |
455 for image in img_lst: | |
456 source = image.get('source') | |
457 path = file.split('/') | |
458 path.pop() | |
459 path.append(str(source)) | |
460 self._widgets["image"].text = unicode(str('/'.join(path))) | |
461 break | |
462 | |
463 def change_animation(self): | |
464 file = self._editor.getObject().getResourceFile() | |
465 tree = ET.parse(file) | |
466 ani_lst = tree.findall("animation") | |
467 if not ani_lst: | |
468 act_lst = tree.findall("action") | |
469 if not act_lst: return | |
470 for act in act_lst: | |
471 ani_lst = act.findall("animation") | |
472 if ani_lst: break | |
473 | |
474 for animation in ani_lst: | |
475 source = animation.get('source') | |
476 path = file.split('/') | |
477 path.pop() | |
478 path.append(str(source)) | |
479 self._widgets["animation"].text = unicode(str('/'.join(path))) | |
480 break | |
481 | |
482 def reset_light(self): | |
483 self._light["stencil"] = -1 | |
484 self._light["alpha"] = 0.0 | |
485 self._light["src"] = -1 | |
486 self._light["dst"] = -1 | |
487 | |
488 self._light["intensity"] = 0 | |
489 self._light["red"] = 0 | |
490 self._light["green"] = 0 | |
491 self._light["blue"] = 0 | |
492 self._light["radius"] = 0 | |
493 self._light["subdivisions"] = 32 | |
494 self._light["xstretch"] = 1 | |
495 self._light["ystretch"] = 1 | |
496 | |
497 self._light["image"] = "" | |
498 self._light["animation"] = "" | |
499 | |
500 self.lightrenderer.removeAll(str(self._widgets["group"]._getText())) | |
501 self._widgets["group"].text = unicode(str("")) | |
502 self._widgets["image"].text = unicode(str("")) | |
503 self._widgets["animation"].text = unicode(str("")) | |
504 self.update_gui() | |
505 | |
506 def use_light(self): | |
507 if not self._instances[0]: return | |
508 counter = 1 | |
509 if self._widgets["ins_id"]._getText() == "": | |
510 objid = self._instances[0].getObject().getId() | |
511 insid = str(objid + str(counter)) | |
512 while bool(self._layer.getInstance(insid)): | |
513 counter = int(counter+1) | |
514 insid = str(objid + str(counter)) | |
515 self._instances[0].setId(insid) | |
516 | |
517 if self._light["stencil"] is not -1 and self._light["alpha"] is not 0.0: self.stencil_test() | |
518 if self._simple_l: self.simple_light() | |
519 if self._image_l: self.image_light() | |
520 if self._animation_l: self.animation_light() | |
521 | |
522 def highlight_selected_instance(self): | |
523 """ highlights selected instance """ | |
524 self.renderer.removeAllOutlines() | |
525 self.renderer.addOutlined(self._instances[0], WHITE["r"], WHITE["g"], WHITE["b"], OUTLINE_SIZE) | |
526 | |
527 def change_light(self, value=0.01, option=None): | |
528 self._light[option] = self._light[option] + value | |
529 if self._light[option]+ value < -1 and (option == "src" or option == "dst" or option == "stencil"): | |
530 self._light[option] = -1 | |
531 if self._light[option]+ value < 0 and option != "src" and option != "dst" and option != "stencil": | |
532 self._light[option] = 0 | |
533 if self._light[option]+ value > 7 and (option == "src" or option == "dst"): | |
534 self._light[option] = 7 | |
535 if self._light[option]+ value > 255 and (option == "intensity" | |
536 or option == "red" | |
537 or option == "green" | |
538 or option == "blue" | |
539 or option == "stencil"): | |
540 self._light[option] = 255 | |
541 if self._light[option]+ value > 1 and option == "alpha": | |
542 self._light[option] = 1.0 | |
543 | |
544 self.update_gui() | |
545 | |
546 def stencil_test(self): | |
547 self.lightrenderer.addStencilTest(str(self._widgets["group"]._getText()), self._light["stencil"], self._light["alpha"]) | |
548 | |
549 def simple_light(self): | |
550 if not self._instances[0]: return | |
551 self.lightrenderer.removeAll(str(self._widgets["group"]._getText())) | |
552 | |
553 node = fife.LightRendererNode(self._instances[0]) | |
554 self.lightrenderer.addSimpleLight(str(self._widgets["group"]._getText()), | |
555 node, | |
556 self._light["intensity"], | |
557 self._light["radius"], | |
558 self._light["subdivisions"], | |
559 self._light["xstretch"], | |
560 self._light["ystretch"], | |
561 self._light["red"], | |
562 self._light["green"], | |
563 self._light["blue"], | |
564 self._light["src"], | |
565 self._light["dst"],) | |
566 | |
567 def image_light(self): | |
568 if not self._instances[0]: return | |
569 self.lightrenderer.removeAll(str(self._widgets["group"]._getText())) | |
570 | |
571 image = str(self._widgets["image"]._getText()) | |
572 if image == "": return | |
573 img_id = self.imagepool.addResourceFromFile(image) | |
574 self._light["image"] = int(img_id) | |
575 node = fife.LightRendererNode(self._instances[0]) | |
576 self.lightrenderer.addImage(str(self._widgets["group"]._getText()), | |
577 node, | |
578 self._light["image"], | |
579 self._light["src"], | |
580 self._light["dst"],) | |
581 | |
582 def animation_light(self): | |
583 if not self._instances[0]: return | |
584 self.lightrenderer.removeAll(str(self._widgets["group"]._getText())) | |
585 | |
586 animation = str(self._widgets["animation"]._getText()) | |
587 if animation == "": return | |
588 rloc = fife.ResourceLocation(animation) | |
589 ani_id = self._animationpool.addResourceFromLocation(rloc) | |
590 self._light["animation"] = int(ani_id) | |
591 node = fife.LightRendererNode(self._instances[0]) | |
592 self.lightrenderer.addAnimation(str(self._widgets["group"]._getText()), | |
593 node, | |
594 self._light["animation"], | |
595 self._light["src"], | |
596 self._light["dst"],) | |
597 | |
598 def reset_global_light(self): | |
599 """ reset global light to default values (1.0) """ | |
600 self._color.update(DEFAULT_GLOBAL_LIGHT) | |
601 self.update_gui() | |
602 self.set_global_light() | |
603 | |
604 def increase_color(self, step=0.1, r=None, g=None, b=None, a=None): | |
605 """ increase a given color value by step value | |
606 | |
607 @type step float | |
608 @param step the step for changing the color channel | |
609 @type r bool | |
610 @param r flag to alter red color value | |
611 @type g bool | |
612 @param g flag to alter green color value | |
613 @type b bool | |
614 @param b flag to alter blue color value | |
615 @type a bool | |
616 @type a flag to alter alpha channel value (no effect atm) | |
617 """ | |
618 if r: | |
619 if self._color["R"] + step > 1.0: | |
620 self._color["R"] = 1.0 | |
621 else: | |
622 self._color["R"] += step | |
623 if g: | |
624 if self._color["G"] + step > 1.0: | |
625 self._color["G"] = 1.0 | |
626 else: | |
627 self._color["G"] += step | |
628 if b: | |
629 if self._color["B"] + step > 1.0: | |
630 self._color["B"] = 1.0 | |
631 else: | |
632 self._color["B"] += step | |
633 if a: | |
634 if self._color["A"] + step > 1.0: | |
635 self._color["A"] = 1.0 | |
636 else: | |
637 self._color["A"] += step | |
638 | |
639 self.update_gui() | |
640 self.set_global_light() | |
641 | |
642 def decrease_color(self, step=0.1, r=None, g=None, b=None, a=None): | |
643 """ decrease a given color value by step value | |
644 | |
645 @type step float | |
646 @param step the step for changing the color channel | |
647 @type r bool | |
648 @param r flag to alter red color value | |
649 @type g bool | |
650 @param g flag to alter green color value | |
651 @type b bool | |
652 @param b flag to alter blue color value | |
653 @type a bool | |
654 @type a flag to alter alpha channel value (no effect atm) | |
655 """ | |
656 if r: | |
657 if self._color["R"] - step < 0.0: | |
658 self._color["R"] = 0.0 | |
659 else: | |
660 self._color["R"] -= step | |
661 if g: | |
662 if self._color["G"] - step < 0.0: | |
663 self._color["G"] = 0.0 | |
664 else: | |
665 self._color["G"] -= step | |
666 if b: | |
667 if self._color["B"] - step < 0.0: | |
668 self._color["B"] = 0.0 | |
669 else: | |
670 self._color["B"] -= step | |
671 if a: | |
672 if self._color["A"] - step < 0.0: | |
673 self._color["A"] = 0.0 | |
674 else: | |
675 self._color["A"] -= step | |
676 | |
677 self.update_gui() | |
678 self.set_global_light() | |
679 | |
680 def random_color(self): | |
681 """ generate random values for color channels """ | |
682 self._color["R"] = random.uniform(0,1) | |
683 self._color["G"] = random.uniform(0,1) | |
684 self._color["B"] = random.uniform(0,1) | |
685 self._color["A"] = random.uniform(0,1) | |
686 | |
687 self.update_gui() | |
688 self.set_global_light() | |
689 | |
690 def set_global_light(self): | |
691 """ update the global light with the current set colors """ | |
692 self._camera.setLightingColor(self._color["R"], | |
693 self._color["G"], | |
694 self._color["B"], | |
695 self._color["A"] | |
696 ) | |
697 | |
698 def input(self, instances): | |
699 if instances != self._instances: | |
700 if self.active is True: | |
701 self._reset() | |
702 self._instances = instances | |
703 | |
704 if self._camera is None: | |
705 self._camera = self._editor.getActiveMapView().getCamera() | |
706 self.renderer = fife.InstanceRenderer.getInstance(self._camera) | |
707 self.lightrenderer = fife.LightRenderer.getInstance(self._camera) | |
708 | |
709 self._layer = self._editor.getActiveMapView().getController()._layer | |
710 | |
711 if self._instances != (): | |
712 self.init_data() | |
713 self.highlight_selected_instance() | |
714 self.update_gui() | |
715 self.container.show() | |
716 else: | |
717 self._reset() | |
718 self.container.hide() | |
719 | |
720 self.container.adaptLayout(False) |