forked from bartvdbraak/blender
Logic Editor: Buttons for moving game properties up/down
D1163 by @panzergame, with minor edits by me (@Severin)
This commit is contained in:
parent
b35743d39f
commit
a8adeeb6fb
@ -71,6 +71,13 @@ class LOGIC_PT_properties(Panel):
|
||||
row.prop(prop, "type", text="")
|
||||
row.prop(prop, "value", text="")
|
||||
row.prop(prop, "show_debug", text="", toggle=True, icon='INFO')
|
||||
sub = row.row(align=True)
|
||||
props = sub.operator("object.game_property_move", text="", icon='TRIA_UP')
|
||||
props.index = i
|
||||
props.direction = "UP"
|
||||
props = sub.operator("object.game_property_move", text="", icon='TRIA_DOWN')
|
||||
props.index = i
|
||||
props.direction = "DOWN"
|
||||
row.operator("object.game_property_remove", text="", icon='X', emboss=False).index = i
|
||||
|
||||
|
||||
|
@ -1769,6 +1769,70 @@ void OBJECT_OT_game_property_remove(wmOperatorType *ot)
|
||||
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
|
||||
}
|
||||
|
||||
#define GAME_PROPERTY_MOVE_UP 1
|
||||
#define GAME_PROPERTY_MOVE_DOWN -1
|
||||
|
||||
static int game_property_move(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
bProperty *prop;
|
||||
bProperty *otherprop = NULL;
|
||||
const int index = RNA_int_get(op->ptr, "index");
|
||||
const int dir = RNA_int_get(op->ptr, "direction");
|
||||
|
||||
if (ob == NULL)
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
prop = BLI_findlink(&ob->prop, index);
|
||||
if (dir == GAME_PROPERTY_MOVE_UP) {
|
||||
otherprop = prop->prev;
|
||||
}
|
||||
else if (dir == GAME_PROPERTY_MOVE_DOWN) {
|
||||
otherprop = prop->next;
|
||||
}
|
||||
else {
|
||||
BLI_assert(0);
|
||||
}
|
||||
|
||||
if (prop && otherprop) {
|
||||
BLI_listbase_swaplinks(&ob->prop, prop, otherprop);
|
||||
|
||||
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
else {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
void OBJECT_OT_game_property_move(wmOperatorType *ot)
|
||||
{
|
||||
static EnumPropertyItem direction_property_move[] = {
|
||||
{GAME_PROPERTY_MOVE_UP, "UP", 0, "Up", ""},
|
||||
{GAME_PROPERTY_MOVE_DOWN, "DOWN", 0, "Down", ""},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
/* identifiers */
|
||||
ot->name = "Move Game Property";
|
||||
ot->description = "Move game property";
|
||||
ot->idname = "OBJECT_OT_game_property_move";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = game_property_move;
|
||||
ot->poll = ED_operator_object_active_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to move", 0, INT_MAX);
|
||||
RNA_def_enum(ot->srna, "direction", direction_property_move, 0, "Direction",
|
||||
"Direction for moving the property");
|
||||
}
|
||||
|
||||
#undef GAME_PROPERTY_MOVE_UP
|
||||
#undef GAME_PROPERTY_MOVE_DOWN
|
||||
|
||||
#define COPY_PROPERTIES_REPLACE 1
|
||||
#define COPY_PROPERTIES_MERGE 2
|
||||
#define COPY_PROPERTIES_COPY 3
|
||||
|
@ -94,6 +94,7 @@ void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_property_copy(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_property_clear(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_property_move(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_logic_bricks_copy(struct wmOperatorType *ot);
|
||||
void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot);
|
||||
|
||||
|
@ -206,6 +206,7 @@ void ED_operatortypes_object(void)
|
||||
WM_operatortype_append(OBJECT_OT_game_property_remove);
|
||||
WM_operatortype_append(OBJECT_OT_game_property_copy);
|
||||
WM_operatortype_append(OBJECT_OT_game_property_clear);
|
||||
WM_operatortype_append(OBJECT_OT_game_property_move);
|
||||
WM_operatortype_append(OBJECT_OT_logic_bricks_copy);
|
||||
WM_operatortype_append(OBJECT_OT_game_physics_copy);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user