LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 * ***** BEGIN GPL LICENSE BLOCK ***** | 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or | 4 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License | 5 * modify it under the terms of the GNU General Public License |
6 * as published by the Free Software Foundation; either version 2 | 6 * as published by the Free Software Foundation; either version 2 |
7 * of the License, or (at your option) any later version.· | 7 * of the License, or (at your option) any later version.· |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "DNA_object_types.h" | 33 #include "DNA_object_types.h" |
34 #include "DNA_sensor_types.h" | 34 #include "DNA_sensor_types.h" |
35 #include "DNA_controller_types.h" | 35 #include "DNA_controller_types.h" |
36 #include "DNA_actuator_types.h" | 36 #include "DNA_actuator_types.h" |
37 #include "DNA_scene_types.h" | 37 #include "DNA_scene_types.h" |
38 | 38 |
39 #include "BLI_blenlib.h" | 39 #include "BLI_blenlib.h" |
40 #include "BLI_utildefines.h" | 40 #include "BLI_utildefines.h" |
41 | 41 |
42 #include "BKE_context.h" | 42 #include "BKE_context.h" |
| 43 #include "BKE_context.h" |
43 #include "BKE_main.h" | 44 #include "BKE_main.h" |
44 #include "BKE_sca.h" | 45 #include "BKE_sca.h" |
45 #include "BKE_material.h" //for texface convert | |
46 | 46 |
47 #include "ED_logic.h" | 47 #include "ED_logic.h" |
48 #include "ED_object.h" | 48 #include "ED_object.h" |
49 #include "ED_screen.h" | |
50 | |
51 #include "RNA_access.h" | |
52 #include "RNA_define.h" | |
53 #include "RNA_enum_types.h" | |
54 | |
55 #include "WM_api.h" | |
56 #include "WM_types.h" | |
57 | |
58 #include "UI_view2d.h" | |
59 | |
60 #include "logic_intern.h" | |
61 | |
62 // temporary new includes for texface functions | |
63 #include "DNA_mesh_types.h" | |
64 #include "DNA_material_types.h" | |
65 #include "DNA_meshdata_types.h" | |
66 | |
67 /* ************* Generic Operator Helpers ************* */ | |
68 static int edit_sensor_poll(bContext *C) | |
69 { | |
70 PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); | |
71 | |
72 if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; | |
73 return 1; | |
74 } | |
75 | |
76 static int edit_controller_poll(bContext *C) | |
77 { | |
78 PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Control
ler); | |
79 | |
80 if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; | |
81 return 1; | |
82 } | |
83 | |
84 static int edit_actuator_poll(bContext *C) | |
85 { | |
86 PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator)
; | |
87 | |
88 if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; | |
89 return 1; | |
90 } | |
91 | |
92 static void edit_sensor_properties(wmOperatorType *ot) | |
93 { | |
94 RNA_def_string(ot->srna, "sensor", "", MAX_NAME, "Sensor", "Name of the
sensor to edit"); | |
95 RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the
object the sensor belongs to"); | |
96 } | |
97 | |
98 static int edit_sensor_invoke_properties(bContext *C, wmOperator *op) | |
99 { | |
100 PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); | |
101 ········ | |
102 if (RNA_struct_property_is_set(op->ptr, "sensor") && RNA_struct_property
_is_set(op->ptr, "object") ) | |
103 return 1; | |
104 ········ | |
105 if (ptr.data) { | |
106 bSensor *sens = ptr.data; | |
107 Object *ob = ptr.id.data; | |
108 ················ | |
109 RNA_string_set(op->ptr, "sensor", sens->name); | |
110 RNA_string_set(op->ptr, "object", ob->id.name + 2); | |
111 return 1; | |
112 } | |
113 ········ | |
114 return 0; | |
115 } | |
116 | |
117 static Object *edit_object_property_get(bContext *C, wmOperator *op) | |
118 { | |
119 char ob_name[MAX_NAME]; | |
120 Object *ob; | |
121 | |
122 RNA_string_get(op->ptr, "object", ob_name); | |
123 | |
124 /* if ob_name is valid try to find the object with this name | |
125 * otherwise gets the active object */ | |
126 if (*ob_name) | |
127 ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offset
of(ID, name) + 2); | |
128 else | |
129 ob = ED_object_active_context(C); | |
130 | |
131 return ob; | |
132 } | |
133 | |
134 static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **o
b) | |
135 { | |
136 char sensor_name[MAX_NAME]; | |
137 bSensor *sens; | |
138 ········ | |
139 RNA_string_get(op->ptr, "sensor", sensor_name); | |
140 | |
141 *ob = edit_object_property_get(C, op); | |
142 if (!*ob) return NULL; | |
143 ········ | |
144 sens = BLI_findstring(&((*ob)->sensors), sensor_name, offsetof(bSensor,
name)); | |
145 return sens; | |
146 } | |
147 | |
148 static void edit_controller_properties(wmOperatorType *ot) | |
149 { | |
150 RNA_def_string(ot->srna, "controller", "", MAX_NAME, "Controller", "Name
of the controller to edit"); | |
151 RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the
object the controller belongs to"); | |
152 } | |
153 | |
154 static int edit_controller_invoke_properties(bContext *C, wmOperator *op) | |
155 { | |
156 PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Control
ler); | |
157 ········ | |
158 if (RNA_struct_property_is_set(op->ptr, "controller") && RNA_struct_prop
erty_is_set(op->ptr, "object") ) | |
159 return 1; | |
160 ········ | |
161 if (ptr.data) { | |
162 bController *cont = ptr.data; | |
163 Object *ob = ptr.id.data; | |
164 ················ | |
165 RNA_string_set(op->ptr, "controller", cont->name); | |
166 RNA_string_set(op->ptr, "object", ob->id.name + 2); | |
167 return 1; | |
168 } | |
169 ········ | |
170 return 0; | |
171 } | |
172 | |
173 static bController *edit_controller_property_get(bContext *C, wmOperator *op, Ob
ject **ob) | |
174 { | |
175 char controller_name[MAX_NAME]; | |
176 bController *cont; | |
177 ········ | |
178 RNA_string_get(op->ptr, "controller", controller_name); | |
179 | |
180 *ob = edit_object_property_get(C, op); | |
181 if (!*ob) return NULL; | |
182 ········ | |
183 cont = BLI_findstring(&((*ob)->controllers), controller_name, offsetof(b
Controller, name)); | |
184 return cont; | |
185 } | |
186 | |
187 static void edit_actuator_properties(wmOperatorType *ot) | |
188 { | |
189 RNA_def_string(ot->srna, "actuator", "", MAX_NAME, "Actuator", "Name of
the actuator to edit"); | |
190 RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the
object the actuator belongs to"); | |
191 } | |
192 | |
193 static int edit_actuator_invoke_properties(bContext *C, wmOperator *op) | |
194 { | |
195 PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator)
; | |
196 ········ | |
197 if (RNA_struct_property_is_set(op->ptr, "actuator") && RNA_struct_proper
ty_is_set(op->ptr, "object") ) | |
198 return 1; | |
199 ········ | |
200 if (ptr.data) { | |
201 bActuator *act = ptr.data; | |
202 Object *ob = ptr.id.data; | |
203 ················ | |
204 RNA_string_set(op->ptr, "actuator", act->name); | |
205 RNA_string_set(op->ptr, "object", ob->id.name + 2); | |
206 return 1; | |
207 } | |
208 ········ | |
209 return 0; | |
210 } | |
211 | |
212 static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object
**ob) | |
213 { | |
214 char actuator_name[MAX_NAME]; | |
215 bActuator *act; | |
216 ········ | |
217 RNA_string_get(op->ptr, "actuator", actuator_name); | |
218 | |
219 *ob = edit_object_property_get(C, op); | |
220 if (!*ob) return NULL; | |
221 ········ | |
222 act = BLI_findstring(&((*ob)->actuators), actuator_name, offsetof(bActua
tor, name)); | |
223 return act; | |
224 } | |
225 | |
226 static int logicbricks_move_property_get(wmOperator *op) | |
227 { | |
228 int type = RNA_enum_get(op->ptr, "direction"); | |
229 | |
230 if (type == 1) | |
231 return TRUE; | |
232 else | |
233 return FALSE; | |
234 } | |
235 | |
236 /* ************* Add/Remove Sensor Operator ************* */ | |
237 | |
238 static int sensor_remove_exec(bContext *C, wmOperator *op) | |
239 { | |
240 Object *ob = NULL; | |
241 bSensor *sens = edit_sensor_property_get(C, op, &ob); | |
242 ········ | |
243 if (!sens) | |
244 return OPERATOR_CANCELLED; | |
245 ········ | |
246 BLI_remlink(&(ob->sensors), sens); | |
247 free_sensor(sens); | |
248 ········ | |
249 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
250 ········ | |
251 return OPERATOR_FINISHED; | |
252 } | |
253 | |
254 static int sensor_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
ED(event)) | |
255 { | |
256 if (edit_sensor_invoke_properties(C, op)) | |
257 return sensor_remove_exec(C, op); | |
258 else | |
259 return OPERATOR_CANCELLED; | |
260 } | |
261 | |
262 static void LOGIC_OT_sensor_remove(wmOperatorType *ot) | |
263 { | |
264 ot->name = "Remove Sensor"; | |
265 ot->description = "Remove a sensor from the active object"; | |
266 ot->idname = "LOGIC_OT_sensor_remove"; | |
267 ········ | |
268 ot->invoke = sensor_remove_invoke; | |
269 ot->exec = sensor_remove_exec; | |
270 ot->poll = edit_sensor_poll; | |
271 ········ | |
272 /* flags */ | |
273 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
274 edit_sensor_properties(ot); | |
275 } | |
276 | |
277 static int sensor_add_exec(bContext *C, wmOperator *op) | |
278 { | |
279 Object *ob; | |
280 bSensor *sens; | |
281 PointerRNA sens_ptr; | |
282 PropertyRNA *prop; | |
283 const char *sens_name; | |
284 char name[MAX_NAME]; | |
285 int type = RNA_enum_get(op->ptr, "type"); | |
286 | |
287 ob = edit_object_property_get(C, op); | |
288 if (!ob) | |
289 return OPERATOR_CANCELLED; | |
290 | |
291 sens = new_sensor(type); | |
292 BLI_addtail(&(ob->sensors), sens); | |
293 ········ | |
294 /* set the sensor name based on rna type enum */ | |
295 RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr); | |
296 prop = RNA_struct_find_property(&sens_ptr, "type"); | |
297 | |
298 RNA_string_get(op->ptr, "name", name); | |
299 if (*name) { | |
300 BLI_strncpy(sens->name, name, sizeof(sens->name)); | |
301 } | |
302 else { | |
303 RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get
(&sens_ptr, prop), &sens_name); | |
304 BLI_strncpy(sens->name, sens_name, sizeof(sens->name)); | |
305 } | |
306 | |
307 make_unique_prop_names(C, sens->name); | |
308 ob->scaflag |= OB_SHOWSENS; | |
309 | |
310 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
311 ········ | |
312 return OPERATOR_FINISHED; | |
313 } | |
314 | |
315 static void LOGIC_OT_sensor_add(wmOperatorType *ot) | |
316 { | |
317 PropertyRNA *prop; | |
318 ········ | |
319 /* identifiers */ | |
320 ot->name = "Add Sensor"; | |
321 ot->description = "Add a sensor to the active object"; | |
322 ot->idname = "LOGIC_OT_sensor_add"; | |
323 ········ | |
324 /* api callbacks */ | |
325 ot->invoke = WM_menu_invoke; | |
326 ot->exec = sensor_add_exec; | |
327 ot->poll = ED_operator_object_active_editable; | |
328 ········ | |
329 /* flags */ | |
330 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
331 ········ | |
332 /* properties */ | |
333 ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SE
NS_ALWAYS, "Type", "Type of sensor to add"); | |
334 RNA_def_enum_funcs(prop, rna_Sensor_type_itemf); | |
335 prop = RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of t
he Sensor to add"); | |
336 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
337 prop = RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name
of the Object to add the Sensor to"); | |
338 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
339 } | |
340 | |
341 /* ************* Add/Remove Controller Operator ************* */ | |
342 | |
343 static int controller_remove_exec(bContext *C, wmOperator *op) | |
344 { | |
345 Object *ob = NULL; | |
346 bController *cont = edit_controller_property_get(C, op, &ob); | |
347 ········ | |
348 if (!cont) | |
349 return OPERATOR_CANCELLED; | |
350 ········ | |
351 BLI_remlink(&(ob->controllers), cont); | |
352 unlink_controller(cont); | |
353 free_controller(cont); | |
354 ········ | |
355 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
356 ········ | |
357 return OPERATOR_FINISHED; | |
358 } | |
359 | |
360 static int controller_remove_invoke(bContext *C, wmOperator *op, const wmEvent *
UNUSED(event)) | |
361 { | |
362 if (edit_controller_invoke_properties(C, op)) | |
363 return controller_remove_exec(C, op); | |
364 else | |
365 return OPERATOR_CANCELLED; | |
366 } | |
367 | |
368 static void LOGIC_OT_controller_remove(wmOperatorType *ot) | |
369 { | |
370 ot->name = "Remove Controller"; | |
371 ot->description = "Remove a controller from the active object"; | |
372 ot->idname = "LOGIC_OT_controller_remove"; | |
373 ········ | |
374 ot->invoke = controller_remove_invoke; | |
375 ot->exec = controller_remove_exec; | |
376 ot->poll = edit_controller_poll; | |
377 ········ | |
378 /* flags */ | |
379 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
380 edit_controller_properties(ot); | |
381 } | |
382 | |
383 static int controller_add_exec(bContext *C, wmOperator *op) | |
384 { | |
385 Object *ob; | |
386 bController *cont; | |
387 PointerRNA cont_ptr; | |
388 PropertyRNA *prop; | |
389 const char *cont_name; | |
390 int bit; | |
391 char name[MAX_NAME]; | |
392 int type = RNA_enum_get(op->ptr, "type"); | |
393 | |
394 ob = edit_object_property_get(C, op); | |
395 if (!ob) | |
396 return OPERATOR_CANCELLED; | |
397 ········ | |
398 cont = new_controller(type); | |
399 BLI_addtail(&(ob->controllers), cont); | |
400 ········ | |
401 /* set the controller name based on rna type enum */ | |
402 RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr); | |
403 prop = RNA_struct_find_property(&cont_ptr, "type"); | |
404 | |
405 RNA_string_get(op->ptr, "name", name); | |
406 if (*name) { | |
407 BLI_strncpy(cont->name, name, sizeof(cont->name)); | |
408 } | |
409 else { | |
410 RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get
(&cont_ptr, prop), &cont_name); | |
411 BLI_strncpy(cont->name, cont_name, sizeof(cont->name)); | |
412 } | |
413 | |
414 make_unique_prop_names(C, cont->name); | |
415 /* set the controller state mask from the current object state. | |
416 * A controller is always in a single state, so select the lowest bit se
t | |
417 * from the object state */ | |
418 for (bit = 0; bit < OB_MAX_STATES; bit++) { | |
419 if (ob->state & (1 << bit)) | |
420 break; | |
421 } | |
422 cont->state_mask = (1 << bit); | |
423 if (cont->state_mask == 0) { | |
424 /* shouldn't happen, object state is never 0 */ | |
425 cont->state_mask = 1; | |
426 } | |
427 ········ | |
428 ob->scaflag |= OB_SHOWCONT; | |
429 ········ | |
430 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
431 ········ | |
432 return OPERATOR_FINISHED; | |
433 } | |
434 | |
435 static void LOGIC_OT_controller_add(wmOperatorType *ot) | |
436 { | |
437 PropertyRNA *prop; | |
438 | |
439 /* identifiers */ | |
440 ot->name = "Add Controller"; | |
441 ot->description = "Add a controller to the active object"; | |
442 ot->idname = "LOGIC_OT_controller_add"; | |
443 ········ | |
444 /* api callbacks */ | |
445 ot->invoke = WM_menu_invoke; | |
446 ot->exec = controller_add_exec; | |
447 ot->poll = ED_operator_object_active_editable; | |
448 ········ | |
449 /* flags */ | |
450 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
451 ········ | |
452 /* properties */ | |
453 ot->prop = RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LO
GIC_AND, "Type", "Type of controller to add"); | |
454 prop = RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of t
he Controller to add"); | |
455 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
456 prop = RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name
of the Object to add the Controller to"); | |
457 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
458 } | |
459 | |
460 /* ************* Add/Remove Actuator Operator ************* */ | |
461 | |
462 static int actuator_remove_exec(bContext *C, wmOperator *op) | |
463 { | |
464 Object *ob = NULL; | |
465 bActuator *act = edit_actuator_property_get(C, op, &ob); | |
466 ········ | |
467 if (!act) | |
468 return OPERATOR_CANCELLED; | |
469 ········ | |
470 BLI_remlink(&(ob->actuators), act); | |
471 unlink_actuator(act); | |
472 free_actuator(act); | |
473 ········ | |
474 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
475 ········ | |
476 return OPERATOR_FINISHED; | |
477 } | |
478 | |
479 static int actuator_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UN
USED(event)) | |
480 { | |
481 if (edit_actuator_invoke_properties(C, op)) | |
482 return actuator_remove_exec(C, op); | |
483 else | |
484 return OPERATOR_CANCELLED; | |
485 } | |
486 | |
487 static void LOGIC_OT_actuator_remove(wmOperatorType *ot) | |
488 { | |
489 ot->name = "Remove Actuator"; | |
490 ot->description = "Remove an actuator from the active object"; | |
491 ot->idname = "LOGIC_OT_actuator_remove"; | |
492 ········ | |
493 ot->invoke = actuator_remove_invoke; | |
494 ot->exec = actuator_remove_exec; | |
495 ot->poll = edit_actuator_poll; | |
496 ········ | |
497 /* flags */ | |
498 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
499 edit_actuator_properties(ot); | |
500 } | |
501 | |
502 static int actuator_add_exec(bContext *C, wmOperator *op) | |
503 { | |
504 Object *ob; | |
505 bActuator *act; | |
506 PointerRNA act_ptr; | |
507 PropertyRNA *prop; | |
508 const char *act_name; | |
509 char name[MAX_NAME]; | |
510 int type = RNA_enum_get(op->ptr, "type"); | |
511 ················ | |
512 ob = edit_object_property_get(C, op); | |
513 if (!ob) | |
514 return OPERATOR_CANCELLED; | |
515 | |
516 act = new_actuator(type); | |
517 BLI_addtail(&(ob->actuators), act); | |
518 ········ | |
519 /* set the actuator name based on rna type enum */ | |
520 RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr); | |
521 prop = RNA_struct_find_property(&act_ptr, "type"); | |
522 | |
523 RNA_string_get(op->ptr, "name", name); | |
524 if (*name) { | |
525 BLI_strncpy(act->name, name, sizeof(act->name)); | |
526 } | |
527 else { | |
528 RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(
&act_ptr, prop), &act_name); | |
529 BLI_strncpy(act->name, act_name, sizeof(act->name)); | |
530 } | |
531 | |
532 make_unique_prop_names(C, act->name); | |
533 ob->scaflag |= OB_SHOWACT; | |
534 ········ | |
535 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
536 ········ | |
537 return OPERATOR_FINISHED; | |
538 } | |
539 | |
540 static void LOGIC_OT_actuator_add(wmOperatorType *ot) | |
541 { | |
542 PropertyRNA *prop; | |
543 ········ | |
544 /* identifiers */ | |
545 ot->name = "Add Actuator"; | |
546 ot->description = "Add an actuator to the active object"; | |
547 ot->idname = "LOGIC_OT_actuator_add"; | |
548 ········ | |
549 /* api callbacks */ | |
550 ot->invoke = WM_menu_invoke; | |
551 ot->exec = actuator_add_exec; | |
552 ot->poll = ED_operator_object_active_editable; | |
553 ········ | |
554 /* flags */ | |
555 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
556 ········ | |
557 /* properties */ | |
558 ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CO
NT_LOGIC_AND, "Type", "Type of actuator to add"); | |
559 RNA_def_enum_funcs(prop, rna_Actuator_type_itemf); | |
560 prop = RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of t
he Actuator to add"); | |
561 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
562 prop = RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name
of the Object to add the Actuator to"); | |
563 RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |
564 } | |
565 | |
566 /* ************* Move Logic Bricks Operator ************* */ | |
567 static EnumPropertyItem logicbricks_move_direction[] = { | |
568 {1, "UP", 0, "Move Up", ""}, | |
569 {2, "DOWN", 0, "Move Down", ""}, | |
570 {0, NULL, 0, NULL, NULL} | |
571 }; | |
572 | |
573 | |
574 static int sensor_move_exec(bContext *C, wmOperator *op) | |
575 { | |
576 Object *ob = NULL; | |
577 bSensor *sens = edit_sensor_property_get(C, op, &ob); | |
578 int move_up = logicbricks_move_property_get(op); | |
579 ········ | |
580 if (!sens) | |
581 return OPERATOR_CANCELLED; | |
582 | |
583 sca_move_sensor(sens, ob, move_up); | |
584 | |
585 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
586 ········ | |
587 return OPERATOR_FINISHED; | |
588 } | |
589 | |
590 static int sensor_move_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED
(event)) | |
591 { | |
592 if (edit_sensor_invoke_properties(C, op)) { | |
593 return sensor_move_exec(C, op); | |
594 } | |
595 else | |
596 return OPERATOR_CANCELLED; | |
597 } | |
598 | |
599 static void LOGIC_OT_sensor_move(wmOperatorType *ot) | |
600 { | |
601 /* identifiers */ | |
602 ot->name = "Move Sensor"; | |
603 ot->description = "Move Sensor"; | |
604 ot->idname = "LOGIC_OT_sensor_move"; | |
605 ········ | |
606 /* api callbacks */ | |
607 ot->invoke = sensor_move_invoke; | |
608 ot->exec = sensor_move_exec; | |
609 ot->poll = edit_sensor_poll; | |
610 ········ | |
611 /* flags */ | |
612 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
613 ········ | |
614 /* properties */ | |
615 edit_sensor_properties(ot); | |
616 RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Dire
ction", "Move Up or Down"); | |
617 } | |
618 | |
619 static int controller_move_exec(bContext *C, wmOperator *op) | |
620 { | |
621 Object *ob = NULL; | |
622 bController *cont = edit_controller_property_get(C, op, &ob); | |
623 int move_up = logicbricks_move_property_get(op); | |
624 ········ | |
625 if (!cont) | |
626 return OPERATOR_CANCELLED; | |
627 | |
628 sca_move_controller(cont, ob, move_up); | |
629 | |
630 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
631 ········ | |
632 return OPERATOR_FINISHED; | |
633 } | |
634 | |
635 static int controller_move_invoke(bContext *C, wmOperator *op, const wmEvent *UN
USED(event)) | |
636 { | |
637 if (edit_controller_invoke_properties(C, op)) { | |
638 return controller_move_exec(C, op); | |
639 } | |
640 else | |
641 return OPERATOR_CANCELLED; | |
642 } | |
643 | |
644 static void LOGIC_OT_controller_move(wmOperatorType *ot) | |
645 { | |
646 /* identifiers */ | |
647 ot->name = "Move Controller"; | |
648 ot->description = "Move Controller"; | |
649 ot->idname = "LOGIC_OT_controller_move"; | |
650 ········ | |
651 /* api callbacks */ | |
652 ot->invoke = controller_move_invoke; | |
653 ot->exec = controller_move_exec; | |
654 ot->poll = edit_controller_poll; | |
655 ········ | |
656 /* flags */ | |
657 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
658 ········ | |
659 /* properties */ | |
660 edit_controller_properties(ot); | |
661 RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Dire
ction", "Move Up or Down"); | |
662 } | |
663 | |
664 static int actuator_move_exec(bContext *C, wmOperator *op) | |
665 { | |
666 Object *ob = NULL; | |
667 bActuator *act = edit_actuator_property_get(C, op, &ob); | |
668 int move_up = logicbricks_move_property_get(op); | |
669 | |
670 if (!act) | |
671 return OPERATOR_CANCELLED; | |
672 | |
673 sca_move_actuator(act, ob, move_up); | |
674 | |
675 WM_event_add_notifier(C, NC_LOGIC, NULL); | |
676 ········ | |
677 return OPERATOR_FINISHED; | |
678 } | |
679 | |
680 static int actuator_move_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
ED(event)) | |
681 { | |
682 if (edit_actuator_invoke_properties(C, op)) { | |
683 return actuator_move_exec(C, op); | |
684 } | |
685 else | |
686 return OPERATOR_CANCELLED; | |
687 } | |
688 | |
689 static void LOGIC_OT_actuator_move(wmOperatorType *ot) | |
690 { | |
691 /* identifiers */ | |
692 ot->name = "Move Actuator"; | |
693 ot->description = "Move Actuator"; | |
694 ot->idname = "LOGIC_OT_actuator_move"; | |
695 ········ | |
696 /* api callbacks */ | |
697 ot->invoke = actuator_move_invoke; | |
698 ot->exec = actuator_move_exec; | |
699 ot->poll = edit_actuator_poll; | |
700 ········ | |
701 /* flags */ | |
702 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; | |
703 ········ | |
704 /* properties */ | |
705 edit_actuator_properties(ot); | |
706 RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Dire
ction", "Move Up or Down"); | |
707 } | |
708 | |
709 /* ************* TexFace Converter Operator ************* */ | |
710 static int texface_convert_exec(bContext *C, wmOperator *UNUSED(op)) | |
711 { | |
712 Main *bmain = CTX_data_main(C); | |
713 do_version_tface(bmain, 0); | |
714 ········ | |
715 return OPERATOR_FINISHED; | |
716 } | |
717 | |
718 static int texface_convert_invoke(bContext *C, wmOperator *op, const wmEvent *UN
USED(event)) | |
719 { | |
720 return texface_convert_exec(C, op); | |
721 } | |
722 | |
723 static void LOGIC_OT_texface_convert(wmOperatorType *ot) | |
724 { | |
725 /* identifiers */ | |
726 ot->name = "TexFace to Material Converter"; | |
727 ot->description = "Convert old texface settings into material. It may cr
eate new materials if needed"; | |
728 ot->idname = "LOGIC_OT_texface_convert"; | |
729 | |
730 /* api callbacks */ | |
731 ot->invoke = texface_convert_invoke; | |
732 ot->exec = texface_convert_exec; | |
733 // ot->poll = texface_convert_poll; | |
734 · | |
735 /* flags */ | |
736 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |
737 } | |
738 | |
739 | |
740 /* ************************ view ********************* */ | |
741 | |
742 static int logic_view_all_exec(bContext *C, wmOperator *op) | |
743 { | |
744 ARegion *ar = CTX_wm_region(C); | |
745 rctf cur_new = ar->v2d.tot; | |
746 float aspect = BLI_rctf_size_y(&ar->v2d.cur) / BLI_rctf_size_x(&ar->v2d.
cur); | |
747 const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | |
748 ········ | |
749 /* force the view2d code to zoom to width, not height */ | |
750 cur_new.ymin = cur_new.ymax - BLI_rctf_size_x(&cur_new) * aspect; | |
751 ········ | |
752 UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx); | |
753 | |
754 return OPERATOR_FINISHED; | |
755 } | |
756 | |
757 static void LOGIC_OT_view_all(wmOperatorType *ot) | |
758 { | |
759 /* identifiers */ | |
760 ot->name = "View All"; | |
761 ot->idname = "LOGIC_OT_view_all"; | |
762 ot->description = "Resize view so you can see all logic bricks"; | |
763 ········ | |
764 /* api callbacks */ | |
765 ot->exec = logic_view_all_exec; | |
766 ot->poll = ED_operator_logic_active; | |
767 ········ | |
768 /* flags */ | |
769 ot->flag = 0; | |
770 } | |
771 | |
772 /* ************************* */ | |
773 | |
774 void ED_operatortypes_logic(void) | |
775 { | |
776 WM_operatortype_append(LOGIC_OT_sensor_remove); | |
777 WM_operatortype_append(LOGIC_OT_sensor_add); | |
778 WM_operatortype_append(LOGIC_OT_sensor_move); | |
779 WM_operatortype_append(LOGIC_OT_controller_remove); | |
780 WM_operatortype_append(LOGIC_OT_controller_add); | |
781 WM_operatortype_append(LOGIC_OT_controller_move); | |
782 WM_operatortype_append(LOGIC_OT_actuator_remove); | |
783 WM_operatortype_append(LOGIC_OT_actuator_add); | |
784 WM_operatortype_append(LOGIC_OT_actuator_move); | |
785 WM_operatortype_append(LOGIC_OT_texface_convert); | |
786 WM_operatortype_append(LOGIC_OT_view_all); | |
787 } | |
LEFT | RIGHT |