[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30136] trunk/blender/source/blender: Logic Editor UI: move s/c/a operators and interface buttons
Dalai Felinto
dfelinto at gmail.com
Fri Jul 9 02:14:46 CEST 2010
Revision: 30136
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30136
Author: dfelinto
Date: 2010-07-09 02:14:46 +0200 (Fri, 09 Jul 2010)
Log Message:
-----------
Logic Editor UI: move s/c/a operators and interface buttons
Tchatcharantcharan ...
Three new operators:
bpy.ops.logic.sensor_move
bpy.ops.logic.controller_move
bpy.ops.logic.actuator_move
direction is a parameter (UP,DOWN)
Moved some interface code to sca.c instead of logic_window.c. (and changed accordingly).
One note: as in 2.49, the move up/down button is only available in non-expanded mode. However instead of one button with two options we have 2 buttons (as we had originally in 2.50).
That also means the s/c/a header is getting more clunky. Design, thoughts, ideas are appreciated. For the time been functionality back is still the priority (mine at least ;)
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_sca.h
trunk/blender/source/blender/blenkernel/intern/sca.c
trunk/blender/source/blender/editors/space_logic/logic_ops.c
trunk/blender/source/blender/editors/space_logic/logic_window.c
Modified: trunk/blender/source/blender/blenkernel/BKE_sca.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_sca.h 2010-07-08 22:07:34 UTC (rev 30135)
+++ trunk/blender/source/blender/blenkernel/BKE_sca.h 2010-07-09 00:14:46 UTC (rev 30136)
@@ -67,5 +67,9 @@
void set_sca_new_poins(void);
void sca_remove_ob_poin(struct Object *obt, struct Object *ob);
+void sca_move_sensor(struct bSensor *sens_to_move, Object *ob, int move_up);
+void sca_move_controller(struct bController *cont_to_move, Object *ob, int move_up);
+void sca_move_actuator(struct bActuator *act_to_move, Object *ob, int move_up);
+
#endif
Modified: trunk/blender/source/blender/blenkernel/intern/sca.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sca.c 2010-07-08 22:07:34 UTC (rev 30135)
+++ trunk/blender/source/blender/blenkernel/intern/sca.c 2010-07-09 00:14:46 UTC (rev 30136)
@@ -683,3 +683,127 @@
act= act->next;
}
}
+
+/* ******************** INTERFACE ******************* */
+void sca_move_sensor(bSensor *sens_to_move, Object *ob, int *move_up)
+{
+ bSensor *sens, *tmp;
+
+ int val;
+ val = move_up ? 1:2;
+
+ /* make sure this sensor belongs to this object */
+ sens= ob->sensors.first;
+ while(sens) {
+ if(sens == sens_to_move) break;
+ sens= sens->next;
+ }
+ if(!sens) return;
+
+ /* move up */
+ if( val==1 && sens->prev) {
+ for (tmp=sens->prev; tmp; tmp=tmp->prev) {
+ if (tmp->flag & SENS_VISIBLE)
+ break;
+ }
+ if (tmp) {
+ BLI_remlink(&ob->sensors, sens);
+ BLI_insertlinkbefore(&ob->sensors, tmp, sens);
+ }
+ }
+ /* move down */
+ else if( val==2 && sens->next) {
+ for (tmp=sens->next; tmp; tmp=tmp->next) {
+ if (tmp->flag & SENS_VISIBLE)
+ break;
+ }
+ if (tmp) {
+ BLI_remlink(&ob->sensors, sens);
+ BLI_insertlink(&ob->sensors, tmp, sens);
+ }
+ }
+}
+
+void sca_move_controller(bController *cont_to_move, Object *ob, int move_up)
+{
+ bController *cont, *tmp;
+
+ int val;
+ val = move_up ? 1:2;
+
+ /* make sure this controller belongs to this object */
+ cont= ob->controllers.first;
+ while(cont) {
+ if(cont == cont_to_move) break;
+ cont= cont->next;
+ }
+ if(!cont) return;
+
+ /* move up */
+ if( val==1 && cont->prev) {
+ /* locate the controller that has the same state mask but is earlier in the list */
+ tmp = cont->prev;
+ while(tmp) {
+ if(tmp->state_mask & cont->state_mask)
+ break;
+ tmp = tmp->prev;
+ }
+ if (tmp) {
+ BLI_remlink(&ob->controllers, cont);
+ BLI_insertlinkbefore(&ob->controllers, tmp, cont);
+ }
+ }
+
+ /* move down */
+ else if( val==2 && cont->next) {
+ tmp = cont->next;
+ while(tmp) {
+ if(tmp->state_mask & cont->state_mask)
+ break;
+ tmp = tmp->next;
+ }
+ BLI_remlink(&ob->controllers, cont);
+ BLI_insertlink(&ob->controllers, tmp, cont);
+ }
+}
+
+void sca_move_actuator(bActuator *act_to_move, Object *ob, int move_up)
+{
+ bActuator *act, *tmp;
+ int val;
+
+ val = move_up ? 1:2;
+
+ /* make sure this actuator belongs to this object */
+ act= ob->actuators.first;
+ while(act) {
+ if(act == act_to_move) break;
+ act= act->next;
+ }
+ if(!act) return;
+
+ /* move up */
+ if( val==1 && act->prev) {
+ /* locate the first visible actuators before this one */
+ for (tmp = act->prev; tmp; tmp=tmp->prev) {
+ if (tmp->flag & ACT_VISIBLE)
+ break;
+ }
+ if (tmp) {
+ BLI_remlink(&ob->actuators, act);
+ BLI_insertlinkbefore(&ob->actuators, tmp, act);
+ }
+ }
+ /* move down */
+ else if( val==2 && act->next) {
+ /* locate the first visible actuators after this one */
+ for (tmp=act->next; tmp; tmp=tmp->next) {
+ if (tmp->flag & ACT_VISIBLE)
+ break;
+ }
+ if (tmp) {
+ BLI_remlink(&ob->actuators, act);
+ BLI_insertlink(&ob->actuators, tmp, act);
+ }
+ }
+}
Modified: trunk/blender/source/blender/editors/space_logic/logic_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_ops.c 2010-07-08 22:07:34 UTC (rev 30135)
+++ trunk/blender/source/blender/editors/space_logic/logic_ops.c 2010-07-09 00:14:46 UTC (rev 30136)
@@ -211,6 +211,16 @@
return act;
}
+static int logicbricks_move_property_get(wmOperator *op)
+{
+ int type = RNA_enum_get(op->ptr, "direction");
+
+ if (type == 1)
+ return TRUE;
+ else
+ return FALSE;
+}
+
/* ************* Add/Remove Sensor Operator ************* */
static int sensor_remove_exec(bContext *C, wmOperator *op)
@@ -530,12 +540,158 @@
RNA_def_string(ot->srna, "object", "", 32, "Object", "Name of the Object to add the Actuator to");
}
+/* ************* Move Logic Bricks Operator ************* */
+static EnumPropertyItem logicbricks_move_direction[] ={
+ {1, "UP", 0, "Move Up", ""},
+ {2, "DOWN", 0, "Move Down", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+
+static int sensor_move_exec(bContext *C, wmOperator *op)
+{
+ Object *ob=NULL;
+ bSensor *sens= edit_sensor_property_get(C, op, &ob);
+ int move_up= logicbricks_move_property_get(op);
+
+ if (!sens)
+ return OPERATOR_CANCELLED;
+
+ sca_move_sensor(sens, ob, move_up);
+
+ WM_event_add_notifier(C, NC_LOGIC, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static int sensor_move_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ if (edit_sensor_invoke_properties(C, op)) {
+ return sensor_move_exec(C, op);
+ }
+ else
+ return OPERATOR_CANCELLED;
+}
+
+void LOGIC_OT_sensor_move(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Move Sensor";
+ ot->description = "Move Densor";
+ ot->idname= "LOGIC_OT_sensor_move";
+
+ /* api callbacks */
+ ot->invoke= sensor_move_invoke;
+ ot->exec= sensor_move_exec;
+ ot->poll= edit_sensor_poll;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ edit_sensor_properties(ot);
+ RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
+}
+
+static int controller_move_exec(bContext *C, wmOperator *op)
+{
+ Object *ob=NULL;
+ bController *cont= edit_controller_property_get(C, op, &ob);
+ int move_up= logicbricks_move_property_get(op);
+
+ if (!cont)
+ return OPERATOR_CANCELLED;
+
+ sca_move_controller(cont, ob, move_up);
+
+ WM_event_add_notifier(C, NC_LOGIC, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static int controller_move_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ if (edit_controller_invoke_properties(C, op)) {
+ return controller_move_exec(C, op);
+ }
+ else
+ return OPERATOR_CANCELLED;
+}
+
+void LOGIC_OT_controller_move(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Move Controller";
+ ot->description = "Move Controller";
+ ot->idname= "LOGIC_OT_controller_move";
+
+ /* api callbacks */
+ ot->invoke= controller_move_invoke;
+ ot->exec= controller_move_exec;
+ ot->poll= edit_controller_poll;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ edit_controller_properties(ot);
+ RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
+}
+
+static int actuator_move_exec(bContext *C, wmOperator *op)
+{
+ Object *ob=NULL;
+ bActuator *act = edit_actuator_property_get(C, op, &ob);
+ int move_up= logicbricks_move_property_get(op);
+
+ if (!act)
+ return OPERATOR_CANCELLED;
+
+ sca_move_actuator(act, ob, move_up);
+
+ WM_event_add_notifier(C, NC_LOGIC, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static int actuator_move_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ if (edit_actuator_invoke_properties(C, op)) {
+ return actuator_move_exec(C, op);
+ }
+ else
+ return OPERATOR_CANCELLED;
+}
+
+void LOGIC_OT_actuator_move(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Move Actuator";
+ ot->description = "Move Actuator";
+ ot->idname= "LOGIC_OT_actuator_move";
+
+ /* api callbacks */
+ ot->invoke= actuator_move_invoke;
+ ot->exec= actuator_move_exec;
+ ot->poll= edit_actuator_poll;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ edit_actuator_properties(ot);
+ RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
+}
+
+
void ED_operatortypes_logic(void)
{
WM_operatortype_append(LOGIC_OT_sensor_remove);
WM_operatortype_append(LOGIC_OT_sensor_add);
+ WM_operatortype_append(LOGIC_OT_sensor_move);
WM_operatortype_append(LOGIC_OT_controller_remove);
WM_operatortype_append(LOGIC_OT_controller_add);
+ WM_operatortype_append(LOGIC_OT_controller_move);
WM_operatortype_append(LOGIC_OT_actuator_remove);
WM_operatortype_append(LOGIC_OT_actuator_add);
+ WM_operatortype_append(LOGIC_OT_actuator_move);
}
Modified: trunk/blender/source/blender/editors/space_logic/logic_window.c
===================================================================
--- trunk/blender/source/blender/editors/space_logic/logic_window.c 2010-07-08 22:07:34 UTC (rev 30135)
+++ trunk/blender/source/blender/editors/space_logic/logic_window.c 2010-07-09 00:14:46 UTC (rev 30136)
@@ -194,8 +194,9 @@
}
-static void sca_move_sensor(bContext *C, void *datav, void *move_up)
+static void old_sca_move_sensor(bContext *C, void *datav, void *move_up)
{
+ /* deprecated, no longer using it (moved to sca.c) */
Scene *scene= CTX_data_scene(C);
bSensor *sens_to_delete= datav;
int val;
@@ -246,8 +247,9 @@
}
}
-static void sca_move_controller(bContext *C, void *datav, void *move_up)
+static void old_sca_move_controller(bContext *C, void *datav, void *move_up)
{
+ /* deprecated, no longer using it (moved to sca.c) */
Scene *scene= CTX_data_scene(C);
bController *controller_to_del= datav;
int val;
@@ -301,8 +303,9 @@
}
}
-static void sca_move_actuator(bContext *C, void *datav, void *move_up)
+static void old_sca_move_actuator(bContext *C, void *datav, void *move_up)
{
+ /* deprecated, no longer using it (moved to sca.c) */
Scene *scene= CTX_data_scene(C);
bActuator *actuator_to_move= datav;
int val;
@@ -3188,6 +3191,11 @@
&& RNA_boolean_get(ptr, "expanded")) || RNA_boolean_get(ptr, "pinned")));
uiItemR(subrow, ptr, "pinned", UI_ITEM_R_NO_BG, "", 0);
+ if(RNA_boolean_get(ptr, "expanded")==0) {
+ uiItemEnumO(row, "LOGIC_OT_sensor_move", "", ICON_TRIA_UP, "direction", 1); // up
+ uiItemEnumO(row, "LOGIC_OT_sensor_move", "", ICON_TRIA_DOWN, "direction", 2); // down
+ }
+
uiItemO(row, "", ICON_X, "LOGIC_OT_sensor_remove");
}
@@ -3527,6 +3535,11 @@
uiItemL(row, name, 0);
uiItemR(row, ptr, "priority", 0, "", 0);
+
+ if(RNA_boolean_get(ptr, "expanded")==0) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list