2d29a45028d5b3c5bbee624fe98b57254b5592a2
[blender.git] / release / ui / buttons_game.py
1
2 import bpy
3  
4 class PhysicsButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.active_object
11                 rd = context.scene.render_data
12                 return ob and ob.game and (rd.engine == 'BLENDER_GAME')
13
14 class PHYSICS_PT_game_physics(PhysicsButtonsPanel):
15         __label__ = "Physics"
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 ob = context.active_object
21                 game = ob.game
22
23                 layout.itemR(game, "physics_type")
24                 layout.itemS()
25                 
26                 split = layout.split()
27                 
28                 col = split.column()
29                 col.itemR(game, "actor")
30                 col.itemR(game, "ghost")
31                 col.itemR(ob, "restrict_render", text="Invisible") # out of place but useful
32                 
33                 col = split.column()
34                 col.itemR(game, "do_fh", text="Use Material Physics")
35                 col.itemR(game, "rotation_fh", text="Rotate From Normal")
36                 col.itemR(game, "no_sleeping")
37                 
38                 layout.itemS()
39                 
40                 split = layout.split()
41                 
42                 col = split.column()
43                 col.itemL(text="Attributes:")
44                 sub = col.column(align=True)
45                 sub.itemR(game, "mass")
46                 sub.itemR(game, "radius")
47                 sub.itemR(game, "form_factor")
48                 
49                 col.itemS()
50                 
51                 col.itemL(text="Damping:")
52                 sub = col.column(align=True)
53                 sub.itemR(game, "damping", text="Translation", slider=True)
54                 sub.itemR(game, "rotation_damping", text="Rotation", slider=True)
55                 
56                 col = split.column()
57                 col.itemL(text="Velocity:")
58                 sub = col.column(align=True)
59                 sub.itemR(game, "minimum_velocity", text="Minimum")
60                 sub.itemR(game, "maximum_velocity", text="Maximum")
61                 
62                 col.itemS()
63                 
64                 col.itemR(game, "anisotropic_friction")
65                 sub = col.column()
66                 sub.active = game.anisotropic_friction
67                 sub.itemR(game, "friction_coefficients", text="", slider=True)
68                 
69                 layout.itemS()
70                 
71                 split = layout.split()
72                 
73                 col = split.column()
74                 col.itemL(text="Lock Translation:")
75                 col.itemR(game, "lock_x_axis", text="X")
76                 col.itemR(game, "lock_y_axis", text="Y")
77                 col.itemR(game, "lock_z_axis", text="Z")
78                 
79                 col = split.column()
80                 col.itemL(text="Lock Rotation:")
81                 col.itemR(game, "lock_x_rot_axis", text="X")
82                 col.itemR(game, "lock_y_rot_axis", text="Y")
83                 col.itemR(game, "lock_z_rot_axis", text="Z")
84
85 class PHYSICS_PT_game_collision_bounds(PhysicsButtonsPanel):
86         __label__ = "Collision Bounds"
87
88         def draw_header(self, context):
89                 layout = self.layout
90                 
91                 ob = context.active_object
92                 game = ob.game
93
94                 layout.itemR(game, "use_collision_bounds", text="")
95         
96         def draw(self, context):
97                 layout = self.layout
98                 
99                 ob = context.scene.objects[0]
100                 game = ob.game
101                 
102                 layout.active = game.use_collision_bounds
103                 layout.itemR(game, "collision_bounds", text="Bounds")
104                 
105                 row = layout.row()
106                 row.itemR(game, "collision_compound", text="Compound")
107                 row.itemR(game, "collision_margin", text="Margin", slider=True)
108
109 bpy.types.register(PHYSICS_PT_game_physics)
110 bpy.types.register(PHYSICS_PT_game_collision_bounds)
111
112 class SceneButtonsPanel(bpy.types.Panel):
113         __space_type__ = "BUTTONS_WINDOW"
114         __region_type__ = "WINDOW"
115         __context__ = "scene"
116
117         def poll(self, context):
118                 rd = context.scene.render_data
119                 return (rd.engine == 'BLENDER_GAME')
120
121 class SCENE_PT_game(SceneButtonsPanel):
122         __label__ = "Game"
123
124         def draw(self, context):
125                 layout = self.layout
126                 
127                 rd = context.scene.render_data
128
129                 row = layout.row()
130                 row.itemO("view3d.game_start", text="Start")
131                 row.itemL()
132
133 class SCENE_PT_game_player(SceneButtonsPanel):
134         __label__ = "Player"
135
136         def draw(self, context):
137                 layout = self.layout
138                 
139                 gs = context.scene.game_data
140                 
141                 layout.itemR(gs, "fullscreen")
142
143                 split = layout.split()
144                 
145                 col = split.column()
146                 col.itemL(text="Resolution:")
147                 sub = col.column(align=True)
148                 sub.itemR(gs, "resolution_x", slider=False, text="X")
149                 sub.itemR(gs, "resolution_y", slider=False, text="Y")
150
151                 col = split.column()
152                 col.itemL(text="Quality:")
153                 sub = col.column(align=True)
154                 sub.itemR(gs, "depth", text="Bit Depth", slider=False)
155                 sub.itemR(gs, "frequency", text="FPS", slider=False)
156
157                 # framing:
158                 col = layout.column()
159                 col.itemL(text="Framing:")
160                 col.row().itemR(gs, "framing_type", expand=True)
161                 sub = col.column()
162                 sub.itemR(gs, "framing_color", text="")
163
164 class SCENE_PT_game_stereo(SceneButtonsPanel):
165         __label__ = "Stereo"
166
167         def draw(self, context):
168                 layout = self.layout
169                 
170                 gs = context.scene.game_data
171                 stereo_mode = gs.stereo
172
173                 # stereo options:
174                 layout.itemR(gs, "stereo", expand=True)
175  
176                 # stereo:
177                 if stereo_mode == 'STEREO':
178                         layout.itemR(gs, "stereo_mode")
179
180                 # dome:
181                 if stereo_mode == 'DOME':
182                         layout.itemR(gs, "dome_mode", text="Dome Type")
183
184                         split=layout.split()
185                         
186                         col=split.column()
187                         col.itemR(gs, "dome_angle", slider=True)
188                         col.itemR(gs, "dome_tesselation", text="Tesselation")
189                         
190                         col=split.column()
191                         col.itemR(gs, "dome_tilt")
192                         col.itemR(gs, "dome_buffer_resolution", text="Resolution", slider=True)
193                         
194                         layout.itemR(gs, "dome_text")
195
196 bpy.types.register(SCENE_PT_game)
197 bpy.types.register(SCENE_PT_game_player)
198 bpy.types.register(SCENE_PT_game_stereo)
199
200 class WorldButtonsPanel(bpy.types.Panel):
201         __space_type__ = "BUTTONS_WINDOW"
202         __region_type__ = "WINDOW"
203         __context__ = "world"
204
205         def poll(self, context):
206                 rd = context.scene.render_data
207                 return (rd.engine == 'BLENDER_GAME')
208
209 class WORLD_PT_game_context_world(WorldButtonsPanel):
210         __show_header__ = False
211
212         def poll(self, context):
213                 rd = context.scene.render_data
214                 return (context.scene) and (rd.use_game_engine)
215
216         def draw(self, context):
217                 layout = self.layout
218                 
219                 scene = context.scene
220                 world = context.world
221                 space = context.space_data
222
223                 split = layout.split(percentage=0.65)
224
225                 if scene:
226                         split.template_ID(scene, "world", new="world.new")
227                 elif world:
228                         split.template_ID(space, "pin_id")
229
230 class WORLD_PT_game_world(WorldButtonsPanel):
231         __label__ = "World"
232
233         def draw(self, context):
234                 layout = self.layout
235                 
236                 world = context.world
237
238                 row = layout.row()
239                 row.column().itemR(world, "horizon_color")
240                 row.column().itemR(world, "ambient_color")
241
242                 layout.itemR(world.mist, "enabled", text="Mist")
243
244                 row = layout.column_flow()
245                 row.active = world.mist.enabled
246                 row.itemR(world.mist, "start")
247                 row.itemR(world.mist, "depth")
248
249
250 """
251 class WORLD_PT_game(WorldButtonsPanel):
252         __space_type__ = "LOGIC_EDITOR"
253         __region_type__ = "UI"
254         __label__ = "Game Settings"
255
256         def draw(self, context):
257                 layout = self.layout
258                 world = context.world
259                 
260                 flow = layout.column_flow()
261                 flow.itemR(world, "physics_engine")
262                 flow.itemR(world, "physics_gravity")
263                 
264                 flow.itemR(world, "game_fps")
265                 flow.itemR(world, "game_logic_step_max")
266                 flow.itemR(world, "game_physics_substep")
267                 flow.itemR(world, "game_physics_step_max")
268                 
269                 flow.itemR(world, "game_use_occlusion_culling", text="Enable Occlusion Culling")
270                 flow.itemR(world, "game_occlusion_culling_resolution")
271 """
272
273 class WORLD_PT_game_physics(WorldButtonsPanel):
274         __label__ = "Physics"
275  
276         def draw(self, context):
277                 layout = self.layout
278                 
279                 gs = context.scene.game_data
280                 
281                 layout.itemR(gs, "physics_engine")
282                 if gs.physics_engine != 'NONE':
283                         layout.itemR(gs, "physics_gravity", text="Gravity")
284  
285                         split = layout.split()
286                         
287                         col = split.column()
288                         col.itemL(text="Physics Steps:")
289                         sub = col.column(align=True)
290                         sub.itemR(gs, "physics_step_max", text="Max")
291                         sub.itemR(gs, "physics_step_sub", text="Substeps")
292                         col.itemR(gs, "fps", text="FPS")
293                         
294                         col = split.column()
295                         col.itemL(text="Logic Steps:")
296                         col.itemR(gs, "logic_step_max", text="Max")
297                         
298                         col = layout.column()
299                         col.itemR(gs, "use_occlusion_culling", text="Occlusion Culling")
300                         sub = col.column()
301                         sub.active = gs.use_occlusion_culling
302                         sub.itemR(gs, "occlusion_culling_resolution", text="Resolution")
303
304                 else:
305                         split = layout.split()
306                         
307                         col = split.column()
308                         col.itemL(text="Physics Steps:")
309                         col.itemR(gs, "fps", text="FPS")
310                         
311                         col = split.column()
312                         col.itemL(text="Logic Steps:")
313                         col.itemR(gs, "logic_step_max", text="Max")
314
315 bpy.types.register(WORLD_PT_game_context_world)
316 bpy.types.register(WORLD_PT_game_world)
317 bpy.types.register(WORLD_PT_game_physics)