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