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 ;)
This commit is contained in:
@@ -67,5 +67,9 @@ void set_sca_new_poins_ob(struct Object *ob);
|
||||
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
|
||||
|
||||
|
||||
@@ -683,3 +683,127 @@ void sca_remove_ob_poin(Object *obt, Object *ob)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +211,16 @@ static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object
|
||||
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 @@ void LOGIC_OT_actuator_add(wmOperatorType *ot)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -194,8 +194,9 @@ static void make_unique_prop_names_cb(bContext *C, void *strv, void *redraw_view
|
||||
}
|
||||
|
||||
|
||||
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_sensor(bContext *C, void *datav, void *move_up)
|
||||
}
|
||||
}
|
||||
|
||||
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_controller(bContext *C, void *datav, void *move_up)
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *lo
|
||||
&& 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 @@ static void draw_controller_header(uiLayout *layout, PointerRNA *ptr)
|
||||
uiItemL(row, name, 0);
|
||||
|
||||
uiItemR(row, ptr, "priority", 0, "", 0);
|
||||
|
||||
if(RNA_boolean_get(ptr, "expanded")==0) {
|
||||
uiItemEnumO(row, "LOGIC_OT_controller_move", "", ICON_TRIA_UP, "direction", 1); // up
|
||||
uiItemEnumO(row, "LOGIC_OT_controller_move", "", ICON_TRIA_DOWN, "direction", 2); // down
|
||||
}
|
||||
uiItemO(row, "", ICON_X, "LOGIC_OT_controller_remove");
|
||||
}
|
||||
|
||||
@@ -3606,6 +3619,10 @@ static void draw_actuator_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *
|
||||
&& 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_actuator_move", "", ICON_TRIA_UP, "direction", 1); // up
|
||||
uiItemEnumO(row, "LOGIC_OT_actuator_move", "", ICON_TRIA_DOWN, "direction", 2); // down
|
||||
}
|
||||
uiItemO(row, "", ICON_X, "LOGIC_OT_actuator_remove");
|
||||
}
|
||||
|
||||
@@ -4825,15 +4842,15 @@ void logic_buttons(bContext *C, ARegion *ar)
|
||||
cpack(0x999999);
|
||||
glRecti(xco+22, yco, xco+width-22,yco+19);
|
||||
but= uiDefBut(block, LABEL, 0, controller_name(cont->type), (short)(xco+22), yco, 70, UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller type");
|
||||
//uiButSetFunc(but, sca_move_controller, cont, NULL);
|
||||
//uiButSetFunc(but, old_sca_move_controller, cont, NULL);
|
||||
but= uiDefBut(block, LABEL, 0, cont->name,(short)(xco+92), yco,(short)(width-158), UI_UNIT_Y, cont, 0, 0, 0, 0, "Controller name");
|
||||
//uiButSetFunc(but, sca_move_controller, cont, NULL);
|
||||
//uiButSetFunc(but, old_sca_move_controller, cont, NULL);
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(110+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
|
||||
uiButSetFunc(but, sca_move_controller, cont, (void *)TRUE);
|
||||
uiButSetFunc(but, old_sca_move_controller, cont, (void *)TRUE);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(88+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
|
||||
uiButSetFunc(but, sca_move_controller, cont, (void *)FALSE);
|
||||
uiButSetFunc(but, old_sca_move_controller, cont, (void *)FALSE);
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
ycoo= yco;
|
||||
@@ -4917,15 +4934,15 @@ void logic_buttons(bContext *C, ARegion *ar)
|
||||
set_col_sensor(sens->type, 1);
|
||||
glRecti(xco+22, yco, xco+width-22,yco+19);
|
||||
but= uiDefBut(block, LABEL, 0, sensor_name(sens->type), (short)(xco+22), yco, 80, UI_UNIT_Y, sens, 0, 0, 0, 0, "");
|
||||
//uiButSetFunc(but, sca_move_sensor, sens, NULL);
|
||||
//uiButSetFunc(but, old_sca_move_sensor, sens, NULL);
|
||||
but= uiDefBut(block, LABEL, 0, sens->name, (short)(xco+102), yco, (short)(width-(pin?146:124)), UI_UNIT_Y, sens, 0, 31, 0, 0, "");
|
||||
//uiButSetFunc(but, sca_move_sensor, sens, NULL);
|
||||
//uiButSetFunc(but, old_sca_move_sensor, sens, NULL);
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
|
||||
uiButSetFunc(but, sca_move_sensor, sens, (void *)TRUE);
|
||||
uiButSetFunc(but, old_sca_move_sensor, sens, (void *)TRUE);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
|
||||
uiButSetFunc(but, sca_move_sensor, sens, (void *)FALSE);
|
||||
uiButSetFunc(but, old_sca_move_sensor, sens, (void *)FALSE);
|
||||
uiBlockEndAlign(block);
|
||||
}
|
||||
|
||||
@@ -4995,15 +5012,15 @@ void logic_buttons(bContext *C, ARegion *ar)
|
||||
set_col_actuator(act->type, 1);
|
||||
glRecti((short)(xco+22), yco, (short)(xco+width-22),(short)(yco+19));
|
||||
but= uiDefBut(block, LABEL, 0, actuator_name(act->type), (short)(xco+22), yco, 90, UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator type");
|
||||
// uiButSetFunc(but, sca_move_actuator, act, NULL);
|
||||
// uiButSetFunc(but, old_sca_move_actuator, act, NULL);
|
||||
but= uiDefBut(block, LABEL, 0, act->name, (short)(xco+112), yco, (short)(width-(pin?156:134)), UI_UNIT_Y, act, 0, 0, 0, 0, "Actuator name");
|
||||
// uiButSetFunc(but, sca_move_actuator, act, NULL);
|
||||
// uiButSetFunc(but, old_sca_move_actuator, act, NULL);
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_UP, (short)(xco+width-(66+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick up");
|
||||
uiButSetFunc(but, sca_move_actuator, act, (void *)TRUE);
|
||||
uiButSetFunc(but, old_sca_move_actuator, act, (void *)TRUE);
|
||||
but= uiDefIconBut(block, BUT, B_REDR, ICON_TRIA_DOWN, (short)(xco+width-(44+5)), yco, 22, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Move this logic brick down");
|
||||
uiButSetFunc(but, sca_move_actuator, act, (void *)FALSE);
|
||||
uiButSetFunc(but, old_sca_move_actuator, act, (void *)FALSE);
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
ycoo= yco;
|
||||
|
||||
Reference in New Issue
Block a user