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