diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2010-05-04 04:06:13 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2010-05-04 04:06:13 +0400 |
commit | 44c0f38e6ceb6d7b2a07aa23b2c0811a609d17d5 (patch) | |
tree | 586192ad47d9191ef26aabbf9d7af2c4232af193 /source/blender/editors/space_logic/logic_ops.c | |
parent | e09c47a0daeee84f6c17498620c3b8e9dca8ba9b (diff) |
BGE Logics UI: commit to receive some feedback from Matt
To test use debug mode > 0 (Ctrl+Alt+D)
* primarly the goal is to put all the bricks there, and then to worry about the proper layout
* sensor header added (need to be more compressed). Also checkbox will not work that well here in my opinion.
we need to see what can be used instead (icons?)
* sensors, and actuators in alphabetical order
* a lot of sensors using the rna (//XXXSENSOR in the ones not using it)
* the logic_window.c code for controller and actuator is there only to display the draw functions for controller and actuators. But the code it's a really bad copy of the sensor code, so it will be fixed later (Matt? :)
* I would love if the non-expanded mode were more compact, more like in 2.49 (the name non-editable).
but this is the kind of think we can worry in the end.
Also instead of "move up/move down" it would be nice to drag/drop the sensors/controllers/actuators
* to do: rna_actuators: to rename type to mode for the enum
Diffstat (limited to 'source/blender/editors/space_logic/logic_ops.c')
-rw-r--r-- | source/blender/editors/space_logic/logic_ops.c | 279 |
1 files changed, 278 insertions, 1 deletions
diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c index 0ed1367e7ea..92db4748ce3 100644 --- a/source/blender/editors/space_logic/logic_ops.c +++ b/source/blender/editors/space_logic/logic_ops.c @@ -30,6 +30,8 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_sensor_types.h" +#include "DNA_controller_types.h" +#include "DNA_actuator_types.h" #include "BLI_blenlib.h" @@ -59,6 +61,22 @@ static int edit_sensor_poll(bContext *C) return 1; } +static int edit_controller_poll(bContext *C) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller); + + if (ptr.data && ((ID*)ptr.id.data)->lib) return 0; + return 1; +} + +static int edit_actuator_poll(bContext *C) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); + + if (ptr.data && ((ID*)ptr.id.data)->lib) return 0; + return 1; +} + /* this is the nice py-api-compatible way to do it, like modifiers, but not entirely working yet.. @@ -104,8 +122,95 @@ static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object *ob return sens; } */ +/* +static void edit_controller_properties(wmOperatorType *ot) +{ + RNA_def_string(ot->srna, "controller", "", 32, "Controller", "Name of the controller to edit"); + RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the object the controller belongs to"); +} + +static int edit_controller_invoke_properties(bContext *C, wmOperator *op) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller); + + if (RNA_property_is_set(op->ptr, "controller") && RNA_property_is_set(op->ptr, "object") ) + return 1; + + if (ptr.data) { + bController *cont = ptr.data; + Object *ob = ptr.id.data; + + RNA_string_set(op->ptr, "controller", cont->name); + RNA_string_set(op->ptr, "object", ob->id.name+2); + return 1; + } + + return 0; +} + +static bController *edit_controller_property_get(bContext *C, wmOperator *op, Object *ob) +{ + char controller_name[32]; + char ob_name[32]; + bController *cont; + + RNA_string_get(op->ptr, "controller", controller_name); + RNA_string_get(op->ptr, "object", ob_name); + + ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2); + if (!ob) + return NULL; + + cont = BLI_findstring(&(ob->controllers), controller_name, offsetof(bController, name)); + return cont; +} + */ + +/* +static void edit_actuator_properties(wmOperatorType *ot) +{ + RNA_def_string(ot->srna, "actuator", "", 32, "Actuator", "Name of the actuator to edit"); + RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the object the actuator belongs to"); +} + +static int edit_actuator_invoke_properties(bContext *C, wmOperator *op) +{ + PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); + + if (RNA_property_is_set(op->ptr, "actuator") && RNA_property_is_set(op->ptr, "object") ) + return 1; + + if (ptr.data) { + bActuator *act = ptr.data; + Object *ob = ptr.id.data; + + RNA_string_set(op->ptr, "actuator",act->name); + RNA_string_set(op->ptr, "object", ob->id.name+2); + return 1; + } + + return 0; +} + +static bController *edit_actuator_property_get(bContext *C, wmOperator *op, Object *ob) +{ + char actuator_name[32]; + char ob_name[32]; + bActuator *act; + + RNA_string_get(op->ptr, "actuator", actuator_name); + RNA_string_get(op->ptr, "object", ob_name); + + ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2); + if (!ob) + return NULL; + + cont = BLI_findstring(&(ob->actuators), actuator_name, offsetof(bActuator, name)); + return act; +} + -/* ************* Remove Sensor Operator ************* */ +/* ************* Add/Remove Sensor Operator ************* */ static int sensor_remove_exec(bContext *C, wmOperator *op) { @@ -189,8 +294,180 @@ void LOGIC_OT_sensor_add(wmOperatorType *ot) prop= RNA_def_enum(ot->srna, "type", sensor_type_items, SENS_ALWAYS, "Type", "Type of sensor to add"); } +/* ************* Add/Remove Controller Operator ************* */ + +static int controller_remove_exec(bContext *C, wmOperator *op) +{ + /* Object *ob; + bController *cont = edit_controller_property_get(C, op, ob); */ + PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Controller); + Object *ob= ptr.id.data; + bController *cont= ptr.data; + + if (!cont) + return OPERATOR_CANCELLED; + + BLI_remlink(&(ob->controllers), cont); + free_controller(cont); + + WM_event_add_notifier(C, NC_LOGIC, NULL); + + return OPERATOR_FINISHED; +} + + +/* commented along with above stuff + static int controller_remove_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + if (edit_controller_invoke_properties(C, op)) + return controller_remove_exec(C, op); + else + return OPERATOR_CANCELLED; +} + */ + +void LOGIC_OT_controller_remove(wmOperatorType *ot) +{ + ot->name= "Remove Controller"; + ot->description= "Remove a controller from the active object"; + ot->idname= "LOGIC_OT_controller_remove"; + + //ot->invoke= controller_remove_invoke; + ot->exec= controller_remove_exec; + ot->poll= edit_controller_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + //edit_controller_properties(ot); +} + +static int controller_add_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_active_context(C); + bController *cont; + int type= RNA_enum_get(op->ptr, "type"); + + cont= new_controller(type); + BLI_addtail(&(ob->controllers), cont); + make_unique_prop_names(C, cont->name); + ob->scaflag |= OB_SHOWCONT; + + WM_event_add_notifier(C, NC_LOGIC, NULL); + + return OPERATOR_FINISHED; +} + +void LOGIC_OT_controller_add(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name= "Add Controller"; + ot->description = "Add a controller to the active object"; + ot->idname= "LOGIC_OT_controller_add"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= controller_add_exec; + ot->poll= ED_operator_object_active_editable; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + prop= RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add"); +} + +/* ************* Add/Remove Actuator Operator ************* */ + +static int actuator_remove_exec(bContext *C, wmOperator *op) +{ + /* Object *ob; + bActuator *cont = edit_actuator_property_get(C, op, ob); */ + PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); + Object *ob= ptr.id.data; + bActuator *act= ptr.data; + + if (!act) + return OPERATOR_CANCELLED; + + BLI_remlink(&(ob->actuators), act); + free_actuator(act); + + WM_event_add_notifier(C, NC_LOGIC, NULL); + + return OPERATOR_FINISHED; +} + + +/* commented along with above stuff + static int actuator_remove_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + if (edit_actuator_invoke_properties(C, op)) + return actuator_remove_exec(C, op); + else + return OPERATOR_CANCELLED; +} + */ + +void LOGIC_OT_actuator_remove(wmOperatorType *ot) +{ + ot->name= "Remove Actuator"; + ot->description= "Remove a actuator from the active object"; + ot->idname= "LOGIC_OT_actuator_remove"; + + //ot->invoke= actuator_remove_invoke; + ot->exec= actuator_remove_exec; + ot->poll= edit_actuator_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + //edit_controller_properties(ot); +} + +static int actuator_add_exec(bContext *C, wmOperator *op) +{ + Object *ob = ED_object_active_context(C); + bActuator *act; + int type= RNA_enum_get(op->ptr, "type"); + + act= new_actuator(type); + BLI_addtail(&(ob->actuators), act); + make_unique_prop_names(C, act->name); + ob->scaflag |= OB_SHOWCONT; + + WM_event_add_notifier(C, NC_LOGIC, NULL); + + return OPERATOR_FINISHED; +} + +void LOGIC_OT_actuator_add(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name= "Add Actuator"; + ot->description = "Add a actuator to the active object"; + ot->idname= "LOGIC_OT_actuator_add"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= actuator_add_exec; + ot->poll= ED_operator_object_active_editable; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + prop= RNA_def_enum(ot->srna, "type", actuator_type_items, CONT_LOGIC_AND, "Type", "Type of actuator to add"); +} + void ED_operatortypes_logic(void) { WM_operatortype_append(LOGIC_OT_sensor_remove); WM_operatortype_append(LOGIC_OT_sensor_add); + WM_operatortype_append(LOGIC_OT_controller_remove); + WM_operatortype_append(LOGIC_OT_controller_add); + WM_operatortype_append(LOGIC_OT_actuator_remove); + WM_operatortype_append(LOGIC_OT_actuator_add); } |