Blender V2.61 - r43446

logic_ops.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2009 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00031 #include <stddef.h>
00032 
00033 #include "DNA_object_types.h"
00034 #include "DNA_sensor_types.h"
00035 #include "DNA_controller_types.h"
00036 #include "DNA_actuator_types.h"
00037 
00038 #include "BLI_blenlib.h"
00039 #include "BLI_utildefines.h"
00040 
00041 #include "BKE_context.h"
00042 #include "BKE_main.h"
00043 #include "BKE_sca.h"
00044 #include "BKE_material.h" //for texface convert
00045 
00046 #include "ED_logic.h"
00047 #include "ED_object.h"
00048 #include "ED_screen.h"
00049 
00050 #include "RNA_access.h"
00051 #include "RNA_define.h"
00052 #include "RNA_enum_types.h"
00053 
00054 #include "WM_api.h"
00055 #include "WM_types.h"
00056 
00057 #include "logic_intern.h"
00058 
00059 // temporary new includes for texface functions
00060 #include "DNA_mesh_types.h"
00061 #include "DNA_material_types.h"
00062 #include "DNA_meshdata_types.h"
00063 
00064 /* ************* Generic Operator Helpers ************* */
00065 static int edit_sensor_poll(bContext *C)
00066 {
00067     PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
00068 
00069     if (ptr.data && ((ID*)ptr.id.data)->lib) return 0;
00070     return 1;
00071 }
00072 
00073 static int edit_controller_poll(bContext *C)
00074 {
00075     PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller);
00076 
00077     if (ptr.data && ((ID*)ptr.id.data)->lib) return 0;
00078     return 1;
00079 }
00080 
00081 static int edit_actuator_poll(bContext *C)
00082 {
00083     PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator);
00084 
00085     if (ptr.data && ((ID*)ptr.id.data)->lib) return 0;
00086     return 1;
00087 }
00088 
00089 static void edit_sensor_properties(wmOperatorType *ot)
00090 {
00091     RNA_def_string(ot->srna, "sensor", "", MAX_NAME, "Sensor", "Name of the sensor to edit");
00092     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the object the sensor belongs to");
00093 }
00094 
00095 static int edit_sensor_invoke_properties(bContext *C, wmOperator *op)
00096 {
00097     PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
00098     
00099     if (RNA_struct_property_is_set(op->ptr, "sensor") && RNA_struct_property_is_set(op->ptr, "object") )
00100         return 1;
00101     
00102     if (ptr.data) {
00103         bSensor *sens = ptr.data;
00104         Object *ob = ptr.id.data;
00105         
00106         RNA_string_set(op->ptr, "sensor", sens->name);
00107         RNA_string_set(op->ptr, "object", ob->id.name+2);
00108         return 1;
00109     }
00110     
00111     return 0;
00112 }
00113 
00114 static Object *edit_object_property_get(bContext *C, wmOperator *op)
00115 {
00116     char ob_name[MAX_NAME];
00117     Object *ob;
00118 
00119     RNA_string_get(op->ptr, "object", ob_name);
00120 
00121     /* if ob_name is valid try to find the object with this name
00122     otherwise gets the active object */
00123     if (BLI_strnlen(ob_name, MAX_NAME) > 0)
00124         ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
00125     else
00126         ob= ED_object_active_context(C);
00127 
00128     return ob;
00129 }
00130 
00131 static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **ob)
00132 {
00133     char sensor_name[MAX_NAME];
00134     bSensor *sens;
00135     
00136     RNA_string_get(op->ptr, "sensor", sensor_name);
00137 
00138     *ob= edit_object_property_get(C, op);
00139     if (!*ob) return NULL;
00140     
00141     sens = BLI_findstring(&((*ob)->sensors), sensor_name, offsetof(bSensor, name)); 
00142     return sens;
00143 }
00144 
00145 static void edit_controller_properties(wmOperatorType *ot)
00146 {
00147     RNA_def_string(ot->srna, "controller", "", MAX_NAME, "Controller", "Name of the controller to edit");
00148     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the object the controller belongs to");
00149 }
00150 
00151 static int edit_controller_invoke_properties(bContext *C, wmOperator *op)
00152 {
00153     PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller);
00154     
00155     if (RNA_struct_property_is_set(op->ptr, "controller") && RNA_struct_property_is_set(op->ptr, "object") )
00156         return 1;
00157     
00158     if (ptr.data) {
00159         bController *cont = ptr.data;
00160         Object *ob = ptr.id.data;
00161         
00162         RNA_string_set(op->ptr, "controller", cont->name);
00163         RNA_string_set(op->ptr, "object", ob->id.name+2);
00164         return 1;
00165     }
00166     
00167     return 0;
00168 }
00169 
00170 static bController *edit_controller_property_get(bContext *C, wmOperator *op, Object **ob)
00171 {
00172     char controller_name[MAX_NAME];
00173     bController *cont;
00174     
00175     RNA_string_get(op->ptr, "controller", controller_name);
00176 
00177     *ob= edit_object_property_get(C, op);
00178     if (!*ob) return NULL;
00179     
00180     cont = BLI_findstring(&((*ob)->controllers), controller_name, offsetof(bController, name)); 
00181     return cont;
00182 }
00183 
00184 static void edit_actuator_properties(wmOperatorType *ot)
00185 {
00186     RNA_def_string(ot->srna, "actuator", "", MAX_NAME, "Actuator", "Name of the actuator to edit");
00187     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the object the actuator belongs to");
00188 }
00189 
00190 static int edit_actuator_invoke_properties(bContext *C, wmOperator *op)
00191 {
00192     PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator);
00193     
00194     if (RNA_struct_property_is_set(op->ptr, "actuator") && RNA_struct_property_is_set(op->ptr, "object") )
00195         return 1;
00196     
00197     if (ptr.data) {
00198         bActuator *act = ptr.data;
00199         Object *ob = ptr.id.data;
00200         
00201         RNA_string_set(op->ptr, "actuator",act->name);
00202         RNA_string_set(op->ptr, "object", ob->id.name+2);
00203         return 1;
00204     }
00205     
00206     return 0;
00207 }
00208 
00209 static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object **ob)
00210 {
00211     char actuator_name[MAX_NAME];
00212     bActuator *act;
00213     
00214     RNA_string_get(op->ptr, "actuator", actuator_name);
00215 
00216     *ob= edit_object_property_get(C, op);
00217     if (!*ob) return NULL;
00218     
00219     act = BLI_findstring(&((*ob)->actuators), actuator_name, offsetof(bActuator, name));    
00220     return act;
00221 }
00222 
00223 static int logicbricks_move_property_get(wmOperator *op)
00224 {
00225     int type = RNA_enum_get(op->ptr, "direction");
00226 
00227     if (type == 1)
00228         return TRUE;
00229     else
00230         return FALSE;
00231 }
00232 
00233 /* ************* Add/Remove Sensor Operator ************* */
00234 
00235 static int sensor_remove_exec(bContext *C, wmOperator *op)
00236 {
00237     Object *ob=NULL;
00238     bSensor *sens = edit_sensor_property_get(C, op, &ob);
00239     
00240     if (!sens)
00241         return OPERATOR_CANCELLED;
00242     
00243     BLI_remlink(&(ob->sensors), sens);
00244     free_sensor(sens);
00245     
00246     WM_event_add_notifier(C, NC_LOGIC, NULL);
00247     
00248     return OPERATOR_FINISHED;
00249 }
00250 
00251  static int sensor_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00252 {
00253     if (edit_sensor_invoke_properties(C, op))
00254         return sensor_remove_exec(C, op);
00255     else
00256         return OPERATOR_CANCELLED;
00257 }
00258 
00259 static void LOGIC_OT_sensor_remove(wmOperatorType *ot)
00260 {
00261     ot->name= "Remove Sensor";
00262     ot->description= "Remove a sensor from the active object";
00263     ot->idname= "LOGIC_OT_sensor_remove";
00264     
00265     ot->invoke= sensor_remove_invoke;
00266     ot->exec= sensor_remove_exec;
00267     ot->poll= edit_sensor_poll;
00268     
00269     /* flags */
00270     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00271     edit_sensor_properties(ot);
00272 }
00273 
00274 static int sensor_add_exec(bContext *C, wmOperator *op)
00275 {
00276     Object *ob;
00277     bSensor *sens;
00278     PointerRNA sens_ptr;
00279     PropertyRNA *prop;
00280     const char *sens_name;
00281     char name[MAX_NAME];
00282     int type= RNA_enum_get(op->ptr, "type");
00283 
00284     ob= edit_object_property_get(C, op);
00285     if (!ob)
00286         return OPERATOR_CANCELLED;
00287 
00288     sens= new_sensor(type);
00289     BLI_addtail(&(ob->sensors), sens);
00290     
00291     /* set the sensor name based on rna type enum */
00292     RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr);
00293     prop = RNA_struct_find_property(&sens_ptr, "type");
00294 
00295     RNA_string_get(op->ptr, "name", name);
00296     if(BLI_strnlen(name, MAX_NAME) < 1){
00297         RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name);
00298         BLI_strncpy(sens->name, sens_name, sizeof(sens->name));
00299     }
00300     else
00301         BLI_strncpy(sens->name, name, sizeof(sens->name));
00302 
00303     make_unique_prop_names(C, sens->name);
00304     ob->scaflag |= OB_SHOWSENS;
00305 
00306     WM_event_add_notifier(C, NC_LOGIC, NULL);
00307     
00308     return OPERATOR_FINISHED;
00309 }
00310 
00311 static void LOGIC_OT_sensor_add(wmOperatorType *ot)
00312 {
00313     PropertyRNA *prop;
00314     
00315     /* identifiers */
00316     ot->name= "Add Sensor";
00317     ot->description = "Add a sensor to the active object";
00318     ot->idname= "LOGIC_OT_sensor_add";
00319     
00320     /* api callbacks */
00321     ot->invoke= WM_menu_invoke;
00322     ot->exec= sensor_add_exec;
00323     ot->poll= ED_operator_object_active_editable;
00324     
00325     /* flags */
00326     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00327     
00328     /* properties */
00329     ot->prop= prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add");
00330     RNA_def_enum_funcs(prop, rna_Sensor_type_itemf);
00331     RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the Sensor to add");
00332     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the Object to add the Sensor to");
00333 }
00334 
00335 /* ************* Add/Remove Controller Operator ************* */
00336 
00337 static int controller_remove_exec(bContext *C, wmOperator *op)
00338 {
00339     Object *ob = NULL;
00340     bController *cont = edit_controller_property_get(C, op, &ob);
00341     
00342     if (!cont)
00343         return OPERATOR_CANCELLED;
00344     
00345     BLI_remlink(&(ob->controllers), cont);
00346     unlink_controller(cont);
00347     free_controller(cont);
00348     
00349     WM_event_add_notifier(C, NC_LOGIC, NULL);
00350     
00351     return OPERATOR_FINISHED;
00352 }
00353 
00354  static int controller_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00355 {
00356     if (edit_controller_invoke_properties(C, op))
00357         return controller_remove_exec(C, op);
00358     else
00359         return OPERATOR_CANCELLED;
00360 }
00361 
00362 static void LOGIC_OT_controller_remove(wmOperatorType *ot)
00363 {
00364     ot->name= "Remove Controller";
00365     ot->description= "Remove a controller from the active object";
00366     ot->idname= "LOGIC_OT_controller_remove";
00367     
00368     ot->invoke= controller_remove_invoke;
00369     ot->exec= controller_remove_exec;
00370     ot->poll= edit_controller_poll;
00371     
00372     /* flags */
00373     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00374     edit_controller_properties(ot);
00375 }
00376 
00377 static int controller_add_exec(bContext *C, wmOperator *op)
00378 {
00379     Object *ob;
00380     bController *cont;
00381     PointerRNA cont_ptr;
00382     PropertyRNA *prop;
00383     const char *cont_name;
00384     int bit;
00385     char name[MAX_NAME];
00386     int type= RNA_enum_get(op->ptr, "type");
00387 
00388     ob= edit_object_property_get(C, op);
00389     if(!ob)
00390         return OPERATOR_CANCELLED;
00391     
00392     cont= new_controller(type);
00393     BLI_addtail(&(ob->controllers), cont);
00394     
00395     /* set the controller name based on rna type enum */
00396     RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr);
00397     prop = RNA_struct_find_property(&cont_ptr, "type");
00398 
00399     RNA_string_get(op->ptr, "name", name);
00400     if(BLI_strnlen(name, MAX_NAME) < 1){
00401         RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name);
00402         BLI_strncpy(cont->name, cont_name, sizeof(cont->name));
00403     }
00404     else
00405         BLI_strncpy(cont->name, name, sizeof(cont->name));
00406 
00407     make_unique_prop_names(C, cont->name);
00408     /* set the controller state mask from the current object state.
00409      A controller is always in a single state, so select the lowest bit set
00410      from the object state */
00411     for (bit=0; bit<OB_MAX_STATES; bit++) {
00412         if (ob->state & (1<<bit))
00413             break;
00414     }
00415     cont->state_mask = (1<<bit);
00416     if (cont->state_mask == 0) {
00417         /* shouldn't happen, object state is never 0 */
00418         cont->state_mask = 1;
00419     }
00420     
00421     ob->scaflag |= OB_SHOWCONT;
00422     
00423     WM_event_add_notifier(C, NC_LOGIC, NULL);
00424     
00425     return OPERATOR_FINISHED;
00426 }
00427 
00428 static void LOGIC_OT_controller_add(wmOperatorType *ot)
00429 {
00430     /* identifiers */
00431     ot->name= "Add Controller";
00432     ot->description = "Add a controller to the active object";
00433     ot->idname= "LOGIC_OT_controller_add";
00434     
00435     /* api callbacks */
00436     ot->invoke= WM_menu_invoke;
00437     ot->exec= controller_add_exec;
00438     ot->poll= ED_operator_object_active_editable;
00439     
00440     /* flags */
00441     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00442     
00443     /* properties */
00444     ot->prop= RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add");
00445     RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the Controller to add");
00446     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the Object to add the Controller to");
00447 }
00448 
00449 /* ************* Add/Remove Actuator Operator ************* */
00450 
00451 static int actuator_remove_exec(bContext *C, wmOperator *op)
00452 {
00453     Object *ob=NULL;
00454     bActuator *act = edit_actuator_property_get(C, op, &ob);
00455     
00456     if (!act)
00457         return OPERATOR_CANCELLED;
00458     
00459     BLI_remlink(&(ob->actuators), act);
00460     unlink_actuator(act);
00461     free_actuator(act);
00462     
00463     WM_event_add_notifier(C, NC_LOGIC, NULL);
00464     
00465     return OPERATOR_FINISHED;
00466 }
00467 
00468 static int actuator_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00469 {
00470     if (edit_actuator_invoke_properties(C, op))
00471         return actuator_remove_exec(C, op);
00472     else
00473         return OPERATOR_CANCELLED;
00474 }
00475 
00476 static void LOGIC_OT_actuator_remove(wmOperatorType *ot)
00477 {
00478     ot->name= "Remove Actuator";
00479     ot->description= "Remove an actuator from the active object";
00480     ot->idname= "LOGIC_OT_actuator_remove";
00481     
00482     ot->invoke= actuator_remove_invoke;
00483     ot->exec= actuator_remove_exec;
00484     ot->poll= edit_actuator_poll;
00485     
00486     /* flags */
00487     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00488     edit_actuator_properties(ot);
00489 }
00490 
00491 static int actuator_add_exec(bContext *C, wmOperator *op)
00492 {
00493     Object *ob;
00494     bActuator *act;
00495     PointerRNA act_ptr;
00496     PropertyRNA *prop;
00497     const char *act_name;
00498     char  name[MAX_NAME];
00499     int type= RNA_enum_get(op->ptr, "type");
00500         
00501     ob= edit_object_property_get(C, op);
00502     if(!ob)
00503         return OPERATOR_CANCELLED;
00504 
00505     act= new_actuator(type);
00506     BLI_addtail(&(ob->actuators), act);
00507     
00508     /* set the actuator name based on rna type enum */
00509     RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr);
00510     prop = RNA_struct_find_property(&act_ptr, "type");
00511 
00512     RNA_string_get(op->ptr, "name", name);
00513     if (BLI_strnlen(name, MAX_NAME) < 1){
00514         RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name);
00515         BLI_strncpy(act->name, act_name, sizeof(act->name));
00516     }
00517     else
00518         BLI_strncpy(act->name, name, sizeof(act->name));
00519 
00520     make_unique_prop_names(C, act->name);
00521     ob->scaflag |= OB_SHOWACT;
00522     
00523     WM_event_add_notifier(C, NC_LOGIC, NULL);
00524     
00525     return OPERATOR_FINISHED;
00526 }
00527 
00528 static void LOGIC_OT_actuator_add(wmOperatorType *ot)
00529 {
00530     PropertyRNA *prop;
00531     
00532     /* identifiers */
00533     ot->name= "Add Actuator";
00534     ot->description = "Add an actuator to the active object";
00535     ot->idname= "LOGIC_OT_actuator_add";
00536     
00537     /* api callbacks */
00538     ot->invoke= WM_menu_invoke;
00539     ot->exec= actuator_add_exec;
00540     ot->poll= ED_operator_object_active_editable;
00541     
00542     /* flags */
00543     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00544     
00545     /* properties */
00546     ot->prop= prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add");
00547     RNA_def_enum_funcs(prop, rna_Actuator_type_itemf);
00548     RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the Actuator to add");
00549     RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the Object to add the Actuator to");
00550 }
00551 
00552 /* ************* Move Logic Bricks Operator ************* */
00553 static EnumPropertyItem logicbricks_move_direction[] ={
00554         {1, "UP", 0, "Move Up", ""},
00555         {2, "DOWN", 0, "Move Down", ""},
00556         {0, NULL, 0, NULL, NULL}};
00557 
00558 
00559 static int sensor_move_exec(bContext *C, wmOperator *op)
00560 {
00561     Object *ob=NULL;
00562     bSensor *sens= edit_sensor_property_get(C, op, &ob);
00563     int move_up= logicbricks_move_property_get(op);
00564     
00565     if (!sens)
00566         return OPERATOR_CANCELLED;
00567 
00568     sca_move_sensor(sens, ob, move_up);
00569 
00570     WM_event_add_notifier(C, NC_LOGIC, NULL);
00571     
00572     return OPERATOR_FINISHED;
00573 }
00574 
00575 static int sensor_move_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00576 {
00577     if (edit_sensor_invoke_properties(C, op)) {
00578         return sensor_move_exec(C, op);
00579     }
00580     else
00581         return OPERATOR_CANCELLED;
00582 }
00583 
00584 static void LOGIC_OT_sensor_move(wmOperatorType *ot)
00585 {
00586     /* identifiers */
00587     ot->name= "Move Sensor";
00588     ot->description = "Move Sensor";
00589     ot->idname= "LOGIC_OT_sensor_move";
00590     
00591     /* api callbacks */
00592     ot->invoke= sensor_move_invoke;
00593     ot->exec= sensor_move_exec;
00594     ot->poll= edit_sensor_poll;
00595     
00596     /* flags */
00597     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00598     
00599     /* properties */
00600     edit_sensor_properties(ot);
00601     RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
00602 }
00603 
00604 static int controller_move_exec(bContext *C, wmOperator *op)
00605 {
00606     Object *ob=NULL;
00607     bController *cont= edit_controller_property_get(C, op, &ob);
00608     int move_up= logicbricks_move_property_get(op);
00609     
00610     if (!cont)
00611         return OPERATOR_CANCELLED;
00612 
00613     sca_move_controller(cont, ob, move_up);
00614 
00615     WM_event_add_notifier(C, NC_LOGIC, NULL);
00616     
00617     return OPERATOR_FINISHED;
00618 }
00619 
00620 static int controller_move_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00621 {
00622     if (edit_controller_invoke_properties(C, op)) {
00623         return controller_move_exec(C, op);
00624     }
00625     else
00626         return OPERATOR_CANCELLED;
00627 }
00628 
00629 static void LOGIC_OT_controller_move(wmOperatorType *ot)
00630 {
00631     /* identifiers */
00632     ot->name= "Move Controller";
00633     ot->description = "Move Controller";
00634     ot->idname= "LOGIC_OT_controller_move";
00635     
00636     /* api callbacks */
00637     ot->invoke= controller_move_invoke;
00638     ot->exec= controller_move_exec;
00639     ot->poll= edit_controller_poll;
00640     
00641     /* flags */
00642     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00643     
00644     /* properties */
00645     edit_controller_properties(ot);
00646     RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
00647 }
00648 
00649 static int actuator_move_exec(bContext *C, wmOperator *op)
00650 {
00651     Object *ob=NULL;
00652     bActuator *act = edit_actuator_property_get(C, op, &ob);
00653     int move_up= logicbricks_move_property_get(op);
00654 
00655     if (!act)
00656         return OPERATOR_CANCELLED;
00657 
00658     sca_move_actuator(act, ob, move_up);
00659 
00660     WM_event_add_notifier(C, NC_LOGIC, NULL);
00661     
00662     return OPERATOR_FINISHED;
00663 }
00664 
00665 static int actuator_move_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00666 {
00667     if (edit_actuator_invoke_properties(C, op)) {
00668         return actuator_move_exec(C, op);
00669     }
00670     else
00671         return OPERATOR_CANCELLED;
00672 }
00673 
00674 static void LOGIC_OT_actuator_move(wmOperatorType *ot)
00675 {
00676     /* identifiers */
00677     ot->name= "Move Actuator";
00678     ot->description = "Move Actuator";
00679     ot->idname= "LOGIC_OT_actuator_move";
00680     
00681     /* api callbacks */
00682     ot->invoke= actuator_move_invoke;
00683     ot->exec= actuator_move_exec;
00684     ot->poll= edit_actuator_poll;
00685     
00686     /* flags */
00687     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00688     
00689     /* properties */
00690     edit_actuator_properties(ot);
00691     RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
00692 }
00693 
00694 /* ************* TexFace Converter Operator ************* */
00695 static int texface_convert_exec(bContext *C, wmOperator *UNUSED(op))
00696 {
00697     Main *bmain= CTX_data_main(C);
00698     do_version_tface(bmain, 0);
00699     
00700     return OPERATOR_FINISHED;
00701 }
00702 
00703 static int texface_convert_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
00704 {
00705     return texface_convert_exec(C, op);
00706 }
00707 
00708  static void LOGIC_OT_texface_convert(wmOperatorType *ot)
00709 {
00710     /* identifiers */
00711     ot->name= "TexFace to Material Converter";
00712     ot->description = "Convert old texface settings into material. It may create new materials if needed";
00713     ot->idname= "LOGIC_OT_texface_convert";
00714 
00715     /* api callbacks */
00716     ot->invoke= texface_convert_invoke;
00717     ot->exec= texface_convert_exec;
00718 //  ot->poll= texface_convert_poll;
00719  
00720     /* flags */
00721     ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
00722 }
00723 
00724 
00725 void ED_operatortypes_logic(void)
00726 {
00727     WM_operatortype_append(LOGIC_OT_sensor_remove);
00728     WM_operatortype_append(LOGIC_OT_sensor_add);
00729     WM_operatortype_append(LOGIC_OT_sensor_move);
00730     WM_operatortype_append(LOGIC_OT_controller_remove);
00731     WM_operatortype_append(LOGIC_OT_controller_add);
00732     WM_operatortype_append(LOGIC_OT_controller_move);
00733     WM_operatortype_append(LOGIC_OT_actuator_remove);
00734     WM_operatortype_append(LOGIC_OT_actuator_add);
00735     WM_operatortype_append(LOGIC_OT_actuator_move);
00736     WM_operatortype_append(LOGIC_OT_texface_convert);
00737 }