annotate clients/editor/plugins/LightEdit.py @ 307:22253b2c9b14

- added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available) - added animation viewer to ObjectEdit - several bugfixes for ObjectEdit plugin FEATURES: - ObjectEdit - viewing and rotating animated instances (rotations are hardcoded for now, FIFE needs to expose available angles to python in order to make animation rotation work for every client) - LightEdit - test global light values
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 11 Aug 2009 15:32:54 +0000
parents
children dfd48d49c044
rev   line source
307
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
1 #!/usr/bin/env python
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
2 # coding: utf-8
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
3 # ###################################################
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
4 # Copyright (C) 2008 The Zero-Projekt team
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
5 # http://zero-projekt.net
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
6 # info@zero-projekt.net
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
7 # This file is part of Zero "Was vom Morgen blieb"
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
8 #
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
9 # The Zero-Projekt codebase is free software; you can redistribute it and/or modify
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
10 # it under the terms of the GNU General Public License as published by
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
11 # the Free Software Foundation; either version 2 of the License, or
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
12 # (at your option) any later version.
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
13 #
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
14 # This program is distributed in the hope that it will be useful,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
17 # GNU General Public License for more details.
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
18 #
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
19 # You should have received a copy of the GNU General Public License
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
20 # along with this program; if not, write to the
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
21 # Free Software Foundation, Inc.,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
22 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
23 # ###################################################
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
24
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
25 """ a tool for FIFEdit to test global light """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
26
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
27 import fife
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
28 import pychan
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
29 import pychan.widgets as widgets
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
30 from pychan.tools import callbackWithArguments as cbwa
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
31
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
32 from fife_timer import Timer
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
33
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
34 import scripts
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
35 import scripts.plugin as plugin
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
36 from scripts.events import *
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
37 from scripts.gui.action import Action
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
38
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
39 import random
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
40
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
41 DEFAULT_GLOBAL_LIGHT = {
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
42 "R" : 1.0,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
43 "G" : 1.0,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
44 "B" : 1.0,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
45 "A" : 1.0,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
46 }
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
47 DEFAULT_LIGHT_ID = "LightEdit"
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
48
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
49 class LightEdit(plugin.Plugin):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
50 """ The B{LightEdit} module is a plugin for FIFedit and allows to change the
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
51 global light value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
52
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
53 FEATURES:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
54 - enable FIFE lighting renderer
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
55 - generate random light values
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
56 - test lightsetups by manipulating the color channels
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
57 - reset to default
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
58 """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
59 def __init__(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
60 self.active = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
61
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
62 self._renderer = None
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
63 self._camera = None
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
64 self._enabled = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
65 self._light = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
66
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
67 self.map_loaded = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
68
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
69 self._color = {}
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
70 self._color.update(DEFAULT_GLOBAL_LIGHT)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
71
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
72 random.seed()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
73
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
74 if "LightRenderer" in dir(fife):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
75 self._renderer_available = True
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
76 else:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
77 self._renderer_available = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
78
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
79 def _reset(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
80 """ resets all dynamic vars """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
81 pass
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
82
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
83 def enable(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
84 """ plugin method """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
85 if not self._renderer_available:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
86 self._enabled = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
87 return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
88 if self._enabled is True:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
89 return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
90
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
91 self._editor = scripts.editor.getEditor()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
92 self.engine = self._editor.getEngine()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
93
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
94 self._showAction = Action(unicode(self.getName(),"utf-8"), checkable=True)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
95 scripts.gui.action.activated.connect(self.toggle_gui, sender=self._showAction)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
96
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
97 self._editor._toolsMenu.addAction(self._showAction)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
98
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
99 events.postMapShown.connect(self.update_renderer)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
100 events.onMapChanged.connect(self.update_renderer)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
101
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
102 self._reset()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
103 self.create_gui()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
104
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
105 def disable(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
106 """ plugin method """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
107 if self._enabled is False:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
108 return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
109
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
110 self._reset()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
111 self.container.hide()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
112 self.removeAllChildren()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
113
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
114 self._editor._toolsMenu.removeAction(self._showAction)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
115
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
116 events.postMapShown.disconnect(self.update_renderer)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
117 events.onMapChanged.disconnect(self.update_renderer)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
118
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
119 def isEnabled(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
120 """ plugin method """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
121 return self._enabled;
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
122
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
123 def getName(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
124 """ plugin method """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
125 return "Light editor"
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
126
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
127 def create_gui(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
128 """ create gui container and setup callbacks """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
129 self.container = pychan.loadXML('gui/lightedit.xml')
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
130 self.container.mapEvents({
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
131 "enable_global_light" : self.toggle_light,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
132 "random_global_light" : self.random_color,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
133 "reset_global_light" : self.reset_global_light,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
134
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
135 "increase_R" : cbwa(self.increase_color, r=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
136 "decrease_R" : cbwa(self.decrease_color, r=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
137 "value_R/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.2, r=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
138 "value_R/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.2, r=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
139
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
140 "increase_G" : cbwa(self.increase_color, g=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
141 "decrease_G" : cbwa(self.decrease_color, g=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
142 "value_G/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.2, g=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
143 "value_G/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.2, g=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
144
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
145 "increase_B" : cbwa(self.increase_color, b=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
146 "decrease_B" : cbwa(self.decrease_color, b=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
147 "value_B/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.2, b=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
148 "value_B/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.2, b=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
149
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
150 "increase_A" : cbwa(self.increase_color, a=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
151 "decrease_A" : cbwa(self.decrease_color, a=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
152 "value_A/mouseWheelMovedUp" : cbwa(self.increase_color, step=0.2, a=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
153 "value_A/mouseWheelMovedDown" : cbwa(self.decrease_color, step=0.2, a=True),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
154 })
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
155 self._widgets = {
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
156 "enable_global_light" : self.container.findChild(name="enable_global_light"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
157 "random_global_light" : self.container.findChild(name="random_global_light"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
158 "reset_global_light" : self.container.findChild(name="reset_global_light"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
159
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
160 "value_R" : self.container.findChild(name="value_R"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
161 "value_G" : self.container.findChild(name="value_G"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
162 "value_B" : self.container.findChild(name="value_B"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
163 "value_A" : self.container.findChild(name="value_A"),
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
164 }
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
165
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
166 def toggle_gui(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
167 """ show / hide the gui """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
168 if self.active:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
169 self.active = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
170 if self.container.isVisible() or self.container.isDocked():
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
171 self.container.setDocked(False)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
172 self.container.hide()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
173 self._showAction.setChecked(False)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
174 else:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
175 self.active = True
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
176 self._showAction.setChecked(True)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
177 self.container.show()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
178
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
179 def toggle_light(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
180 """ toggle light on / off """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
181 if not self._renderer:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
182 self._widgets['enable_global_light']._setToggled(False)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
183 return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
184
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
185 if self._light:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
186 self._light = False
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
187 self.reset_global_light()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
188 self._renderer.setEnabled(False)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
189 else:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
190 self._light = True
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
191 self._renderer.setEnabled(True)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
192
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
193 def update_renderer(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
194 """ sets current camera and renderer
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
195 bound to FIFedit core (updated on map change)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
196 """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
197 self._camera = self._editor.getActiveMapView().getCamera()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
198 self._renderer = fife.LightRenderer.getInstance(self._camera)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
199
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
200 def update_gui(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
201 """ update gui widgets according to plugin data """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
202 self._widgets["value_R"].text = unicode(str(self._color["R"]))
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
203 self._widgets["value_G"].text = unicode(str(self._color["G"]))
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
204 self._widgets["value_B"].text = unicode(str(self._color["B"]))
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
205 self._widgets["value_A"].text = unicode(str(self._color["A"]))
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
206
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
207 def reset_global_light(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
208 """ reset global light to default values (1.0) """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
209 if not self._renderer: return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
210
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
211 self._color.update(DEFAULT_GLOBAL_LIGHT)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
212 self.update_gui()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
213 self.set_global_light()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
214
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
215 def increase_color(self, step=0.1, r=None, g=None, b=None, a=None):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
216 """ increase a given color value by step value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
217
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
218 @type step float
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
219 @param step the step for changing the color channel
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
220 @type r bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
221 @param r flag to alter red color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
222 @type g bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
223 @param g flag to alter green color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
224 @type b bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
225 @param b flag to alter blue color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
226 @type a bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
227 @type a flag to alter alpha channel value (no effect atm)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
228 """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
229 if r:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
230 self._color["R"] += step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
231 if g:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
232 self._color["G"] += step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
233 if b:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
234 self._color["B"] += step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
235 if a:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
236 self._color["A"] += step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
237
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
238 self.update_gui()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
239 self.set_global_light()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
240
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
241 def decrease_color(self, step=0.1, r=None, g=None, b=None, a=None):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
242 """ decrease a given color value by step value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
243
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
244 @type step float
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
245 @param step the step for changing the color channel
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
246 @type r bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
247 @param r flag to alter red color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
248 @type g bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
249 @param g flag to alter green color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
250 @type b bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
251 @param b flag to alter blue color value
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
252 @type a bool
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
253 @type a flag to alter alpha channel value (no effect atm)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
254 """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
255 if r:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
256 self._color["R"] -= step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
257 if g:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
258 self._color["G"] -= step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
259 if b:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
260 self._color["B"] -= step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
261 if a:
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
262 self._color["A"] -= step
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
263
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
264 self.update_gui()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
265 self.set_global_light()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
266
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
267 def random_color(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
268 """ generate random values for color channels """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
269 if not self._renderer: return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
270
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
271 self._color["R"] = random.uniform(0,2)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
272 self._color["G"] = random.uniform(0,2)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
273 self._color["B"] = random.uniform(0,2)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
274 self._color["A"] = random.uniform(0,2)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
275
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
276 self.update_gui()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
277 self.set_global_light()
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
278
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
279 def set_global_light(self):
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
280 """ update the global light with the current set colors """
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
281 if not self._renderer: return
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
282
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
283 self._renderer.removeAll(DEFAULT_LIGHT_ID)
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
284 self._renderer.setglobalLight(
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
285 DEFAULT_LIGHT_ID,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
286 1,
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
287 self._color["R"],
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
288 self._color["G"],
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
289 self._color["B"],
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
290 self._color["A"]
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
291 )
22253b2c9b14 - added LightEdit editor plugin (needs light branch to work; deactivated if lighting renderer is not available)
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff changeset
292