rna UI api rename...
[blender.git] / release / scripts / ui / properties_game.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 class PhysicsButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "physics"
29
30     def poll(self, context):
31         ob = context.active_object
32         rd = context.scene.render_data
33         return ob and ob.game and (rd.engine == 'BLENDER_GAME')
34
35
36 class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
37     bl_label = "Physics"
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.active_object
43         game = ob.game
44         soft = ob.game.soft_body
45         wide_ui = context.region.width > narrowui
46
47         if wide_ui:
48             layout.prop(game, "physics_type")
49         else:
50             layout.prop(game, "physics_type", text="")
51         layout.separator()
52
53         #if game.physics_type == 'DYNAMIC':
54         if game.physics_type in ('DYNAMIC', 'RIGID_BODY'):
55             split = layout.split()
56
57             col = split.column()
58             col.prop(game, "actor")
59             col.prop(game, "ghost")
60             col.prop(ob, "restrict_render", text="Invisible") # out of place but useful
61
62             if wide_ui:
63                 col = split.column()
64             col.prop(game, "material_physics")
65             col.prop(game, "rotate_from_normal")
66             col.prop(game, "no_sleeping")
67
68             layout.separator()
69
70             split = layout.split()
71
72             col = split.column()
73             col.label(text="Attributes:")
74             col.prop(game, "mass")
75             col.prop(game, "radius")
76             col.prop(game, "form_factor")
77
78             if wide_ui:
79                 col = split.column()
80             sub = col.column()
81             sub.active = (game.physics_type == 'RIGID_BODY')
82             sub.prop(game, "anisotropic_friction")
83             subsub = sub.column()
84             subsub.active = game.anisotropic_friction
85             subsub.prop(game, "friction_coefficients", text="", slider=True)
86
87             split = layout.split()
88
89             col = split.column()
90             col.label(text="Velocity:")
91             sub = col.column(align=True)
92             sub.prop(game, "minimum_velocity", text="Minimum")
93             sub.prop(game, "maximum_velocity", text="Maximum")
94
95             if wide_ui:
96                 col = split.column()
97             col.label(text="Damping:")
98             sub = col.column(align=True)
99             sub.prop(game, "damping", text="Translation", slider=True)
100             sub.prop(game, "rotation_damping", text="Rotation", slider=True)
101
102             layout.separator()
103
104             split = layout.split()
105
106             col = split.column()
107             col.label(text="Lock Translation:")
108             col.prop(game, "lock_x_axis", text="X")
109             col.prop(game, "lock_y_axis", text="Y")
110             col.prop(game, "lock_z_axis", text="Z")
111
112             col = split.column()
113             col.label(text="Lock Rotation:")
114             col.prop(game, "lock_x_rot_axis", text="X")
115             col.prop(game, "lock_y_rot_axis", text="Y")
116             col.prop(game, "lock_z_rot_axis", text="Z")
117
118         elif game.physics_type == 'SOFT_BODY':
119             col = layout.column()
120             col.prop(game, "actor")
121             col.prop(game, "ghost")
122             col.prop(ob, "restrict_render", text="Invisible")
123
124             layout.separator()
125
126             split = layout.split()
127
128             col = split.column()
129             col.label(text="Attributes:")
130             col.prop(game, "mass")
131             col.prop(soft, "welding")
132             col.prop(soft, "position_iterations")
133             col.prop(soft, "linstiff", slider=True)
134             col.prop(soft, "dynamic_friction", slider=True)
135             col.prop(soft, "margin", slider=True)
136             col.prop(soft, "bending_const", text="Bending Constraints")
137
138             if wide_ui:
139                 col = split.column()
140             col.prop(soft, "shape_match")
141             sub = col.column()
142             sub.active = soft.shape_match
143             sub.prop(soft, "threshold", slider=True)
144
145             col.separator()
146
147             col.label(text="Cluster Collision:")
148             col.prop(soft, "cluster_rigid_to_softbody")
149             col.prop(soft, "cluster_soft_to_softbody")
150             sub = col.column()
151             sub.active = (soft.cluster_rigid_to_softbody or soft.cluster_soft_to_softbody)
152             sub.prop(soft, "cluster_iterations", text="Iterations")
153
154         elif game.physics_type == 'STATIC':
155             col = layout.column()
156             col.prop(game, "actor")
157             col.prop(game, "ghost")
158             col.prop(ob, "restrict_render", text="Invisible")
159
160         elif game.physics_type in ('SENSOR', 'INVISIBLE', 'NO_COLLISION', 'OCCLUDE'):
161             layout.prop(ob, "restrict_render", text="Invisible")
162
163
164 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
165     bl_label = "Collision Bounds"
166
167     def poll(self, context):
168         game = context.object.game
169         rd = context.scene.render_data
170         return (game.physics_type in ('DYNAMIC', 'RIGID_BODY', 'SENSOR', 'SOFT_BODY', 'STATIC')) and (rd.engine == 'BLENDER_GAME')
171
172     def draw_header(self, context):
173         game = context.active_object.game
174
175         self.layout.prop(game, "use_collision_bounds", text="")
176
177     def draw(self, context):
178         layout = self.layout
179
180         game = context.active_object.game
181         wide_ui = context.region.width > narrowui
182
183         layout.active = game.use_collision_bounds
184         if wide_ui:
185             layout.prop(game, "collision_bounds", text="Bounds")
186         else:
187             layout.prop(game, "collision_bounds", text="")
188
189         split = layout.split()
190
191         col = split.column()
192         col.prop(game, "collision_margin", text="Margin", slider=True)
193
194         if wide_ui:
195             col = split.column()
196         col.prop(game, "collision_compound", text="Compound")
197
198
199 bpy.types.register(PHYSICS_PT_game_physics)
200 bpy.types.register(PHYSICS_PT_game_collision_bounds)
201
202
203 class RenderButtonsPanel(bpy.types.Panel):
204     bl_space_type = 'PROPERTIES'
205     bl_region_type = 'WINDOW'
206     bl_context = "render"
207
208     def poll(self, context):
209         rd = context.scene.render_data
210         return (rd.engine == 'BLENDER_GAME')
211
212
213 class RENDER_PT_game(RenderButtonsPanel):
214     bl_label = "Game"
215
216     def draw(self, context):
217         layout = self.layout
218
219         row = layout.row()
220         row.operator("view3d.game_start", text="Start")
221         row.label()
222
223
224 class RENDER_PT_game_player(RenderButtonsPanel):
225     bl_label = "Standalone Player"
226
227     def draw(self, context):
228         layout = self.layout
229
230         gs = context.scene.game_data
231         wide_ui = context.region.width > narrowui
232
233         layout.prop(gs, "fullscreen")
234
235         split = layout.split()
236
237         col = split.column()
238         col.label(text="Resolution:")
239         sub = col.column(align=True)
240         sub.prop(gs, "resolution_x", slider=False, text="X")
241         sub.prop(gs, "resolution_y", slider=False, text="Y")
242
243         if wide_ui:
244             col = split.column()
245         col.label(text="Quality:")
246         sub = col.column(align=True)
247         sub.prop(gs, "depth", text="Bit Depth", slider=False)
248         sub.prop(gs, "frequency", text="FPS", slider=False)
249
250         # framing:
251         col = layout.column()
252         col.label(text="Framing:")
253         if wide_ui:
254             col.row().prop(gs, "framing_type", expand=True)
255         else:
256             col.prop(gs, "framing_type", text="")
257         if gs.framing_type == 'LETTERBOX':
258             col.prop(gs, "framing_color", text="")
259
260
261 class RENDER_PT_game_stereo(RenderButtonsPanel):
262     bl_label = "Stereo"
263
264     def draw(self, context):
265         layout = self.layout
266
267         gs = context.scene.game_data
268         stereo_mode = gs.stereo
269         wide_ui = context.region.width > narrowui
270
271         # stereo options:
272         layout.prop(gs, "stereo", expand=True)
273
274         # stereo:
275         if stereo_mode == 'STEREO':
276             layout.prop(gs, "stereo_mode")
277             layout.label(text="To do: Focal Length")
278             layout.label(text="To do: Eye Separation")
279
280         # dome:
281         elif stereo_mode == 'DOME':
282             if wide_ui:
283                 layout.prop(gs, "dome_mode", text="Dome Type")
284             else:
285                 layout.prop(gs, "dome_mode", text="")
286
287             dome_type = gs.dome_mode
288
289             split = layout.split()
290
291             if dome_type == 'FISHEYE' or \
292                dome_type == 'TRUNCATED_REAR' or \
293                dome_type == 'TRUNCATED_FRONT':
294
295                 col = split.column()
296                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
297                 col.prop(gs, "dome_angle", slider=True)
298
299                 if wide_ui:
300                     col = split.column()
301                 col.prop(gs, "dome_tesselation", text="Tesselation")
302                 col.prop(gs, "dome_tilt")
303
304             elif dome_type == 'PANORAM_SPH':
305                 col = split.column()
306
307                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
308                 if wide_ui:
309                     col = split.column()
310                 col.prop(gs, "dome_tesselation", text="Tesselation")
311
312             else: # cube map
313                 col = split.column()
314                 col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True)
315                 if wide_ui:
316                     col = split.column()
317
318             layout.prop(gs, "dome_text")
319
320
321 class RENDER_PT_game_shading(RenderButtonsPanel):
322     bl_label = "Shading"
323
324     def draw(self, context):
325         layout = self.layout
326
327         gs = context.scene.game_data
328         wide_ui = context.region.width > narrowui
329
330         if wide_ui:
331             layout.prop(gs, "material_mode", expand=True)
332         else:
333             layout.prop(gs, "material_mode", text="")
334
335         if gs.material_mode == 'GLSL':
336             split = layout.split()
337
338             col = split.column()
339             col.prop(gs, "glsl_lights", text="Lights")
340             col.prop(gs, "glsl_shaders", text="Shaders")
341             col.prop(gs, "glsl_shadows", text="Shadows")
342
343             col = split.column()
344             col.prop(gs, "glsl_ramps", text="Ramps")
345             col.prop(gs, "glsl_nodes", text="Nodes")
346             col.prop(gs, "glsl_extra_textures", text="Extra Textures")
347
348
349 class RENDER_PT_game_performance(RenderButtonsPanel):
350     bl_label = "Performance"
351
352     def draw(self, context):
353         layout = self.layout
354
355         gs = context.scene.game_data
356         wide_ui = context.region.width > narrowui
357
358         split = layout.split()
359
360         col = split.column()
361         col.label(text="Show:")
362         col.prop(gs, "show_debug_properties", text="Debug Properties")
363         col.prop(gs, "show_framerate_profile", text="Framerate and Profile")
364         col.prop(gs, "show_physics_visualization", text="Physics Visualization")
365         col.prop(gs, "deprecation_warnings")
366
367         if wide_ui:
368             col = split.column()
369         col.label(text="Render:")
370         col.prop(gs, "all_frames")
371         col.prop(gs, "display_lists")
372
373
374 class RENDER_PT_game_sound(RenderButtonsPanel):
375     bl_label = "Sound"
376
377     def draw(self, context):
378         layout = self.layout
379
380         scene = context.scene
381         wide_ui = context.region.width > narrowui
382
383         if wide_ui:
384             layout.prop(scene, "distance_model")
385         else:
386             layout.prop(scene, "distance_model", text="")
387         layout.prop(scene, "speed_of_sound", text="Speed")
388         layout.prop(scene, "doppler_factor")
389
390 bpy.types.register(RENDER_PT_game)
391 bpy.types.register(RENDER_PT_game_player)
392 bpy.types.register(RENDER_PT_game_stereo)
393 bpy.types.register(RENDER_PT_game_shading)
394 bpy.types.register(RENDER_PT_game_performance)
395 bpy.types.register(RENDER_PT_game_sound)
396
397
398 class WorldButtonsPanel(bpy.types.Panel):
399     bl_space_type = 'PROPERTIES'
400     bl_region_type = 'WINDOW'
401     bl_context = "world"
402
403     def poll(self, context):
404         rd = context.scene.render_data
405         return (rd.engine == 'BLENDER_GAME')
406
407
408 class WORLD_PT_game_context_world(WorldButtonsPanel):
409     bl_label = ""
410     bl_show_header = False
411
412     def poll(self, context):
413         rd = context.scene.render_data
414         return (context.scene) and (rd.use_game_engine)
415
416     def draw(self, context):
417         layout = self.layout
418
419         scene = context.scene
420         world = context.world
421         space = context.space_data
422         wide_ui = context.region.width > narrowui
423
424         if wide_ui:
425             split = layout.split(percentage=0.65)
426             if scene:
427                 split.template_ID(scene, "world", new="world.new")
428             elif world:
429                 split.template_ID(space, "pin_id")
430         else:
431             if scene:
432                 layout.template_ID(scene, "world", new="world.new")
433             elif world:
434                 layout.template_ID(space, "pin_id")
435
436
437 class WORLD_PT_game_world(WorldButtonsPanel):
438     bl_label = "World"
439
440     def draw(self, context):
441         layout = self.layout
442
443         world = context.world
444         wide_ui = context.region.width > narrowui
445
446         split = layout.split()
447
448         col = split.column()
449         col.prop(world, "horizon_color")
450
451         if wide_ui:
452             col = split.column()
453         col.prop(world, "ambient_color")
454
455
456 class WORLD_PT_game_mist(WorldButtonsPanel):
457     bl_label = "Mist"
458
459     def draw_header(self, context):
460         world = context.world
461
462         self.layout.prop(world.mist, "enabled", text="")
463
464     def draw(self, context):
465         layout = self.layout
466
467         world = context.world
468         wide_ui = context.region.width > narrowui
469
470         layout.active = world.mist.enabled
471         split = layout.split()
472
473         col = split.column()
474         col.prop(world.mist, "start")
475
476         if wide_ui:
477             col = split.column()
478         col.prop(world.mist, "depth")
479
480
481 class WORLD_PT_game_physics(WorldButtonsPanel):
482     bl_label = "Physics"
483
484     def draw(self, context):
485         layout = self.layout
486
487         gs = context.scene.game_data
488         wide_ui = context.region.width > narrowui
489
490         layout.prop(gs, "physics_engine")
491         if gs.physics_engine != 'NONE':
492             layout.prop(gs, "physics_gravity", text="Gravity")
493
494             split = layout.split()
495
496             col = split.column()
497             col.label(text="Physics Steps:")
498             sub = col.column(align=True)
499             sub.prop(gs, "physics_step_max", text="Max")
500             sub.prop(gs, "physics_step_sub", text="Substeps")
501             col.prop(gs, "fps", text="FPS")
502
503             if wide_ui:
504                 col = split.column()
505             col.label(text="Logic Steps:")
506             col.prop(gs, "logic_step_max", text="Max")
507
508             col = layout.column()
509             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
510             sub = col.column()
511             sub.active = gs.use_occlusion_culling
512             sub.prop(gs, "occlusion_culling_resolution", text="Resolution")
513
514         else:
515             split = layout.split()
516
517             col = split.column()
518             col.label(text="Physics Steps:")
519             col.prop(gs, "fps", text="FPS")
520
521             col = split.column()
522             col.label(text="Logic Steps:")
523             col.prop(gs, "logic_step_max", text="Max")
524
525 bpy.types.register(WORLD_PT_game_context_world)
526 bpy.types.register(WORLD_PT_game_world)
527 bpy.types.register(WORLD_PT_game_mist)
528 bpy.types.register(WORLD_PT_game_physics)